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])