Companion for #13683 (#6944)

* Companion for #13683

* Wraps trait is not required

* update lockfile for {"substrate"}

---------

Co-authored-by: parity-processbot <>
This commit is contained in:
Davide Galassi
2023-03-24 15:43:21 +01:00
committed by GitHub
parent bd209c2d70
commit 260d073658
14 changed files with 228 additions and 247 deletions
+7 -10
View File
@@ -49,9 +49,9 @@ use polkadot_primitives::{
ValidatorSignature,
};
pub use rand;
use sp_application_crypto::AppKey;
use sp_application_crypto::AppCrypto;
use sp_core::ByteArray;
use sp_keystore::{Error as KeystoreError, Keystore, KeystorePtr};
use sp_keystore::{Error as KeystoreError, KeystorePtr};
use std::time::Duration;
use thiserror::Error;
@@ -276,7 +276,7 @@ pub fn signing_key_and_index(
keystore: &KeystorePtr,
) -> Option<(ValidatorId, ValidatorIndex)> {
for (i, v) in validators.iter().enumerate() {
if Keystore::has_keys(&**keystore, &[(v.to_raw_vec(), ValidatorId::ID)]) {
if keystore.has_keys(&[(v.to_raw_vec(), ValidatorId::ID)]) {
return Some((v.clone(), ValidatorIndex(i as _)))
}
}
@@ -292,13 +292,10 @@ pub fn sign(
key: &ValidatorId,
data: &[u8],
) -> Result<Option<ValidatorSignature>, KeystoreError> {
let signature = Keystore::sign_with(&**keystore, ValidatorId::ID, &key.into(), &data)?;
match signature {
Some(sig) =>
Ok(Some(sig.try_into().map_err(|_| KeystoreError::KeyNotSupported(ValidatorId::ID))?)),
None => Ok(None),
}
let signature = keystore
.sr25519_sign(ValidatorId::ID, key.as_ref(), data)?
.map(|sig| sig.into());
Ok(signature)
}
/// Find the validator group the given validator index belongs to.
@@ -21,7 +21,7 @@ use std::num::NonZeroUsize;
use lru::LruCache;
use parity_scale_codec::Encode;
use sp_application_crypto::AppKey;
use sp_application_crypto::AppCrypto;
use sp_core::crypto::ByteArray;
use sp_keystore::{Keystore, KeystorePtr};