Skip to content

Commit

Permalink
Make offers::Amount Copy and export it in bindings
Browse files Browse the repository at this point in the history
`Amount` is less than two pointers long, so there's no reason it
shouldn't be `Copy`. Further, because its an enum, bindings can't
map a reference to it in an `Option`. Thus, here, we simply make it
`Copy` and return it in `Option`s rather than a reference to it.
  • Loading branch information
TheBlueMatt committed May 11, 2024
1 parent 2802993 commit c6b5dc2
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 6 deletions.
4 changes: 2 additions & 2 deletions lightning/src/offers/invoice.rs
Original file line number Diff line number Diff line change
Expand Up @@ -697,7 +697,7 @@ macro_rules! invoice_accessors { ($self: ident, $contents: expr) => {
///
/// [`Offer`]: crate::offers::offer::Offer
/// [`Offer::amount`]: crate::offers::offer::Offer::amount
pub fn amount(&$self) -> Option<&Amount> {
pub fn amount(&$self) -> Option<Amount> {
$contents.amount()
}

Expand Down Expand Up @@ -944,7 +944,7 @@ impl InvoiceContents {
}
}

fn amount(&self) -> Option<&Amount> {
fn amount(&self) -> Option<Amount> {
match self {
InvoiceContents::ForOffer { invoice_request, .. } =>
invoice_request.inner.offer.amount(),
Expand Down
8 changes: 4 additions & 4 deletions lightning/src/offers/offer.rs
Original file line number Diff line number Diff line change
Expand Up @@ -582,7 +582,7 @@ macro_rules! offer_accessors { ($self: ident, $contents: expr) => {
}

/// The minimum amount required for a successful payment of a single item.
pub fn amount(&$self) -> Option<&$crate::offers::offer::Amount> {
pub fn amount(&$self) -> Option<$crate::offers::offer::Amount> {
$contents.amount()
}

Expand Down Expand Up @@ -808,8 +808,8 @@ impl OfferContents {
self.metadata.as_ref().and_then(|metadata| metadata.as_bytes())
}

pub fn amount(&self) -> Option<&Amount> {
self.amount.as_ref()
pub fn amount(&self) -> Option<Amount> {
self.amount
}

pub fn description(&self) -> Option<PrintableString> {
Expand Down Expand Up @@ -982,7 +982,7 @@ impl Writeable for OfferContents {

/// The minimum amount required for an item in an [`Offer`], denominated in either bitcoin or
/// another currency.
#[derive(Clone, Debug, PartialEq)]
#[derive(Clone, Copy, Debug, PartialEq)]
pub enum Amount {
/// An amount of bitcoin.
Bitcoin {
Expand Down

0 comments on commit c6b5dc2

Please sign in to comment.