Skip to content

Commit 8dc3754

Browse files
michalkucharczykbkchr
authored andcommitted
BlockId removal: CallApiAt::state_at (paritytech#13394)
* BlockId removal: CallApiAt::state_at It changes the arguments of: - `CallApiAt::state_at`, - `Client::code_at`, - `Client::state_at` from: `BlockId<Block>` to: `Block::Hash` * Apply suggestions from code review Co-authored-by: Bastian Köcher <git@kchr.de> --------- Co-authored-by: Bastian Köcher <git@kchr.de> Co-authored-by: parity-processbot <>
1 parent dbd25db commit 8dc3754

File tree

3 files changed

+6
-8
lines changed

3 files changed

+6
-8
lines changed

client/service/src/client/client.rs

+3-5
Original file line numberDiff line numberDiff line change
@@ -481,8 +481,7 @@ where
481481
}
482482

483483
/// Get the code at a given block.
484-
pub fn code_at(&self, id: &BlockId<Block>) -> sp_blockchain::Result<Vec<u8>> {
485-
let hash = self.backend.blockchain().expect_block_hash_from_id(id)?;
484+
pub fn code_at(&self, hash: Block::Hash) -> sp_blockchain::Result<Vec<u8>> {
486485
Ok(StorageProvider::storage(self, hash, &StorageKey(well_known_keys::CODE.to_vec()))?
487486
.expect(
488487
"None is returned if there's no value stored for the given key;\
@@ -1746,9 +1745,8 @@ where
17461745
CallExecutor::runtime_version(&self.executor, hash).map_err(Into::into)
17471746
}
17481747

1749-
fn state_at(&self, at: &BlockId<Block>) -> Result<Self::StateBackend, sp_api::ApiError> {
1750-
let hash = self.backend.blockchain().expect_block_hash_from_id(at)?;
1751-
self.state_at(hash).map_err(Into::into)
1748+
fn state_at(&self, at: Block::Hash) -> Result<Self::StateBackend, sp_api::ApiError> {
1749+
self.state_at(at).map_err(Into::into)
17521750
}
17531751
}
17541752

primitives/api/src/lib.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -622,7 +622,7 @@ pub trait CallApiAt<Block: BlockT> {
622622
fn runtime_version_at(&self, at: &BlockId<Block>) -> Result<RuntimeVersion, ApiError>;
623623

624624
/// Get the state `at` the given block.
625-
fn state_at(&self, at: &BlockId<Block>) -> Result<Self::StateBackend, ApiError>;
625+
fn state_at(&self, at: Block::Hash) -> Result<Self::StateBackend, ApiError>;
626626
}
627627

628628
/// Auxiliary wrapper that holds an api instance and binds it to the given lifetime.

primitives/api/test/tests/runtime_calls.rs

+2-2
Original file line numberDiff line numberDiff line change
@@ -147,13 +147,12 @@ fn record_proof_works() {
147147
.set_execution_strategy(ExecutionStrategy::Both)
148148
.build_with_longest_chain();
149149

150-
let block_id = BlockId::Number(client.chain_info().best_number);
151150
let storage_root =
152151
*futures::executor::block_on(longest_chain.best_chain()).unwrap().state_root();
153152

154153
let runtime_code = sp_core::traits::RuntimeCode {
155154
code_fetcher: &sp_core::traits::WrappedRuntimeCode(
156-
client.code_at(&block_id).unwrap().into(),
155+
client.code_at(client.chain_info().best_hash).unwrap().into(),
157156
),
158157
hash: vec![1],
159158
heap_pages: None,
@@ -167,6 +166,7 @@ fn record_proof_works() {
167166
}
168167
.into_signed_tx();
169168

169+
let block_id = BlockId::Hash(client.chain_info().best_hash);
170170
// Build the block and record proof
171171
let mut builder = client
172172
.new_block_at(&block_id, Default::default(), true)

0 commit comments

Comments
 (0)