From 744b4e2dc31f3fc4ffad774d42cf1b98003af227 Mon Sep 17 00:00:00 2001 From: jangko Date: Sat, 13 Jan 2024 19:03:42 +0700 Subject: [PATCH] Fix RtBlockIdentifier parser --- tests/test_json_marshalling.nim | 7 +++++++ web3/conversions.nim | 8 +++++++- web3/eth_api_types.nim | 3 +++ 3 files changed, 17 insertions(+), 1 deletion(-) diff --git a/tests/test_json_marshalling.nim b/tests/test_json_marshalling.nim index 68d98fb..d4145e9 100644 --- a/tests/test_json_marshalling.nim +++ b/tests/test_json_marshalling.nim @@ -187,3 +187,10 @@ suite "JSON-RPC Quantity": checkRandomObject(ExecutionPayload) checkRandomObject(PayloadAttributes) checkRandomObject(GetPayloadResponse) + + test "check blockId": + let a = RtBlockIdentifier(kind: bidNumber, number: 77.uint64) + let x = JrpcConv.encode(a) + let c = JrpcConv.decode(x, RtBlockIdentifier) + check c.kind == bidNumber + check c.number == 77 diff --git a/web3/conversions.nim b/web3/conversions.nim index 2a55770..5cf999b 100644 --- a/web3/conversions.nim +++ b/web3/conversions.nim @@ -150,7 +150,13 @@ template wrapValueError(body: untyped) = r.raiseUnexpectedValue(exc.msg) func valid(hex: string): bool = - for x in hex: + var start = 0 + if hex.len >= 2: + if hex[0] == '0' and hex[1] in {'x', 'X'}: + start = 2 + + for i in start..