From 34178713700fc2ee1c9cc13a64c1a920458f7b5d Mon Sep 17 00:00:00 2001 From: cheatfate Date: Mon, 12 Apr 2021 19:05:13 +0300 Subject: [PATCH] Address #2489. --- beacon_chain/rpc/eth2_json_rest_serialization.nim | 13 +++++++++++++ 1 file changed, 13 insertions(+) diff --git a/beacon_chain/rpc/eth2_json_rest_serialization.nim b/beacon_chain/rpc/eth2_json_rest_serialization.nim index ab307b537..ba415b2fc 100644 --- a/beacon_chain/rpc/eth2_json_rest_serialization.nim +++ b/beacon_chain/rpc/eth2_json_rest_serialization.nim @@ -339,3 +339,16 @@ proc decodeBody*[T](t: typedesc[T], except CatchableError as exc: return err("Unexpected deserialization error") ok(data) + +RestJson.useCustomSerialization(BeaconState.justification_bits): + read: + let s = reader.readValue(string) + if s.len != 4: + raiseUnexpectedValue(reader, "A string with 4 characters expected") + try: + hexToByteArray(s, 1)[0] + except ValueError: + raiseUnexpectedValue(reader, + "The `justification_bits` value must be a hex string") + write: + writer.writeValue "0x" & toHex([value])