BlockId removal: refactor: Backend::body (#12587)

It changes the arguments of `Backend::body` method from: `BlockId<Block>` to: `&Block::Hash`

This PR is part of BlockId::Number refactoring analysis (paritytech/substrate#11292)

Co-authored-by: parity-processbot <>
This commit is contained in:
Michal Kucharczyk
2022-11-01 17:24:09 +01:00
committed by GitHub
parent c68bd397d8
commit 76bcbd09a5
16 changed files with 93 additions and 74 deletions
+14 -8
View File
@@ -1053,9 +1053,9 @@ where
/// Get block body by id.
pub fn body(
&self,
id: &BlockId<Block>,
hash: &Block::Hash,
) -> sp_blockchain::Result<Option<Vec<<Block as BlockT>::Extrinsic>>> {
self.backend.blockchain().body(*id)
self.backend.blockchain().body(hash)
}
/// Gets the uncles of the block with `target_hash` going back `max_generation` ancestors.
@@ -1939,16 +1939,22 @@ where
{
fn block_body(
&self,
id: &BlockId<Block>,
hash: &Block::Hash,
) -> sp_blockchain::Result<Option<Vec<<Block as BlockT>::Extrinsic>>> {
self.body(id)
self.body(hash)
}
fn block(&self, id: &BlockId<Block>) -> sp_blockchain::Result<Option<SignedBlock<Block>>> {
Ok(match (self.header(id)?, self.body(id)?, self.justifications(id)?) {
(Some(header), Some(extrinsics), justifications) =>
Some(SignedBlock { block: Block::new(header, extrinsics), justifications }),
_ => None,
Ok(match self.header(id)? {
Some(header) => {
let hash = header.hash();
match (self.body(&hash)?, self.justifications(id)?) {
(Some(extrinsics), justifications) =>
Some(SignedBlock { block: Block::new(header, extrinsics), justifications }),
_ => None,
}
},
None => None,
})
}
@@ -396,16 +396,19 @@ fn block_builder_does_not_include_invalid() {
let block = builder.build().unwrap().block;
block_on(client.import(BlockOrigin::Own, block)).unwrap();
let hash0 = client
let hashof0 = client
.expect_block_hash_from_id(&BlockId::Number(0))
.expect("block 0 was just imported. qed");
let hash1 = client
let hashof1 = client
.expect_block_hash_from_id(&BlockId::Number(1))
.expect("block 1 was just imported. qed");
assert_eq!(client.chain_info().best_number, 1);
assert_ne!(client.state_at(&hash1).unwrap().pairs(), client.state_at(&hash0).unwrap().pairs());
assert_eq!(client.body(&BlockId::Number(1)).unwrap().unwrap().len(), 1)
assert_ne!(
client.state_at(&hashof1).unwrap().pairs(),
client.state_at(&hashof0).unwrap().pairs()
);
assert_eq!(client.body(&hashof1).unwrap().unwrap().len(), 1)
}
#[test]