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:
Kim De Mey 2024-10-11 16:43:06 +02:00 committed by GitHub
parent 0ebab78136
commit 6e114dc950
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194

View File

@ -100,13 +100,13 @@ proc readValue*(
r.raiseUnexpectedValue("Invalid ENR")
proc writeValue*(w: var JsonWriter[JrpcConv], v: NodeId) {.gcsafe, raises: [IOError].} =
w.writeValue("0x" & v.toHex())
w.writeValue(v.toBytesBE().to0xHex())
proc writeValue*(
w: var JsonWriter[JrpcConv], v: Opt[NodeId]
) {.gcsafe, raises: [IOError].} =
if v.isSome():
w.writeValue("0x" & v.get().toHex())
w.writeValue(v.get())
else:
w.writeValue("0x")
@ -139,7 +139,8 @@ proc writeValue*(
) {.gcsafe, raises: [IOError].} =
w.beginRecord()
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()
proc readValue*(