Skip to content

Commit

Permalink
Resolve ambiguous call (#181)
Browse files Browse the repository at this point in the history
* Resolve ambiguous call

* uint64 encoding only for JrpcConv
  • Loading branch information
jangko authored Nov 26, 2024
1 parent 2a8bebb commit c8f36f5
Showing 1 changed file with 16 additions and 17 deletions.
33 changes: 16 additions & 17 deletions web3/conversions.nim
Original file line number Diff line number Diff line change
Expand Up @@ -203,13 +203,6 @@ proc writeValue*[F: CommonJsonFlavors](w: var JsonWriter[F], v: RlpEncodedBytes)
{.gcsafe, raises: [IOError].} =
writeHexValue w, distinctBase(v)

proc writeValue*[F: CommonJsonFlavors](
w: var JsonWriter[F], v: uint64
) {.gcsafe, raises: [IOError].} =
w.stream.write "\"0x"
w.stream.toHex(v)
w.stream.write "\""

proc writeValue*[F: CommonJsonFlavors](
w: var JsonWriter[F], v: Quantity
) {.gcsafe, raises: [IOError].} =
Expand Down Expand Up @@ -260,29 +253,21 @@ proc readValue*[F: CommonJsonFlavors](r: var JsonReader[F], val: var RlpEncodedB
# skip empty hex
val = RlpEncodedBytes hexToSeqByte(hexStr)

proc readValue*[F: CommonJsonFlavors](r: var JsonReader[F], val: var uint64)
{.gcsafe, raises: [IOError, JsonReaderError].} =
let hexStr = r.parseString()
if hexStr.invalidQuantityPrefix:
r.raiseUnexpectedValue("Uint64 value has invalid leading 0")
wrapValueError:
val = fromHex[uint64](hexStr)

proc readValue*[F: CommonJsonFlavors](r: var JsonReader[F], val: var Quantity)
{.gcsafe, raises: [IOError, JsonReaderError].} =
let hexStr = r.parseString()
if hexStr.invalidQuantityPrefix:
r.raiseUnexpectedValue("Quantity value has invalid leading 0")
wrapValueError:
val = Quantity fromHex[uint64](hexStr)
val = Quantity strutils.fromHex[uint64](hexStr)

proc readValue*[F: CommonJsonFlavors](r: var JsonReader[F], val: var ChainId)
{.gcsafe, raises: [IOError, JsonReaderError].} =
let hexStr = r.parseString()
if hexStr.invalidQuantityPrefix:
r.raiseUnexpectedValue("ChainId value has invalid leading 0")
wrapValueError:
val = ChainId fromHex[uint64](hexStr)
val = ChainId strutils.fromHex[uint64](hexStr)

proc readValue*[F: CommonJsonFlavors](r: var JsonReader[F], val: var PayloadExecutionStatus)
{.gcsafe, raises: [IOError, JsonReaderError].} =
Expand All @@ -305,6 +290,20 @@ proc writeValue*[F: CommonJsonFlavors](w: var JsonWriter[F], v: PayloadExecution
# Exclusive to JrpcConv
#------------------------------------------------------------------------------

proc writeValue*(w: var JsonWriter[JrpcConv], v: uint64)
{.gcsafe, raises: [IOError].} =
w.stream.write "\"0x"
w.stream.toHex(v)
w.stream.write "\""

proc readValue*(r: var JsonReader[JrpcConv], val: var uint64)
{.gcsafe, raises: [IOError, JsonReaderError].} =
let hexStr = r.parseString()
if hexStr.invalidQuantityPrefix:
r.raiseUnexpectedValue("Uint64 value has invalid leading 0")
wrapValueError:
val = strutils.fromHex[uint64](hexStr)

proc writeValue*(w: var JsonWriter[JrpcConv], val: UInt256)
{.gcsafe, raises: [IOError].} =
w.writeValue("0x" & val.toHex)
Expand Down

0 comments on commit c8f36f5

Please sign in to comment.