handle null case

This commit is contained in:
Bryan Stitt 2022-12-05 16:18:31 -08:00
parent 33f7256236
commit a54a061bd2
2 changed files with 16 additions and 13 deletions

@ -149,16 +149,16 @@ impl Web3Connections {
let get_block_params = (*hash, false);
// TODO: if error, retry?
let block: ArcBlock = match rpc {
Some(rpc) => {
rpc.wait_for_request_handle(authorization, Duration::from_secs(30), false)
Some(rpc) => rpc
.wait_for_request_handle(authorization, Duration::from_secs(30), false)
.await?
.request(
.request::<_, Option<_>>(
"eth_getBlockByHash",
&json!(get_block_params),
Level::Error.into(),
)
.await?
}
.context("no block!")?,
None => {
// TODO: helper for method+params => JsonRpcRequest
// TODO: does this id matter?
@ -172,7 +172,9 @@ impl Web3Connections {
let block = response.result.context("failed fetching block")?;
serde_json::from_str(block.get())?
let block: Option<ArcBlock> = serde_json::from_str(block.get())?;
block.context("no block!")?
}
};

@ -193,13 +193,14 @@ impl Web3Connection {
let head_block: ArcBlock = self
.wait_for_request_handle(authorization, Duration::from_secs(30), true)
.await?
.request(
.request::<_, Option<_>>(
"eth_getBlockByNumber",
&json!(("latest", false)),
// error here are expected, so keep the level low
Level::Debug.into(),
)
.await?;
.await?
.context("no block!")?;
if SavedBlock::from(head_block).syncing() {
// if the node is syncing, we can't check its block data limit