contracts: Add RPC that allows instantiating of a contract (#8451)

* contracts: Add RPC that allows instantiating of a contract

* Encode `debug_message` as bytes because usage of `String` is forbidden

* Remove erroneous derive attribute

* Fix rpc tests for new `debug_message` encoding

* Fix typo

Co-authored-by: Andrew Jones <ascjones@gmail.com>

Co-authored-by: Andrew Jones <ascjones@gmail.com>
This commit is contained in:
Alexander Theißen
2021-04-13 13:26:52 +02:00
committed by GitHub
parent 24311eee3e
commit f854194139
16 changed files with 471 additions and 191 deletions
@@ -25,18 +25,21 @@
use codec::Codec;
use sp_std::vec::Vec;
use pallet_contracts_primitives::{ContractExecResult, GetStorageResult, RentProjectionResult};
use pallet_contracts_primitives::{
ContractExecResult, GetStorageResult, RentProjectionResult, Code, ContractInstantiateResult,
};
sp_api::decl_runtime_apis! {
/// The API to interact with contracts without using executive.
pub trait ContractsApi<AccountId, Balance, BlockNumber> where
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 the contracts' `call` dispatchable function for more details.
/// See [`pallet_contracts::Pallet::call`].
fn call(
origin: AccountId,
dest: AccountId,
@@ -45,6 +48,18 @@ sp_api::decl_runtime_apis! {
input_data: Vec<u8>,
) -> ContractExecResult;
/// Instantiate a new contract.
///
/// See [`pallet_contracts::Pallet::instantiate`].
fn instantiate(
origin: AccountId,
endowment: Balance,
gas_limit: u64,
code: Code<Hash>,
data: Vec<u8>,
salt: Vec<u8>,
) -> ContractInstantiateResult<AccountId, BlockNumber>;
/// 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