From 53001225d33261f71ec802304181803d823c20e7 Mon Sep 17 00:00:00 2001 From: todaylab Date: Tue, 22 Aug 2023 00:41:16 +0800 Subject: [PATCH] add get_last_block_number/get_unfinalized_tail_block_number in eth2-pallet-init --- .../src/substrate_pallet_client.rs | 29 ++++++++++++------- 1 file changed, 19 insertions(+), 10 deletions(-) diff --git a/crates/eth2-pallet-init/src/substrate_pallet_client.rs b/crates/eth2-pallet-init/src/substrate_pallet_client.rs index 298ca83d..e7535be2 100644 --- a/crates/eth2-pallet-init/src/substrate_pallet_client.rs +++ b/crates/eth2-pallet-init/src/substrate_pallet_client.rs @@ -364,18 +364,27 @@ impl EthClientPalletTrait for EthClientPallet { } async fn get_last_block_number(&self) -> anyhow::Result { - Err(std::io::Error::new( - std::io::ErrorKind::Other, - "Unable to get value for get_last_block_number".to_string(), - ) - .into()) + let addr = tangle::storage() + .eth2_client() + .finalized_execution_header(convert_typed_chain_ids(self.chain)); + + if let Some(head) = self.get_value(&addr).await? { + Ok(head.block_number) + } else { + Ok(0) + } } + async fn get_unfinalized_tail_block_number(&self) -> anyhow::Result> { - Err(std::io::Error::new( - std::io::ErrorKind::Other, - "Unable to get value for get_unfinalized_tail_block_number".to_string(), - ) - .into()) + let addr = tangle::storage() + .eth2_client() + .unfinalized_tail_execution_header(convert_typed_chain_ids(self.chain)); + + if let Some(head) = self.get_value(&addr).await? { + Ok(Some(head.block_number)) + } else { + Ok(None) + } } }