diff --git a/src/builder.rs b/src/builder.rs index 2d01d0482..bcf0b95d7 100644 --- a/src/builder.rs +++ b/src/builder.rs @@ -46,6 +46,25 @@ 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); + + /// Returns the number of logical actions that the builder will add to the bundle + /// as a consequence of this padding rule, given the specified number of spends + /// and recipients. + 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. @@ -414,19 +433,9 @@ impl Builder { ) -> Result, 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<_> = {