referrerpolicy=no-referrer-when-downgrade

sc_rpc_spec_v2/archive/
api.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//! API trait of the archive methods.
20
21use crate::{
22	archive::{
23		error::{Error, Infallible},
24		types::MethodResult,
25	},
26	common::events::{
27		ArchiveStorageDiffEvent, ArchiveStorageDiffItem, ArchiveStorageEvent, StorageQuery,
28	},
29};
30use jsonrpsee::proc_macros::rpc;
31
32#[rpc(client, server)]
33pub trait ArchiveApi<Hash> {
34	/// Retrieves the body (list of transactions) of a given block hash.
35	///
36	/// Returns an array of strings containing the hexadecimal-encoded SCALE-codec-encoded
37	/// transactions in that block. If no block with that hash is found, null.
38	///
39	/// # Unstable
40	///
41	/// This method is unstable and subject to change in the future.
42	#[method(name = "archive_v1_body")]
43	fn archive_v1_body(&self, hash: Hash) -> Result<Option<Vec<String>>, Infallible>;
44
45	/// Get the chain's genesis hash.
46	///
47	/// Returns a string containing the hexadecimal-encoded hash of the genesis block of the chain.
48	///
49	/// # Unstable
50	///
51	/// This method is unstable and subject to change in the future.
52	#[method(name = "archive_v1_genesisHash")]
53	fn archive_v1_genesis_hash(&self) -> Result<String, Infallible>;
54
55	/// Get the block's header.
56	///
57	/// Returns a string containing the hexadecimal-encoded SCALE-codec encoding header of the
58	/// block.
59	///
60	/// # Unstable
61	///
62	/// This method is unstable and subject to change in the future.
63	#[method(name = "archive_v1_header")]
64	fn archive_v1_header(&self, hash: Hash) -> Result<Option<String>, Infallible>;
65
66	/// Get the height of the current finalized block.
67	///
68	/// Returns an integer height of the current finalized block of the chain.
69	///
70	/// # Unstable
71	///
72	/// This method is unstable and subject to change in the future.
73	#[method(name = "archive_v1_finalizedHeight")]
74	fn archive_v1_finalized_height(&self) -> Result<u64, Infallible>;
75
76	/// Get the hashes of blocks from the given height.
77	///
78	/// Returns an array (possibly empty) of strings containing an hexadecimal-encoded hash of a
79	/// block header.
80	///
81	/// # Unstable
82	///
83	/// This method is unstable and subject to change in the future.
84	#[method(name = "archive_v1_hashByHeight")]
85	fn archive_v1_hash_by_height(&self, height: u64) -> Result<Vec<String>, Error>;
86
87	/// Call into the Runtime API at a specified block's state.
88	///
89	/// # Unstable
90	///
91	/// This method is unstable and subject to change in the future.
92	#[method(name = "archive_v1_call")]
93	fn archive_v1_call(
94		&self,
95		hash: Hash,
96		function: String,
97		call_parameters: String,
98	) -> Result<MethodResult, Error>;
99
100	/// Returns storage entries at a specific block's state.
101	///
102	/// # Unstable
103	///
104	/// This method is unstable and subject to change in the future.
105	#[subscription(
106		name = "archive_v1_storage" => "archive_v1_storageEvent",
107		unsubscribe = "archive_v1_stopStorage",
108		item = ArchiveStorageEvent,
109	)]
110	fn archive_v1_storage(
111		&self,
112		hash: Hash,
113		items: Vec<StorageQuery<String>>,
114		child_trie: Option<String>,
115	);
116
117	/// Returns the storage difference between two blocks.
118	///
119	/// # Unstable
120	///
121	/// This method is unstable and can change in minor or patch releases.
122	#[subscription(
123		name = "archive_v1_storageDiff" => "archive_v1_storageDiffEvent",
124		unsubscribe = "archive_v1_storageDiff_stopStorageDiff",
125		item = ArchiveStorageDiffEvent,
126	)]
127	fn archive_v1_storage_diff(
128		&self,
129		hash: Hash,
130		items: Vec<ArchiveStorageDiffItem<String>>,
131		previous_hash: Option<Hash>,
132	);
133}