Add an RPC method for calling a contract. (#3563)

* Sketch

* Some work on docs.

* Doc improvements.

* More docs.

* Some more docs.

* Yet another comment.

* Bump impl_version.

* Accept the block hash

* Use NumberOrHex

* Update node/rpc/src/contracts.rs

Co-Authored-By: Tomasz Drwięga <tomusdrw@users.noreply.github.com>

* Move rpc/primitives
This commit is contained in:
Sergei Pepyakin
2019-09-12 13:30:10 +02:00
committed by GitHub
parent 294d172187
commit 4daac15d22
18 changed files with 279 additions and 27 deletions
+38
View File
@@ -20,10 +20,15 @@
#![cfg_attr(not(feature = "std"), no_std)]
use rstd::prelude::*;
use sr_primitives::{
generic, traits::{Verify, BlakeTwo256}, OpaqueExtrinsic, AnySignature
};
#[cfg(feature = "std")]
use serde::{Serialize, Deserialize};
use codec::{Encode, Decode};
/// An index to a block.
pub type BlockNumber = u32;
@@ -67,10 +72,43 @@ pub type BlockId = generic::BlockId<Block>;
/// Opaque, encoded, unchecked extrinsic.
pub type UncheckedExtrinsic = OpaqueExtrinsic;
/// A result of execution of a contract.
#[derive(Eq, PartialEq, Encode, Decode)]
#[cfg_attr(feature = "std", derive(Debug, Serialize, Deserialize))]
pub enum ContractExecResult {
/// The contract returned successfully.
///
/// There is a status code and, optionally, some data returned by the contract.
Success {
/// Status code returned by the contract.
status: u8,
/// Output data returned by the contract.
///
/// Can be empty.
data: Vec<u8>,
},
/// The contract execution either trapped or returned an error.
Error,
}
client::decl_runtime_apis! {
/// The API to query account account nonce (aka index).
pub trait AccountNonceApi {
/// Get current account nonce of given `AccountId`.
fn account_nonce(account: AccountId) -> Index;
}
/// The API to interact with contracts without using executive.
pub trait ContractsApi {
/// Perform a call from a specified account to a given contract.
///
/// See the contracts' `call` dispatchable function for more details.
fn call(
origin: AccountId,
dest: AccountId,
value: Balance,
gas_limit: u64,
input_data: Vec<u8>,
) -> ContractExecResult;
}
}