diff --git a/substrate/core/rpc/src/state/mod.rs b/substrate/core/rpc/src/state/mod.rs index 0e90198ffa5445ae1fd2aef0ba0bc1ab8e4f212f..ff5404460d5df8eb759a19c97041b21f4eb45d2a 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<u8>, Trailing<Hash>) -> Result<Vec<u8>>; + fn call(&self, String, Bytes, Trailing<Hash>) -> Result<Bytes>; /// Returns a storage entry at a specific block's state. #[rpc(name = "state_getStorage", alias = ["state_getStorageAt", ])] @@ -121,10 +121,17 @@ impl<B, E, Block> StateApi<Block::Hash> for State<B, E, Block> where { type Metadata = ::metadata::Metadata; - fn call(&self, method: String, data: Vec<u8>, block: Trailing<Block::Hash>) -> Result<Vec<u8>> { + fn call(&self, method: String, data: Bytes, block: Trailing<Block::Hash>) -> Result<Bytes> { 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<Block::Hash>) -> Result<Option<StorageData>> { diff --git a/substrate/core/rpc/src/state/tests.rs b/substrate/core/rpc/src/state/tests.rs index bad934b8405a30d095d52ddd3d9f15d5bf679dee..8c401ec1bbf84f70f5c9f2ddfffa207ad1215e33 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(_)), _)) ) }