Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: functionality update for smove (multi-signer case) #162

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
Loading