soil_rpc/api/author/mod.rs
1// This file is part of Soil.
2
3// Copyright (C) Soil contributors.
4// Copyright (C) Parity Technologies (UK) Ltd.
5// SPDX-License-Identifier: GPL-3.0-or-later WITH Classpath-exception-2.0
6
7//! Substrate block-author/full-node API.
8
9use error::Error;
10use jsonrpsee::proc_macros::rpc;
11use soil_client::transaction_pool::TransactionStatus;
12use subsoil::core::Bytes;
13
14pub mod error;
15pub mod hash;
16
17/// Output of [`AuthorApiServer::rotate_keys_with_owner`].
18#[derive(serde::Serialize, serde::Deserialize, Clone)]
19pub struct GeneratedSessionKeys {
20 /// The public session keys for registering them on chain.
21 pub keys: Bytes,
22
23 /// The `proof` for verifying ownership of the generated session keys.
24 ///
25 /// This will be `None` iff the chain doesn't support generating the `proof`.
26 #[serde(skip_serializing_if = "Option::is_none")]
27 #[serde(default)]
28 pub proof: Option<Bytes>,
29}
30
31/// Substrate authoring RPC API
32#[rpc(client, server)]
33pub trait AuthorApi<Hash, BlockHash> {
34 /// Submit hex-encoded extrinsic for inclusion in block.
35 #[method(name = "author_submitExtrinsic")]
36 async fn submit_extrinsic(&self, extrinsic: Bytes) -> Result<Hash, Error>;
37
38 /// Insert a key into the keystore.
39 #[method(name = "author_insertKey", with_extensions)]
40 fn insert_key(&self, key_type: String, suri: String, public: Bytes) -> Result<(), Error>;
41
42 /// Generate new session keys and returns the corresponding public keys.
43 #[method(name = "author_rotateKeys", with_extensions)]
44 fn rotate_keys(&self) -> Result<Bytes, Error>;
45
46 /// Generate new session keys and returns the corresponding public keys.
47 ///
48 /// The `owner` should be something that can be used on chain for verifying the ownership of the
49 /// generated keys using the returned `proof`. For example, `owner` could be set to the account
50 /// id of the account registering the returned public session keys. The actual data to pass for
51 /// `owner` depends on the runtime logic verifying the `proof`.
52 #[method(name = "author_rotateKeysWithOwner", with_extensions)]
53 fn rotate_keys_with_owner(&self, owner: Bytes) -> Result<GeneratedSessionKeys, Error>;
54
55 /// Checks if the keystore has private keys for the given session public keys.
56 ///
57 /// `session_keys` is the SCALE encoded session keys object from the runtime.
58 ///
59 /// Returns `true` iff all private keys could be found.
60 #[method(name = "author_hasSessionKeys", with_extensions)]
61 fn has_session_keys(&self, session_keys: Bytes) -> Result<bool, Error>;
62
63 /// Checks if the keystore has private keys for the given public key and key type.
64 ///
65 /// Returns `true` if a private key could be found.
66 #[method(name = "author_hasKey", with_extensions)]
67 fn has_key(&self, public_key: Bytes, key_type: String) -> Result<bool, Error>;
68
69 /// Returns all pending extrinsics, potentially grouped by sender.
70 #[method(name = "author_pendingExtrinsics")]
71 fn pending_extrinsics(&self) -> Result<Vec<Bytes>, Error>;
72
73 /// Remove given extrinsic from the pool and temporarily ban it to prevent reimporting.
74 #[method(name = "author_removeExtrinsic", with_extensions)]
75 async fn remove_extrinsic(
76 &self,
77 bytes_or_hash: Vec<hash::ExtrinsicOrHash<Hash>>,
78 ) -> Result<Vec<Hash>, Error>;
79
80 /// Submit an extrinsic to watch.
81 ///
82 /// See [`TransactionStatus`] for details on
83 /// transaction life cycle.
84 #[subscription(
85 name = "author_submitAndWatchExtrinsic" => "author_extrinsicUpdate",
86 unsubscribe = "author_unwatchExtrinsic",
87 item = TransactionStatus<Hash, BlockHash>,
88 )]
89 fn watch_extrinsic(&self, bytes: Bytes);
90}