mirror of
https://github.com/pezkuwichain/pezkuwi-subxt.git
synced 2026-05-30 18:41:03 +00:00
introduce a method for fetching relay chain header to RelayChainInterface (#2794)
* introduce a method for fetching header to RelayChainInterface * cargo fmt * return Option<Header>
This commit is contained in:
@@ -23,7 +23,9 @@ use cumulus_primitives_core::{
|
||||
},
|
||||
InboundDownwardMessage, ParaId, PersistedValidationData,
|
||||
};
|
||||
use cumulus_relay_chain_interface::{RelayChainError, RelayChainInterface, RelayChainResult};
|
||||
use cumulus_relay_chain_interface::{
|
||||
PHeader, RelayChainError, RelayChainInterface, RelayChainResult,
|
||||
};
|
||||
use futures::{FutureExt, Stream, StreamExt};
|
||||
use polkadot_overseer::Handle;
|
||||
|
||||
@@ -33,6 +35,7 @@ use sp_state_machine::StorageValue;
|
||||
use sp_storage::StorageKey;
|
||||
use std::pin::Pin;
|
||||
|
||||
use cumulus_primitives_core::relay_chain::BlockId;
|
||||
pub use url::Url;
|
||||
|
||||
mod reconnecting_ws_client;
|
||||
@@ -75,6 +78,19 @@ impl RelayChainInterface for RelayChainRpcInterface {
|
||||
.await
|
||||
}
|
||||
|
||||
async fn header(&self, block_id: BlockId) -> RelayChainResult<Option<PHeader>> {
|
||||
let hash = match block_id {
|
||||
BlockId::Hash(hash) => hash,
|
||||
BlockId::Number(num) =>
|
||||
self.rpc_client.chain_get_block_hash(Some(num)).await?.ok_or_else(|| {
|
||||
RelayChainError::GenericError(format!("block with number {num} not found"))
|
||||
})?,
|
||||
};
|
||||
let header = self.rpc_client.chain_get_header(Some(hash)).await?;
|
||||
|
||||
Ok(header)
|
||||
}
|
||||
|
||||
async fn persisted_validation_data(
|
||||
&self,
|
||||
hash: RelayHash,
|
||||
|
||||
Reference in New Issue
Block a user