Skip to content

Commit cca49bf

Browse files
committed
Remove new RPC and fix up some comments
1 parent d004457 commit cca49bf

File tree

4 files changed

+37
-54
lines changed

4 files changed

+37
-54
lines changed

substrate/client/rpc-api/src/author/mod.rs

Lines changed: 0 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -54,15 +54,6 @@ pub trait AuthorApi<Hash, BlockHash> {
5454
#[method(name = "author_rotateKeys")]
5555
fn rotate_keys(&self) -> RpcResult<Bytes>;
5656

57-
/// Generate new session keys and returns the corresponding public keys.
58-
///
59-
/// The `owner` should be something that can be used on chain for verifying the ownership of the
60-
/// generated keys using the returned `proof`. For example `owner` could be set to the account
61-
/// id of the account registering the returned public session keys. The actual data to pass for
62-
/// `owner` depends on the runtime logic verifying the `proof`.
63-
#[method(name = "author_rotateKeysWithOwner")]
64-
fn rotate_keys_with_owner(&self, owner: Bytes) -> RpcResult<GeneratedSessionKeys>;
65-
6657
/// Checks if the keystore has private keys for the given session public keys.
6758
///
6859
/// `session_keys` is the SCALE encoded session keys object from the runtime.

substrate/client/rpc/src/author/mod.rs

Lines changed: 28 additions & 43 deletions
Original file line numberDiff line numberDiff line change
@@ -75,45 +75,6 @@ impl<P, Client> Author<P, Client> {
7575
}
7676
}
7777

78-
impl<P, Client> Author<P, Client>
79-
where
80-
P: TransactionPool + Sync + Send + 'static,
81-
Client: HeaderBackend<P::Block> + ProvideRuntimeApi<P::Block> + Send + Sync + 'static,
82-
Client::Api: SessionKeys<P::Block>,
83-
P::Hash: Unpin,
84-
<P::Block as BlockT>::Hash: Unpin,
85-
{
86-
fn rotate_keys_impl(&self, owner: Vec<u8>) -> RpcResult<GeneratedSessionKeys> {
87-
self.deny_unsafe.check_if_safe()?;
88-
89-
let best_block_hash = self.client.info().best_hash;
90-
let mut runtime_api = self.client.runtime_api();
91-
92-
runtime_api.register_extension(KeystoreExt::from(self.keystore.clone()));
93-
94-
let version = runtime_api
95-
.api_version::<dyn SessionKeys<P::Block>>(best_block_hash)
96-
.map_err(|api_err| Error::Client(Box::new(api_err)))?
97-
.ok_or_else(|| Error::MissingSessionKeysApi)?;
98-
99-
if version < 2 {
100-
#[allow(deprecated)]
101-
runtime_api
102-
.generate_session_keys_before_version_2(best_block_hash, None)
103-
.map(|sk| GeneratedSessionKeys { keys: sk.into(), proof: None })
104-
.map_err(|api_err| Error::Client(Box::new(api_err)).into())
105-
} else {
106-
runtime_api
107-
.generate_session_keys(best_block_hash, owner, None)
108-
.map(|sk| GeneratedSessionKeys {
109-
keys: sk.keys.into(),
110-
proof: Some(sk.proof.into()),
111-
})
112-
.map_err(|api_err| Error::Client(Box::new(api_err)).into())
113-
}
114-
}
115-
}
116-
11778
/// Currently we treat all RPC transactions as externals.
11879
///
11980
/// Possibly in the future we could allow opt-in for special treatment
@@ -158,11 +119,35 @@ where
158119
}
159120

160121
fn rotate_keys(&self) -> RpcResult<Bytes> {
161-
self.rotate_keys_impl(Vec::new()).map(|k| k.keys)
162-
}
122+
self.deny_unsafe.check_if_safe()?;
123+
124+
let best_block_hash = self.client.info().best_hash;
125+
let mut runtime_api = self.client.runtime_api();
126+
127+
runtime_api.register_extension(KeystoreExt::from(self.keystore.clone()));
128+
129+
let version = runtime_api
130+
.api_version::<dyn SessionKeys<P::Block>>(best_block_hash)
131+
.map_err(|api_err| Error::Client(Box::new(api_err)))?
132+
.ok_or_else(|| Error::MissingSessionKeysApi)?;
133+
134+
let res = if version < 2 {
135+
#[allow(deprecated)]
136+
runtime_api
137+
.generate_session_keys_before_version_2(best_block_hash, None)
138+
.map(|sk| GeneratedSessionKeys { keys: sk.into(), proof: None })
139+
.map_err(|api_err| Error::Client(Box::new(api_err)))
140+
} else {
141+
runtime_api
142+
.generate_session_keys(best_block_hash, Vec::new(), None)
143+
.map(|sk| GeneratedSessionKeys {
144+
keys: sk.keys.into(),
145+
proof: Some(sk.proof.into()),
146+
})
147+
.map_err(|api_err| Error::Client(Box::new(api_err)))
148+
}?;
163149

164-
fn rotate_keys_with_owner(&self, owner: Bytes) -> RpcResult<GeneratedSessionKeys> {
165-
self.rotate_keys_impl(owner.0)
150+
Ok(res.keys)
166151
}
167152

168153
fn has_session_keys(&self, session_keys: Bytes) -> RpcResult<bool> {

substrate/primitives/runtime/src/traits.rs

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2159,7 +2159,8 @@ macro_rules! impl_opaque_keys_inner {
21592159
/// Contains the public session keys and a `proof` to verify the ownership of these keys.
21602160
///
21612161
/// To generate session keys the [`impl_opaque_keys!`](crate::impl_opaque_keys) needs to be used
2162-
/// first to create the session keys type and this type provides the `generate` function.
2162+
/// first to create the session keys type and this type provides the `generate` function which
2163+
/// output is this type.
21632164
#[derive(Debug, Clone, Encode, Decode, TypeInfo)]
21642165
pub struct GeneratedSessionKeys {
21652166
/// The opaque public session keys for registering on-chain.

substrate/primitives/session/src/lib.rs

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -37,10 +37,16 @@ sp_api::decl_runtime_apis! {
3737
#[api_version(2)]
3838
pub trait SessionKeys {
3939
/// Generate a set of session keys with optionally using the given seed.
40+
///
4041
/// The keys should be stored within the keystore exposed via runtime
4142
/// externalities.
4243
///
43-
/// The seed needs to be a valid `utf8` string.
44+
/// - `owner`: The `owner` will be used for constructing a `proof` of ownership of the
45+
/// generated session keys. This is used by the on-chain logic to verify the ownership.
46+
/// The data for `owner` depends on the runtime implementation, e.g. for FRAME this should
47+
/// be the SCALE encoded account id.
48+
/// - `seed`: A `seed/phrase` that is used to construct the private key. If `None`,
49+
/// a random private key is generated.
4450
///
4551
/// Returns the concatenated SCALE encoded public keys.
4652
fn generate_session_keys(owner: Vec<u8>, seed: Option<Vec<u8>>) -> GeneratedSessionKeys;

0 commit comments

Comments
 (0)