Skip to content

Commit

Permalink
client: remove duplicate implementation of block_status (paritytech#7694
Browse files Browse the repository at this point in the history
)
  • Loading branch information
andresilva authored and darkfriend77 committed Jan 11, 2021
1 parent 284f424 commit 046038b
Showing 1 changed file with 2 additions and 22 deletions.
24 changes: 2 additions & 22 deletions client/service/src/client/client.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1901,8 +1901,7 @@ impl<B, E, Block, RA> BlockBackend<Block> for Client<B, E, Block, RA>
self.body(id)
}

fn block(&self, id: &BlockId<Block>) -> sp_blockchain::Result<Option<SignedBlock<Block>>>
{
fn block(&self, id: &BlockId<Block>) -> sp_blockchain::Result<Option<SignedBlock<Block>>> {
Ok(match (self.header(id)?, self.body(id)?, self.justification(id)?) {
(Some(header), Some(extrinsics), justification) =>
Some(SignedBlock { block: Block::new(header, extrinsics), justification }),
Expand All @@ -1911,26 +1910,7 @@ impl<B, E, Block, RA> BlockBackend<Block> for Client<B, E, Block, RA>
}

fn block_status(&self, id: &BlockId<Block>) -> sp_blockchain::Result<BlockStatus> {
// this can probably be implemented more efficiently
if let BlockId::Hash(ref h) = id {
if self.importing_block.read().as_ref().map_or(false, |importing| h == importing) {
return Ok(BlockStatus::Queued);
}
}
let hash_and_number = match id.clone() {
BlockId::Hash(hash) => self.backend.blockchain().number(hash)?.map(|n| (hash, n)),
BlockId::Number(n) => self.backend.blockchain().hash(n)?.map(|hash| (hash, n)),
};
match hash_and_number {
Some((hash, number)) => {
if self.backend.have_state_at(&hash, number) {
Ok(BlockStatus::InChainWithState)
} else {
Ok(BlockStatus::InChainPruned)
}
}
None => Ok(BlockStatus::Unknown),
}
Client::block_status(self, id)
}

fn justification(&self, id: &BlockId<Block>) -> sp_blockchain::Result<Option<Justification>> {
Expand Down

0 comments on commit 046038b

Please sign in to comment.