From f4eb08dae5f844d75249bf773b04d311d00e73bf Mon Sep 17 00:00:00 2001 From: Sergey Pepyakin Date: Sat, 29 Sep 2018 18:56:00 +0100 Subject: [PATCH] Take and return the result in bytes (#842) --- substrate/core/rpc/src/state/mod.rs | 17 ++++++++++++----- substrate/core/rpc/src/state/tests.rs | 2 +- 2 files changed, 13 insertions(+), 6 deletions(-) diff --git a/substrate/core/rpc/src/state/mod.rs b/substrate/core/rpc/src/state/mod.rs index 0e90198ffa..ff5404460d 100644 --- a/substrate/core/rpc/src/state/mod.rs +++ b/substrate/core/rpc/src/state/mod.rs @@ -27,7 +27,7 @@ use jsonrpc_macros::pubsub; use jsonrpc_pubsub::SubscriptionId; use primitives::hexdisplay::HexDisplay; use primitives::storage::{StorageKey, StorageData, StorageChangeSet}; -use primitives::{Blake2Hasher}; +use primitives::{Blake2Hasher, Bytes}; use rpc::Result as RpcResult; use rpc::futures::{stream, Future, Sink, Stream}; use runtime_primitives::generic::BlockId; @@ -49,7 +49,7 @@ build_rpc_trait! { /// Call a contract at a block's state. #[rpc(name = "state_call", alias = ["state_callAt", ])] - fn call(&self, String, Vec, Trailing) -> Result>; + fn call(&self, String, Bytes, Trailing) -> Result; /// Returns a storage entry at a specific block's state. #[rpc(name = "state_getStorage", alias = ["state_getStorageAt", ])] @@ -121,10 +121,17 @@ impl StateApi for State where { type Metadata = ::metadata::Metadata; - fn call(&self, method: String, data: Vec, block: Trailing) -> Result> { + fn call(&self, method: String, data: Bytes, block: Trailing) -> Result { let block = self.unwrap_or_best(block)?; - trace!(target: "rpc", "Calling runtime at {:?} for method {} ({})", block, method, HexDisplay::from(&data)); - Ok(self.client.executor().call(&BlockId::Hash(block), &method, &data)?.return_data) + trace!(target: "rpc", "Calling runtime at {:?} for method {} ({})", block, method, HexDisplay::from(&data.0)); + let return_data = self.client + .executor() + .call( + &BlockId::Hash(block), + &method, &data.0 + )? + .return_data; + Ok(Bytes(return_data)) } fn storage(&self, key: StorageKey, block: Trailing) -> Result> { diff --git a/substrate/core/rpc/src/state/tests.rs b/substrate/core/rpc/src/state/tests.rs index bad934b840..8c401ec1bb 100644 --- a/substrate/core/rpc/src/state/tests.rs +++ b/substrate/core/rpc/src/state/tests.rs @@ -43,7 +43,7 @@ fn should_call_contract() { let client = State::new(client, core.executor()); assert_matches!( - client.call("balanceOf".into(), vec![1,2,3], Some(genesis_hash).into()), + client.call("balanceOf".into(), Bytes(vec![1,2,3]), Some(genesis_hash).into()), Err(Error(ErrorKind::Client(client::error::ErrorKind::Execution(_)), _)) ) }