Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 10 additions & 0 deletions cumulus/parachains/runtimes/assets/asset-hub-westend/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2421,6 +2421,16 @@ impl_runtime_apis! {
)
}

fn get_storage_var_key(
address: H160,
key: Vec<u8>,
) -> pallet_revive::GetStorageResult {
Revive::get_storage_var_key(
address,
key
)
}

fn trace_block(
block: Block,
config: pallet_revive::evm::TracerConfig
Expand Down
14 changes: 14 additions & 0 deletions prdoc/pr_8274.prdoc
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
title: '[pallet-revive] add get_storage_var_key for variable-sized keys'

doc:
- audience: Runtime Dev
description: |-
This adds a new runtime ReviveApi call get_storage_var_key, which does the same as get_storage, but for variable-sized keys.

crates:
- name: asset-hub-westend-runtime
bump: minor
- name: kitchensink-runtime
bump: minor
- name: pallet-revive
bump: major
10 changes: 10 additions & 0 deletions substrate/bin/node/runtime/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3443,6 +3443,16 @@ impl_runtime_apis! {
)
}

fn get_storage_var_key(
address: H160,
key: Vec<u8>,
) -> pallet_revive::GetStorageResult {
Revive::get_storage_var_key(
address,
key
)
}

fn get_storage(
address: H160,
key: [u8; 32],
Expand Down
22 changes: 22 additions & 0 deletions substrate/frame/revive/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1397,6 +1397,19 @@ where
Ok(maybe_value)
}

/// Query storage of a specified contract under a specified variable-sized key.
pub fn get_storage_var_key(address: H160, key: Vec<u8>) -> GetStorageResult {
let contract_info =
ContractInfoOf::<T>::get(&address).ok_or(ContractAccessError::DoesntExist)?;

let maybe_value = contract_info.read(
&Key::try_from_var(key)
.map_err(|_| ContractAccessError::KeyDecodingFailed)?
.into(),
);
Ok(maybe_value)
}

/// Uploads new code and returns the Wasm blob and deposit amount collected.
fn try_upload_code(
origin: T::AccountId,
Expand Down Expand Up @@ -1541,6 +1554,15 @@ sp_api::decl_runtime_apis! {
key: [u8; 32],
) -> GetStorageResult;

/// Query a given variable-sized storage key in a given contract.
///
/// Returns `Ok(Some(Vec<u8>))` if the storage value exists under the given key in the
/// specified account and `Ok(None)` if it doesn't. If the account specified by the address
/// doesn't exist, or doesn't have a contract then `Err` is returned.
fn get_storage_var_key(
address: H160,
key: Vec<u8>,
) -> GetStorageResult;

/// Traces the execution of an entire block and returns call traces.
///
Expand Down
Loading