mirror of
https://github.com/pezkuwichain/pezkuwi-subxt.git
synced 2026-07-04 04:37:23 +00:00
BlockId removal: &Hash to Hash (#12626)
It changes &Block::Hash argument to Block::Hash. This PR is part of BlockId::Number refactoring analysis (paritytech/substrate#11292)
This commit is contained in:
committed by
GitHub
parent
7c4bfc9749
commit
1ed70004e7
@@ -25,7 +25,7 @@ use std::{collections::HashMap, sync::Arc};
|
||||
|
||||
/// Export the raw state at the given `block`. If `block` is `None`, the
|
||||
/// best block will be used.
|
||||
pub fn export_raw_state<B, BA, C>(client: Arc<C>, hash: &B::Hash) -> Result<Storage, Error>
|
||||
pub fn export_raw_state<B, BA, C>(client: Arc<C>, hash: B::Hash) -> Result<Storage, Error>
|
||||
where
|
||||
C: UsageProvider<B> + StorageProvider<B, BA>,
|
||||
B: BlockT,
|
||||
|
||||
@@ -148,7 +148,7 @@ where
|
||||
) -> sp_blockchain::Result<Vec<u8>> {
|
||||
let mut changes = OverlayedChanges::default();
|
||||
let at_hash = self.backend.blockchain().expect_block_hash_from_id(at)?;
|
||||
let state = self.backend.state_at(&at_hash)?;
|
||||
let state = self.backend.state_at(at_hash)?;
|
||||
let state_runtime_code = sp_state_machine::backend::BackendRuntimeCode::new(&state);
|
||||
let runtime_code =
|
||||
state_runtime_code.runtime_code().map_err(sp_blockchain::Error::RuntimeCode)?;
|
||||
@@ -193,7 +193,7 @@ where
|
||||
let mut storage_transaction_cache = storage_transaction_cache.map(|c| c.borrow_mut());
|
||||
|
||||
let at_hash = self.backend.blockchain().expect_block_hash_from_id(at)?;
|
||||
let state = self.backend.state_at(&at_hash)?;
|
||||
let state = self.backend.state_at(at_hash)?;
|
||||
|
||||
let changes = &mut *changes.borrow_mut();
|
||||
|
||||
@@ -251,7 +251,7 @@ where
|
||||
let mut overlay = OverlayedChanges::default();
|
||||
|
||||
let at_hash = self.backend.blockchain().expect_block_hash_from_id(id)?;
|
||||
let state = self.backend.state_at(&at_hash)?;
|
||||
let state = self.backend.state_at(at_hash)?;
|
||||
let mut cache = StorageTransactionCache::<Block, B::State>::default();
|
||||
let mut ext = Ext::new(&mut overlay, &mut cache, &state, None);
|
||||
let state_runtime_code = sp_state_machine::backend::BackendRuntimeCode::new(&state);
|
||||
@@ -269,7 +269,7 @@ where
|
||||
call_data: &[u8],
|
||||
) -> sp_blockchain::Result<(Vec<u8>, StorageProof)> {
|
||||
let at_hash = self.backend.blockchain().expect_block_hash_from_id(at)?;
|
||||
let state = self.backend.state_at(&at_hash)?;
|
||||
let state = self.backend.state_at(at_hash)?;
|
||||
|
||||
let trie_backend = state.as_trie_backend();
|
||||
|
||||
|
||||
@@ -414,14 +414,14 @@ where
|
||||
}
|
||||
|
||||
/// Get a reference to the state at a given block.
|
||||
pub fn state_at(&self, hash: &Block::Hash) -> sp_blockchain::Result<B::State> {
|
||||
pub fn state_at(&self, hash: Block::Hash) -> sp_blockchain::Result<B::State> {
|
||||
self.backend.state_at(hash)
|
||||
}
|
||||
|
||||
/// Get the code at a given block.
|
||||
pub fn code_at(&self, id: &BlockId<Block>) -> sp_blockchain::Result<Vec<u8>> {
|
||||
let hash = self.backend.blockchain().expect_block_hash_from_id(id)?;
|
||||
Ok(StorageProvider::storage(self, &hash, &StorageKey(well_known_keys::CODE.to_vec()))?
|
||||
Ok(StorageProvider::storage(self, hash, &StorageKey(well_known_keys::CODE.to_vec()))?
|
||||
.expect(
|
||||
"None is returned if there's no value stored for the given key;\
|
||||
':code' key is always defined; qed",
|
||||
@@ -586,7 +586,7 @@ where
|
||||
Some(storage_changes) => {
|
||||
let storage_changes = match storage_changes {
|
||||
sc_consensus::StorageChanges::Changes(storage_changes) => {
|
||||
self.backend.begin_state_operation(&mut operation.op, &parent_hash)?;
|
||||
self.backend.begin_state_operation(&mut operation.op, parent_hash)?;
|
||||
let (main_sc, child_sc, offchain_sc, tx, _, tx_index) =
|
||||
storage_changes.into_inner();
|
||||
|
||||
@@ -813,7 +813,7 @@ where
|
||||
Block::new(import_block.header.clone(), body.clone()),
|
||||
)?;
|
||||
|
||||
let state = self.backend.state_at(parent_hash)?;
|
||||
let state = self.backend.state_at(*parent_hash)?;
|
||||
let gen_storage_changes = runtime_api
|
||||
.into_storage_changes(&state, *parent_hash)
|
||||
.map_err(sp_blockchain::Error::Storage)?;
|
||||
@@ -877,17 +877,17 @@ where
|
||||
// plugable we cannot make a better choice here. usages that need
|
||||
// an accurate "best" block need to go through `SelectChain`
|
||||
// instead.
|
||||
operation.op.mark_head(&block)?;
|
||||
operation.op.mark_head(block)?;
|
||||
}
|
||||
|
||||
let enacted = route_from_finalized.enacted();
|
||||
assert!(enacted.len() > 0);
|
||||
for finalize_new in &enacted[..enacted.len() - 1] {
|
||||
operation.op.mark_finalized(&finalize_new.hash, None)?;
|
||||
operation.op.mark_finalized(finalize_new.hash, None)?;
|
||||
}
|
||||
|
||||
assert_eq!(enacted.last().map(|e| e.hash), Some(block));
|
||||
operation.op.mark_finalized(&block, justification)?;
|
||||
operation.op.mark_finalized(block, justification)?;
|
||||
|
||||
if notify {
|
||||
let finalized =
|
||||
@@ -1033,7 +1033,7 @@ where
|
||||
};
|
||||
match hash_and_number {
|
||||
Some((hash, number)) =>
|
||||
if self.backend.have_state_at(&hash, number) {
|
||||
if self.backend.have_state_at(hash, number) {
|
||||
Ok(BlockStatus::InChainWithState)
|
||||
} else {
|
||||
Ok(BlockStatus::InChainPruned)
|
||||
@@ -1053,7 +1053,7 @@ where
|
||||
/// Get block body by id.
|
||||
pub fn body(
|
||||
&self,
|
||||
hash: &Block::Hash,
|
||||
hash: Block::Hash,
|
||||
) -> sp_blockchain::Result<Option<Vec<<Block as BlockT>::Extrinsic>>> {
|
||||
self.backend.blockchain().body(hash)
|
||||
}
|
||||
@@ -1151,7 +1151,7 @@ where
|
||||
{
|
||||
fn read_proof(
|
||||
&self,
|
||||
hash: &Block::Hash,
|
||||
hash: Block::Hash,
|
||||
keys: &mut dyn Iterator<Item = &[u8]>,
|
||||
) -> sp_blockchain::Result<StorageProof> {
|
||||
self.state_at(hash)
|
||||
@@ -1160,7 +1160,7 @@ where
|
||||
|
||||
fn read_child_proof(
|
||||
&self,
|
||||
hash: &Block::Hash,
|
||||
hash: Block::Hash,
|
||||
child_info: &ChildInfo,
|
||||
keys: &mut dyn Iterator<Item = &[u8]>,
|
||||
) -> sp_blockchain::Result<StorageProof> {
|
||||
@@ -1170,16 +1170,16 @@ where
|
||||
|
||||
fn execution_proof(
|
||||
&self,
|
||||
hash: &Block::Hash,
|
||||
hash: Block::Hash,
|
||||
method: &str,
|
||||
call_data: &[u8],
|
||||
) -> sp_blockchain::Result<(Vec<u8>, StorageProof)> {
|
||||
self.executor.prove_execution(&BlockId::Hash(*hash), method, call_data)
|
||||
self.executor.prove_execution(&BlockId::Hash(hash), method, call_data)
|
||||
}
|
||||
|
||||
fn read_proof_collection(
|
||||
&self,
|
||||
hash: &Block::Hash,
|
||||
hash: Block::Hash,
|
||||
start_key: &[Vec<u8>],
|
||||
size_limit: usize,
|
||||
) -> sp_blockchain::Result<(CompactProof, u32)> {
|
||||
@@ -1198,14 +1198,14 @@ where
|
||||
|
||||
fn storage_collection(
|
||||
&self,
|
||||
hash: &Block::Hash,
|
||||
hash: Block::Hash,
|
||||
start_key: &[Vec<u8>],
|
||||
size_limit: usize,
|
||||
) -> sp_blockchain::Result<Vec<(KeyValueStorageLevel, bool)>> {
|
||||
if start_key.len() > MAX_NESTED_TRIE_DEPTH {
|
||||
return Err(Error::Backend("Invalid start key.".to_string()))
|
||||
}
|
||||
let state = self.state_at(&hash)?;
|
||||
let state = self.state_at(hash)?;
|
||||
let child_info = |storage_key: &Vec<u8>| -> sp_blockchain::Result<ChildInfo> {
|
||||
let storage_key = PrefixedStorageKey::new_ref(storage_key);
|
||||
match ChildType::from_prefixed_key(storage_key) {
|
||||
@@ -1398,7 +1398,7 @@ where
|
||||
{
|
||||
fn storage_keys(
|
||||
&self,
|
||||
hash: &Block::Hash,
|
||||
hash: Block::Hash,
|
||||
key_prefix: &StorageKey,
|
||||
) -> sp_blockchain::Result<Vec<StorageKey>> {
|
||||
let keys = self.state_at(hash)?.keys(&key_prefix.0).into_iter().map(StorageKey).collect();
|
||||
@@ -1407,7 +1407,7 @@ where
|
||||
|
||||
fn storage_pairs(
|
||||
&self,
|
||||
hash: &<Block as BlockT>::Hash,
|
||||
hash: <Block as BlockT>::Hash,
|
||||
key_prefix: &StorageKey,
|
||||
) -> sp_blockchain::Result<Vec<(StorageKey, StorageData)>> {
|
||||
let state = self.state_at(hash)?;
|
||||
@@ -1424,7 +1424,7 @@ where
|
||||
|
||||
fn storage_keys_iter<'a>(
|
||||
&self,
|
||||
hash: &<Block as BlockT>::Hash,
|
||||
hash: <Block as BlockT>::Hash,
|
||||
prefix: Option<&'a StorageKey>,
|
||||
start_key: Option<&StorageKey>,
|
||||
) -> sp_blockchain::Result<KeyIterator<'a, B::State, Block>> {
|
||||
@@ -1435,7 +1435,7 @@ where
|
||||
|
||||
fn child_storage_keys_iter<'a>(
|
||||
&self,
|
||||
hash: &<Block as BlockT>::Hash,
|
||||
hash: <Block as BlockT>::Hash,
|
||||
child_info: ChildInfo,
|
||||
prefix: Option<&'a StorageKey>,
|
||||
start_key: Option<&StorageKey>,
|
||||
@@ -1447,7 +1447,7 @@ where
|
||||
|
||||
fn storage(
|
||||
&self,
|
||||
hash: &Block::Hash,
|
||||
hash: Block::Hash,
|
||||
key: &StorageKey,
|
||||
) -> sp_blockchain::Result<Option<StorageData>> {
|
||||
Ok(self
|
||||
@@ -1459,7 +1459,7 @@ where
|
||||
|
||||
fn storage_hash(
|
||||
&self,
|
||||
hash: &<Block as BlockT>::Hash,
|
||||
hash: <Block as BlockT>::Hash,
|
||||
key: &StorageKey,
|
||||
) -> sp_blockchain::Result<Option<Block::Hash>> {
|
||||
self.state_at(hash)?
|
||||
@@ -1469,7 +1469,7 @@ where
|
||||
|
||||
fn child_storage_keys(
|
||||
&self,
|
||||
hash: &<Block as BlockT>::Hash,
|
||||
hash: <Block as BlockT>::Hash,
|
||||
child_info: &ChildInfo,
|
||||
key_prefix: &StorageKey,
|
||||
) -> sp_blockchain::Result<Vec<StorageKey>> {
|
||||
@@ -1484,7 +1484,7 @@ where
|
||||
|
||||
fn child_storage(
|
||||
&self,
|
||||
hash: &<Block as BlockT>::Hash,
|
||||
hash: <Block as BlockT>::Hash,
|
||||
child_info: &ChildInfo,
|
||||
key: &StorageKey,
|
||||
) -> sp_blockchain::Result<Option<StorageData>> {
|
||||
@@ -1497,7 +1497,7 @@ where
|
||||
|
||||
fn child_storage_hash(
|
||||
&self,
|
||||
hash: &<Block as BlockT>::Hash,
|
||||
hash: <Block as BlockT>::Hash,
|
||||
child_info: &ChildInfo,
|
||||
key: &StorageKey,
|
||||
) -> sp_blockchain::Result<Option<Block::Hash>> {
|
||||
@@ -1683,7 +1683,7 @@ where
|
||||
|
||||
fn state_at(&self, at: &BlockId<Block>) -> Result<Self::StateBackend, sp_api::ApiError> {
|
||||
let hash = self.backend.blockchain().expect_block_hash_from_id(at)?;
|
||||
self.state_at(&hash).map_err(Into::into)
|
||||
self.state_at(hash).map_err(Into::into)
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1844,17 +1844,17 @@ where
|
||||
fn apply_finality(
|
||||
&self,
|
||||
operation: &mut ClientImportOperation<Block, B>,
|
||||
hash: &Block::Hash,
|
||||
hash: Block::Hash,
|
||||
justification: Option<Justification>,
|
||||
notify: bool,
|
||||
) -> sp_blockchain::Result<()> {
|
||||
let last_best = self.backend.blockchain().info().best_hash;
|
||||
self.apply_finality_with_block_hash(operation, *hash, justification, last_best, notify)
|
||||
self.apply_finality_with_block_hash(operation, hash, justification, last_best, notify)
|
||||
}
|
||||
|
||||
fn finalize_block(
|
||||
&self,
|
||||
hash: &Block::Hash,
|
||||
hash: Block::Hash,
|
||||
justification: Option<Justification>,
|
||||
notify: bool,
|
||||
) -> sp_blockchain::Result<()> {
|
||||
@@ -1873,7 +1873,7 @@ where
|
||||
fn apply_finality(
|
||||
&self,
|
||||
operation: &mut ClientImportOperation<Block, B>,
|
||||
hash: &Block::Hash,
|
||||
hash: Block::Hash,
|
||||
justification: Option<Justification>,
|
||||
notify: bool,
|
||||
) -> sp_blockchain::Result<()> {
|
||||
@@ -1882,7 +1882,7 @@ where
|
||||
|
||||
fn finalize_block(
|
||||
&self,
|
||||
hash: &Block::Hash,
|
||||
hash: Block::Hash,
|
||||
justification: Option<Justification>,
|
||||
notify: bool,
|
||||
) -> sp_blockchain::Result<()> {
|
||||
@@ -1939,7 +1939,7 @@ where
|
||||
{
|
||||
fn block_body(
|
||||
&self,
|
||||
hash: &Block::Hash,
|
||||
hash: Block::Hash,
|
||||
) -> sp_blockchain::Result<Option<Vec<<Block as BlockT>::Extrinsic>>> {
|
||||
self.body(hash)
|
||||
}
|
||||
@@ -1948,7 +1948,7 @@ where
|
||||
Ok(match self.header(id)? {
|
||||
Some(header) => {
|
||||
let hash = header.hash();
|
||||
match (self.body(&hash)?, self.justifications(&hash)?) {
|
||||
match (self.body(hash)?, self.justifications(hash)?) {
|
||||
(Some(extrinsics), justifications) =>
|
||||
Some(SignedBlock { block: Block::new(header, extrinsics), justifications }),
|
||||
_ => None,
|
||||
@@ -1962,7 +1962,7 @@ where
|
||||
Client::block_status(self, id)
|
||||
}
|
||||
|
||||
fn justifications(&self, hash: &Block::Hash) -> sp_blockchain::Result<Option<Justifications>> {
|
||||
fn justifications(&self, hash: Block::Hash) -> sp_blockchain::Result<Option<Justifications>> {
|
||||
self.backend.blockchain().justifications(hash)
|
||||
}
|
||||
|
||||
@@ -1970,18 +1970,15 @@ where
|
||||
self.backend.blockchain().hash(number)
|
||||
}
|
||||
|
||||
fn indexed_transaction(&self, hash: &Block::Hash) -> sp_blockchain::Result<Option<Vec<u8>>> {
|
||||
fn indexed_transaction(&self, hash: Block::Hash) -> sp_blockchain::Result<Option<Vec<u8>>> {
|
||||
self.backend.blockchain().indexed_transaction(hash)
|
||||
}
|
||||
|
||||
fn has_indexed_transaction(&self, hash: &Block::Hash) -> sp_blockchain::Result<bool> {
|
||||
fn has_indexed_transaction(&self, hash: Block::Hash) -> sp_blockchain::Result<bool> {
|
||||
self.backend.blockchain().has_indexed_transaction(hash)
|
||||
}
|
||||
|
||||
fn block_indexed_body(
|
||||
&self,
|
||||
hash: &Block::Hash,
|
||||
) -> sp_blockchain::Result<Option<Vec<Vec<u8>>>> {
|
||||
fn block_indexed_body(&self, hash: Block::Hash) -> sp_blockchain::Result<Option<Vec<Vec<u8>>>> {
|
||||
self.backend.blockchain().block_indexed_body(hash)
|
||||
}
|
||||
|
||||
@@ -2085,7 +2082,7 @@ where
|
||||
|
||||
self.backend
|
||||
.blockchain()
|
||||
.block_indexed_body(&hash)
|
||||
.block_indexed_body(hash)
|
||||
.map_err(|e| sp_transaction_storage_proof::Error::Application(Box::new(e)))
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user