Skip to content
This repository has been archived by the owner on Oct 23, 2024. It is now read-only.

Commit

Permalink
update eth2-pallet-init/substrate_pallet_client.rs get_client_mode (#46)
Browse files Browse the repository at this point in the history
  • Loading branch information
baidang201 authored Aug 24, 2023
1 parent 820d3ac commit 50e3932
Showing 1 changed file with 18 additions and 5 deletions.
23 changes: 18 additions & 5 deletions crates/eth2-pallet-init/src/substrate_pallet_client.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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<OnlineClient<PolkadotConfig>> {
let api: OnlineClient<PolkadotConfig> = OnlineClient::<PolkadotConfig>::new().await?;
Ok(api)
Expand Down Expand Up @@ -357,11 +366,15 @@ impl EthClientPalletTrait for EthClientPallet {
}

async fn get_client_mode(&self) -> anyhow::Result<ClientMode> {
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<u64> {
Expand Down

0 comments on commit 50e3932

Please sign in to comment.