Revert "BlockId removal: refactor: HeaderBackend::header (#1977)"

This reverts commit b7dff85939.
This commit is contained in:
EgorPopelyaev
2022-12-21 12:15:09 +01:00
parent fa953ab35a
commit 0f59d20a1e
5 changed files with 150 additions and 25 deletions
+1 -1
View File
@@ -422,7 +422,7 @@ mod tests {
let para_id = ParaId::from(100);
let announce_block = |_, _| ();
let client = Arc::new(TestClientBuilder::new().build());
let header = client.header(client.chain_info().genesis_hash).unwrap().unwrap();
let header = client.header(&BlockId::Number(0)).unwrap().unwrap();
let (sub_tx, sub_rx) = mpsc::channel(64);
@@ -381,9 +381,20 @@ fn block_local<T>(fut: impl Future<Output = T>) -> T {
impl HeaderBackend<Block> for BlockChainRpcClient {
fn header(
&self,
hash: <Block as polkadot_service::BlockT>::Hash,
id: BlockId,
) -> sp_blockchain::Result<Option<<Block as polkadot_service::BlockT>::Header>> {
Ok(block_local(self.rpc_client.chain_get_header(Some(hash)))?)
let fetch_header = |hash| block_local(self.rpc_client.chain_get_header(Some(hash)));
match id {
BlockId::Hash(hash) => Ok(fetch_header(hash)?),
BlockId::Number(number) => {
if let Some(hash) = HeaderBackend::<Block>::hash(self, number)? {
Ok(fetch_header(hash)?)
} else {
Ok(None)
}
},
}
}
fn info(&self) -> Info<Block> {
@@ -414,7 +425,7 @@ impl HeaderBackend<Block> for BlockChainRpcClient {
id: sp_api::BlockId<Block>,
) -> sp_blockchain::Result<sp_blockchain::BlockStatus> {
let exists = match id {
BlockId::Hash(hash) => self.header(hash)?.is_some(),
BlockId::Hash(_) => self.header(id)?.is_some(),
BlockId::Number(n) => {
let best_header = block_local(self.rpc_client.chain_get_header(None))?;
if let Some(best) = best_header {