diff --git a/cumulus/parachains/runtimes/assets/asset-hub-westend/src/lib.rs b/cumulus/parachains/runtimes/assets/asset-hub-westend/src/lib.rs index 4cf540a2f8b19..2786b2288cceb 100644 --- a/cumulus/parachains/runtimes/assets/asset-hub-westend/src/lib.rs +++ b/cumulus/parachains/runtimes/assets/asset-hub-westend/src/lib.rs @@ -2421,6 +2421,16 @@ impl_runtime_apis! { ) } + fn get_storage_var_key( + address: H160, + key: Vec, + ) -> pallet_revive::GetStorageResult { + Revive::get_storage_var_key( + address, + key + ) + } + fn trace_block( block: Block, config: pallet_revive::evm::TracerConfig diff --git a/prdoc/pr_8274.prdoc b/prdoc/pr_8274.prdoc new file mode 100644 index 0000000000000..6a442521e04a3 --- /dev/null +++ b/prdoc/pr_8274.prdoc @@ -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 diff --git a/substrate/bin/node/runtime/src/lib.rs b/substrate/bin/node/runtime/src/lib.rs index 723bead6a1c1b..4f6b9eee2d84c 100644 --- a/substrate/bin/node/runtime/src/lib.rs +++ b/substrate/bin/node/runtime/src/lib.rs @@ -3443,6 +3443,16 @@ impl_runtime_apis! { ) } + fn get_storage_var_key( + address: H160, + key: Vec, + ) -> pallet_revive::GetStorageResult { + Revive::get_storage_var_key( + address, + key + ) + } + fn get_storage( address: H160, key: [u8; 32], diff --git a/substrate/frame/revive/src/lib.rs b/substrate/frame/revive/src/lib.rs index 127dfa1248a30..03f21c1c175c3 100644 --- a/substrate/frame/revive/src/lib.rs +++ b/substrate/frame/revive/src/lib.rs @@ -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) -> GetStorageResult { + let contract_info = + ContractInfoOf::::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, @@ -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))` 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, + ) -> GetStorageResult; /// Traces the execution of an entire block and returns call traces. ///