From 50e39324977a91a36580e2b82c622c34faf6053f Mon Sep 17 00:00:00 2001 From: Li Smith Date: Thu, 24 Aug 2023 17:26:01 +0800 Subject: [PATCH] update eth2-pallet-init/substrate_pallet_client.rs get_client_mode (#46) --- .../src/substrate_pallet_client.rs | 23 +++++++++++++++---- 1 file changed, 18 insertions(+), 5 deletions(-) diff --git a/crates/eth2-pallet-init/src/substrate_pallet_client.rs b/crates/eth2-pallet-init/src/substrate_pallet_client.rs index b79999e2..9166d6f2 100644 --- a/crates/eth2-pallet-init/src/substrate_pallet_client.rs +++ b/crates/eth2-pallet-init/src/substrate_pallet_client.rs @@ -48,6 +48,15 @@ pub fn convert_typed_chain_ids( } } +pub fn convert_mode(t: tangle::runtime_types::eth_types::pallet::ClientMode) -> ClientMode { + match t { + tangle::runtime_types::eth_types::pallet::ClientMode::SubmitLightClientUpdate => + ClientMode::SubmitLightClientUpdate, + tangle::runtime_types::eth_types::pallet::ClientMode::SubmitHeader => + ClientMode::SubmitHeader, + } +} + pub async fn setup_api() -> anyhow::Result> { let api: OnlineClient = OnlineClient::::new().await?; Ok(api) @@ -357,11 +366,15 @@ impl EthClientPalletTrait for EthClientPallet { } async fn get_client_mode(&self) -> anyhow::Result { - Err(std::io::Error::new( - std::io::ErrorKind::Other, - "Unable to get value for get_client_mode".to_string(), - ) - .into()) + let addr = tangle::storage() + .eth2_client() + .client_mode_for_chain(convert_typed_chain_ids(self.chain)); + + if let Some(mode) = self.get_value(&addr).await? { + Ok(convert_mode(mode)) + } else { + Ok(ClientMode::SubmitLightClientUpdate) + } } async fn get_last_block_number(&self) -> anyhow::Result {