1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
use crate::{
client::OnlineClientT,
error::Error,
Config,
};
use derivative::Derivative;
use std::{
future::Future,
marker::PhantomData,
};
#[derive(Derivative)]
#[derivative(Clone(bound = "Client: Clone"))]
pub struct RuntimeApi<T: Config, Client> {
client: Client,
block_hash: T::Hash,
_marker: PhantomData<T>,
}
impl<T: Config, Client> RuntimeApi<T, Client> {
pub(crate) fn new(client: Client, block_hash: T::Hash) -> Self {
Self {
client,
block_hash,
_marker: PhantomData,
}
}
}
impl<T, Client> RuntimeApi<T, Client>
where
T: Config,
Client: OnlineClientT<T>,
{
pub fn call_raw<'a>(
&self,
function: &'a str,
call_parameters: Option<&'a [u8]>,
) -> impl Future<Output = Result<Vec<u8>, Error>> + 'a {
let client = self.client.clone();
let block_hash = self.block_hash;
async move {
let data = client
.rpc()
.state_call(function, call_parameters, Some(block_hash))
.await?;
Ok(data.0)
}
}
}