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

contracts: Adapt dry-run runtime APIs to WeightV2 #12429

Merged
merged 1 commit into from
Oct 6, 2022
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
14 changes: 1 addition & 13 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 0 additions & 1 deletion Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -87,7 +87,6 @@ members = [
"frame/collective",
"frame/contracts",
"frame/contracts/primitives",
"frame/contracts/runtime-api",
"frame/conviction-voting",
"frame/democracy",
"frame/fast-unstake",
Expand Down
2 changes: 0 additions & 2 deletions bin/node/runtime/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,6 @@ pallet-child-bounties = { version = "4.0.0-dev", default-features = false, path
pallet-collective = { version = "4.0.0-dev", default-features = false, path = "../../../frame/collective" }
pallet-contracts = { version = "4.0.0-dev", default-features = false, path = "../../../frame/contracts" }
pallet-contracts-primitives = { version = "6.0.0", default-features = false, path = "../../../frame/contracts/primitives/" }
pallet-contracts-runtime-api = { version = "4.0.0-dev", default-features = false, path = "../../../frame/contracts/runtime-api/" }
pallet-conviction-voting = { version = "4.0.0-dev", default-features = false, path = "../../../frame/conviction-voting" }
pallet-democracy = { version = "4.0.0-dev", default-features = false, path = "../../../frame/democracy" }
pallet-election-provider-multi-phase = { version = "4.0.0-dev", default-features = false, path = "../../../frame/election-provider-multi-phase" }
Expand Down Expand Up @@ -139,7 +138,6 @@ std = [
"pallet-collective/std",
"pallet-contracts/std",
"pallet-contracts-primitives/std",
"pallet-contracts-runtime-api/std",
"pallet-conviction-voting/std",
"pallet-democracy/std",
"pallet-elections-phragmen/std",
Expand Down
15 changes: 7 additions & 8 deletions bin/node/runtime/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1941,33 +1941,32 @@ impl_runtime_apis! {
}
}

impl pallet_contracts_runtime_api::ContractsApi<
Block, AccountId, Balance, BlockNumber, Hash,
>
for Runtime
impl pallet_contracts::ContractsApi<Block, AccountId, Balance, BlockNumber, Hash> for Runtime
{
fn call(
origin: AccountId,
dest: AccountId,
value: Balance,
gas_limit: u64,
gas_limit: Option<Weight>,
storage_deposit_limit: Option<Balance>,
input_data: Vec<u8>,
) -> pallet_contracts_primitives::ContractExecResult<Balance> {
Contracts::bare_call(origin, dest, value, Weight::from_ref_time(gas_limit), storage_deposit_limit, input_data, true)
let gas_limit = gas_limit.unwrap_or(RuntimeBlockWeights::get().max_block);
Contracts::bare_call(origin, dest, value, gas_limit, storage_deposit_limit, input_data, true)
}

fn instantiate(
origin: AccountId,
value: Balance,
gas_limit: u64,
gas_limit: Option<Weight>,
storage_deposit_limit: Option<Balance>,
code: pallet_contracts_primitives::Code<Hash>,
data: Vec<u8>,
salt: Vec<u8>,
) -> pallet_contracts_primitives::ContractInstantiateResult<AccountId, Balance>
{
Contracts::bare_instantiate(origin, value, Weight::from_ref_time(gas_limit), storage_deposit_limit, code, data, salt, true)
let gas_limit = gas_limit.unwrap_or(RuntimeBlockWeights::get().max_block);
Contracts::bare_instantiate(origin, value, gas_limit, storage_deposit_limit, code, data, salt, true)
}

fn upload_code(
Expand Down
1 change: 1 addition & 0 deletions frame/contracts/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,7 @@ frame-support = { version = "4.0.0-dev", default-features = false, path = "../su
frame-system = { version = "4.0.0-dev", default-features = false, path = "../system" }
pallet-contracts-primitives = { version = "6.0.0", default-features = false, path = "primitives" }
pallet-contracts-proc-macro = { version = "4.0.0-dev", path = "proc-macro" }
sp-api = { version = "4.0.0-dev", default-features = false, path = "../../primitives/api" }
sp-core = { version = "6.0.0", default-features = false, path = "../../primitives/core" }
sp-io = { version = "6.0.0", default-features = false, path = "../../primitives/io" }
sp-runtime = { version = "6.0.0", default-features = false, path = "../../primitives/runtime" }
Expand Down
34 changes: 0 additions & 34 deletions frame/contracts/runtime-api/Cargo.toml

This file was deleted.

7 changes: 0 additions & 7 deletions frame/contracts/runtime-api/README.md

This file was deleted.

85 changes: 0 additions & 85 deletions frame/contracts/runtime-api/src/lib.rs

This file was deleted.

57 changes: 56 additions & 1 deletion frame/contracts/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -105,7 +105,7 @@ use crate::{
wasm::{OwnerInfo, PrefabWasmModule},
weights::WeightInfo,
};
use codec::{Encode, HasCompact};
use codec::{Codec, Encode, HasCompact};
use frame_support::{
dispatch::{Dispatchable, GetDispatchInfo, Pays, PostDispatchInfo},
ensure,
Expand Down Expand Up @@ -1171,3 +1171,58 @@ where
Weight::from(gas_limit).set_proof_size(u64::from(T::MaxCodeLen::get()) * 2)
}
}

sp_api::decl_runtime_apis! {
/// The API used to dry-run contract interactions.
pub trait ContractsApi<AccountId, Balance, BlockNumber, Hash> where
AccountId: Codec,
Balance: Codec,
BlockNumber: Codec,
Hash: Codec,
{
/// Perform a call from a specified account to a given contract.
///
/// See [`crate::Pallet::bare_call`].
fn call(
origin: AccountId,
dest: AccountId,
value: Balance,
gas_limit: Option<Weight>,
storage_deposit_limit: Option<Balance>,
input_data: Vec<u8>,
) -> ContractExecResult<Balance>;

/// Instantiate a new contract.
///
/// See `[crate::Pallet::bare_instantiate]`.
fn instantiate(
origin: AccountId,
value: Balance,
gas_limit: Option<Weight>,
storage_deposit_limit: Option<Balance>,
code: Code<Hash>,
data: Vec<u8>,
salt: Vec<u8>,
) -> ContractInstantiateResult<AccountId, Balance>;


/// Upload new code without instantiating a contract from it.
///
/// See [`crate::Pallet::bare_upload_code`].
fn upload_code(
origin: AccountId,
code: Vec<u8>,
storage_deposit_limit: Option<Balance>,
) -> CodeUploadResult<Hash, Balance>;

/// Query a given 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(
address: AccountId,
key: Vec<u8>,
) -> GetStorageResult;
}
}