Skip to content

Commit

Permalink
feat: functionality update for smove, enabling gas estimation in mult…
Browse files Browse the repository at this point in the history
…i-signer case
  • Loading branch information
neutrinoks committed Mar 25, 2024
1 parent e6b9e48 commit d68cfec
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 3 deletions.
22 changes: 20 additions & 2 deletions pallet/src/balance.rs
Original file line number Diff line number Diff line change
Expand Up @@ -69,14 +69,34 @@ impl<T: Config + SysConfig> BalanceAdapter<T> {
}
}

/// Creates a new [`BalanceAdapter`] with unlimited cheque-limits for every signer for the
/// usage within a dry-run. Therefor, the extracted arguments and the signer count of a given
/// script transaction has to be provided.
pub fn for_dry_run(args: &[&[u8]], signer_count: usize) -> Result<BalanceAdapter<T>, Error<T>> {
let mut handler = BalanceAdapter::new();

let accounts = Pallet::<T>::extract_account_ids_from_args(args, signer_count)?;

for acc in &accounts {
handler.write_cheque_internal(acc, &BalanceOf::<T>::from(u128::MAX));
}

Ok(handler)
}

/// Writes a cheque for the account.
pub fn write_cheque(
&mut self,
account: &AccountIdOf<T>,
balance: &BalanceOf<T>,
) -> DispatchResult {
self.ensure_can_withdraw(account, balance)?;
self.write_cheque_internal(account, balance);
Ok(())
}

// Internal method for writing the cheque.
fn write_cheque_internal(&mut self, account: &AccountIdOf<T>, balance: &BalanceOf<T>) {
let account: EncodedAccount = account.encode();

let mut cheques = self.cheques.borrow_mut();
Expand All @@ -91,8 +111,6 @@ impl<T: Config + SysConfig> BalanceAdapter<T> {
} else {
self.initial_state.insert(account.clone(), *balance);
}

Ok(())
}

/// Executes the true transactions on the blockchain/substrate side after execution of
Expand Down
2 changes: 1 addition & 1 deletion pallet/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -515,7 +515,7 @@ pub mod pallet {
.map_err(|e| format!("error in get_resource: {e:?}").into())
}

fn extract_account_ids_from_args(
pub(crate) fn extract_account_ids_from_args(
script_args: &[&[u8]],
signer_count: usize,
) -> Result<Vec<T::AccountId>, Error<T>> {
Expand Down

0 comments on commit d68cfec

Please sign in to comment.