Skip to content

Commit

Permalink
multisig: clearActionsForBatchId
Browse files Browse the repository at this point in the history
  • Loading branch information
CostinCarabas committed Dec 2, 2024
1 parent dab4a14 commit 6c13007
Showing 1 changed file with 28 additions and 4 deletions.
32 changes: 28 additions & 4 deletions multisig/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -19,8 +19,11 @@ use transaction::TxBatchSplitInFields;
use transaction::*;
use user_role::UserRole;

use core::cmp::max;
use multiversx_sc::imports::*;

const MAX_ACTIONS_INTER: usize = 10;

/// Multi-signature smart contract implementation.
/// Acts like a wallet that needs multiple signers for any action performed.
#[multiversx_sc::contract]
Expand Down Expand Up @@ -456,8 +459,11 @@ pub trait Multisig:
// if there's only one proposed action,
// the action was already cleared at the beginning of this function
if action_ids_mapper.len() > 1 {
for act_id in action_ids_mapper.values() {
self.clear_action(act_id);
for _ in 0..max(action_ids_mapper.len(), MAX_ACTIONS_INTER) {
match action_ids_mapper.values().next() {
Some(act_id) => self.clear_action(act_id),
None => sc_panic!("Could not retrieve an action id"),
};
}
}

Expand All @@ -481,8 +487,11 @@ pub trait Multisig:
// if there's only one proposed action,
// the action was already cleared at the beginning of this function
if action_ids_mapper.len() > 1 {
for act_id in action_ids_mapper.values() {
self.clear_action(act_id);
for _ in 0..max(action_ids_mapper.len(), MAX_ACTIONS_INTER) {
match action_ids_mapper.values().next() {
Some(act_id) => self.clear_action(act_id),
None => sc_panic!("Could not retrieve an action id"),
};
}
}

Expand All @@ -505,4 +514,19 @@ pub trait Multisig:
}
}
}

#[endpoint(clearActionsForBatchId)]
fn clear_actions_for_batch_id(&self, eth_batch_id: u64) {
let last_executed_eth_batch_id = self.last_executed_eth_batch_id().get();
require!(
eth_batch_id < last_executed_eth_batch_id,
"Batch needs to be already executed"
);

let action_ids_mapper = self.batch_id_to_action_id_mapping(eth_batch_id);

for act_id in action_ids_mapper.values() {
self.clear_action(act_id);
}
}
}

0 comments on commit 6c13007

Please sign in to comment.