Skip to content
This repository was archived by the owner on Nov 15, 2023. It is now read-only.
75 changes: 58 additions & 17 deletions Cargo.lock

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

1 change: 1 addition & 0 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -103,6 +103,7 @@ members = [
"srml/staking/reward-curve",
"srml/sudo",
"srml/system",
"srml/system/rpc",
"srml/timestamp",
"srml/treasury",
"srml/utility",
Expand Down
2 changes: 1 addition & 1 deletion core/rpc/src/state/tests.rs
Original file line number Diff line number Diff line change
Expand Up @@ -282,7 +282,7 @@ fn should_return_runtime_version() {
\"specVersion\":1,\"implVersion\":1,\"apis\":[[\"0xdf6acb689907609b\",2],\
[\"0x37e397fc7c91f5e4\",1],[\"0xd2bc9897eed08f15\",1],[\"0x40fe3ad401f8959a\",3],\
[\"0xc6e9a76309f39b09\",1],[\"0xdd718d5cc53262d4\",1],[\"0xcbca25e39f142387\",1],\
[\"0xf78b278be53f454c\",1],[\"0xab3c0572291feb8b\",1]]}";
[\"0xf78b278be53f454c\",1],[\"0xab3c0572291feb8b\",1],[\"0xbc9d89904f5b923f\",1]]}";

let runtime_version = api.runtime_version(None.into()).wait().unwrap();
let serialized = serde_json::to_string(&runtime_version).unwrap();
Expand Down
2 changes: 2 additions & 0 deletions core/test-runtime/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@ cfg-if = "0.1.10"
srml-babe = { path = "../../srml/babe", default-features = false }
srml-timestamp = { path = "../../srml/timestamp", default-features = false }
srml-system = { path = "../../srml/system", default-features = false }
srml-system-rpc-runtime-api = { path = "../../srml/system/rpc/runtime-api", default-features = false }

[dev-dependencies]
substrate-executor = { path = "../executor" }
Expand Down Expand Up @@ -68,6 +69,7 @@ std = [
"srml-babe/std",
"srml-timestamp/std",
"srml-system/std",
"srml-system-rpc-runtime-api/std",
"app-crypto/std",
"session/std",
]
12 changes: 12 additions & 0 deletions core/test-runtime/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -648,6 +648,12 @@ cfg_if! {
SessionKeys::generate(None)
}
}

impl srml_system_rpc_runtime_api::AccountNonceApi<Block, AccountId, Index> for Runtime {
fn account_nonce(_account: AccountId) -> Index {
0
}
}
}
} else {
impl_runtime_apis! {
Expand Down Expand Up @@ -858,6 +864,12 @@ cfg_if! {
SessionKeys::generate(None)
}
}

impl srml_system_rpc_runtime_api::AccountNonceApi<Block, AccountId, Index> for Runtime {
fn account_nonce(_account: AccountId) -> Index {
0
}
}
}
}
}
Expand Down
19 changes: 6 additions & 13 deletions core/test-runtime/src/system.rs
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@
//! and depositing logs.

use rstd::prelude::*;
use runtime_io::{storage_root, storage_changes_root, twox_128, blake2_256};
use runtime_io::{storage_root, storage_changes_root, blake2_256};
use runtime_support::storage::{self, StorageValue, StorageMap};
use runtime_support::storage_items;
use sr_primitives::{
Expand Down Expand Up @@ -170,22 +170,14 @@ pub fn validate_transaction(utx: Extrinsic) -> TransactionValidity {
return InvalidTransaction::Future.into();
}

let hash = |from: &AccountId, nonce: u64| {
twox_128(&nonce.to_keyed_vec(&from.encode())).to_vec()
};
let encode = |from: &AccountId, nonce: u64| (from, nonce).encode();
let requires = if tx.nonce != expected_nonce && tx.nonce > 0 {
let mut deps = Vec::new();
deps.push(hash(&tx.from, tx.nonce - 1));
deps
vec![encode(&tx.from, tx.nonce - 1)]
} else {
Vec::new()
vec![]
};

let provides = {
let mut p = Vec::new();
p.push(hash(&tx.from, tx.nonce));
p
};
let provides = vec![encode(&tx.from, tx.nonce)];

Ok(ValidTransaction {
priority: tx.amount,
Expand Down Expand Up @@ -324,6 +316,7 @@ mod tests {
use crate::{Header, Transfer, WASM_BINARY};
use primitives::{NeverNativeValue, map, traits::CodeExecutor};
use substrate_executor::{NativeExecutor, WasmExecutionMethod, native_executor_instance};
use runtime_io::twox_128;

// Declare an instance of the native executor dispatch for the test runtime.
native_executor_instance!(
Expand Down
8 changes: 0 additions & 8 deletions node/primitives/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -5,11 +5,7 @@ authors = ["Parity Technologies <admin@parity.io>"]
edition = "2018"

[dependencies]
client = { package = "substrate-client", path = "../../core/client", default-features = false }
codec = { package = "parity-scale-codec", version = "1.0.0", default-features = false, features = ["derive"] }
primitives = { package = "substrate-primitives", path = "../../core/primitives", default-features = false }
rstd = { package = "sr-std", path = "../../core/sr-std", default-features = false }
serde = { version = "1.0.101", optional = true, features = ["derive"] }
sr-primitives = { path = "../../core/sr-primitives", default-features = false }

[dev-dependencies]
Expand All @@ -19,10 +15,6 @@ pretty_assertions = "0.6.1"
[features]
default = ["std"]
std = [
"client/std",
"codec/std",
"primitives/std",
"rstd/std",
"serde",
"sr-primitives/std",
]
45 changes: 0 additions & 45 deletions node/primitives/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -20,15 +20,10 @@

#![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;

Expand Down Expand Up @@ -72,43 +67,3 @@ 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;
}
}
17 changes: 2 additions & 15 deletions node/rpc/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -7,21 +7,8 @@ edition = "2018"
[dependencies]
client = { package = "substrate-client", path = "../../core/client" }
jsonrpc-core = "13.2.0"
jsonrpc-core-client = "13.2.0"
jsonrpc-derive = "13.2.0"
jsonrpc-pubsub = "13.2.0"
keyring = { package = "substrate-keyring", path = "../../core/keyring" }
log = "0.4.8"
node-primitives = { path = "../primitives" }
codec = { package = "parity-scale-codec", version = "1.0.0" }
serde = { version = "1.0.101", features = ["derive"] }
sr-primitives = { path = "../../core/sr-primitives" }
substrate-primitives = { path = "../../core/primitives" }
rpc-primitives = { package = "substrate-rpc-primitives", path = "../../core/rpc/primitives" }
srml-contracts-rpc = { path = "../../srml/contracts/rpc/" }
srml-system-rpc = { path = "../../srml/system/rpc/" }
transaction_pool = { package = "substrate-transaction-pool", path = "../../core/transaction-pool" }

[dev-dependencies]
node-testing = { path = "../testing" }
node-runtime = { path = "../runtime" }
env_logger = "0.7.0"
futures03 = { package = "futures-preview", version = "=0.3.0-alpha.19" }
25 changes: 7 additions & 18 deletions node/rpc/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -25,43 +25,32 @@
//! The RPCs available in this crate however can make some assumptions
//! about how the runtime is constructed and what `SRML` modules
//! are part of it. Therefore all node-runtime-specific RPCs can
//! be placed here.
//! be placed here or imported from corresponding `SRML` RPC definitions.
#![warn(missing_docs)]

use std::sync::Arc;

use node_primitives::{Block, AccountNonceApi, ContractsApi};
use node_primitives::{Block, AccountId, Index, Balance};
use sr_primitives::traits::ProvideRuntimeApi;
use transaction_pool::txpool::{ChainApi, Pool};

pub mod accounts;
pub mod contracts;

mod constants {
/// A status code indicating an error happened while trying to call into the runtime.
///
/// This typically means that the runtime trapped.
pub const RUNTIME_ERROR: i64 = 1;
}

/// Instantiate all RPC extensions.
pub fn create<C, P, M>(client: Arc<C>, pool: Arc<Pool<P>>) -> jsonrpc_core::IoHandler<M> where
C: ProvideRuntimeApi,
C: client::blockchain::HeaderBackend<Block>,
C: Send + Sync + 'static,
C::Api: AccountNonceApi<Block> + ContractsApi<Block>,
C::Api: srml_system_rpc::AccountNonceApi<Block, AccountId, Index>,
C::Api: srml_contracts_rpc::ContractsRuntimeApi<Block, AccountId, Balance>,
P: ChainApi + Sync + Send + 'static,
M: jsonrpc_core::Metadata + Default,
{
use self::{
accounts::{Accounts, AccountsApi},
contracts::{Contracts, ContractsApi},
};
use srml_system_rpc::{System, SystemApi};
use srml_contracts_rpc::{Contracts, ContractsApi};

let mut io = jsonrpc_core::IoHandler::default();
io.extend_with(
AccountsApi::to_delegate(Accounts::new(client.clone(), pool))
SystemApi::to_delegate(System::new(client.clone(), pool))
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Very detailed but to avoid confusion with similar names defined in node/runtime I would consider renaming these structs that implement rpc api to some name that suggests more clearly what they are doing, e.g.

Suggested change
SystemApi::to_delegate(System::new(client.clone(), pool))
SystemApi::to_delegate(SystemRpcHandler::new(client.clone(), pool))

);
io.extend_with(
ContractsApi::to_delegate(Contracts::new(client))
Expand Down
Loading