Skip to content

Commit

Permalink
Merge pull request #1495 from multiversx/multisig-unified
Browse files Browse the repository at this point in the history
Unified syntax in multisig
  • Loading branch information
andrei-marinica authored Mar 27, 2024
2 parents 5603c27 + 335a54e commit 04a5f97
Show file tree
Hide file tree
Showing 8 changed files with 231 additions and 175 deletions.
2 changes: 1 addition & 1 deletion contracts/examples/multisig/interact/config.toml
Original file line number Diff line number Diff line change
@@ -1,2 +1,2 @@
gateway = 'https://testnet-gateway.multiversx.com'
gateway = 'https://devnet-gateway.multiversx.com'
quorum = 2
132 changes: 76 additions & 56 deletions contracts/examples/multisig/interact/src/multisig_interact.rs
Original file line number Diff line number Diff line change
Expand Up @@ -6,27 +6,26 @@ mod multisig_interact_wegld;

use clap::Parser;
use multisig::{
multisig_perform::ProxyTrait as _, multisig_propose::ProxyTrait as _,
multisig_state::ProxyTrait as _, ProxyTrait as _,
multisig_perform::ProxyTrait as _, multisig_propose::ProxyTrait as _, multisig_proxy,
ProxyTrait as _,
};
use multisig_interact_config::Config;
use multisig_interact_state::State;
use multiversx_sc_modules::dns::ProxyTrait as _;
use multiversx_sc_scenario::{
mandos_system::ScenarioRunner, multiversx_sc::codec::multi_types::IgnoreValue,
mandos_system::ScenarioRunner,
multiversx_sc::types::{BigUint, ReturnsNewAddress, ReturnsResult},
scenario_format::interpret_trait::InterpretableFrom,
standalone::retrieve_account_as_scenario_set_state, test_wallets,
standalone::retrieve_account_as_scenario_set_state,
test_wallets,
};
use multiversx_sc_snippets::{
dns_address_for_name, env_logger,
multiversx_sc::{
codec::multi_types::MultiValueVec, storage::mappers::SingleValue, types::Address,
},
multiversx_sc::{codec::multi_types::MultiValueVec, types::Address},
multiversx_sc_scenario::{
api::StaticApi, bech32, scenario_format::interpret_trait::InterpreterContext,
scenario_model::*, ContractInfo,
},
tokio, Interactor, StepBuffer,
tokio, Interactor, InteractorPrepareAsync, StepBuffer,
};

const SYSTEM_SC_BECH32: &str = "erd1qqqqqqqqqqqqqqqpqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqzllls8a5w6u";
Expand Down Expand Up @@ -160,23 +159,21 @@ impl MultisigInteract {
self.set_state().await;

let board = self.board();
let (new_address, _) = self

let new_address = self
.interactor
.sc_deploy_get_result::<_, IgnoreValue>(
ScDeployStep::new()
.call(
self.state
.default_multisig()
.init(Config::load_config().quorum(), board),
)
.from(&self.wallet_address)
.code(&self.multisig_code)
.gas_limit("100,000,000")
.expect(TxExpect::ok().additional_error_message("deploy failed: ")),
)
.tx()
.from(&self.wallet_address)
.typed(multisig_proxy::MultisigProxy)
.init(&Config::load_config().quorum(), board)
.code(&self.multisig_code)
.with_gas_limit(100_000_000u64)
.returns(ReturnsNewAddress)
.prepare_async()
.run()
.await;

let new_address_bech32 = bech32::encode(&new_address);
let new_address_bech32 = bech32::encode(&new_address.to_address());
println!("new address: {new_address_bech32}");

let new_address_expr = format!("bech32:{new_address_bech32}");
Expand Down Expand Up @@ -243,33 +240,31 @@ impl MultisigInteract {
}

async fn feed_contract_egld(&mut self) {
let _ = self
.interactor
.transfer(
TransferStep::new()
.from(&self.wallet_address)
.to(self.state.multisig())
.egld_value("0,050000000000000000"),
)
self.interactor
.tx()
.from(&self.wallet_address)
.to(self.state.multisig().to_address())
.egld(BigUint::from(50_000_000_000_000_000u64)) // 0,05 or 5 * 10^16
.prepare_async()
.run()
.await;
}

async fn perform_action(&mut self, action_id: usize, gas_expr: &str) {
async fn perform_action(&mut self, action_id: usize, gas_expr: u64) {
if !self.quorum_reached(action_id).await && !self.sign(action_id).await {
return;
}
println!("quorum reached for action `{action_id}`");

self.interactor
.sc_call(
ScCallStep::new()
.call(self.state.multisig().perform_action_endpoint(action_id))
.from(&self.wallet_address)
.gas_limit(gas_expr)
.expect(TxExpect::ok().additional_error_message(format!(
"perform action `{action_id}` failed with: "
))),
)
.tx()
.from(&self.wallet_address)
.to(self.state.multisig().to_address())
.with_gas_limit(gas_expr)
.typed(multisig_proxy::MultisigProxy)
.perform_action_endpoint(action_id)
.prepare_async()
.run()
.await;

println!("successfully performed action `{action_id}`");
Expand Down Expand Up @@ -310,13 +305,25 @@ impl MultisigInteract {

async fn quorum_reached(&mut self, action_id: usize) -> bool {
self.interactor
.quick_query(self.state.multisig().quorum_reached(action_id))
.query()
.to(self.state.multisig().to_address())
.typed(multisig_proxy::MultisigProxy)
.quorum_reached(action_id)
.returns(ReturnsResult)
.prepare_async()
.run()
.await
}

async fn signed(&mut self, signer: &Address, action_id: usize) -> bool {
self.interactor
.quick_query(self.state.multisig().signed(signer, action_id))
.query()
.to(self.state.multisig().to_address())
.typed(multisig_proxy::MultisigProxy)
.signed(signer, action_id)
.returns(ReturnsResult)
.prepare_async()
.run()
.await
}

Expand Down Expand Up @@ -361,33 +368,46 @@ impl MultisigInteract {
async fn dns_register(&mut self, name: &str) {
let dns_address = dns_address_for_name(name);
self.interactor
.sc_call(
ScCallStep::new()
.call(self.state.multisig().dns_register(dns_address, name))
.from(&self.wallet_address)
.gas_limit("30,000,000")
.expect(TxExpect::ok().additional_error_message("dns register failed with: ")),
)
.tx()
.from(&self.wallet_address)
.to(self.state.multisig().to_address())
.with_gas_limit(30_000_000u64)
.typed(multisig_proxy::MultisigProxy)
.dns_register(dns_address, name)
.prepare_async()
.run()
.await;

println!("successfully registered dns");
}

async fn print_quorum(&mut self) {
let quorum: SingleValue<usize> = self
let quorum = self
.interactor
.quick_query(self.state.multisig().quorum())
.query()
.to(self.state.multisig().to_address())
.typed(multisig_proxy::MultisigProxy)
.quorum()
.returns(ReturnsResult)
.prepare_async()
.run()
.await;

println!("quorum: {}", quorum.into());
println!("quorum: {}", quorum);
}

async fn print_board(&mut self) {
let board: SingleValue<usize> = self
let board = self
.interactor
.quick_query(self.state.multisig().num_board_members())
.query()
.to(self.state.multisig().to_address())
.typed(multisig_proxy::MultisigProxy)
.num_board_members()
.returns(ReturnsResult)
.prepare_async()
.run()
.await;

println!("board: {}", board.into());
println!("board: {}", board);
}
}
Loading

0 comments on commit 04a5f97

Please sign in to comment.