Skip to content

Commit 4e4b15f

Browse files
committed
f - special case Quantity::Max(1) in builder
1 parent 14431fd commit 4e4b15f

File tree

1 file changed

+14
-1
lines changed

1 file changed

+14
-1
lines changed

lightning/src/offers/offer.rs

+14-1
Original file line numberDiff line numberDiff line change
@@ -163,7 +163,10 @@ impl OfferBuilder {
163163
///
164164
/// Successive calls to this method will override the previous setting.
165165
pub fn supported_quantity(mut self, quantity: Quantity) -> Self {
166-
self.offer.supported_quantity = quantity;
166+
self.offer.supported_quantity = match quantity {
167+
Quantity::Max(n) if n.get() == 1 => Quantity::One,
168+
_ => quantity,
169+
};
167170
self
168171
}
169172

@@ -658,6 +661,7 @@ mod tests {
658661

659662
#[test]
660663
fn builds_offer_with_supported_quantity() {
664+
let one = NonZeroU64::new(1).unwrap();
661665
let ten = NonZeroU64::new(10).unwrap();
662666

663667
let offer = OfferBuilder::new("foo".into(), pubkey(42))
@@ -692,5 +696,14 @@ mod tests {
692696
let tlv_stream = offer.as_tlv_stream();
693697
assert_eq!(offer.supported_quantity(), Quantity::One);
694698
assert_eq!(tlv_stream.quantity_max, None);
699+
700+
let offer = OfferBuilder::new("foo".into(), pubkey(42))
701+
.supported_quantity(Quantity::Max(one))
702+
.build()
703+
.unwrap();
704+
let tlv_stream = offer.as_tlv_stream();
705+
assert_eq!(offer.supported_quantity(), Quantity::One);
706+
assert_eq!(tlv_stream.quantity_max, None);
707+
695708
}
696709
}

0 commit comments

Comments
 (0)