mirror of
https://github.com/pezkuwichain/pezkuwi-subxt.git
synced 2026-04-29 11:27:58 +00:00
Introduces author_hasKey and author_hasSessionKeys rpc endpoints (#4720)
* Introduces `author_hasKey` and `author_hasSessionKeys` rpc endpoints Both endpoints can be used to check if a key is present in the keystore. - `hasKey` works on with an individual public key and key type. It checks if a private key for the given combination exists in the keystore. - `hasSessionKeys` works with the full encoded session key blob stored on-chain in `nextKeys`. This requires that the given blob can be decoded by the runtime. It will return `true`, iff all public keys of the session key exist in the storage. Fixes: https://github.com/paritytech/substrate/issues/4696 * Update client/rpc-api/src/author/error.rs Co-Authored-By: Nikolay Volf <nikvolf@gmail.com> * Indentation Co-authored-by: Nikolay Volf <nikvolf@gmail.com>
This commit is contained in:
@@ -112,6 +112,22 @@ where
|
||||
).map(Into::into).map_err(|e| Error::Client(Box::new(e)))
|
||||
}
|
||||
|
||||
fn has_session_keys(&self, session_keys: Bytes) -> Result<bool> {
|
||||
let best_block_hash = self.client.chain_info().best_hash;
|
||||
let keys = self.client.runtime_api().decode_session_keys(
|
||||
&generic::BlockId::Hash(best_block_hash),
|
||||
session_keys.to_vec(),
|
||||
).map_err(|e| Error::Client(Box::new(e)))?
|
||||
.ok_or_else(|| Error::InvalidSessionKeys)?;
|
||||
|
||||
Ok(self.keystore.read().has_keys(&keys))
|
||||
}
|
||||
|
||||
fn has_key(&self, public_key: Bytes, key_type: String) -> Result<bool> {
|
||||
let key_type = key_type.as_str().try_into().map_err(|_| Error::BadKeyType)?;
|
||||
Ok(self.keystore.read().has_keys(&[(public_key.to_vec(), key_type)]))
|
||||
}
|
||||
|
||||
fn submit_extrinsic(&self, ext: Bytes) -> FutureResult<TxHash<P>> {
|
||||
let xt = match Decode::decode(&mut &ext[..]) {
|
||||
Ok(xt) => xt,
|
||||
|
||||
Reference in New Issue
Block a user