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:
Web3 Philosopher
2023-07-04 16:27:31 +02:00
committed by GitHub
parent 7f2238a218
commit 9c183893ae
5 changed files with 60 additions and 4 deletions
+13
View File
@@ -16,6 +16,7 @@
use super::*;
use async_trait::async_trait;
use cumulus_primitives_core::relay_chain::BlockId;
use cumulus_relay_chain_inprocess_interface::{check_block_in_chain, BlockCheckStatus};
use cumulus_relay_chain_interface::{
OverseerHandle, PHeader, ParaId, RelayChainError, RelayChainResult,
@@ -237,6 +238,18 @@ impl RelayChainInterface for DummyRelayChainInterface {
});
Ok(Box::pin(notifications_stream))
}
async fn header(&self, block_id: BlockId) -> RelayChainResult<Option<PHeader>> {
let hash = match block_id {
BlockId::Hash(hash) => hash,
BlockId::Number(num) => self.relay_client.hash(num)?.ok_or_else(|| {
RelayChainError::GenericError(format!("block with number {num} not found"))
})?,
};
let header = self.relay_client.header(hash)?;
Ok(header)
}
}
fn make_validator_and_api(