mirror of
https://github.com/pezkuwichain/pezkuwi-subxt.git
synced 2026-05-30 15:11:02 +00:00
add authority discovery module (#444)
This commit is contained in:
committed by
Robert Habermeier
parent
4f4baa9b07
commit
821a59ca8d
@@ -55,7 +55,8 @@ use sr_staking_primitives::SessionIndex;
|
||||
use srml_support::{
|
||||
parameter_types, construct_runtime, traits::{SplitTwoWays, Currency}
|
||||
};
|
||||
use im_online::sr25519::{AuthorityId as ImOnlineId};
|
||||
use authority_discovery_primitives::{AuthorityId as EncodedAuthorityId, Signature as EncodedSignature};
|
||||
use im_online::sr25519::{AuthorityId as ImOnlineId, AuthoritySignature as ImOnlineSignature};
|
||||
use system::offchain::TransactionSubmitter;
|
||||
|
||||
#[cfg(feature = "std")]
|
||||
@@ -242,7 +243,7 @@ parameter_types! {
|
||||
pub const Offset: BlockNumber = 0;
|
||||
}
|
||||
|
||||
type SessionHandlers = (Grandpa, Babe, ImOnline, Parachains);
|
||||
type SessionHandlers = (Grandpa, Babe, ImOnline, AuthorityDiscovery, Parachains);
|
||||
impl_opaque_keys! {
|
||||
pub struct SessionKeys {
|
||||
#[id(key_types::GRANDPA)]
|
||||
@@ -444,6 +445,8 @@ impl im_online::Trait for Runtime {
|
||||
type ReportUnresponsiveness = ();
|
||||
}
|
||||
|
||||
impl authority_discovery::Trait for Runtime {}
|
||||
|
||||
impl grandpa::Trait for Runtime {
|
||||
type Event = Event;
|
||||
}
|
||||
@@ -530,6 +533,7 @@ construct_runtime!(
|
||||
FinalityTracker: finality_tracker::{Module, Call, Inherent},
|
||||
Grandpa: grandpa::{Module, Call, Storage, Config, Event},
|
||||
ImOnline: im_online::{Module, Call, Storage, Event<T>, ValidateUnsigned, Config<T>},
|
||||
AuthorityDiscovery: authority_discovery::{Module, Call, Config<T>},
|
||||
|
||||
// Governance stuff; uncallable initially.
|
||||
Democracy: democracy::{Module, Call, Storage, Config, Event<T>},
|
||||
@@ -684,6 +688,35 @@ impl_runtime_apis! {
|
||||
}
|
||||
}
|
||||
|
||||
impl authority_discovery_primitives::AuthorityDiscoveryApi<Block> for Runtime {
|
||||
fn authorities() -> Vec<EncodedAuthorityId> {
|
||||
AuthorityDiscovery::authorities().into_iter()
|
||||
.map(|id| id.encode())
|
||||
.map(EncodedAuthorityId)
|
||||
.collect()
|
||||
}
|
||||
|
||||
fn sign(payload: &Vec<u8>) -> Option<(EncodedSignature, EncodedAuthorityId)> {
|
||||
AuthorityDiscovery::sign(payload).map(|(sig, id)| {
|
||||
(EncodedSignature(sig.encode()), EncodedAuthorityId(id.encode()))
|
||||
})
|
||||
}
|
||||
|
||||
fn verify(payload: &Vec<u8>, signature: &EncodedSignature, authority_id: &EncodedAuthorityId) -> bool {
|
||||
let signature = match ImOnlineSignature::decode(&mut &signature.0[..]) {
|
||||
Ok(s) => s,
|
||||
_ => return false,
|
||||
};
|
||||
|
||||
let authority_id = match ImOnlineId::decode(&mut &authority_id.0[..]) {
|
||||
Ok(id) => id,
|
||||
_ => return false,
|
||||
};
|
||||
|
||||
AuthorityDiscovery::verify(payload, signature, authority_id)
|
||||
}
|
||||
}
|
||||
|
||||
impl substrate_session::SessionKeys<Block> for Runtime {
|
||||
fn generate_session_keys(seed: Option<Vec<u8>>) -> Vec<u8> {
|
||||
let seed = seed.as_ref().map(|s| rstd::str::from_utf8(&s).expect("Seed is an utf8 string"));
|
||||
|
||||
Reference in New Issue
Block a user