From 40d7714a6781f55542c44c1a72a755d81eed2a08 Mon Sep 17 00:00:00 2001 From: Ben Bierens <39762930+benbierens@users.noreply.github.com> Date: Wed, 15 Nov 2023 14:29:17 +0100 Subject: [PATCH] Fixes json formatting for NodeId (#614) --- codex/rest/json.nim | 15 +++++++++++++-- 1 file changed, 13 insertions(+), 2 deletions(-) diff --git a/codex/rest/json.nim b/codex/rest/json.nim index 018ab2e1..da26af0a 100644 --- a/codex/rest/json.nim +++ b/codex/rest/json.nim @@ -39,7 +39,7 @@ type manifest* {.serialize.}: Manifest RestNode* = object - nodeId* {.serialize.}: NodeId + nodeId* {.serialize.}: RestNodeId peerId* {.serialize.}: PeerId record* {.serialize.}: SignedPeerRecord address* {.serialize.}: Option[dn.Address] @@ -54,6 +54,9 @@ type seqNo* {.serialize.}: uint64 addresses* {.serialize.}: seq[AddressInfo] + RestNodeId* = object + id*: NodeId + proc init*(_: type RestContent, cid: Cid, manifest: Manifest): RestContent = RestContent( cid: cid, @@ -62,7 +65,7 @@ proc init*(_: type RestContent, cid: Cid, manifest: Manifest): RestContent = proc init*(_: type RestNode, node: dn.Node): RestNode = RestNode( - nodeId: node.id, + nodeId: RestNodeId.init(node.id), peerId: node.record.data.peerId, record: node.record, address: node.address, @@ -87,6 +90,11 @@ proc init*(_: type RestPeerRecord, peerRecord: PeerRecord): RestPeerRecord = addresses: peerRecord.addresses ) +proc init*(_: type RestNodeId, id: NodeId): RestNodeId = + RestNodeId( + id: id + ) + func `%`*(obj: StorageRequest | Slot): JsonNode = let jsonObj = newJObject() for k, v in obj.fieldPairs: jsonObj[k] = %v @@ -100,6 +108,9 @@ func `%`*(obj: Cid): JsonNode = func `%`*(obj: PeerId): JsonNode = % $obj +func `%`*(obj: RestNodeId): JsonNode = + % $obj.id + func `%`*(obj: SignedPeerRecord): JsonNode = % $obj