sc_rpc_api/author/
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 block-author/full-node API.
20
21pub mod error;
22pub mod hash;
23
24use error::Error;
25use jsonrpsee::proc_macros::rpc;
26use sc_transaction_pool_api::TransactionStatus;
27use sp_core::Bytes;
28
29/// Substrate authoring RPC API
30#[rpc(client, server)]
31pub trait AuthorApi<Hash, BlockHash> {
32	/// Submit hex-encoded extrinsic for inclusion in block.
33	#[method(name = "author_submitExtrinsic")]
34	async fn submit_extrinsic(&self, extrinsic: Bytes) -> Result<Hash, Error>;
35
36	/// Insert a key into the keystore.
37	#[method(name = "author_insertKey", with_extensions)]
38	fn insert_key(&self, key_type: String, suri: String, public: Bytes) -> Result<(), Error>;
39
40	/// Generate new session keys and returns the corresponding public keys.
41	#[method(name = "author_rotateKeys", with_extensions)]
42	fn rotate_keys(&self) -> Result<Bytes, Error>;
43
44	/// Checks if the keystore has private keys for the given session public keys.
45	///
46	/// `session_keys` is the SCALE encoded session keys object from the runtime.
47	///
48	/// Returns `true` iff all private keys could be found.
49	#[method(name = "author_hasSessionKeys", with_extensions)]
50	fn has_session_keys(&self, session_keys: Bytes) -> Result<bool, Error>;
51
52	/// Checks if the keystore has private keys for the given public key and key type.
53	///
54	/// Returns `true` if a private key could be found.
55	#[method(name = "author_hasKey", with_extensions)]
56	fn has_key(&self, public_key: Bytes, key_type: String) -> Result<bool, Error>;
57
58	/// Returns all pending extrinsics, potentially grouped by sender.
59	#[method(name = "author_pendingExtrinsics")]
60	fn pending_extrinsics(&self) -> Result<Vec<Bytes>, Error>;
61
62	/// Remove given extrinsic from the pool and temporarily ban it to prevent reimporting.
63	#[method(name = "author_removeExtrinsic", with_extensions)]
64	fn remove_extrinsic(
65		&self,
66		bytes_or_hash: Vec<hash::ExtrinsicOrHash<Hash>>,
67	) -> Result<Vec<Hash>, Error>;
68
69	/// Submit an extrinsic to watch.
70	///
71	/// See [`TransactionStatus`](sc_transaction_pool_api::TransactionStatus) for details on
72	/// transaction life cycle.
73	#[subscription(
74		name = "author_submitAndWatchExtrinsic" => "author_extrinsicUpdate",
75		unsubscribe = "author_unwatchExtrinsic",
76		item = TransactionStatus<Hash, BlockHash>,
77	)]
78	fn watch_extrinsic(&self, bytes: Bytes);
79}