From b476a56ad6071e8bff6ac53adfa22ed94624fbdd Mon Sep 17 00:00:00 2001 From: Bryan Stitt Date: Fri, 7 Jul 2023 15:28:24 -0700 Subject: [PATCH] check for U64 instead of just BlockNumber i thouht block number would be smart enough to deserialize, but it seems like not --- web3_proxy/src/block_number.rs | 22 +++++++++++++++++++--- 1 file changed, 19 insertions(+), 3 deletions(-) diff --git a/web3_proxy/src/block_number.rs b/web3_proxy/src/block_number.rs index 41e93cd0..7028df99 100644 --- a/web3_proxy/src/block_number.rs +++ b/web3_proxy/src/block_number.rs @@ -64,7 +64,8 @@ impl From<&Web3ProxyBlock> for BlockNumAndHash { } } -/// modify params to always have a block number and not "latest" +/// modify params to always have a block hash and not "latest" +/// TODO: this should replace all block numbers with hashes, not just "latest" pub async fn clean_block_number( authorization: &Arc, params: &mut serde_json::Value, @@ -112,7 +113,22 @@ pub async fn clean_block_number( // it might be a string like "latest" or a block number or a block hash // TODO: "BlockNumber" needs a better name // TODO: move this to a helper function? - if let Ok(block_number) = serde_json::from_value::(x.clone()) { + if let Ok(block_num) = serde_json::from_value::(x.clone()) { + let (block_hash, _) = rpcs + .block_hash(authorization, &block_num) + .await + .context("fetching block hash from number")?; + + let block = rpcs + .block(authorization, &block_hash, None, Some(3), None) + .await + .context("fetching block from hash")?; + + // TODO: do true here? will that work for **all** methods on **all** chains? if not we need something smarter + (BlockNumAndHash::from(&block), false) + } else if let Ok(block_number) = + serde_json::from_value::(x.clone()) + { let (block_num, change) = BlockNumber_to_U64(block_number, latest_block.number()); @@ -145,7 +161,7 @@ pub async fn clean_block_number( } }; - // if we changed "latest" to a number, update the params to match + // if we changed "latest" to a hash, update the params to match if change { trace!(old=%x, new=%block.hash(), "changing block number"); *x = json!(block.hash());