From bf1dbdc95921462b0678e9a12ec3e9fefd1b9cd6 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Piotr=20Miko=C5=82ajczyk?= Date: Thu, 5 Jan 2023 16:00:40 +0100 Subject: [PATCH] playground updated --- bin/cliain/src/commands.rs | 2 ++ bin/cliain/src/main.rs | 72 +++++++++++++++++++++++++++++++++++++- 2 files changed, 73 insertions(+), 1 deletion(-) diff --git a/bin/cliain/src/commands.rs b/bin/cliain/src/commands.rs index 1847a6f849..e0004271e6 100644 --- a/bin/cliain/src/commands.rs +++ b/bin/cliain/src/commands.rs @@ -361,4 +361,6 @@ pub enum Command { #[clap(long, value_enum, default_value_t=ExtrinsicState::Finalized)] expected_state: ExtrinsicState, }, + + Multisig, } diff --git a/bin/cliain/src/main.rs b/bin/cliain/src/main.rs index ff06959770..0fac39cb19 100644 --- a/bin/cliain/src/main.rs +++ b/bin/cliain/src/main.rs @@ -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, @@ -36,6 +47,7 @@ fn read_seed(command: &Command, seed: Option) -> String { hash: _, finalizer_seed: _, } + | Command::Multisig | Command::NextSessionKeys { account_id: _ } | Command::RotateKeys | Command::SeedToSS58 { input: _ } @@ -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::>(); + + 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(()) }