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
21use error::Error;
22use jsonrpsee::proc_macros::rpc;
23use sc_transaction_pool_api::TransactionStatus;
24use sp_core::Bytes;
25
26pub mod error;
27pub mod hash;
28
29/// Output of [`AuthorApiServer::rotate_keys_with_owner`].
30#[derive(serde::Serialize, serde::Deserialize, Clone)]
31pub struct GeneratedSessionKeys {
32	/// The public session keys for registering them on chain.
33	pub keys: Bytes,
34
35	/// The `proof` for verifying ownership of the generated session keys.
36	///
37	/// This will be `None` iff the chain doesn't support generating the `proof`.
38	#[serde(skip_serializing_if = "Option::is_none")]
39	#[serde(default)]
40	pub proof: Option<Bytes>,
41}
42
43/// Substrate authoring RPC API
44#[rpc(client, server)]
45pub trait AuthorApi<Hash, BlockHash> {
46	/// Submit hex-encoded extrinsic for inclusion in block.
47	#[method(name = "author_submitExtrinsic")]
48	async fn submit_extrinsic(&self, extrinsic: Bytes) -> Result<Hash, Error>;
49
50	/// Insert a key into the keystore.
51	#[method(name = "author_insertKey", with_extensions)]
52	fn insert_key(&self, key_type: String, suri: String, public: Bytes) -> Result<(), Error>;
53
54	/// Generate new session keys and returns the corresponding public keys.
55	#[method(name = "author_rotateKeys", with_extensions)]
56	fn rotate_keys(&self) -> Result<Bytes, Error>;
57
58	/// Generate new session keys and returns the corresponding public keys.
59	///
60	/// The `owner` should be something that can be used on chain for verifying the ownership of the
61	/// generated keys using the returned `proof`. For example, `owner` could be set to the account
62	/// id of the account registering the returned public session keys. The actual data to pass for
63	/// `owner` depends on the runtime logic verifying the `proof`.
64	#[method(name = "author_rotateKeysWithOwner", with_extensions)]
65	fn rotate_keys_with_owner(&self, owner: Bytes) -> Result<GeneratedSessionKeys, Error>;
66
67	/// Checks if the keystore has private keys for the given session public keys.
68	///
69	/// `session_keys` is the SCALE encoded session keys object from the runtime.
70	///
71	/// Returns `true` iff all private keys could be found.
72	#[method(name = "author_hasSessionKeys", with_extensions)]
73	fn has_session_keys(&self, session_keys: Bytes) -> Result<bool, Error>;
74
75	/// Checks if the keystore has private keys for the given public key and key type.
76	///
77	/// Returns `true` if a private key could be found.
78	#[method(name = "author_hasKey", with_extensions)]
79	fn has_key(&self, public_key: Bytes, key_type: String) -> Result<bool, Error>;
80
81	/// Returns all pending extrinsics, potentially grouped by sender.
82	#[method(name = "author_pendingExtrinsics")]
83	fn pending_extrinsics(&self) -> Result<Vec<Bytes>, Error>;
84
85	/// Remove given extrinsic from the pool and temporarily ban it to prevent reimporting.
86	#[method(name = "author_removeExtrinsic", with_extensions)]
87	async fn remove_extrinsic(
88		&self,
89		bytes_or_hash: Vec<hash::ExtrinsicOrHash<Hash>>,
90	) -> Result<Vec<Hash>, Error>;
91
92	/// Submit an extrinsic to watch.
93	///
94	/// See [`TransactionStatus`](sc_transaction_pool_api::TransactionStatus) for details on
95	/// transaction life cycle.
96	#[subscription(
97		name = "author_submitAndWatchExtrinsic" => "author_extrinsicUpdate",
98		unsubscribe = "author_unwatchExtrinsic",
99		item = TransactionStatus<Hash, BlockHash>,
100	)]
101	fn watch_extrinsic(&self, bytes: Bytes);
102}