Skip to content
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: 17 additions & 5 deletions src/builder.rs
Original file line number Diff line number Diff line change
Expand Up @@ -464,6 +464,18 @@ impl Builder {
i64::try_from(value_balance).and_then(|i| V::try_from(i).map_err(|_| value::OverflowError))
}

/// Returns the number of actions to add to this bundle in order to contain at least MIN_ACTION actions.
fn num_missing_actions(&self) -> usize {
let num_actions = [self.spends.len(), self.recipients.len()]
.iter()
.max()
.cloned()
.unwrap();
(num_actions < MIN_ACTIONS)
.then(|| MIN_ACTIONS - num_actions)
.unwrap_or(0)
}

/// Builds a bundle containing the given spent notes and recipients.
///
/// The returned bundle will have no proof or signatures; these can be applied with
Expand All @@ -480,11 +492,11 @@ impl Builder {
{
let num_spends = spends.len();
let num_recipients = recipients.len();
let num_actions = [num_spends, num_recipients, MIN_ACTIONS]
.iter()
.max()
.cloned()
.unwrap();
let mut num_actions = [num_spends, num_recipients].iter().max().cloned().unwrap();
// We might have to add dummy/split actions only for the first asset to reach MIN_ACTIONS.
pre_actions
.is_empty()
.then(|| num_actions += self.num_missing_actions());

let first_spend = spends.first().cloned();

Expand Down
8 changes: 4 additions & 4 deletions tests/zsa.rs
Original file line number Diff line number Diff line change
Expand Up @@ -408,7 +408,7 @@ fn zsa_issue_and_transfer() {
],
vec![],
anchor,
4,
2,
&keys,
)
.unwrap();
Expand Down Expand Up @@ -436,7 +436,7 @@ fn zsa_issue_and_transfer() {
],
vec![],
native_anchor,
5,
4,
&keys,
)
.unwrap();
Expand Down Expand Up @@ -468,7 +468,7 @@ fn zsa_issue_and_transfer() {
],
vec![],
anchor_t7,
4,
2,
&keys,
)
.unwrap();
Expand All @@ -489,7 +489,7 @@ fn zsa_issue_and_transfer() {
],
vec![],
anchor_t7,
4,
2,
&keys,
)
.unwrap();
Expand Down