mirror of
https://github.com/codex-storage/nim-codex.git
synced 2025-01-09 12:35:51 +00:00
f567f4ec15
* 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
35 lines
786 B
Nim
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
|