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
// --- crates.io ---
use serde::Serialize;
use serde_json::{json, Value};
// --- subrpcer ---
use crate::{rpc, DEFAULT_ID};

#[subrpcer_impl::rpc]
pub fn get_metadata() -> Value {
	rpc(DEFAULT_ID, "state_getMetadata", Value::Null)
}

#[subrpcer_impl::rpc]
pub fn get_runtime_version() -> Value {
	rpc(DEFAULT_ID, "state_getRuntimeVersion", Value::Null)
}

#[subrpcer_impl::rpc]
pub fn get_storage(key: impl Serialize, at: Option<impl Serialize>) -> Value {
	rpc(
		DEFAULT_ID,
		"state_getStorage",
		json!([
			key,
			at.map(|at| serde_json::to_value(at).unwrap())
				.unwrap_or(Value::Null)
		]),
	)
}

#[subrpcer_impl::rpc]
pub fn subscribe_storage(storage_keys: impl Serialize) -> Value {
	rpc(DEFAULT_ID, "state_subscribeStorage", json!([storage_keys]))
}

#[subrpcer_impl::rpc]
pub fn unsubscribe_storage(subscription_id: impl Serialize) -> Value {
	rpc(
		DEFAULT_ID,
		"state_unsubscribeStorage",
		json!([subscription_id]),
	)
}