|
1 | 1 | use std::env;
|
2 | 2 |
|
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 | +}; |
4 | 15 | use clap::Parser;
|
5 | 16 | use cliain::{
|
6 | 17 | 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 {
|
36 | 47 | hash: _,
|
37 | 48 | finalizer_seed: _,
|
38 | 49 | }
|
| 50 | + | Command::Multisig |
39 | 51 | | Command::NextSessionKeys { account_id: _ }
|
40 | 52 | | Command::RotateKeys
|
41 | 53 | | Command::SeedToSS58 { input: _ }
|
@@ -244,6 +256,64 @@ async fn main() -> anyhow::Result<()> {
|
244 | 256 | Ok(_) => {}
|
245 | 257 | Err(why) => error!("Unable to schedule an upgrade {:?}", why),
|
246 | 258 | },
|
| 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 | + } |
247 | 317 | }
|
248 | 318 | Ok(())
|
249 | 319 | }
|
|
0 commit comments