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 manifest* {.serialize.}: Manifest
RestNode* = object RestNode* = object
nodeId* {.serialize.}: NodeId nodeId* {.serialize.}: RestNodeId
peerId* {.serialize.}: PeerId peerId* {.serialize.}: PeerId
record* {.serialize.}: SignedPeerRecord record* {.serialize.}: SignedPeerRecord
address* {.serialize.}: Option[dn.Address] address* {.serialize.}: Option[dn.Address]
@ -54,6 +54,9 @@ type
seqNo* {.serialize.}: uint64 seqNo* {.serialize.}: uint64
addresses* {.serialize.}: seq[AddressInfo] addresses* {.serialize.}: seq[AddressInfo]
RestNodeId* = object
id*: NodeId
proc init*(_: type RestContent, cid: Cid, manifest: Manifest): RestContent = proc init*(_: type RestContent, cid: Cid, manifest: Manifest): RestContent =
RestContent( RestContent(
cid: cid, cid: cid,
@ -62,7 +65,7 @@ proc init*(_: type RestContent, cid: Cid, manifest: Manifest): RestContent =
proc init*(_: type RestNode, node: dn.Node): RestNode = proc init*(_: type RestNode, node: dn.Node): RestNode =
RestNode( RestNode(
nodeId: node.id, nodeId: RestNodeId.init(node.id),
peerId: node.record.data.peerId, peerId: node.record.data.peerId,
record: node.record, record: node.record,
address: node.address, address: node.address,
@ -87,6 +90,11 @@ proc init*(_: type RestPeerRecord, peerRecord: PeerRecord): RestPeerRecord =
addresses: peerRecord.addresses addresses: peerRecord.addresses
) )
proc init*(_: type RestNodeId, id: NodeId): RestNodeId =
RestNodeId(
id: id
)
func `%`*(obj: StorageRequest | Slot): JsonNode = func `%`*(obj: StorageRequest | Slot): JsonNode =
let jsonObj = newJObject() let jsonObj = newJObject()
for k, v in obj.fieldPairs: jsonObj[k] = %v for k, v in obj.fieldPairs: jsonObj[k] = %v
@ -100,6 +108,9 @@ func `%`*(obj: Cid): JsonNode =
func `%`*(obj: PeerId): JsonNode = func `%`*(obj: PeerId): JsonNode =
% $obj % $obj
func `%`*(obj: RestNodeId): JsonNode =
% $obj.id
func `%`*(obj: SignedPeerRecord): JsonNode = func `%`*(obj: SignedPeerRecord): JsonNode =
% $obj % $obj