Fix block number request (#2470)

leading 0's not tolerated
This commit is contained in:
Jacek Sieka 2021-04-01 14:43:03 +02:00 committed by GitHub
parent 8f441588cd
commit e746cb09c2
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
1 changed files with 3 additions and 1 deletions

View File

@ -394,7 +394,9 @@ proc getBlockByHash*(p: Web3DataProviderRef, hash: BlockHash):
proc getBlockByNumber*(p: Web3DataProviderRef,
number: Eth1BlockNumber): Future[BlockObject] =
p.web3.provider.eth_getBlockByNumber("0x" & toHex(number), false)
let hexNumber = try: &"0x{number:X}" # No leading 0's!
except ValueError as exc: raiseAssert exc.msg # Never fails
p.web3.provider.eth_getBlockByNumber(hexNumber, false)
template readJsonField(j: JsonNode, fieldName: string, ValueType: type): untyped =
var res: ValueType