From c8f36f59cb354196cfe117b6866e81d450c8cfd7 Mon Sep 17 00:00:00 2001 From: andri lim Date: Tue, 26 Nov 2024 14:04:43 +0700 Subject: [PATCH] Resolve ambiguous call (#181) * Resolve ambiguous call * uint64 encoding only for JrpcConv --- web3/conversions.nim | 33 ++++++++++++++++----------------- 1 file changed, 16 insertions(+), 17 deletions(-) diff --git a/web3/conversions.nim b/web3/conversions.nim index a472d1c..a349e24 100644 --- a/web3/conversions.nim +++ b/web3/conversions.nim @@ -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].} = @@ -260,21 +253,13 @@ 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].} = @@ -282,7 +267,7 @@ proc readValue*[F: CommonJsonFlavors](r: var JsonReader[F], val: var ChainId) 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].} = @@ -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)