Skip to content

Commit

Permalink
Expose num_actions as a method on PaddingRule
Browse files Browse the repository at this point in the history
  • Loading branch information
nuttycom committed Dec 8, 2023
1 parent 5ebf22d commit 9ff6d6f
Showing 1 changed file with 19 additions and 13 deletions.
32 changes: 19 additions & 13 deletions src/builder.rs
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,22 @@ impl PaddingRule {
/// The default padding rule, which ensures that the constructed bundle will contain at least 2
/// actions if any genuine Orchard spends or outputs are requested.
pub const DEFAULT: PaddingRule = PaddingRule::PadTo(MIN_ACTIONS);

pub fn num_actions(&self, num_spends: usize, num_recipients: usize) -> usize {
let num_real_actions = core::cmp::max(num_spends, num_recipients);

match self {
PaddingRule::Require(n) => core::cmp::max(num_real_actions, *n),
PaddingRule::PadTo(n) => {
if num_real_actions == 0 {
0
} else {
core::cmp::max(num_real_actions, *n)
}
}
PaddingRule::None => num_real_actions,
}
}
}

/// An error type for the kinds of errors that can occur during bundle construction.
Expand Down Expand Up @@ -414,19 +430,9 @@ impl Builder {
) -> Result<Bundle<InProgress<Unproven, Unauthorized>, V>, BuildError> {
let num_real_spends = self.spends.len();
let num_real_recipients = self.recipients.len();
let num_real_actions = core::cmp::max(num_real_spends, num_real_recipients);

let num_actions = match self.padding_rule {
PaddingRule::Require(n) => core::cmp::max(num_real_actions, n),
PaddingRule::PadTo(n) => {
if num_real_actions == 0 {
0
} else {
core::cmp::max(num_real_actions, n)
}
}
PaddingRule::None => num_real_actions,
};
let num_actions = self
.padding_rule
.num_actions(num_real_spends, num_real_recipients);

// Pair up the spends and recipients, extending with dummy values as necessary.
let pre_actions: Vec<_> = {
Expand Down

0 comments on commit 9ff6d6f

Please sign in to comment.