mirror of
https://github.com/status-im/nimbus-eth1.git
synced 2025-01-27 20:45:48 +00:00
Fix JSON encoding for NodeId, no leading zeroes dropped (#2730)
Portal JSON-RPC API specifications dictate that the NodeId must be the 32 byte identifier. We had leading zeroes being dropped in our implementation.
This commit is contained in:
parent
0ebab78136
commit
6e114dc950
@ -100,13 +100,13 @@ proc readValue*(
|
|||||||
r.raiseUnexpectedValue("Invalid ENR")
|
r.raiseUnexpectedValue("Invalid ENR")
|
||||||
|
|
||||||
proc writeValue*(w: var JsonWriter[JrpcConv], v: NodeId) {.gcsafe, raises: [IOError].} =
|
proc writeValue*(w: var JsonWriter[JrpcConv], v: NodeId) {.gcsafe, raises: [IOError].} =
|
||||||
w.writeValue("0x" & v.toHex())
|
w.writeValue(v.toBytesBE().to0xHex())
|
||||||
|
|
||||||
proc writeValue*(
|
proc writeValue*(
|
||||||
w: var JsonWriter[JrpcConv], v: Opt[NodeId]
|
w: var JsonWriter[JrpcConv], v: Opt[NodeId]
|
||||||
) {.gcsafe, raises: [IOError].} =
|
) {.gcsafe, raises: [IOError].} =
|
||||||
if v.isSome():
|
if v.isSome():
|
||||||
w.writeValue("0x" & v.get().toHex())
|
w.writeValue(v.get())
|
||||||
else:
|
else:
|
||||||
w.writeValue("0x")
|
w.writeValue("0x")
|
||||||
|
|
||||||
@ -139,7 +139,8 @@ proc writeValue*(
|
|||||||
) {.gcsafe, raises: [IOError].} =
|
) {.gcsafe, raises: [IOError].} =
|
||||||
w.beginRecord()
|
w.beginRecord()
|
||||||
w.writeField("enrSeq", v.enrSeq)
|
w.writeField("enrSeq", v.enrSeq)
|
||||||
w.writeField("dataRadius", "0x" & v.dataRadius.toHex)
|
# Portal json-rpc specifications allows for dropping leading zeroes.
|
||||||
|
w.writeField("dataRadius", "0x" & v.dataRadius.toHex())
|
||||||
w.endRecord()
|
w.endRecord()
|
||||||
|
|
||||||
proc readValue*(
|
proc readValue*(
|
||||||
|
Loading…
x
Reference in New Issue
Block a user