Skip to content
This repository was archived by the owner on Nov 15, 2023. It is now read-only.

Commit b60c825

Browse files
author
Ross Bulat
committed
Revert "BlockId removal: CallApiAt::state_at (#13394)"
This reverts commit d7f3acc.
1 parent d3a09e2 commit b60c825

File tree

3 files changed

+8
-6
lines changed

3 files changed

+8
-6
lines changed

client/service/src/client/client.rs

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -481,7 +481,8 @@ where
481481
}
482482

483483
/// Get the code at a given block.
484-
pub fn code_at(&self, hash: Block::Hash) -> sp_blockchain::Result<Vec<u8>> {
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)?;
485486
Ok(StorageProvider::storage(self, hash, &StorageKey(well_known_keys::CODE.to_vec()))?
486487
.expect(
487488
"None is returned if there's no value stored for the given key;\
@@ -1745,8 +1746,9 @@ where
17451746
CallExecutor::runtime_version(&self.executor, hash).map_err(Into::into)
17461747
}
17471748

1748-
fn state_at(&self, at: Block::Hash) -> Result<Self::StateBackend, sp_api::ApiError> {
1749-
self.state_at(at).map_err(Into::into)
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)
17501752
}
17511753
}
17521754

primitives/api/src/lib.rs

Lines changed: 1 addition & 1 deletion
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: Block::Hash) -> Result<Self::StateBackend, ApiError>;
625+
fn state_at(&self, at: &BlockId<Block>) -> 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

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -147,12 +147,13 @@ 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);
150151
let storage_root =
151152
*futures::executor::block_on(longest_chain.best_chain()).unwrap().state_root();
152153

153154
let runtime_code = sp_core::traits::RuntimeCode {
154155
code_fetcher: &sp_core::traits::WrappedRuntimeCode(
155-
client.code_at(client.chain_info().best_hash).unwrap().into(),
156+
client.code_at(&block_id).unwrap().into(),
156157
),
157158
hash: vec![1],
158159
heap_pages: None,
@@ -166,7 +167,6 @@ fn record_proof_works() {
166167
}
167168
.into_signed_tx();
168169

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)