Apply suggestions from code review

Co-authored-by: str4d <thestr4d@gmail.com>
This commit is contained in:
Kris Nuttycombe 2024-01-09 15:14:12 -07:00 committed by GitHub
parent b60ef5c7ea
commit 3f7acee282
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
1 changed files with 21 additions and 15 deletions

View File

@ -373,8 +373,12 @@ impl ActionInfo {
/// This is returned by [`Builder::build`]. /// This is returned by [`Builder::build`].
pub type UnauthorizedBundle<V> = Bundle<InProgress<Unproven, Unauthorized>, V>; pub type UnauthorizedBundle<V> = Bundle<InProgress<Unproven, Unauthorized>, V>;
/// Metadata about a how a transaction created by a [`bundle`] ordered actions relative to the /// Metadata about a bundle created by [`bundle`] or [`Builder::build`] that is not
/// order in which spends and outputs were provided /// necessarily recoverable from the bundle itself.
///
/// This includes information about how [`Action`]s within the bundle are ordered (after
/// padding and randomization) relative to the order in which spends and outputs were
/// provided (to [`bundle`]), or the order in which [`Builder`] mutations were performed.
#[derive(Debug, Clone, PartialEq, Eq)] #[derive(Debug, Clone, PartialEq, Eq)]
pub struct BundleMetadata { pub struct BundleMetadata {
spend_indices: Vec<usize>, spend_indices: Vec<usize>,
@ -389,29 +393,31 @@ impl BundleMetadata {
} }
} }
/// Returns a new empty [`BundleMetadata`]. /// Returns the metadata for a [`Bundle`] that contains only dummy actions, if any.
pub fn empty() -> Self { pub fn empty() -> Self {
Self::new(0, 0) Self::new(0, 0)
} }
/// Returns the index within the transaction of the [`Action`] corresponding to the `n`-th /// Returns the index within the bundle of the [`Action`] corresponding to the `n`-th
/// spend specified in bundle construction. If a [`Builder`] was used, this refers to the spend /// spend specified in bundle construction. If a [`Builder`] was used, this refers to
/// added by the `n`-th call to [`Builder::add_spend`]. /// the spend added by the `n`-th call to [`Builder::add_spend`].
/// ///
/// Note positions are randomized when building transactions for indistinguishability. /// For the purpose of improving indistinguishability, actions are padded and note
/// This means that the transaction consumer cannot assume that e.g. the first spend /// positions are randomized when building bundles. This means that the bundle
/// they added corresponds to the first [`Action`] in the transaction. /// consumer cannot assume that e.g. the first spend they added corresponds to the
/// first action in the bundle.
pub fn spend_action_index(&self, n: usize) -> Option<usize> { pub fn spend_action_index(&self, n: usize) -> Option<usize> {
self.spend_indices.get(n).copied() self.spend_indices.get(n).copied()
} }
/// Returns the index within the transaction of the [`Action`] corresponding to the `n`-th /// Returns the index within the bundle of the [`Action`] corresponding to the `n`-th
/// output specified in bundle construction. If a [`Builder`] was used, this refers to the /// output specified in bundle construction. If a [`Builder`] was used, this refers to
/// output added by the `n`-th call to [`Builder::add_output`]. /// the output added by the `n`-th call to [`Builder::add_output`].
/// ///
/// Note positions are randomized when building transactions for indistinguishability. /// For the purpose of improving indistinguishability, actions are padded and note
/// This means that the transaction consumer cannot assume that e.g. the first output /// positions are randomized when building bundles. This means that the bundle
/// they added corresponds to the first [`Action`] in the transaction. /// consumer cannot assume that e.g. the first output they added corresponds to the
/// first action in the bundle.
pub fn output_action_index(&self, n: usize) -> Option<usize> { pub fn output_action_index(&self, n: usize) -> Option<usize> {
self.output_indices.get(n).copied() self.output_indices.get(n).copied()
} }