mirror of
https://github.com/status-im/nimbus-eth1.git
synced 2025-02-23 17:28:27 +00:00
Add json converters for byte array and UInt256 types to hex string
This commit is contained in:
parent
ee15f4a995
commit
88ab097a61
@ -10,6 +10,8 @@
|
||||
## This module implements the Ethereum hexadecimal string formats for JSON
|
||||
## See: https://github.com/ethereum/wiki/wiki/JSON-RPC#hex-value-encoding
|
||||
|
||||
import eth_common/eth_types, stint, byteutils
|
||||
|
||||
type
|
||||
HexQuantityStr* = distinct string
|
||||
HexDataStr* = distinct string
|
||||
@ -135,6 +137,17 @@ proc `%`*(value: EthAddressStr): JsonNode =
|
||||
proc `%`*(value: EthHashStr): JsonNode =
|
||||
result = %(value.string)
|
||||
|
||||
# Overloads to support expected representation of hex data
|
||||
|
||||
proc `%`*(value: EthAddress): JsonNode =
|
||||
result = %("0x" & value.toHex)
|
||||
|
||||
proc `%`*(value: UInt256): JsonNode =
|
||||
result = %("0x" & value.toString)
|
||||
|
||||
proc `%`*(value: openArray[seq]): JsonNode =
|
||||
result = %("0x" & value.toHex)
|
||||
|
||||
proc fromJson*(n: JsonNode, argName: string, result: var HexQuantityStr) =
|
||||
# Note that '0x' is stripped after validation
|
||||
n.kind.expect(JString, argName)
|
||||
|
Loading…
x
Reference in New Issue
Block a user