Skip to content

Commit

Permalink
Fix RtBlockIdentifier parser
Browse files Browse the repository at this point in the history
  • Loading branch information
jangko committed Jan 13, 2024
1 parent dffeb12 commit 744b4e2
Show file tree
Hide file tree
Showing 3 changed files with 17 additions and 1 deletion.
7 changes: 7 additions & 0 deletions tests/test_json_marshalling.nim
Original file line number Diff line number Diff line change
Expand Up @@ -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
8 changes: 7 additions & 1 deletion web3/conversions.nim
Original file line number Diff line number Diff line change
Expand Up @@ -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..<hex.len:
let x = hex[i]
if x notin HexDigits: return false
true

Expand Down
3 changes: 3 additions & 0 deletions web3/eth_api_types.nim
Original file line number Diff line number Diff line change
Expand Up @@ -271,3 +271,6 @@ proc `source=`*(c: var EthCall, a: Option[Address]) =

func source*(c: EthCall): Option[Address] =
c.`from`

template `==`*(a, b: RlpEncodedBytes): bool =
distinctBase(a) == distinctBase(b)

0 comments on commit 744b4e2

Please sign in to comment.