Skip to content

Commit

Permalink
A0-1361: cliain: Add possibility to query NextKeys for a specified Ac…
Browse files Browse the repository at this point in the history
…countId (#620)
  • Loading branch information
krzysztofziobro authored Sep 15, 2022
1 parent 7f04f01 commit 6337f12
Show file tree
Hide file tree
Showing 13 changed files with 61 additions and 19 deletions.
2 changes: 1 addition & 1 deletion aleph-client/Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion aleph-client/Cargo.toml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
[package]
name = "aleph_client"
version = "1.5.2"
version = "1.5.3"
edition = "2021"
license = "Apache 2.0"

Expand Down
7 changes: 4 additions & 3 deletions aleph-client/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -22,9 +22,10 @@ pub use primitives::{Balance, BlockHash, BlockNumber, Header};
pub use rpc::{emergency_finalize, rotate_keys, rotate_keys_raw_result, state_query_storage_at};
pub use session::{
change_next_era_reserved_validators, change_validators, get_current_session,
get_current_validator_count, get_current_validators, get_session, get_session_first_block,
get_session_period, get_validators_for_session, set_keys, wait_for as wait_for_session,
wait_for_at_least as wait_for_at_least_session, Keys as SessionKeys,
get_current_validator_count, get_current_validators, get_next_session_keys, get_session,
get_session_first_block, get_session_period, get_validators_for_session, set_keys,
wait_for as wait_for_session, wait_for_at_least as wait_for_at_least_session,
Keys as SessionKeys,
};
use sp_core::{ed25519, sr25519, storage::StorageKey, Pair, H256};
pub use staking::{
Expand Down
7 changes: 7 additions & 0 deletions aleph-client/src/session.rs
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,13 @@ impl TryFrom<String> for Keys {
}
}

pub fn get_next_session_keys<C: AnyConnection>(
connection: &C,
account_id: AccountId,
) -> Option<Keys> {
connection.read_storage_map(PALLET, "NextKeys", account_id, None)
}

pub fn change_validators(
sudo_connection: &RootConnection,
new_reserved_validators: Option<Vec<AccountId>>,
Expand Down
2 changes: 1 addition & 1 deletion benches/payout-stakers/Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

5 changes: 3 additions & 2 deletions bin/cliain/Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

3 changes: 2 additions & 1 deletion bin/cliain/Cargo.toml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
[package]
name = "cliain"
version = "0.5.1"
version = "0.5.2"
edition = "2021"
license = "GPL-3.0-or-later"

Expand All @@ -12,6 +12,7 @@ codec = { package = 'parity-scale-codec', version = "3.0.0", features = ['derive
contract-metadata = { git = "https://github.com/paritytech/cargo-contract.git", tag = "v1.4.0"}
contract-transcode = { version = "0.1.0" }
dialoguer = "0.10.0"
hex = "0.4.3"
env_logger = "0.8"
ink_metadata = { version = "3.0", features = ["derive"] }
log = "0.4"
Expand Down
7 changes: 7 additions & 0 deletions bin/cliain/src/commands.rs
Original file line number Diff line number Diff line change
Expand Up @@ -164,6 +164,13 @@ pub enum Command {
finalizer_seed: Option<String>,
},

/// Gets next session keys for a validator with specified AccountId
NextSessionKeys {
/// SS58 id of the validator for which we want to retrieve the keys
#[clap(long)]
account_id: String,
},

/// Declare the desire to nominate target account
Nominate {
#[clap(long)]
Expand Down
23 changes: 20 additions & 3 deletions bin/cliain/src/keys.rs
Original file line number Diff line number Diff line change
@@ -1,9 +1,12 @@
use aleph_client::{
rotate_keys as rotate, rotate_keys_raw_result, set_keys as set, staking_bond, AnyConnection,
RootConnection, SessionKeys, SignedConnection,
get_next_session_keys, rotate_keys as rotate, rotate_keys_raw_result, set_keys as set,
staking_bond, AnyConnection, Connection, RootConnection, SessionKeys, SignedConnection,
};
use log::info;
use hex::ToHex;
use log::{error, info};
use primitives::staking::MIN_VALIDATOR_BOND;
use serde_json::json;
use sp_core::crypto::Ss58Codec;
use substrate_api_client::{AccountId, XtStatus};

pub fn prepare_keys(connection: RootConnection, controller_account_id: AccountId) {
Expand All @@ -29,3 +32,17 @@ pub fn rotate_keys<C: AnyConnection>(connection: C) {
let new_keys = rotate_keys_raw_result(&connection).expect("Failed to retrieve keys");
info!("Rotated keys: {:?}", new_keys);
}

pub fn next_session_keys(connection: &Connection, account_id: String) {
let account_id = AccountId::from_ss58check(&account_id).expect("Address is valid");
match get_next_session_keys(connection, account_id) {
Some(keys) => {
let keys_json = json!({
"aura": "0x".to_owned() + keys.aura.encode_hex::<String>().as_str(),
"aleph": "0x".to_owned() + keys.aleph.encode_hex::<String>().as_str(),
});
println!("{}", serde_json::to_string_pretty(&keys_json).unwrap());
}
None => error!("No keys set for the specified account."),
}
}
12 changes: 10 additions & 2 deletions bin/cliain/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -10,11 +10,13 @@ mod treasury;
mod validators;
mod vesting;

use aleph_client::{keypair_from_string, RootConnection, SignedConnection};
use aleph_client::{
create_connection, keypair_from_string, Connection, RootConnection, SignedConnection,
};
pub use commands::Command;
pub use contracts::{call, instantiate, instantiate_with_code, remove_code, upload_code};
pub use finalization::{finalize, set_emergency_finalizer};
pub use keys::{prepare_keys, rotate_keys, set_keys};
pub use keys::{next_session_keys, prepare_keys, rotate_keys, set_keys};
pub use runtime::update_runtime;
pub use secret::prompt_password_hidden;
pub use staking::{bond, force_new_era, nominate, set_staking_limits, validate};
Expand All @@ -39,6 +41,12 @@ impl ConnectionConfig {
}
}

impl From<ConnectionConfig> for Connection {
fn from(cfg: ConnectionConfig) -> Self {
create_connection(cfg.node_endpoint.as_str())
}
}

impl From<ConnectionConfig> for SignedConnection {
fn from(cfg: ConnectionConfig) -> Self {
let key = keypair_from_string(&cfg.signer_seed);
Expand Down
4 changes: 3 additions & 1 deletion bin/cliain/src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ use aleph_client::{
use clap::Parser;
use cliain::{
bond, call, change_validators, finalize, force_new_era, instantiate, instantiate_with_code,
nominate, prepare_keys, prompt_password_hidden, remove_code, rotate_keys,
next_session_keys, nominate, prepare_keys, prompt_password_hidden, remove_code, rotate_keys,
set_emergency_finalizer, set_keys, set_staking_limits, transfer, treasury_approve,
treasury_propose, treasury_reject, update_runtime, upload_code, validate, vest, vest_other,
vested_transfer, Command, ConnectionConfig,
Expand Down Expand Up @@ -40,6 +40,7 @@ fn read_seed(command: &Command, seed: Option<String>) -> String {
hash: _,
finalizer_seed: _,
}
| Command::NextSessionKeys { account_id: _ }
| Command::RotateKeys
| Command::DebugStorage
| Command::SeedToSS58 { input: _ } => String::new(),
Expand Down Expand Up @@ -114,6 +115,7 @@ fn main() {
Command::TreasuryApprove { proposal_id } => treasury_approve(cfg.into(), proposal_id),
Command::TreasuryReject { proposal_id } => treasury_reject(cfg.into(), proposal_id),
Command::RotateKeys => rotate_keys::<SignedConnection>(cfg.into()),
Command::NextSessionKeys { account_id } => next_session_keys(&cfg.into(), account_id),
Command::SetStakingLimits {
minimal_nominator_stake,
minimal_validator_stake,
Expand Down
4 changes: 1 addition & 3 deletions e2e-tests/Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion flooder/Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

0 comments on commit 6337f12

Please sign in to comment.