Move srml RPC extensions to separate crates (#3791)

* Move srml-system RPC out.

* Fix tests for system-rpc module.

* Contracts RPC moved.

* Fix rpc test.

* Clean up.

* Update lockfile.

* Bump runtime version.

* Update srml/contracts/rpc/runtime-api/src/lib.rs

Co-Authored-By: Bastian Köcher <bkchr@users.noreply.github.com>

* Bump impl version.
This commit is contained in:
Tomasz Drwięga
2019-10-16 12:40:35 +02:00
committed by Gavin Wood
parent 642c8504c4
commit dc92631180
20 changed files with 344 additions and 182 deletions
+1 -1
View File
@@ -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();
+2
View File
@@ -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" }
@@ -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
View File
@@ -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! {
@@ -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
}
}
}
}
}
+6 -13
View File
@@ -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::{
@@ -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,
@@ -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!(