mirror of
https://github.com/pezkuwichain/pezkuwi-subxt.git
synced 2026-06-19 03:01:02 +00:00
Take and return the result in bytes (#842)
This commit is contained in:
committed by
Gav Wood
parent
6d8bea5137
commit
f4eb08dae5
@@ -27,7 +27,7 @@ use jsonrpc_macros::pubsub;
|
|||||||
use jsonrpc_pubsub::SubscriptionId;
|
use jsonrpc_pubsub::SubscriptionId;
|
||||||
use primitives::hexdisplay::HexDisplay;
|
use primitives::hexdisplay::HexDisplay;
|
||||||
use primitives::storage::{StorageKey, StorageData, StorageChangeSet};
|
use primitives::storage::{StorageKey, StorageData, StorageChangeSet};
|
||||||
use primitives::{Blake2Hasher};
|
use primitives::{Blake2Hasher, Bytes};
|
||||||
use rpc::Result as RpcResult;
|
use rpc::Result as RpcResult;
|
||||||
use rpc::futures::{stream, Future, Sink, Stream};
|
use rpc::futures::{stream, Future, Sink, Stream};
|
||||||
use runtime_primitives::generic::BlockId;
|
use runtime_primitives::generic::BlockId;
|
||||||
@@ -49,7 +49,7 @@ build_rpc_trait! {
|
|||||||
|
|
||||||
/// Call a contract at a block's state.
|
/// Call a contract at a block's state.
|
||||||
#[rpc(name = "state_call", alias = ["state_callAt", ])]
|
#[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.
|
/// Returns a storage entry at a specific block's state.
|
||||||
#[rpc(name = "state_getStorage", alias = ["state_getStorageAt", ])]
|
#[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;
|
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)?;
|
let block = self.unwrap_or_best(block)?;
|
||||||
trace!(target: "rpc", "Calling runtime at {:?} for method {} ({})", block, method, HexDisplay::from(&data));
|
trace!(target: "rpc", "Calling runtime at {:?} for method {} ({})", block, method, HexDisplay::from(&data.0));
|
||||||
Ok(self.client.executor().call(&BlockId::Hash(block), &method, &data)?.return_data)
|
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>> {
|
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());
|
let client = State::new(client, core.executor());
|
||||||
|
|
||||||
assert_matches!(
|
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(_)), _))
|
Err(Error(ErrorKind::Client(client::error::ErrorKind::Execution(_)), _))
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user