Skip to content

Commit

Permalink
multi exec interactor migration & fix
Browse files Browse the repository at this point in the history
  • Loading branch information
andrei-marinica committed Apr 5, 2024
1 parent 9e3a529 commit f4a3205
Showing 1 changed file with 24 additions and 18 deletions.
42 changes: 24 additions & 18 deletions contracts/examples/multisig/interact/src/multisig_interact.rs
Original file line number Diff line number Diff line change
Expand Up @@ -5,15 +5,12 @@ mod multisig_interact_state;
mod multisig_interact_wegld;

use clap::Parser;
use multisig::{multisig_perform::ProxyTrait as _, multisig_proxy, ProxyTrait as _};
use multisig::multisig_proxy;
use multisig_interact_config::Config;
use multisig_interact_state::State;
use multiversx_sc_scenario::{
mandos_system::ScenarioRunner,
multiversx_sc::{
imports::OptionalValue,
types::{BigUint, ReturnsNewAddress, ReturnsResult},
},
multiversx_sc::types::{BigUint, ReturnsNewAddress, ReturnsResult},
scenario_format::interpret_trait::InterpretableFrom,
standalone::retrieve_account_as_scenario_set_state,
test_wallets, NumExpr,
Expand All @@ -25,7 +22,7 @@ use multiversx_sc_snippets::{
api::StaticApi, bech32, scenario_format::interpret_trait::InterpreterContext,
scenario_model::*, ContractInfo,
},
tokio, Interactor, InteractorPrepareAsync, StepBuffer,
tokio, Interactor, InteractorPrepareAsync,
};

const SYSTEM_SC_BECH32: &str = "erd1qqqqqqqqqqqqqqqpqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqzllls8a5w6u";
Expand Down Expand Up @@ -258,23 +255,28 @@ impl MultisigInteract {
}

async fn perform_actions(&mut self, actions: Vec<usize>, gas_expr: u64) {
let mut buffer = self.interactor.homogenous_call_buffer();
let multisig_address = self.state.multisig().to_address();
let from = &self.wallet_address;

let mut pending_action_ids = Vec::<usize>::new();
for &action_id in actions.iter() {
if self.quorum_reached(action_id).await && self.sign(action_id).await {
buffer.push_tx(|tx| {
tx.from(from)
.to(&multisig_address)
.gas(gas_expr)
.typed(multisig_proxy::MultisigProxy)
.perform_action_endpoint(action_id)
.returns(ReturnsResult)
});
pending_action_ids.push(action_id);
}
}

let from = &self.wallet_address;
let mut buffer = self.interactor.homogenous_call_buffer();
for action_id in pending_action_ids {
buffer.push_tx(|tx| {
tx.from(from)
.to(&multisig_address)
.gas(gas_expr)
.typed(multisig_proxy::MultisigProxy)
.perform_action_endpoint(action_id)
.returns(ReturnsResult)
});
}

let deployed_addresses = buffer.run().await;

for (action_id, address) in deployed_addresses.iter().enumerate() {
Expand Down Expand Up @@ -314,18 +316,22 @@ impl MultisigInteract {

async fn sign(&mut self, action_id: usize) -> bool {
println!("signing action `{action_id}`...");
let mut buffer = self.interactor.homogenous_call_buffer();
let multisig_address = self.state.multisig().to_address();

let mut pending_signers = Vec::<Address>::new();
for signer in self.board().iter() {
if self.signed(signer, action_id).await {
println!(
"{} - already signed action `{action_id}`",
bech32::encode(signer)
);
continue;
} else {
pending_signers.push(signer.clone());
}
}

let mut buffer = self.interactor.homogenous_call_buffer();
for signer in pending_signers {
buffer.push_tx(|tx| {
tx.from(signer)
.to(&multisig_address)
Expand Down

0 comments on commit f4a3205

Please sign in to comment.