Skip to content
Snippets Groups Projects
Commit f4eb08da authored by Sergey Pepyakin's avatar Sergey Pepyakin Committed by Gav Wood
Browse files

Take and return the result in bytes (#842)

parent 6d8bea51
No related merge requests found
......@@ -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>> {
......
......@@ -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(_)), _))
)
}
......
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment