Skip to content

Commit a27088d

Browse files
authored
Merge pull request #3018 from jkczyz/2024-04-optional-description
Optional description for `Offer` and `Refund`
2 parents 3d5a691 + e61001f commit a27088d

File tree

8 files changed

+292
-256
lines changed

8 files changed

+292
-256
lines changed

lightning/src/ln/channelmanager.rs

Lines changed: 9 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1549,11 +1549,12 @@ where
15491549
/// # fn example<T: AChannelManager>(channel_manager: T) -> Result<(), Bolt12SemanticError> {
15501550
/// # let channel_manager = channel_manager.get_cm();
15511551
/// let offer = channel_manager
1552-
/// .create_offer_builder("coffee".to_string())?
1552+
/// .create_offer_builder()?
15531553
/// # ;
15541554
/// # // Needed for compiling for c_bindings
15551555
/// # let builder: lightning::offers::offer::OfferBuilder<_, _> = offer.into();
15561556
/// # let offer = builder
1557+
/// .description("coffee".to_string())
15571558
/// .amount_msats(10_000_000)
15581559
/// .build()?;
15591560
/// let bech32_offer = offer.to_string();
@@ -1652,13 +1653,13 @@ where
16521653
/// let payment_id = PaymentId([42; 32]);
16531654
/// let refund = channel_manager
16541655
/// .create_refund_builder(
1655-
/// "coffee".to_string(), amount_msats, absolute_expiry, payment_id, retry,
1656-
/// max_total_routing_fee_msat
1656+
/// amount_msats, absolute_expiry, payment_id, retry, max_total_routing_fee_msat
16571657
/// )?
16581658
/// # ;
16591659
/// # // Needed for compiling for c_bindings
16601660
/// # let builder: lightning::offers::refund::RefundBuilder<_> = refund.into();
16611661
/// # let refund = builder
1662+
/// .description("coffee".to_string())
16621663
/// .payer_note("refund for order 1234".to_string())
16631664
/// .build()?;
16641665
/// let bech32_refund = refund.to_string();
@@ -8562,17 +8563,15 @@ macro_rules! create_offer_builder { ($self: ident, $builder: ty) => {
85628563
///
85638564
/// [`Offer`]: crate::offers::offer::Offer
85648565
/// [`InvoiceRequest`]: crate::offers::invoice_request::InvoiceRequest
8565-
pub fn create_offer_builder(
8566-
&$self, description: String
8567-
) -> Result<$builder, Bolt12SemanticError> {
8566+
pub fn create_offer_builder(&$self) -> Result<$builder, Bolt12SemanticError> {
85688567
let node_id = $self.get_our_node_id();
85698568
let expanded_key = &$self.inbound_payment_key;
85708569
let entropy = &*$self.entropy_source;
85718570
let secp_ctx = &$self.secp_ctx;
85728571

85738572
let path = $self.create_blinded_path().map_err(|_| Bolt12SemanticError::MissingPaths)?;
85748573
let builder = OfferBuilder::deriving_signing_pubkey(
8575-
description, node_id, expanded_key, entropy, secp_ctx
8574+
node_id, expanded_key, entropy, secp_ctx
85768575
)
85778576
.chain_hash($self.chain_hash)
85788577
.path(path);
@@ -8631,8 +8630,8 @@ macro_rules! create_refund_builder { ($self: ident, $builder: ty) => {
86318630
/// [`Bolt12Invoice::payment_paths`]: crate::offers::invoice::Bolt12Invoice::payment_paths
86328631
/// [Avoiding Duplicate Payments]: #avoiding-duplicate-payments
86338632
pub fn create_refund_builder(
8634-
&$self, description: String, amount_msats: u64, absolute_expiry: Duration,
8635-
payment_id: PaymentId, retry_strategy: Retry, max_total_routing_fee_msat: Option<u64>
8633+
&$self, amount_msats: u64, absolute_expiry: Duration, payment_id: PaymentId,
8634+
retry_strategy: Retry, max_total_routing_fee_msat: Option<u64>
86368635
) -> Result<$builder, Bolt12SemanticError> {
86378636
let node_id = $self.get_our_node_id();
86388637
let expanded_key = &$self.inbound_payment_key;
@@ -8641,7 +8640,7 @@ macro_rules! create_refund_builder { ($self: ident, $builder: ty) => {
86418640

86428641
let path = $self.create_blinded_path().map_err(|_| Bolt12SemanticError::MissingPaths)?;
86438642
let builder = RefundBuilder::deriving_payer_id(
8644-
description, node_id, expanded_key, entropy, secp_ctx, amount_msats, payment_id
8643+
node_id, expanded_key, entropy, secp_ctx, amount_msats, payment_id
86458644
)?
86468645
.chain_hash($self.chain_hash)
86478646
.absolute_expiry(absolute_expiry)

lightning/src/ln/offers_tests.rs

Lines changed: 20 additions & 32 deletions
Original file line numberDiff line numberDiff line change
@@ -267,7 +267,7 @@ fn prefers_non_tor_nodes_in_blinded_paths() {
267267
announce_node_address(charlie, &[alice, bob, david, &nodes[4], &nodes[5]], tor.clone());
268268

269269
let offer = bob.node
270-
.create_offer_builder("coffee".to_string()).unwrap()
270+
.create_offer_builder().unwrap()
271271
.amount_msats(10_000_000)
272272
.build().unwrap();
273273
assert_ne!(offer.signing_pubkey(), Some(bob_id));
@@ -282,7 +282,7 @@ fn prefers_non_tor_nodes_in_blinded_paths() {
282282
announce_node_address(&nodes[5], &[alice, bob, charlie, david, &nodes[4]], tor.clone());
283283

284284
let offer = bob.node
285-
.create_offer_builder("coffee".to_string()).unwrap()
285+
.create_offer_builder().unwrap()
286286
.amount_msats(10_000_000)
287287
.build().unwrap();
288288
assert_ne!(offer.signing_pubkey(), Some(bob_id));
@@ -332,7 +332,7 @@ fn prefers_more_connected_nodes_in_blinded_paths() {
332332
disconnect_peers(david, &[bob, &nodes[4], &nodes[5]]);
333333

334334
let offer = bob.node
335-
.create_offer_builder("coffee".to_string()).unwrap()
335+
.create_offer_builder().unwrap()
336336
.amount_msats(10_000_000)
337337
.build().unwrap();
338338
assert_ne!(offer.signing_pubkey(), Some(bob_id));
@@ -381,7 +381,7 @@ fn creates_and_pays_for_offer_using_two_hop_blinded_path() {
381381
disconnect_peers(david, &[bob, &nodes[4], &nodes[5]]);
382382

383383
let offer = alice.node
384-
.create_offer_builder("coffee".to_string())
384+
.create_offer_builder()
385385
.unwrap()
386386
.amount_msats(10_000_000)
387387
.build().unwrap();
@@ -481,9 +481,7 @@ fn creates_and_pays_for_refund_using_two_hop_blinded_path() {
481481
let absolute_expiry = Duration::from_secs(u64::MAX);
482482
let payment_id = PaymentId([1; 32]);
483483
let refund = david.node
484-
.create_refund_builder(
485-
"refund".to_string(), 10_000_000, absolute_expiry, payment_id, Retry::Attempts(0), None
486-
)
484+
.create_refund_builder(10_000_000, absolute_expiry, payment_id, Retry::Attempts(0), None)
487485
.unwrap()
488486
.build().unwrap();
489487
assert_eq!(refund.amount_msats(), 10_000_000);
@@ -541,7 +539,7 @@ fn creates_and_pays_for_offer_using_one_hop_blinded_path() {
541539
let bob_id = bob.node.get_our_node_id();
542540

543541
let offer = alice.node
544-
.create_offer_builder("coffee".to_string()).unwrap()
542+
.create_offer_builder().unwrap()
545543
.amount_msats(10_000_000)
546544
.build().unwrap();
547545
assert_ne!(offer.signing_pubkey(), Some(alice_id));
@@ -608,9 +606,7 @@ fn creates_and_pays_for_refund_using_one_hop_blinded_path() {
608606
let absolute_expiry = Duration::from_secs(u64::MAX);
609607
let payment_id = PaymentId([1; 32]);
610608
let refund = bob.node
611-
.create_refund_builder(
612-
"refund".to_string(), 10_000_000, absolute_expiry, payment_id, Retry::Attempts(0), None
613-
)
609+
.create_refund_builder(10_000_000, absolute_expiry, payment_id, Retry::Attempts(0), None)
614610
.unwrap()
615611
.build().unwrap();
616612
assert_eq!(refund.amount_msats(), 10_000_000);
@@ -663,7 +659,7 @@ fn pays_for_offer_without_blinded_paths() {
663659
let bob_id = bob.node.get_our_node_id();
664660

665661
let offer = alice.node
666-
.create_offer_builder("coffee".to_string()).unwrap()
662+
.create_offer_builder().unwrap()
667663
.clear_paths()
668664
.amount_msats(10_000_000)
669665
.build().unwrap();
@@ -717,9 +713,7 @@ fn pays_for_refund_without_blinded_paths() {
717713
let absolute_expiry = Duration::from_secs(u64::MAX);
718714
let payment_id = PaymentId([1; 32]);
719715
let refund = bob.node
720-
.create_refund_builder(
721-
"refund".to_string(), 10_000_000, absolute_expiry, payment_id, Retry::Attempts(0), None
722-
)
716+
.create_refund_builder(10_000_000, absolute_expiry, payment_id, Retry::Attempts(0), None)
723717
.unwrap()
724718
.clear_paths()
725719
.build().unwrap();
@@ -753,7 +747,7 @@ fn fails_creating_offer_without_blinded_paths() {
753747

754748
create_unannounced_chan_between_nodes_with_value(&nodes, 0, 1, 10_000_000, 1_000_000_000);
755749

756-
match nodes[0].node.create_offer_builder("coffee".to_string()) {
750+
match nodes[0].node.create_offer_builder() {
757751
Ok(_) => panic!("Expected error"),
758752
Err(e) => assert_eq!(e, Bolt12SemanticError::MissingPaths),
759753
}
@@ -773,7 +767,7 @@ fn fails_creating_refund_without_blinded_paths() {
773767
let payment_id = PaymentId([1; 32]);
774768

775769
match nodes[0].node.create_refund_builder(
776-
"refund".to_string(), 10_000, absolute_expiry, payment_id, Retry::Attempts(0), None
770+
10_000, absolute_expiry, payment_id, Retry::Attempts(0), None
777771
) {
778772
Ok(_) => panic!("Expected error"),
779773
Err(e) => assert_eq!(e, Bolt12SemanticError::MissingPaths),
@@ -796,7 +790,7 @@ fn fails_creating_invoice_request_for_unsupported_chain() {
796790
let bob = &nodes[1];
797791

798792
let offer = alice.node
799-
.create_offer_builder("coffee".to_string()).unwrap()
793+
.create_offer_builder().unwrap()
800794
.clear_chains()
801795
.chain(Network::Signet)
802796
.build().unwrap();
@@ -824,9 +818,7 @@ fn fails_sending_invoice_with_unsupported_chain_for_refund() {
824818
let absolute_expiry = Duration::from_secs(u64::MAX);
825819
let payment_id = PaymentId([1; 32]);
826820
let refund = bob.node
827-
.create_refund_builder(
828-
"refund".to_string(), 10_000_000, absolute_expiry, payment_id, Retry::Attempts(0), None
829-
)
821+
.create_refund_builder(10_000_000, absolute_expiry, payment_id, Retry::Attempts(0), None)
830822
.unwrap()
831823
.chain(Network::Signet)
832824
.build().unwrap();
@@ -858,7 +850,7 @@ fn fails_creating_invoice_request_without_blinded_reply_path() {
858850
disconnect_peers(david, &[bob, &nodes[4], &nodes[5]]);
859851

860852
let offer = alice.node
861-
.create_offer_builder("coffee".to_string()).unwrap()
853+
.create_offer_builder().unwrap()
862854
.amount_msats(10_000_000)
863855
.build().unwrap();
864856

@@ -892,7 +884,7 @@ fn fails_creating_invoice_request_with_duplicate_payment_id() {
892884
disconnect_peers(alice, &[charlie, david, &nodes[4], &nodes[5]]);
893885

894886
let offer = alice.node
895-
.create_offer_builder("coffee".to_string()).unwrap()
887+
.create_offer_builder().unwrap()
896888
.amount_msats(10_000_000)
897889
.build().unwrap();
898890

@@ -925,13 +917,13 @@ fn fails_creating_refund_with_duplicate_payment_id() {
925917
let payment_id = PaymentId([1; 32]);
926918
assert!(
927919
nodes[0].node.create_refund_builder(
928-
"refund".to_string(), 10_000, absolute_expiry, payment_id, Retry::Attempts(0), None
920+
10_000, absolute_expiry, payment_id, Retry::Attempts(0), None
929921
).is_ok()
930922
);
931923
expect_recent_payment!(nodes[0], RecentPaymentDetails::AwaitingInvoice, payment_id);
932924

933925
match nodes[0].node.create_refund_builder(
934-
"refund".to_string(), 10_000, absolute_expiry, payment_id, Retry::Attempts(0), None
926+
10_000, absolute_expiry, payment_id, Retry::Attempts(0), None
935927
) {
936928
Ok(_) => panic!("Expected error"),
937929
Err(e) => assert_eq!(e, Bolt12SemanticError::DuplicatePaymentId),
@@ -978,7 +970,7 @@ fn fails_sending_invoice_without_blinded_payment_paths_for_offer() {
978970
disconnect_peers(david, &[bob, &nodes[4], &nodes[5]]);
979971

980972
let offer = alice.node
981-
.create_offer_builder("coffee".to_string()).unwrap()
973+
.create_offer_builder().unwrap()
982974
.amount_msats(10_000_000)
983975
.build().unwrap();
984976

@@ -1042,9 +1034,7 @@ fn fails_sending_invoice_without_blinded_payment_paths_for_refund() {
10421034
let absolute_expiry = Duration::from_secs(u64::MAX);
10431035
let payment_id = PaymentId([1; 32]);
10441036
let refund = david.node
1045-
.create_refund_builder(
1046-
"refund".to_string(), 10_000_000, absolute_expiry, payment_id, Retry::Attempts(0), None
1047-
)
1037+
.create_refund_builder(10_000_000, absolute_expiry, payment_id, Retry::Attempts(0), None)
10481038
.unwrap()
10491039
.build().unwrap();
10501040

@@ -1093,9 +1083,7 @@ fn fails_paying_invoice_more_than_once() {
10931083
let absolute_expiry = Duration::from_secs(u64::MAX);
10941084
let payment_id = PaymentId([1; 32]);
10951085
let refund = david.node
1096-
.create_refund_builder(
1097-
"refund".to_string(), 10_000_000, absolute_expiry, payment_id, Retry::Attempts(0), None
1098-
)
1086+
.create_refund_builder(10_000_000, absolute_expiry, payment_id, Retry::Attempts(0), None)
10991087
.unwrap()
11001088
.build().unwrap();
11011089
expect_recent_payment!(david, RecentPaymentDetails::AwaitingInvoice, payment_id);

lightning/src/ln/outbound_payment.rs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2194,7 +2194,7 @@ mod tests {
21942194
assert!(outbound_payments.has_pending_payments());
21952195

21962196
let created_at = now() - DEFAULT_RELATIVE_EXPIRY;
2197-
let invoice = OfferBuilder::new("foo".into(), recipient_pubkey())
2197+
let invoice = OfferBuilder::new(recipient_pubkey())
21982198
.amount_msats(1000)
21992199
.build().unwrap()
22002200
.request_invoice(vec![1; 32], payer_pubkey()).unwrap()
@@ -2237,7 +2237,7 @@ mod tests {
22372237
let payment_id = PaymentId([0; 32]);
22382238
let expiration = StaleExpiration::AbsoluteTimeout(Duration::from_secs(100));
22392239

2240-
let invoice = OfferBuilder::new("foo".into(), recipient_pubkey())
2240+
let invoice = OfferBuilder::new(recipient_pubkey())
22412241
.amount_msats(1000)
22422242
.build().unwrap()
22432243
.request_invoice(vec![1; 32], payer_pubkey()).unwrap()
@@ -2296,7 +2296,7 @@ mod tests {
22962296
let payment_id = PaymentId([0; 32]);
22972297
let expiration = StaleExpiration::AbsoluteTimeout(Duration::from_secs(100));
22982298

2299-
let invoice = OfferBuilder::new("foo".into(), recipient_pubkey())
2299+
let invoice = OfferBuilder::new(recipient_pubkey())
23002300
.amount_msats(1000)
23012301
.build().unwrap()
23022302
.request_invoice(vec![1; 32], payer_pubkey()).unwrap()

0 commit comments

Comments
 (0)