nimbus-eth2/beacon_chain/networking/libp2p_json_serialization.nim
Jacek Sieka f70ff38b53
enable styleCheck:usages (#3573)
Some upstream repos still need fixes, but this gets us close enough that
style hints can be enabled by default.

In general, "canonical" spellings are preferred even if they violate
nep-1 - this applies in particular to spec-related stuff like
`genesis_validators_root` which appears throughout the codebase.
2022-04-08 16:22:49 +00:00

36 lines
1.3 KiB
Nim

# beacon_chain
# Copyright (c) 2018-2021 Status Research & Development GmbH
# Licensed and distributed under either of
# * MIT license (license terms in the root directory or at https://opensource.org/licenses/MIT).
# * Apache v2 license (license terms in the root directory or at https://www.apache.org/licenses/LICENSE-2.0).
# at your option. This file may not be copied, modified, or distributed except according to those terms.
{.push raises: [Defect].}
import libp2p/[peerid, multiaddress], json_serialization
export json_serialization
proc writeValue*(writer: var JsonWriter, value: PeerId) {.
raises: [Defect, IOError].} =
writer.writeValue $value
proc readValue*(reader: var JsonReader, value: var PeerId) {.
raises: [Defect, IOError, SerializationError].} =
let res = PeerId.init reader.readValue(string)
if res.isOk:
value = res.get()
else:
raiseUnexpectedValue(reader, $res.error)
proc writeValue*(writer: var JsonWriter, value: MultiAddress) {.
raises: [Defect, IOError].} =
writer.writeValue $value
proc readValue*(reader: var JsonReader, value: var MultiAddress) {.
raises: [Defect, IOError, SerializationError].} =
let res = MultiAddress.init reader.readValue(string)
if res.isOk:
value = res.value
else:
raiseUnexpectedValue(reader, $res.error)