Add blockByNumber to engine_client of simulator (#2902)
This commit is contained in:
parent
359eb6d974
commit
5a3bfe486f
|
@ -25,7 +25,7 @@ const
|
|||
defaultProtectedHeader = "eyJ0eXAiOiJKV1QiLCJhbGciOiJIUzI1NiJ9"
|
||||
|
||||
createRpcSigsFromNim(RpcClient):
|
||||
proc engine_getClientVersionV1(version: ClientVersionV1): ClientVersionV1
|
||||
proc engine_getClientVersionV1(version: ClientVersionV1): seq[ClientVersionV1]
|
||||
|
||||
func base64urlEncode(x: auto): string =
|
||||
base64.encode(x, safe = true).replace("=", "")
|
||||
|
|
|
@ -40,6 +40,8 @@ template wrapTry(body: untyped) =
|
|||
return err(e.msg)
|
||||
except JsonRpcError as ex:
|
||||
return err(ex.msg)
|
||||
except JsonReaderError as ex:
|
||||
return err(ex.formatMsg("rpc"))
|
||||
except CatchableError as ex:
|
||||
return err(ex.msg)
|
||||
|
||||
|
@ -455,6 +457,18 @@ proc latestBlock*(client: RpcClient): Result[Block, string] =
|
|||
)
|
||||
return ok(output)
|
||||
|
||||
proc blockByNumber*(client: RpcClient, number: uint64): Result[Block, string] =
|
||||
wrapTry:
|
||||
let res = waitFor client.eth_getBlockByNumber(blockId(number), true)
|
||||
if res.isNil:
|
||||
return err("failed to get block " & $number)
|
||||
let output = Block(
|
||||
header: toBlockHeader(res),
|
||||
transactions: toTransactions(res.transactions),
|
||||
withdrawals: res.withdrawals,
|
||||
)
|
||||
return ok(output)
|
||||
|
||||
proc namedHeader*(client: RpcClient, name: string): Result[Header, string] =
|
||||
wrapTry:
|
||||
let res = waitFor client.eth_getBlockByNumber(name, false)
|
||||
|
|
Loading…
Reference in New Issue