Fixes json formatting for NodeId (#614)

This commit is contained in:
Ben Bierens 2023-11-15 14:29:17 +01:00 committed by GitHub
parent 4d50ecf504
commit 40d7714a67
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
1 changed files with 13 additions and 2 deletions

View File

@ -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