From 067c6f9c745a51ed97771f6852a7126d153289d8 Mon Sep 17 00:00:00 2001 From: "Demi M. Obenour" Date: Wed, 3 Jun 2020 00:49:55 -0400 Subject: [PATCH] Implement `set_keys` This is needed for Ledgeracio. --- Cargo.toml | 5 +++++ src/frame/session.rs | 16 +++++++++++++++ src/lib.rs | 1 - src/runtimes.rs | 46 ++++++++++++++++++++++++++++++++++++++++++++ 4 files changed, 67 insertions(+), 1 deletion(-) diff --git a/Cargo.toml b/Cargo.toml index 254d303767..8ab63c2956 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -38,6 +38,11 @@ sp-core = { version = "2.0.0-rc2", package = "sp-core" } sc-rpc-api = { version = "0.8.0-rc2", package = "sc-rpc-api" } sp-transaction-pool = { version = "2.0.0-rc2", package = "sp-transaction-pool" } substrate-subxt-proc-macro = { version = "0.8.0", path = "proc-macro" } +sp-std = "2.0.0-rc2" +sp-finality-grandpa = "2.0.0-rc2" +sp-consensus-babe = "0.8.0-rc2" +pallet-im-online = "2.0.0-rc2" +sp-authority-discovery = "2.0.0-rc2" [dev-dependencies] async-std = { version = "1.5.0", features = ["attributes"] } diff --git a/src/frame/session.rs b/src/frame/session.rs index de534ba7ff..d0ffa0eb32 100644 --- a/src/frame/session.rs +++ b/src/frame/session.rs @@ -22,6 +22,10 @@ use crate::frame::system::{ }; use codec::Encode; use frame_support::Parameter; +use sp_runtime::traits::{ + Member, + OpaqueKeys, +}; use std::{ fmt::Debug, marker::PhantomData, @@ -36,6 +40,9 @@ pub trait Session: System { /// The validator account identifier type for the runtime. type SessionIndex: Parameter + Debug + Ord + Default + Send + Sync + 'static; + + /// The keys. + type Keys: OpaqueKeys + Member + Parameter + Default; } /// The current set of validators. @@ -62,3 +69,12 @@ pub struct QueuedChangedStore { /// Marker for the runtime pub _runtime: PhantomData, } + +/// The current set of validators. +#[derive(Encode, Call)] +pub struct SetKeysCall { + /// The keys + pub keys: T::Keys, + /// The proof. This is not currently used and can be set to an empty vector. + pub proof: Vec, +} diff --git a/src/lib.rs b/src/lib.rs index 5c28706056..df03eb63b9 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -21,7 +21,6 @@ bad_style, const_err, improper_ctypes, - missing_docs, non_shorthand_field_patterns, no_mangle_generic_items, overflowing_literals, diff --git a/src/runtimes.rs b/src/runtimes.rs index c7a02044c1..011897c5c2 100644 --- a/src/runtimes.rs +++ b/src/runtimes.rs @@ -13,9 +13,12 @@ // // You should have received a copy of the GNU General Public License // along with substrate-subxt. If not, see . +#![allow(missing_docs)] +use pallet_im_online::sr25519::AuthorityId as ImOnlineId; use sp_runtime::{ generic::Header, + impl_opaque_keys, traits::{ BlakeTwo256, IdentifyAccount, @@ -24,6 +27,47 @@ use sp_runtime::{ MultiSignature, OpaqueExtrinsic, }; +use sp_std::prelude::*; + +/// BABE marker struct +pub struct Babe; +impl sp_runtime::BoundToRuntimeAppPublic for Babe { + type Public = sp_consensus_babe::AuthorityId; +} + +/// ImOnline marker struct +pub struct ImOnline; +impl sp_runtime::BoundToRuntimeAppPublic for ImOnline { + type Public = ImOnlineId; +} + +/// GRANDPA marker struct +pub struct Grandpa; +impl sp_runtime::BoundToRuntimeAppPublic for Grandpa { + type Public = sp_finality_grandpa::AuthorityId; +} + +use sp_authority_discovery::AuthorityId as AuthorityDiscoveryId; + +/// Authority discovery marker struct +pub struct AuthorityDiscovery; +impl sp_runtime::BoundToRuntimeAppPublic for AuthorityDiscovery { + type Public = AuthorityDiscoveryId; +} + +impl_opaque_keys! { + /// Runtime keys + pub struct SessionKeys { + //// GRANDPA session key + pub grandpa: Grandpa, + //// BABE session key + pub babe: Babe, + //// ImOnline session key + pub im_online: ImOnline, + //// AuthorityDiscovery session key + pub authority_discovery: AuthorityDiscovery, + } +} use crate::frame::{ balances::{ @@ -73,6 +117,7 @@ impl Balances for DefaultNodeRuntime { impl Session for DefaultNodeRuntime { type SessionIndex = u32; type ValidatorId = ::AccountId; + type Keys = SessionKeys; } impl Contracts for DefaultNodeRuntime {} @@ -101,6 +146,7 @@ impl System for KusamaRuntime { impl Session for KusamaRuntime { type SessionIndex = u32; type ValidatorId = ::AccountId; + type Keys = SessionKeys; } impl Staking for KusamaRuntime {