nim-codex/codex/utils/json.nim
Eric f567f4ec15
refactor: use serde for json de/serialization instead of utils/json (#704)
* json > nim-serde bump

Should wait until serde is integrated into nim-ethers before making these changes as there will be less import exceptions required.

* bump nim-serde

* change func to proc due to chronicles side effects

* import serde into utils/json, use as proxy

import nim-serde into utils/json and use utils/json as a proxy for serde functions, including overloading `%` and `fromJson` for application types.

* update tests to use serde

* bump serde to latest

* remove testjson -- no longer needed

* bump serde in nimble

* updates to reconcile rebase with master
2024-03-19 03:25:13 +00:00

35 lines
786 B
Nim

import std/options
import std/typetraits
from pkg/ethers import Address
from pkg/libp2p import Cid, PeerId, SignedPeerRecord, MultiAddress, AddressInfo, init, `$`
import pkg/contractabi
import pkg/codexdht/discv5/node as dn
import pkg/serde/json
import pkg/questionable/results
import ../errors
export json
proc fromJson*(
_: type Cid,
json: JsonNode
): ?!Cid =
expectJsonKind(Cid, JString, json)
Cid.init(json.str).mapFailure
func `%`*(cid: Cid): JsonNode = % $cid
func `%`*(obj: PeerId): JsonNode = % $obj
func `%`*(obj: SignedPeerRecord): JsonNode = % $obj
func `%`*(obj: dn.Address): JsonNode = % $obj
func `%`*(obj: AddressInfo): JsonNode = % $obj.address
func `%`*(obj: MultiAddress): JsonNode = % $obj
func `%`*(address: ethers.Address): JsonNode = % $address