2021-03-26 06:52:01 +00:00
|
|
|
# beacon_chain
|
2024-01-06 14:26:56 +00:00
|
|
|
# Copyright (c) 2018-2024 Status Research & Development GmbH
|
2021-03-26 06:52:01 +00:00
|
|
|
# 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.
|
|
|
|
|
2023-01-20 14:14:37 +00:00
|
|
|
{.push raises: [].}
|
2021-03-26 06:52:01 +00:00
|
|
|
|
|
|
|
import libp2p/[peerid, multiaddress], json_serialization
|
2019-06-24 15:13:48 +00:00
|
|
|
export json_serialization
|
|
|
|
|
2023-08-19 15:11:56 +00:00
|
|
|
proc writeValue*(
|
|
|
|
writer: var JsonWriter, value: PeerId) {.raises: [IOError].} =
|
2020-09-06 08:39:25 +00:00
|
|
|
writer.writeValue $value
|
2019-06-24 15:13:48 +00:00
|
|
|
|
2022-04-08 16:22:49 +00:00
|
|
|
proc readValue*(reader: var JsonReader, value: var PeerId) {.
|
2023-08-25 09:29:07 +00:00
|
|
|
raises: [IOError, SerializationError].} =
|
2022-04-08 16:22:49 +00:00
|
|
|
let res = PeerId.init reader.readValue(string)
|
2020-07-01 11:41:40 +00:00
|
|
|
if res.isOk:
|
|
|
|
value = res.get()
|
|
|
|
else:
|
|
|
|
raiseUnexpectedValue(reader, $res.error)
|
2019-06-24 15:13:48 +00:00
|
|
|
|
2023-08-19 15:11:56 +00:00
|
|
|
proc writeValue*(
|
|
|
|
writer: var JsonWriter, value: MultiAddress) {.raises: [IOError].} =
|
2019-06-24 15:13:48 +00:00
|
|
|
writer.writeValue $value
|
|
|
|
|
2021-03-26 06:52:01 +00:00
|
|
|
proc readValue*(reader: var JsonReader, value: var MultiAddress) {.
|
2023-08-25 09:29:07 +00:00
|
|
|
raises: [IOError, SerializationError].} =
|
2020-07-01 11:41:40 +00:00
|
|
|
let res = MultiAddress.init reader.readValue(string)
|
|
|
|
if res.isOk:
|
|
|
|
value = res.value
|
2020-06-05 15:08:50 +00:00
|
|
|
else:
|
2020-07-01 11:41:40 +00:00
|
|
|
raiseUnexpectedValue(reader, $res.error)
|