Skip to content

Commit bf1dbdc

Browse files
playground updated
1 parent 556fba5 commit bf1dbdc

File tree

2 files changed

+73
-1
lines changed

2 files changed

+73
-1
lines changed

bin/cliain/src/commands.rs

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -361,4 +361,6 @@ pub enum Command {
361361
#[clap(long, value_enum, default_value_t=ExtrinsicState::Finalized)]
362362
expected_state: ExtrinsicState,
363363
},
364+
365+
Multisig,
364366
}

bin/cliain/src/main.rs

Lines changed: 71 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,17 @@
11
use std::env;
22

3-
use aleph_client::{account_from_keypair, aleph_keypair_from_string, keypair_from_string, Pair};
3+
use aleph_client::{
4+
account_from_keypair, aleph_keypair_from_string,
5+
aleph_runtime::RuntimeCall,
6+
keypair_from_string,
7+
pallet_balances::pallet::Call,
8+
pallets::multisig::{
9+
compute_call_hash, ContextAfterUse, MultisigContextualApi, MultisigParty,
10+
DEFAULT_MAX_WEIGHT,
11+
},
12+
Pair, SignedConnection,
13+
TxStatus::Finalized,
14+
};
415
use clap::Parser;
516
use cliain::{
617
bond, call, change_validators, finalize, force_new_era, instantiate, instantiate_with_code,
@@ -36,6 +47,7 @@ fn read_seed(command: &Command, seed: Option<String>) -> String {
3647
hash: _,
3748
finalizer_seed: _,
3849
}
50+
| Command::Multisig
3951
| Command::NextSessionKeys { account_id: _ }
4052
| Command::RotateKeys
4153
| Command::SeedToSS58 { input: _ }
@@ -244,6 +256,64 @@ async fn main() -> anyhow::Result<()> {
244256
Ok(_) => {}
245257
Err(why) => error!("Unable to schedule an upgrade {:?}", why),
246258
},
259+
260+
Command::Multisig => {
261+
let _0 = keypair_from_string("//0");
262+
let _1 = keypair_from_string("//1");
263+
let _2 = keypair_from_string("//2");
264+
265+
let keys = [
266+
keypair_from_string("//0"),
267+
keypair_from_string("//1"),
268+
keypair_from_string("//2"),
269+
];
270+
let accounts = keys
271+
.iter()
272+
.map(|k| account_from_keypair(k.signer()))
273+
.collect::<Vec<_>>();
274+
275+
let threshold = 3;
276+
let party =
277+
MultisigParty::new(&accounts, threshold).expect("Failed to create multisig party");
278+
279+
let call = RuntimeCall::Balances(Call::transfer {
280+
dest: accounts[1].clone().into(),
281+
value: 0,
282+
});
283+
284+
let conn_0 = SignedConnection::from_connection(cfg.get_connection().await, _0);
285+
let (_, context) = conn_0
286+
.initiate(
287+
&party,
288+
&DEFAULT_MAX_WEIGHT,
289+
compute_call_hash(&call),
290+
Finalized,
291+
)
292+
.await
293+
.expect("failed to initiate multisig aggregation");
294+
295+
let conn_1 = SignedConnection::from_connection(cfg.get_connection().await, _1);
296+
let (_, context) = conn_1
297+
.approve(context, Finalized)
298+
.await
299+
.expect("failed to approve");
300+
301+
let context = match context {
302+
ContextAfterUse::Ongoing(context) => context,
303+
ContextAfterUse::Closed(_) => panic!("Process should continue"),
304+
};
305+
306+
let conn_2 = SignedConnection::from_connection(cfg.get_connection().await, _2);
307+
let (_, context) = conn_2
308+
.approve_with_call(context, Some(call), Finalized)
309+
.await
310+
.expect("failed to execute");
311+
312+
match context {
313+
ContextAfterUse::Ongoing(_) => panic!("Failed to conclude aggregation"),
314+
ContextAfterUse::Closed(_) => {}
315+
};
316+
}
247317
}
248318
Ok(())
249319
}

0 commit comments

Comments
 (0)