mirror of
https://github.com/pezkuwichain/pezkuwi-subxt.git
synced 2026-06-11 17:41:08 +00:00
becc3b0a4f
* {core,srml}/authority-discovery: Move generic to specific session keys
* {srml,core}/authority-discovery: Verify signature outside of runtime
Given that the `core/authority-discovery` uses concrete authority
identifiers and signatures, one can verify a signature with the
authority discovery within `core`. Given the above, the `verify` runtime
api is obsolete and thus removed.
* *: Add authority discovery to the set of session keys
* *: Sign authority discovery DHT payload with keystore instead of runtime
Instead of calling a runtime function to sign a dht payload, which then
invokes the keystore, pass the keystore to the authority discovery
module and use it directly.
* core/authority-discovery: Give libp2p Kademlia time to start up
* core/authority-discovery: Move authorities priority group name to const
* node/runtime/src/lib.rs: Bump runtime spec version
* *: Fix lints and node/testing test failures
* *: Fix formatting
* core/authority-discovery: Box dht event channel in unit tests
* node/cli/src/service.rs: Fix future import
* node/cli/src/service.rs: Replace unwrap by expect with proof
* node/cli/src/chain_spec: Remove TODO for testnet key generation
* core/authority-discovery/src/lib: Remove scale encoding TODOs
* srml/authority-discovery: Make comment a doc comment
* core/authority-discovery: Remove unused StreamExt import
* node/runtime: Bump impl version to debug CI
* Test ci.
* Change the line width to 100.
* Revert "Change the line width to 100."
This reverts commit edff1f855bc71e0418bf3a967f81a35591d882e3.
* Fix a check for polkadot to work on forked repos.
* Revert "node/runtime: Bump impl version to debug CI"
This reverts commit 1a90903b4c929bc55a9e0a538af34b50b7f65139.
* Revert "Test ci."
This reverts commit a2c9df574e645158f77cd2b3d4d9355bcae33aab.
* Cargo.lock: Fix wrong lock file merge
* srml/authority-discovery: Keep track of new validator set not upcoming
* core/authority-discovery: Document key retrieval functions
103 lines
2.9 KiB
Rust
103 lines
2.9 KiB
Rust
// Copyright 2019 Parity Technologies (UK) Ltd.
|
|
// This file is part of Substrate.
|
|
|
|
// Substrate is free software: you can redistribute it and/or modify
|
|
// it under the terms of the GNU General Public License as published by
|
|
// the Free Software Foundation, either version 3 of the License, or
|
|
// (at your option) any later version.
|
|
|
|
// Substrate is distributed in the hope that it will be useful,
|
|
// but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
// GNU General Public License for more details.
|
|
|
|
// You should have received a copy of the GNU General Public License
|
|
// along with Substrate. If not, see <http://www.gnu.org/licenses/>.
|
|
|
|
//! Test accounts.
|
|
|
|
use keyring::{AccountKeyring, Sr25519Keyring, Ed25519Keyring};
|
|
use node_primitives::{AccountId, Balance, Index};
|
|
use node_runtime::{CheckedExtrinsic, UncheckedExtrinsic, SessionKeys, SignedExtra};
|
|
use sr_primitives::generic::Era;
|
|
use codec::Encode;
|
|
|
|
/// Alice's account id.
|
|
pub fn alice() -> AccountId { AccountKeyring::Alice.into() }
|
|
|
|
/// Bob's account id.
|
|
pub fn bob() -> AccountId {
|
|
AccountKeyring::Bob.into()
|
|
}
|
|
|
|
/// Charlie's account id.
|
|
pub fn charlie() -> AccountId {
|
|
AccountKeyring::Charlie.into()
|
|
}
|
|
|
|
/// Dave's account id.
|
|
pub fn dave() -> AccountId {
|
|
AccountKeyring::Dave.into()
|
|
}
|
|
|
|
/// Eve's account id.
|
|
pub fn eve() -> AccountId {
|
|
AccountKeyring::Eve.into()
|
|
}
|
|
|
|
/// Ferdie's account id.
|
|
pub fn ferdie() -> AccountId {
|
|
AccountKeyring::Ferdie.into()
|
|
}
|
|
|
|
/// Convert keyrings into `SessionKeys`.
|
|
pub fn to_session_keys(
|
|
ed25519_keyring: &Ed25519Keyring,
|
|
sr25519_keyring: &Sr25519Keyring,
|
|
) -> SessionKeys {
|
|
SessionKeys {
|
|
grandpa: ed25519_keyring.to_owned().public().into(),
|
|
babe: sr25519_keyring.to_owned().public().into(),
|
|
im_online: sr25519_keyring.to_owned().public().into(),
|
|
authority_discovery: sr25519_keyring.to_owned().public().into(),
|
|
}
|
|
}
|
|
|
|
/// Returns transaction extra.
|
|
pub fn signed_extra(nonce: Index, extra_fee: Balance) -> SignedExtra {
|
|
(
|
|
system::CheckVersion::new(),
|
|
system::CheckGenesis::new(),
|
|
system::CheckEra::from(Era::mortal(256, 0)),
|
|
system::CheckNonce::from(nonce),
|
|
system::CheckWeight::new(),
|
|
transaction_payment::ChargeTransactionPayment::from(extra_fee),
|
|
Default::default(),
|
|
)
|
|
}
|
|
|
|
/// Sign given `CheckedExtrinsic`.
|
|
pub fn sign(xt: CheckedExtrinsic, version: u32, genesis_hash: [u8; 32]) -> UncheckedExtrinsic {
|
|
match xt.signed {
|
|
Some((signed, extra)) => {
|
|
let payload = (xt.function, extra.clone(), version, genesis_hash, genesis_hash);
|
|
let key = AccountKeyring::from_account_id(&signed).unwrap();
|
|
let signature = payload.using_encoded(|b| {
|
|
if b.len() > 256 {
|
|
key.sign(&runtime_io::hashing::blake2_256(b))
|
|
} else {
|
|
key.sign(b)
|
|
}
|
|
}).into();
|
|
UncheckedExtrinsic {
|
|
signature: Some((indices::address::Address::Id(signed), signature, extra)),
|
|
function: payload.0,
|
|
}
|
|
}
|
|
None => UncheckedExtrinsic {
|
|
signature: None,
|
|
function: xt.function,
|
|
},
|
|
}
|
|
}
|