sc_rpc_api/child_state/
mod.rs

1// This file is part of Substrate.
2
3// Copyright (C) Parity Technologies (UK) Ltd.
4// SPDX-License-Identifier: GPL-3.0-or-later WITH Classpath-exception-2.0
5
6// This program is free software: you can redistribute it and/or modify
7// it under the terms of the GNU General Public License as published by
8// the Free Software Foundation, either version 3 of the License, or
9// (at your option) any later version.
10
11// This program is distributed in the hope that it will be useful,
12// but WITHOUT ANY WARRANTY; without even the implied warranty of
13// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14// GNU General Public License for more details.
15
16// You should have received a copy of the GNU General Public License
17// along with this program. If not, see <https://www.gnu.org/licenses/>.
18
19//! Substrate child state API
20use crate::state::{Error, ReadProof};
21use jsonrpsee::proc_macros::rpc;
22use sp_core::storage::{PrefixedStorageKey, StorageData, StorageKey};
23
24/// Substrate child state API
25///
26/// Note that all `PrefixedStorageKey` are deserialized
27/// from json and not guaranteed valid.
28#[rpc(client, server)]
29pub trait ChildStateApi<Hash> {
30	/// Returns the keys with prefix from a child storage, leave empty to get all the keys
31	#[method(name = "childstate_getKeys", blocking)]
32	#[deprecated(since = "2.0.0", note = "Please use `getKeysPaged` with proper paging support")]
33	fn storage_keys(
34		&self,
35		child_storage_key: PrefixedStorageKey,
36		prefix: StorageKey,
37		hash: Option<Hash>,
38	) -> Result<Vec<StorageKey>, Error>;
39
40	/// Returns the keys with prefix from a child storage with pagination support.
41	/// Up to `count` keys will be returned.
42	/// If `start_key` is passed, return next keys in storage in lexicographic order.
43	#[method(name = "childstate_getKeysPaged", aliases = ["childstate_getKeysPagedAt"], blocking)]
44	fn storage_keys_paged(
45		&self,
46		child_storage_key: PrefixedStorageKey,
47		prefix: Option<StorageKey>,
48		count: u32,
49		start_key: Option<StorageKey>,
50		hash: Option<Hash>,
51	) -> Result<Vec<StorageKey>, Error>;
52
53	/// Returns a child storage entry at a specific block's state.
54	#[method(name = "childstate_getStorage", blocking)]
55	fn storage(
56		&self,
57		child_storage_key: PrefixedStorageKey,
58		key: StorageKey,
59		hash: Option<Hash>,
60	) -> Result<Option<StorageData>, Error>;
61
62	/// Returns child storage entries for multiple keys at a specific block's state.
63	#[method(name = "childstate_getStorageEntries", blocking)]
64	fn storage_entries(
65		&self,
66		child_storage_key: PrefixedStorageKey,
67		keys: Vec<StorageKey>,
68		hash: Option<Hash>,
69	) -> Result<Vec<Option<StorageData>>, Error>;
70
71	/// Returns the hash of a child storage entry at a block's state.
72	#[method(name = "childstate_getStorageHash", blocking)]
73	fn storage_hash(
74		&self,
75		child_storage_key: PrefixedStorageKey,
76		key: StorageKey,
77		hash: Option<Hash>,
78	) -> Result<Option<Hash>, Error>;
79
80	/// Returns the size of a child storage entry at a block's state.
81	#[method(name = "childstate_getStorageSize", blocking)]
82	fn storage_size(
83		&self,
84		child_storage_key: PrefixedStorageKey,
85		key: StorageKey,
86		hash: Option<Hash>,
87	) -> Result<Option<u64>, Error>;
88
89	/// Returns proof of storage for child key entries at a specific block's state.
90	#[method(name = "state_getChildReadProof", blocking)]
91	fn read_child_proof(
92		&self,
93		child_storage_key: PrefixedStorageKey,
94		keys: Vec<StorageKey>,
95		hash: Option<Hash>,
96	) -> Result<ReadProof<Hash>, Error>;
97}