Skip to content

Commit

Permalink
playground updated
Browse files Browse the repository at this point in the history
  • Loading branch information
pmikolajczyk41 committed Jan 5, 2023
1 parent 556fba5 commit bf1dbdc
Show file tree
Hide file tree
Showing 2 changed files with 73 additions and 1 deletion.
2 changes: 2 additions & 0 deletions bin/cliain/src/commands.rs
Original file line number Diff line number Diff line change
Expand Up @@ -361,4 +361,6 @@ pub enum Command {
#[clap(long, value_enum, default_value_t=ExtrinsicState::Finalized)]
expected_state: ExtrinsicState,
},

Multisig,
}
72 changes: 71 additions & 1 deletion bin/cliain/src/main.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1,17 @@
use std::env;

use aleph_client::{account_from_keypair, aleph_keypair_from_string, keypair_from_string, Pair};
use aleph_client::{
account_from_keypair, aleph_keypair_from_string,
aleph_runtime::RuntimeCall,
keypair_from_string,
pallet_balances::pallet::Call,
pallets::multisig::{
compute_call_hash, ContextAfterUse, MultisigContextualApi, MultisigParty,
DEFAULT_MAX_WEIGHT,
},
Pair, SignedConnection,
TxStatus::Finalized,
};
use clap::Parser;
use cliain::{
bond, call, change_validators, finalize, force_new_era, instantiate, instantiate_with_code,
Expand Down Expand Up @@ -36,6 +47,7 @@ fn read_seed(command: &Command, seed: Option<String>) -> String {
hash: _,
finalizer_seed: _,
}
| Command::Multisig
| Command::NextSessionKeys { account_id: _ }
| Command::RotateKeys
| Command::SeedToSS58 { input: _ }
Expand Down Expand Up @@ -244,6 +256,64 @@ async fn main() -> anyhow::Result<()> {
Ok(_) => {}
Err(why) => error!("Unable to schedule an upgrade {:?}", why),
},

Command::Multisig => {
let _0 = keypair_from_string("//0");
let _1 = keypair_from_string("//1");
let _2 = keypair_from_string("//2");

let keys = [
keypair_from_string("//0"),
keypair_from_string("//1"),
keypair_from_string("//2"),
];
let accounts = keys
.iter()
.map(|k| account_from_keypair(k.signer()))
.collect::<Vec<_>>();

let threshold = 3;
let party =
MultisigParty::new(&accounts, threshold).expect("Failed to create multisig party");

let call = RuntimeCall::Balances(Call::transfer {
dest: accounts[1].clone().into(),
value: 0,
});

let conn_0 = SignedConnection::from_connection(cfg.get_connection().await, _0);
let (_, context) = conn_0
.initiate(
&party,
&DEFAULT_MAX_WEIGHT,
compute_call_hash(&call),
Finalized,
)
.await
.expect("failed to initiate multisig aggregation");

let conn_1 = SignedConnection::from_connection(cfg.get_connection().await, _1);
let (_, context) = conn_1
.approve(context, Finalized)
.await
.expect("failed to approve");

let context = match context {
ContextAfterUse::Ongoing(context) => context,
ContextAfterUse::Closed(_) => panic!("Process should continue"),
};

let conn_2 = SignedConnection::from_connection(cfg.get_connection().await, _2);
let (_, context) = conn_2
.approve_with_call(context, Some(call), Finalized)
.await
.expect("failed to execute");

match context {
ContextAfterUse::Ongoing(_) => panic!("Failed to conclude aggregation"),
ContextAfterUse::Closed(_) => {}
};
}
}
Ok(())
}
Expand Down

0 comments on commit bf1dbdc

Please sign in to comment.