Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
38 changes: 20 additions & 18 deletions lightning/src/ln/channelmanager.rs
Original file line numberDiff line numberDiff line change
Expand Up@@ -1554,11 +1554,12 @@ where
/// # fn example<T: AChannelManager>(channel_manager: T) -> Result<(), Bolt12SemanticError> {
/// # let channel_manager = channel_manager.get_cm();
/// let offer = channel_manager
/// .create_offer_builder("coffee".to_string())?
/// .create_offer_builder()?
/// # ;
/// # // Needed for compiling for c_bindings
/// # let builder: lightning::offers::offer::OfferBuilder<_, _> = offer.into();
/// # let offer = builder
/// .description("coffee".to_string())
/// .amount_msats(10_000_000)
/// .build()?;
/// let bech32_offer = offer.to_string();
Expand DownExpand Up@@ -1657,13 +1658,13 @@ where
/// let payment_id = PaymentId([42; 32]);
/// let refund = channel_manager
/// .create_refund_builder(
/// "coffee".to_string(), amount_msats, absolute_expiry, payment_id, retry,
/// max_total_routing_fee_msat
/// amount_msats, absolute_expiry, payment_id, retry, max_total_routing_fee_msat
/// )?
/// # ;
/// # // Needed for compiling for c_bindings
/// # let builder: lightning::offers::refund::RefundBuilder<_> = refund.into();
/// # let refund = builder
/// .description("coffee".to_string())
/// .payer_note("refund for order 1234".to_string())
/// .build()?;
/// let bech32_refund = refund.to_string();
Expand DownExpand Up@@ -8553,17 +8554,15 @@ macro_rules! create_offer_builder { ($self: ident, $builder: ty) => {
///
/// [`Offer`]: crate::offers::offer::Offer
/// [`InvoiceRequest`]: crate::offers::invoice_request::InvoiceRequest
pub fn create_offer_builder(
&$self, description: String
) -> Result<$builder, Bolt12SemanticError> {
pub fn create_offer_builder(&$self) -> Result<$builder, Bolt12SemanticError> {
let node_id = $self.get_our_node_id();
let expanded_key = &$self.inbound_payment_key;
let entropy = &*$self.entropy_source;
let secp_ctx = &$self.secp_ctx;

let path = $self.create_blinded_path().map_err(|_| Bolt12SemanticError::MissingPaths)?;
let builder = OfferBuilder::deriving_signing_pubkey(
description, node_id, expanded_key, entropy, secp_ctx
node_id, expanded_key, entropy, secp_ctx
)
.chain_hash($self.chain_hash)
.path(path);
Expand DownExpand Up@@ -8622,8 +8621,8 @@ macro_rules! create_refund_builder { ($self: ident, $builder: ty) => {
/// [`Bolt12Invoice::payment_paths`]: crate::offers::invoice::Bolt12Invoice::payment_paths
/// [Avoiding Duplicate Payments]: #avoiding-duplicate-payments
pub fn create_refund_builder(
&$self, description: String, amount_msats: u64, absolute_expiry: Duration,
payment_id: PaymentId, retry_strategy: Retry, max_total_routing_fee_msat: Option<u64>
&$self, amount_msats: u64, absolute_expiry: Duration, payment_id: PaymentId,
retry_strategy: Retry, max_total_routing_fee_msat: Option<u64>
) -> Result<$builder, Bolt12SemanticError> {
let node_id = $self.get_our_node_id();
let expanded_key = &$self.inbound_payment_key;
Expand All@@ -8632,7 +8631,7 @@ macro_rules! create_refund_builder { ($self: ident, $builder: ty) => {

let path = $self.create_blinded_path().map_err(|_| Bolt12SemanticError::MissingPaths)?;
let builder = RefundBuilder::deriving_payer_id(
description, node_id, expanded_key, entropy, secp_ctx, amount_msats, payment_id
node_id, expanded_key, entropy, secp_ctx, amount_msats, payment_id
)?
.chain_hash($self.chain_hash)
.absolute_expiry(absolute_expiry)
Expand DownExpand Up@@ -8765,14 +8764,7 @@ where
.map_err(|_| Bolt12SemanticError::DuplicatePaymentId)?;

let mut pending_offers_messages = self.pending_offers_messages.lock().unwrap();
if offer.paths().is_empty() {
let message = new_pending_onion_message(
OffersMessage::InvoiceRequest(invoice_request),
Destination::Node(offer.signing_pubkey()),
Some(reply_path),
);
pending_offers_messages.push(message);
} else {
if !offer.paths().is_empty() {
// Send as many invoice requests as there are paths in the offer (with an upper bound).
// Using only one path could result in a failure if the path no longer exists. But only
// one invoice for a given payment id will be paid, even if more than one is received.
Expand All@@ -8785,6 +8777,16 @@ where
);
pending_offers_messages.push(message);
}
} else if let Some(signing_pubkey) = offer.signing_pubkey() {
let message = new_pending_onion_message(
OffersMessage::InvoiceRequest(invoice_request),
Destination::Node(signing_pubkey),
Some(reply_path),
);
pending_offers_messages.push(message);
} else {
debug_assert!(false);
return Err(Bolt12SemanticError::MissingSigningPubkey);
}

Ok(())
Expand Down
64 changes: 26 additions & 38 deletions lightning/src/ln/offers_tests.rs
Original file line numberDiff line numberDiff line change
Expand Up@@ -268,10 +268,10 @@ fn prefers_non_tor_nodes_in_blinded_paths() {
announce_node_address(charlie, &[alice, bob, david, &nodes[4], &nodes[5]], tor.clone());

let offer = bob.node
.create_offer_builder("coffee".to_string()).unwrap()
.create_offer_builder().unwrap()
.amount_msats(10_000_000)
.build().unwrap();
assert_ne!(offer.signing_pubkey(), bob_id);
assert_ne!(offer.signing_pubkey(), Some(bob_id));
assert!(!offer.paths().is_empty());
for path in offer.paths() {
assert_ne!(path.introduction_node, IntroductionNode::NodeId(bob_id));
Expand All@@ -283,10 +283,10 @@ fn prefers_non_tor_nodes_in_blinded_paths() {
announce_node_address(&nodes[5], &[alice, bob, charlie, david, &nodes[4]], tor.clone());

let offer = bob.node
.create_offer_builder("coffee".to_string()).unwrap()
.create_offer_builder().unwrap()
.amount_msats(10_000_000)
.build().unwrap();
assert_ne!(offer.signing_pubkey(), bob_id);
assert_ne!(offer.signing_pubkey(), Some(bob_id));
assert!(!offer.paths().is_empty());
for path in offer.paths() {
assert_eq!(path.introduction_node, IntroductionNode::NodeId(bob_id));
Expand DownExpand Up@@ -333,10 +333,10 @@ fn prefers_more_connected_nodes_in_blinded_paths() {
disconnect_peers(david, &[bob, &nodes[4], &nodes[5]]);

let offer = bob.node
.create_offer_builder("coffee".to_string()).unwrap()
.create_offer_builder().unwrap()
.amount_msats(10_000_000)
.build().unwrap();
assert_ne!(offer.signing_pubkey(), bob_id);
assert_ne!(offer.signing_pubkey(), Some(bob_id));
assert!(!offer.paths().is_empty());
for path in offer.paths() {
assert_eq!(path.introduction_node, IntroductionNode::NodeId(nodes[4].node.get_our_node_id()));
Expand DownExpand Up@@ -382,11 +382,11 @@ fn creates_and_pays_for_offer_using_two_hop_blinded_path() {
disconnect_peers(david, &[bob, &nodes[4], &nodes[5]]);

let offer = alice.node
.create_offer_builder("coffee".to_string())
.create_offer_builder()
.unwrap()
.amount_msats(10_000_000)
.build().unwrap();
assert_ne!(offer.signing_pubkey(), alice_id);
assert_ne!(offer.signing_pubkey(), Some(alice_id));
assert!(!offer.paths().is_empty());
for path in offer.paths() {
assert_eq!(path.introduction_node, IntroductionNode::NodeId(bob_id));
Expand DownExpand Up@@ -484,9 +484,7 @@ fn creates_and_pays_for_refund_using_two_hop_blinded_path() {
let absolute_expiry = Duration::from_secs(u64::MAX);
let payment_id = PaymentId([1; 32]);
let refund = david.node
.create_refund_builder(
"refund".to_string(), 10_000_000, absolute_expiry, payment_id, Retry::Attempts(0), None
)
.create_refund_builder(10_000_000, absolute_expiry, payment_id, Retry::Attempts(0), None)
.unwrap()
.build().unwrap();
assert_eq!(refund.amount_msats(), 10_000_000);
Expand DownExpand Up@@ -544,10 +542,10 @@ fn creates_and_pays_for_offer_using_one_hop_blinded_path() {
let bob_id = bob.node.get_our_node_id();

let offer = alice.node
.create_offer_builder("coffee".to_string()).unwrap()
.create_offer_builder().unwrap()
.amount_msats(10_000_000)
.build().unwrap();
assert_ne!(offer.signing_pubkey(), alice_id);
assert_ne!(offer.signing_pubkey(), Some(alice_id));
assert!(!offer.paths().is_empty());
for path in offer.paths() {
assert_eq!(path.introduction_node, IntroductionNode::NodeId(alice_id));
Expand DownExpand Up@@ -613,9 +611,7 @@ fn creates_and_pays_for_refund_using_one_hop_blinded_path() {
let absolute_expiry = Duration::from_secs(u64::MAX);
let payment_id = PaymentId([1; 32]);
let refund = bob.node
.create_refund_builder(
"refund".to_string(), 10_000_000, absolute_expiry, payment_id, Retry::Attempts(0), None
)
.create_refund_builder(10_000_000, absolute_expiry, payment_id, Retry::Attempts(0), None)
.unwrap()
.build().unwrap();
assert_eq!(refund.amount_msats(), 10_000_000);
Expand DownExpand Up@@ -668,11 +664,11 @@ fn pays_for_offer_without_blinded_paths() {
let bob_id = bob.node.get_our_node_id();

let offer = alice.node
.create_offer_builder("coffee".to_string()).unwrap()
.create_offer_builder().unwrap()
.clear_paths()
.amount_msats(10_000_000)
.build().unwrap();
assert_eq!(offer.signing_pubkey(), alice_id);
assert_eq!(offer.signing_pubkey(), Some(alice_id));
assert!(offer.paths().is_empty());

let payment_id = PaymentId([1; 32]);
Expand DownExpand Up@@ -724,9 +720,7 @@ fn pays_for_refund_without_blinded_paths() {
let absolute_expiry = Duration::from_secs(u64::MAX);
let payment_id = PaymentId([1; 32]);
let refund = bob.node
.create_refund_builder(
"refund".to_string(), 10_000_000, absolute_expiry, payment_id, Retry::Attempts(0), None
)
.create_refund_builder(10_000_000, absolute_expiry, payment_id, Retry::Attempts(0), None)
.unwrap()
.clear_paths()
.build().unwrap();
Expand DownExpand Up@@ -760,7 +754,7 @@ fn fails_creating_offer_without_blinded_paths() {

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

match nodes[0].node.create_offer_builder("coffee".to_string()) {
match nodes[0].node.create_offer_builder() {
Ok(_) => panic!("Expected error"),
Err(e) => assert_eq!(e, Bolt12SemanticError::MissingPaths),
}
Expand All@@ -780,7 +774,7 @@ fn fails_creating_refund_without_blinded_paths() {
let payment_id = PaymentId([1; 32]);

match nodes[0].node.create_refund_builder(
"refund".to_string(), 10_000, absolute_expiry, payment_id, Retry::Attempts(0), None
10_000, absolute_expiry, payment_id, Retry::Attempts(0), None
) {
Ok(_) => panic!("Expected error"),
Err(e) => assert_eq!(e, Bolt12SemanticError::MissingPaths),
Expand All@@ -803,7 +797,7 @@ fn fails_creating_invoice_request_for_unsupported_chain() {
let bob = &nodes[1];

let offer = alice.node
.create_offer_builder("coffee".to_string()).unwrap()
.create_offer_builder().unwrap()
.clear_chains()
.chain(Network::Signet)
.build().unwrap();
Expand DownExpand Up@@ -831,9 +825,7 @@ fn fails_sending_invoice_with_unsupported_chain_for_refund() {
let absolute_expiry = Duration::from_secs(u64::MAX);
let payment_id = PaymentId([1; 32]);
let refund = bob.node
.create_refund_builder(
"refund".to_string(), 10_000_000, absolute_expiry, payment_id, Retry::Attempts(0), None
)
.create_refund_builder(10_000_000, absolute_expiry, payment_id, Retry::Attempts(0), None)
.unwrap()
.chain(Network::Signet)
.build().unwrap();
Expand DownExpand Up@@ -865,7 +857,7 @@ fn fails_creating_invoice_request_without_blinded_reply_path() {
disconnect_peers(david, &[bob, &nodes[4], &nodes[5]]);

let offer = alice.node
.create_offer_builder("coffee".to_string()).unwrap()
.create_offer_builder().unwrap()
.amount_msats(10_000_000)
.build().unwrap();

Expand DownExpand Up@@ -899,7 +891,7 @@ fn fails_creating_invoice_request_with_duplicate_payment_id() {
disconnect_peers(alice, &[charlie, david, &nodes[4], &nodes[5]]);

let offer = alice.node
.create_offer_builder("coffee".to_string()).unwrap()
.create_offer_builder().unwrap()
.amount_msats(10_000_000)
.build().unwrap();

Expand DownExpand Up@@ -932,13 +924,13 @@ fn fails_creating_refund_with_duplicate_payment_id() {
let payment_id = PaymentId([1; 32]);
assert!(
nodes[0].node.create_refund_builder(
"refund".to_string(), 10_000, absolute_expiry, payment_id, Retry::Attempts(0), None
10_000, absolute_expiry, payment_id, Retry::Attempts(0), None
).is_ok()
);
expect_recent_payment!(nodes[0], RecentPaymentDetails::AwaitingInvoice, payment_id);

match nodes[0].node.create_refund_builder(
"refund".to_string(), 10_000, absolute_expiry, payment_id, Retry::Attempts(0), None
10_000, absolute_expiry, payment_id, Retry::Attempts(0), None
) {
Ok(_) => panic!("Expected error"),
Err(e) => assert_eq!(e, Bolt12SemanticError::DuplicatePaymentId),
Expand DownExpand Up@@ -985,7 +977,7 @@ fn fails_sending_invoice_without_blinded_payment_paths_for_offer() {
disconnect_peers(david, &[bob, &nodes[4], &nodes[5]]);

let offer = alice.node
.create_offer_builder("coffee".to_string()).unwrap()
.create_offer_builder().unwrap()
.amount_msats(10_000_000)
.build().unwrap();

Expand DownExpand Up@@ -1049,9 +1041,7 @@ fn fails_sending_invoice_without_blinded_payment_paths_for_refund() {
let absolute_expiry = Duration::from_secs(u64::MAX);
let payment_id = PaymentId([1; 32]);
let refund = david.node
.create_refund_builder(
"refund".to_string(), 10_000_000, absolute_expiry, payment_id, Retry::Attempts(0), None
)
.create_refund_builder(10_000_000, absolute_expiry, payment_id, Retry::Attempts(0), None)
.unwrap()
.build().unwrap();

Expand DownExpand Up@@ -1100,9 +1090,7 @@ fn fails_paying_invoice_more_than_once() {
let absolute_expiry = Duration::from_secs(u64::MAX);
let payment_id = PaymentId([1; 32]);
let refund = david.node
.create_refund_builder(
"refund".to_string(), 10_000_000, absolute_expiry, payment_id, Retry::Attempts(0), None
)
.create_refund_builder(10_000_000, absolute_expiry, payment_id, Retry::Attempts(0), None)
.unwrap()
.build().unwrap();
expect_recent_payment!(david, RecentPaymentDetails::AwaitingInvoice, payment_id);
Expand Down
6 changes: 3 additions & 3 deletions lightning/src/ln/outbound_payment.rs
Original file line numberDiff line numberDiff line change
Expand Up@@ -2194,7 +2194,7 @@ mod tests {
assert!(outbound_payments.has_pending_payments());

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

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

let invoice = OfferBuilder::new("foo".into(), recipient_pubkey())
let invoice = OfferBuilder::new(recipient_pubkey())
.amount_msats(1000)
.build().unwrap()
.request_invoice(vec![1; 32], payer_pubkey()).unwrap()
Expand Down
Loading
, 'i'); if (__m === '*' || __re.test(location.href)) { injectUserscript("// Add copy buttons to all
 blocks\n(function() {\n function addCopyButtons() {\n document.querySelectorAll('pre code').forEach(function(codeBlock) {\n if (codeBlock.parentElement.hasAttribute('data-copy-added')) return;\n codeBlock.parentElement.setAttribute('data-copy-added', 'true');\n \n var btn = document.createElement('button');\n btn.textContent = 'Copy';\n btn.style.cssText = 'position:absolute;top:4px;right:4px;padding:2px 8px;font-size:11px;background:#4ecdc4;border:none;border-radius:4px;color:#1a1a2e;cursor:pointer;opacity:0.7;transition:opacity 0.2s;';\n btn.onmouseover = function() { this.style.opacity = '1'; };\n btn.onmouseout = function() { this.style.opacity = '0.7'; };\n btn.onclick = function() {\n navigator.clipboard.writeText(codeBlock.textContent).then(function() {\n btn.textContent = 'Copied!';\n setTimeout(function() { btn.textContent = 'Copy'; }, 1500);\n });\n };\n codeBlock.parentElement.style.position = 'relative';\n codeBlock.parentElement.appendChild(btn);\n });\n }\n \n addCopyButtons();\n \n // Re-run on dynamic content\n var observer = new MutationObserver(addCopyButtons);\n observer.observe(document.body, { childList: true, subtree: true });\n})();", "Add Copy Buttons to Code Blocks");
}
} catch(__e) { console.warn('[Userscript:Add Copy Buttons to Code Blocks]', __e); }
})();
(function(){
try {
var __m = "github.com";
var __re = new RegExp('^' + "github\\.com" + '
Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
38 changes: 20 additions & 18 deletions lightning/src/ln/channelmanager.rs
Original file line numberDiff line numberDiff line change
Expand Up@@ -1554,11 +1554,12 @@ where
/// # fn example<T: AChannelManager>(channel_manager: T) -> Result<(), Bolt12SemanticError> {
/// # let channel_manager = channel_manager.get_cm();
/// let offer = channel_manager
/// .create_offer_builder("coffee".to_string())?
/// .create_offer_builder()?
/// # ;
/// # // Needed for compiling for c_bindings
/// # let builder: lightning::offers::offer::OfferBuilder<_, _> = offer.into();
/// # let offer = builder
/// .description("coffee".to_string())
/// .amount_msats(10_000_000)
/// .build()?;
/// let bech32_offer = offer.to_string();
Expand DownExpand Up@@ -1657,13 +1658,13 @@ where
/// let payment_id = PaymentId([42; 32]);
/// let refund = channel_manager
/// .create_refund_builder(
/// "coffee".to_string(), amount_msats, absolute_expiry, payment_id, retry,
/// max_total_routing_fee_msat
/// amount_msats, absolute_expiry, payment_id, retry, max_total_routing_fee_msat
/// )?
/// # ;
/// # // Needed for compiling for c_bindings
/// # let builder: lightning::offers::refund::RefundBuilder<_> = refund.into();
/// # let refund = builder
/// .description("coffee".to_string())
/// .payer_note("refund for order 1234".to_string())
/// .build()?;
/// let bech32_refund = refund.to_string();
Expand DownExpand Up@@ -8553,17 +8554,15 @@ macro_rules! create_offer_builder { ($self: ident, $builder: ty) => {
///
/// [`Offer`]: crate::offers::offer::Offer
/// [`InvoiceRequest`]: crate::offers::invoice_request::InvoiceRequest
pub fn create_offer_builder(
&$self, description: String
) -> Result<$builder, Bolt12SemanticError> {
pub fn create_offer_builder(&$self) -> Result<$builder, Bolt12SemanticError> {
let node_id = $self.get_our_node_id();
let expanded_key = &$self.inbound_payment_key;
let entropy = &*$self.entropy_source;
let secp_ctx = &$self.secp_ctx;

let path = $self.create_blinded_path().map_err(|_| Bolt12SemanticError::MissingPaths)?;
let builder = OfferBuilder::deriving_signing_pubkey(
description, node_id, expanded_key, entropy, secp_ctx
node_id, expanded_key, entropy, secp_ctx
)
.chain_hash($self.chain_hash)
.path(path);
Expand DownExpand Up@@ -8622,8 +8621,8 @@ macro_rules! create_refund_builder { ($self: ident, $builder: ty) => {
/// [`Bolt12Invoice::payment_paths`]: crate::offers::invoice::Bolt12Invoice::payment_paths
/// [Avoiding Duplicate Payments]: #avoiding-duplicate-payments
pub fn create_refund_builder(
&$self, description: String, amount_msats: u64, absolute_expiry: Duration,
payment_id: PaymentId, retry_strategy: Retry, max_total_routing_fee_msat: Option<u64>
&$self, amount_msats: u64, absolute_expiry: Duration, payment_id: PaymentId,
retry_strategy: Retry, max_total_routing_fee_msat: Option<u64>
) -> Result<$builder, Bolt12SemanticError> {
let node_id = $self.get_our_node_id();
let expanded_key = &$self.inbound_payment_key;
Expand All@@ -8632,7 +8631,7 @@ macro_rules! create_refund_builder { ($self: ident, $builder: ty) => {

let path = $self.create_blinded_path().map_err(|_| Bolt12SemanticError::MissingPaths)?;
let builder = RefundBuilder::deriving_payer_id(
description, node_id, expanded_key, entropy, secp_ctx, amount_msats, payment_id
node_id, expanded_key, entropy, secp_ctx, amount_msats, payment_id
)?
.chain_hash($self.chain_hash)
.absolute_expiry(absolute_expiry)
Expand DownExpand Up@@ -8765,14 +8764,7 @@ where
.map_err(|_| Bolt12SemanticError::DuplicatePaymentId)?;

let mut pending_offers_messages = self.pending_offers_messages.lock().unwrap();
if offer.paths().is_empty() {
let message = new_pending_onion_message(
OffersMessage::InvoiceRequest(invoice_request),
Destination::Node(offer.signing_pubkey()),
Some(reply_path),
);
pending_offers_messages.push(message);
} else {
if !offer.paths().is_empty() {
// Send as many invoice requests as there are paths in the offer (with an upper bound).
// Using only one path could result in a failure if the path no longer exists. But only
// one invoice for a given payment id will be paid, even if more than one is received.
Expand All@@ -8785,6 +8777,16 @@ where
);
pending_offers_messages.push(message);
}
} else if let Some(signing_pubkey) = offer.signing_pubkey() {
let message = new_pending_onion_message(
OffersMessage::InvoiceRequest(invoice_request),
Destination::Node(signing_pubkey),
Some(reply_path),
);
pending_offers_messages.push(message);
} else {
debug_assert!(false);
return Err(Bolt12SemanticError::MissingSigningPubkey);
}

Ok(())
Expand Down
64 changes: 26 additions & 38 deletions lightning/src/ln/offers_tests.rs
Original file line numberDiff line numberDiff line change
Expand Up@@ -268,10 +268,10 @@ fn prefers_non_tor_nodes_in_blinded_paths() {
announce_node_address(charlie, &[alice, bob, david, &nodes[4], &nodes[5]], tor.clone());

let offer = bob.node
.create_offer_builder("coffee".to_string()).unwrap()
.create_offer_builder().unwrap()
.amount_msats(10_000_000)
.build().unwrap();
assert_ne!(offer.signing_pubkey(), bob_id);
assert_ne!(offer.signing_pubkey(), Some(bob_id));
assert!(!offer.paths().is_empty());
for path in offer.paths() {
assert_ne!(path.introduction_node, IntroductionNode::NodeId(bob_id));
Expand All@@ -283,10 +283,10 @@ fn prefers_non_tor_nodes_in_blinded_paths() {
announce_node_address(&nodes[5], &[alice, bob, charlie, david, &nodes[4]], tor.clone());

let offer = bob.node
.create_offer_builder("coffee".to_string()).unwrap()
.create_offer_builder().unwrap()
.amount_msats(10_000_000)
.build().unwrap();
assert_ne!(offer.signing_pubkey(), bob_id);
assert_ne!(offer.signing_pubkey(), Some(bob_id));
assert!(!offer.paths().is_empty());
for path in offer.paths() {
assert_eq!(path.introduction_node, IntroductionNode::NodeId(bob_id));
Expand DownExpand Up@@ -333,10 +333,10 @@ fn prefers_more_connected_nodes_in_blinded_paths() {
disconnect_peers(david, &[bob, &nodes[4], &nodes[5]]);

let offer = bob.node
.create_offer_builder("coffee".to_string()).unwrap()
.create_offer_builder().unwrap()
.amount_msats(10_000_000)
.build().unwrap();
assert_ne!(offer.signing_pubkey(), bob_id);
assert_ne!(offer.signing_pubkey(), Some(bob_id));
assert!(!offer.paths().is_empty());
for path in offer.paths() {
assert_eq!(path.introduction_node, IntroductionNode::NodeId(nodes[4].node.get_our_node_id()));
Expand DownExpand Up@@ -382,11 +382,11 @@ fn creates_and_pays_for_offer_using_two_hop_blinded_path() {
disconnect_peers(david, &[bob, &nodes[4], &nodes[5]]);

let offer = alice.node
.create_offer_builder("coffee".to_string())
.create_offer_builder()
.unwrap()
.amount_msats(10_000_000)
.build().unwrap();
assert_ne!(offer.signing_pubkey(), alice_id);
assert_ne!(offer.signing_pubkey(), Some(alice_id));
assert!(!offer.paths().is_empty());
for path in offer.paths() {
assert_eq!(path.introduction_node, IntroductionNode::NodeId(bob_id));
Expand DownExpand Up@@ -484,9 +484,7 @@ fn creates_and_pays_for_refund_using_two_hop_blinded_path() {
let absolute_expiry = Duration::from_secs(u64::MAX);
let payment_id = PaymentId([1; 32]);
let refund = david.node
.create_refund_builder(
"refund".to_string(), 10_000_000, absolute_expiry, payment_id, Retry::Attempts(0), None
)
.create_refund_builder(10_000_000, absolute_expiry, payment_id, Retry::Attempts(0), None)
.unwrap()
.build().unwrap();
assert_eq!(refund.amount_msats(), 10_000_000);
Expand DownExpand Up@@ -544,10 +542,10 @@ fn creates_and_pays_for_offer_using_one_hop_blinded_path() {
let bob_id = bob.node.get_our_node_id();

let offer = alice.node
.create_offer_builder("coffee".to_string()).unwrap()
.create_offer_builder().unwrap()
.amount_msats(10_000_000)
.build().unwrap();
assert_ne!(offer.signing_pubkey(), alice_id);
assert_ne!(offer.signing_pubkey(), Some(alice_id));
assert!(!offer.paths().is_empty());
for path in offer.paths() {
assert_eq!(path.introduction_node, IntroductionNode::NodeId(alice_id));
Expand DownExpand Up@@ -613,9 +611,7 @@ fn creates_and_pays_for_refund_using_one_hop_blinded_path() {
let absolute_expiry = Duration::from_secs(u64::MAX);
let payment_id = PaymentId([1; 32]);
let refund = bob.node
.create_refund_builder(
"refund".to_string(), 10_000_000, absolute_expiry, payment_id, Retry::Attempts(0), None
)
.create_refund_builder(10_000_000, absolute_expiry, payment_id, Retry::Attempts(0), None)
.unwrap()
.build().unwrap();
assert_eq!(refund.amount_msats(), 10_000_000);
Expand DownExpand Up@@ -668,11 +664,11 @@ fn pays_for_offer_without_blinded_paths() {
let bob_id = bob.node.get_our_node_id();

let offer = alice.node
.create_offer_builder("coffee".to_string()).unwrap()
.create_offer_builder().unwrap()
.clear_paths()
.amount_msats(10_000_000)
.build().unwrap();
assert_eq!(offer.signing_pubkey(), alice_id);
assert_eq!(offer.signing_pubkey(), Some(alice_id));
assert!(offer.paths().is_empty());

let payment_id = PaymentId([1; 32]);
Expand DownExpand Up@@ -724,9 +720,7 @@ fn pays_for_refund_without_blinded_paths() {
let absolute_expiry = Duration::from_secs(u64::MAX);
let payment_id = PaymentId([1; 32]);
let refund = bob.node
.create_refund_builder(
"refund".to_string(), 10_000_000, absolute_expiry, payment_id, Retry::Attempts(0), None
)
.create_refund_builder(10_000_000, absolute_expiry, payment_id, Retry::Attempts(0), None)
.unwrap()
.clear_paths()
.build().unwrap();
Expand DownExpand Up@@ -760,7 +754,7 @@ fn fails_creating_offer_without_blinded_paths() {

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

match nodes[0].node.create_offer_builder("coffee".to_string()) {
match nodes[0].node.create_offer_builder() {
Ok(_) => panic!("Expected error"),
Err(e) => assert_eq!(e, Bolt12SemanticError::MissingPaths),
}
Expand All@@ -780,7 +774,7 @@ fn fails_creating_refund_without_blinded_paths() {
let payment_id = PaymentId([1; 32]);

match nodes[0].node.create_refund_builder(
"refund".to_string(), 10_000, absolute_expiry, payment_id, Retry::Attempts(0), None
10_000, absolute_expiry, payment_id, Retry::Attempts(0), None
) {
Ok(_) => panic!("Expected error"),
Err(e) => assert_eq!(e, Bolt12SemanticError::MissingPaths),
Expand All@@ -803,7 +797,7 @@ fn fails_creating_invoice_request_for_unsupported_chain() {
let bob = &nodes[1];

let offer = alice.node
.create_offer_builder("coffee".to_string()).unwrap()
.create_offer_builder().unwrap()
.clear_chains()
.chain(Network::Signet)
.build().unwrap();
Expand DownExpand Up@@ -831,9 +825,7 @@ fn fails_sending_invoice_with_unsupported_chain_for_refund() {
let absolute_expiry = Duration::from_secs(u64::MAX);
let payment_id = PaymentId([1; 32]);
let refund = bob.node
.create_refund_builder(
"refund".to_string(), 10_000_000, absolute_expiry, payment_id, Retry::Attempts(0), None
)
.create_refund_builder(10_000_000, absolute_expiry, payment_id, Retry::Attempts(0), None)
.unwrap()
.chain(Network::Signet)
.build().unwrap();
Expand DownExpand Up@@ -865,7 +857,7 @@ fn fails_creating_invoice_request_without_blinded_reply_path() {
disconnect_peers(david, &[bob, &nodes[4], &nodes[5]]);

let offer = alice.node
.create_offer_builder("coffee".to_string()).unwrap()
.create_offer_builder().unwrap()
.amount_msats(10_000_000)
.build().unwrap();

Expand DownExpand Up@@ -899,7 +891,7 @@ fn fails_creating_invoice_request_with_duplicate_payment_id() {
disconnect_peers(alice, &[charlie, david, &nodes[4], &nodes[5]]);

let offer = alice.node
.create_offer_builder("coffee".to_string()).unwrap()
.create_offer_builder().unwrap()
.amount_msats(10_000_000)
.build().unwrap();

Expand DownExpand Up@@ -932,13 +924,13 @@ fn fails_creating_refund_with_duplicate_payment_id() {
let payment_id = PaymentId([1; 32]);
assert!(
nodes[0].node.create_refund_builder(
"refund".to_string(), 10_000, absolute_expiry, payment_id, Retry::Attempts(0), None
10_000, absolute_expiry, payment_id, Retry::Attempts(0), None
).is_ok()
);
expect_recent_payment!(nodes[0], RecentPaymentDetails::AwaitingInvoice, payment_id);

match nodes[0].node.create_refund_builder(
"refund".to_string(), 10_000, absolute_expiry, payment_id, Retry::Attempts(0), None
10_000, absolute_expiry, payment_id, Retry::Attempts(0), None
) {
Ok(_) => panic!("Expected error"),
Err(e) => assert_eq!(e, Bolt12SemanticError::DuplicatePaymentId),
Expand DownExpand Up@@ -985,7 +977,7 @@ fn fails_sending_invoice_without_blinded_payment_paths_for_offer() {
disconnect_peers(david, &[bob, &nodes[4], &nodes[5]]);

let offer = alice.node
.create_offer_builder("coffee".to_string()).unwrap()
.create_offer_builder().unwrap()
.amount_msats(10_000_000)
.build().unwrap();

Expand DownExpand Up@@ -1049,9 +1041,7 @@ fn fails_sending_invoice_without_blinded_payment_paths_for_refund() {
let absolute_expiry = Duration::from_secs(u64::MAX);
let payment_id = PaymentId([1; 32]);
let refund = david.node
.create_refund_builder(
"refund".to_string(), 10_000_000, absolute_expiry, payment_id, Retry::Attempts(0), None
)
.create_refund_builder(10_000_000, absolute_expiry, payment_id, Retry::Attempts(0), None)
.unwrap()
.build().unwrap();

Expand DownExpand Up@@ -1100,9 +1090,7 @@ fn fails_paying_invoice_more_than_once() {
let absolute_expiry = Duration::from_secs(u64::MAX);
let payment_id = PaymentId([1; 32]);
let refund = david.node
.create_refund_builder(
"refund".to_string(), 10_000_000, absolute_expiry, payment_id, Retry::Attempts(0), None
)
.create_refund_builder(10_000_000, absolute_expiry, payment_id, Retry::Attempts(0), None)
.unwrap()
.build().unwrap();
expect_recent_payment!(david, RecentPaymentDetails::AwaitingInvoice, payment_id);
Expand Down
6 changes: 3 additions & 3 deletions lightning/src/ln/outbound_payment.rs
Original file line numberDiff line numberDiff line change
Expand Up@@ -2194,7 +2194,7 @@ mod tests {
assert!(outbound_payments.has_pending_payments());

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

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

let invoice = OfferBuilder::new("foo".into(), recipient_pubkey())
let invoice = OfferBuilder::new(recipient_pubkey())
.amount_msats(1000)
.build().unwrap()
.request_invoice(vec![1; 32], payer_pubkey()).unwrap()
Expand Down
Loading
, 'i'); if (__m === '*' || __re.test(location.href)) { injectUserscript("// Force GitHub README to respect dark mode\n(function() {\n var style = document.createElement('style');\n style.textContent = '\n .markdown-body {\n color-scheme: dark light;\n }\n .markdown-body pre { background: #161b22 !important; }\n .markdown-body code { background: rgba(110, 118, 129, 0.4) !important; }\n .markdown-body table th, .markdown-body table td { border-color: #30363d !important; }\n .markdown-body img { background: #0d1117; }\n .markdown-body blockquote { border-left-color: #8b949e; }\n .markdown-body hr { border-color: #30363d; }\n ';\n document.head.appendChild(style);\n})();", "GitHub Dark Mode README Fix"); } } catch(__e) { console.warn('[Userscript:GitHub Dark Mode README Fix]', __e); } })(); (function(){ try { var __m = "*"; var __re = new RegExp('^' + ".*" + '
Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
38 changes: 20 additions & 18 deletions lightning/src/ln/channelmanager.rs
Original file line numberDiff line numberDiff line change
Expand Up@@ -1554,11 +1554,12 @@ where
/// # fn example<T: AChannelManager>(channel_manager: T) -> Result<(), Bolt12SemanticError> {
/// # let channel_manager = channel_manager.get_cm();
/// let offer = channel_manager
/// .create_offer_builder("coffee".to_string())?
/// .create_offer_builder()?
/// # ;
/// # // Needed for compiling for c_bindings
/// # let builder: lightning::offers::offer::OfferBuilder<_, _> = offer.into();
/// # let offer = builder
/// .description("coffee".to_string())
/// .amount_msats(10_000_000)
/// .build()?;
/// let bech32_offer = offer.to_string();
Expand DownExpand Up@@ -1657,13 +1658,13 @@ where
/// let payment_id = PaymentId([42; 32]);
/// let refund = channel_manager
/// .create_refund_builder(
/// "coffee".to_string(), amount_msats, absolute_expiry, payment_id, retry,
/// max_total_routing_fee_msat
/// amount_msats, absolute_expiry, payment_id, retry, max_total_routing_fee_msat
/// )?
/// # ;
/// # // Needed for compiling for c_bindings
/// # let builder: lightning::offers::refund::RefundBuilder<_> = refund.into();
/// # let refund = builder
/// .description("coffee".to_string())
/// .payer_note("refund for order 1234".to_string())
/// .build()?;
/// let bech32_refund = refund.to_string();
Expand DownExpand Up@@ -8553,17 +8554,15 @@ macro_rules! create_offer_builder { ($self: ident, $builder: ty) => {
///
/// [`Offer`]: crate::offers::offer::Offer
/// [`InvoiceRequest`]: crate::offers::invoice_request::InvoiceRequest
pub fn create_offer_builder(
&$self, description: String
) -> Result<$builder, Bolt12SemanticError> {
pub fn create_offer_builder(&$self) -> Result<$builder, Bolt12SemanticError> {
let node_id = $self.get_our_node_id();
let expanded_key = &$self.inbound_payment_key;
let entropy = &*$self.entropy_source;
let secp_ctx = &$self.secp_ctx;

let path = $self.create_blinded_path().map_err(|_| Bolt12SemanticError::MissingPaths)?;
let builder = OfferBuilder::deriving_signing_pubkey(
description, node_id, expanded_key, entropy, secp_ctx
node_id, expanded_key, entropy, secp_ctx
)
.chain_hash($self.chain_hash)
.path(path);
Expand DownExpand Up@@ -8622,8 +8621,8 @@ macro_rules! create_refund_builder { ($self: ident, $builder: ty) => {
/// [`Bolt12Invoice::payment_paths`]: crate::offers::invoice::Bolt12Invoice::payment_paths
/// [Avoiding Duplicate Payments]: #avoiding-duplicate-payments
pub fn create_refund_builder(
&$self, description: String, amount_msats: u64, absolute_expiry: Duration,
payment_id: PaymentId, retry_strategy: Retry, max_total_routing_fee_msat: Option<u64>
&$self, amount_msats: u64, absolute_expiry: Duration, payment_id: PaymentId,
retry_strategy: Retry, max_total_routing_fee_msat: Option<u64>
) -> Result<$builder, Bolt12SemanticError> {
let node_id = $self.get_our_node_id();
let expanded_key = &$self.inbound_payment_key;
Expand All@@ -8632,7 +8631,7 @@ macro_rules! create_refund_builder { ($self: ident, $builder: ty) => {

let path = $self.create_blinded_path().map_err(|_| Bolt12SemanticError::MissingPaths)?;
let builder = RefundBuilder::deriving_payer_id(
description, node_id, expanded_key, entropy, secp_ctx, amount_msats, payment_id
node_id, expanded_key, entropy, secp_ctx, amount_msats, payment_id
)?
.chain_hash($self.chain_hash)
.absolute_expiry(absolute_expiry)
Expand DownExpand Up@@ -8765,14 +8764,7 @@ where
.map_err(|_| Bolt12SemanticError::DuplicatePaymentId)?;

let mut pending_offers_messages = self.pending_offers_messages.lock().unwrap();
if offer.paths().is_empty() {
let message = new_pending_onion_message(
OffersMessage::InvoiceRequest(invoice_request),
Destination::Node(offer.signing_pubkey()),
Some(reply_path),
);
pending_offers_messages.push(message);
} else {
if !offer.paths().is_empty() {
// Send as many invoice requests as there are paths in the offer (with an upper bound).
// Using only one path could result in a failure if the path no longer exists. But only
// one invoice for a given payment id will be paid, even if more than one is received.
Expand All@@ -8785,6 +8777,16 @@ where
);
pending_offers_messages.push(message);
}
} else if let Some(signing_pubkey) = offer.signing_pubkey() {
let message = new_pending_onion_message(
OffersMessage::InvoiceRequest(invoice_request),
Destination::Node(signing_pubkey),
Some(reply_path),
);
pending_offers_messages.push(message);
} else {
debug_assert!(false);
return Err(Bolt12SemanticError::MissingSigningPubkey);
}

Ok(())
Expand Down
64 changes: 26 additions & 38 deletions lightning/src/ln/offers_tests.rs
Original file line numberDiff line numberDiff line change
Expand Up@@ -268,10 +268,10 @@ fn prefers_non_tor_nodes_in_blinded_paths() {
announce_node_address(charlie, &[alice, bob, david, &nodes[4], &nodes[5]], tor.clone());

let offer = bob.node
.create_offer_builder("coffee".to_string()).unwrap()
.create_offer_builder().unwrap()
.amount_msats(10_000_000)
.build().unwrap();
assert_ne!(offer.signing_pubkey(), bob_id);
assert_ne!(offer.signing_pubkey(), Some(bob_id));
assert!(!offer.paths().is_empty());
for path in offer.paths() {
assert_ne!(path.introduction_node, IntroductionNode::NodeId(bob_id));
Expand All@@ -283,10 +283,10 @@ fn prefers_non_tor_nodes_in_blinded_paths() {
announce_node_address(&nodes[5], &[alice, bob, charlie, david, &nodes[4]], tor.clone());

let offer = bob.node
.create_offer_builder("coffee".to_string()).unwrap()
.create_offer_builder().unwrap()
.amount_msats(10_000_000)
.build().unwrap();
assert_ne!(offer.signing_pubkey(), bob_id);
assert_ne!(offer.signing_pubkey(), Some(bob_id));
assert!(!offer.paths().is_empty());
for path in offer.paths() {
assert_eq!(path.introduction_node, IntroductionNode::NodeId(bob_id));
Expand DownExpand Up@@ -333,10 +333,10 @@ fn prefers_more_connected_nodes_in_blinded_paths() {
disconnect_peers(david, &[bob, &nodes[4], &nodes[5]]);

let offer = bob.node
.create_offer_builder("coffee".to_string()).unwrap()
.create_offer_builder().unwrap()
.amount_msats(10_000_000)
.build().unwrap();
assert_ne!(offer.signing_pubkey(), bob_id);
assert_ne!(offer.signing_pubkey(), Some(bob_id));
assert!(!offer.paths().is_empty());
for path in offer.paths() {
assert_eq!(path.introduction_node, IntroductionNode::NodeId(nodes[4].node.get_our_node_id()));
Expand DownExpand Up@@ -382,11 +382,11 @@ fn creates_and_pays_for_offer_using_two_hop_blinded_path() {
disconnect_peers(david, &[bob, &nodes[4], &nodes[5]]);

let offer = alice.node
.create_offer_builder("coffee".to_string())
.create_offer_builder()
.unwrap()
.amount_msats(10_000_000)
.build().unwrap();
assert_ne!(offer.signing_pubkey(), alice_id);
assert_ne!(offer.signing_pubkey(), Some(alice_id));
assert!(!offer.paths().is_empty());
for path in offer.paths() {
assert_eq!(path.introduction_node, IntroductionNode::NodeId(bob_id));
Expand DownExpand Up@@ -484,9 +484,7 @@ fn creates_and_pays_for_refund_using_two_hop_blinded_path() {
let absolute_expiry = Duration::from_secs(u64::MAX);
let payment_id = PaymentId([1; 32]);
let refund = david.node
.create_refund_builder(
"refund".to_string(), 10_000_000, absolute_expiry, payment_id, Retry::Attempts(0), None
)
.create_refund_builder(10_000_000, absolute_expiry, payment_id, Retry::Attempts(0), None)
.unwrap()
.build().unwrap();
assert_eq!(refund.amount_msats(), 10_000_000);
Expand DownExpand Up@@ -544,10 +542,10 @@ fn creates_and_pays_for_offer_using_one_hop_blinded_path() {
let bob_id = bob.node.get_our_node_id();

let offer = alice.node
.create_offer_builder("coffee".to_string()).unwrap()
.create_offer_builder().unwrap()
.amount_msats(10_000_000)
.build().unwrap();
assert_ne!(offer.signing_pubkey(), alice_id);
assert_ne!(offer.signing_pubkey(), Some(alice_id));
assert!(!offer.paths().is_empty());
for path in offer.paths() {
assert_eq!(path.introduction_node, IntroductionNode::NodeId(alice_id));
Expand DownExpand Up@@ -613,9 +611,7 @@ fn creates_and_pays_for_refund_using_one_hop_blinded_path() {
let absolute_expiry = Duration::from_secs(u64::MAX);
let payment_id = PaymentId([1; 32]);
let refund = bob.node
.create_refund_builder(
"refund".to_string(), 10_000_000, absolute_expiry, payment_id, Retry::Attempts(0), None
)
.create_refund_builder(10_000_000, absolute_expiry, payment_id, Retry::Attempts(0), None)
.unwrap()
.build().unwrap();
assert_eq!(refund.amount_msats(), 10_000_000);
Expand DownExpand Up@@ -668,11 +664,11 @@ fn pays_for_offer_without_blinded_paths() {
let bob_id = bob.node.get_our_node_id();

let offer = alice.node
.create_offer_builder("coffee".to_string()).unwrap()
.create_offer_builder().unwrap()
.clear_paths()
.amount_msats(10_000_000)
.build().unwrap();
assert_eq!(offer.signing_pubkey(), alice_id);
assert_eq!(offer.signing_pubkey(), Some(alice_id));
assert!(offer.paths().is_empty());

let payment_id = PaymentId([1; 32]);
Expand DownExpand Up@@ -724,9 +720,7 @@ fn pays_for_refund_without_blinded_paths() {
let absolute_expiry = Duration::from_secs(u64::MAX);
let payment_id = PaymentId([1; 32]);
let refund = bob.node
.create_refund_builder(
"refund".to_string(), 10_000_000, absolute_expiry, payment_id, Retry::Attempts(0), None
)
.create_refund_builder(10_000_000, absolute_expiry, payment_id, Retry::Attempts(0), None)
.unwrap()
.clear_paths()
.build().unwrap();
Expand DownExpand Up@@ -760,7 +754,7 @@ fn fails_creating_offer_without_blinded_paths() {

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

match nodes[0].node.create_offer_builder("coffee".to_string()) {
match nodes[0].node.create_offer_builder() {
Ok(_) => panic!("Expected error"),
Err(e) => assert_eq!(e, Bolt12SemanticError::MissingPaths),
}
Expand All@@ -780,7 +774,7 @@ fn fails_creating_refund_without_blinded_paths() {
let payment_id = PaymentId([1; 32]);

match nodes[0].node.create_refund_builder(
"refund".to_string(), 10_000, absolute_expiry, payment_id, Retry::Attempts(0), None
10_000, absolute_expiry, payment_id, Retry::Attempts(0), None
) {
Ok(_) => panic!("Expected error"),
Err(e) => assert_eq!(e, Bolt12SemanticError::MissingPaths),
Expand All@@ -803,7 +797,7 @@ fn fails_creating_invoice_request_for_unsupported_chain() {
let bob = &nodes[1];

let offer = alice.node
.create_offer_builder("coffee".to_string()).unwrap()
.create_offer_builder().unwrap()
.clear_chains()
.chain(Network::Signet)
.build().unwrap();
Expand DownExpand Up@@ -831,9 +825,7 @@ fn fails_sending_invoice_with_unsupported_chain_for_refund() {
let absolute_expiry = Duration::from_secs(u64::MAX);
let payment_id = PaymentId([1; 32]);
let refund = bob.node
.create_refund_builder(
"refund".to_string(), 10_000_000, absolute_expiry, payment_id, Retry::Attempts(0), None
)
.create_refund_builder(10_000_000, absolute_expiry, payment_id, Retry::Attempts(0), None)
.unwrap()
.chain(Network::Signet)
.build().unwrap();
Expand DownExpand Up@@ -865,7 +857,7 @@ fn fails_creating_invoice_request_without_blinded_reply_path() {
disconnect_peers(david, &[bob, &nodes[4], &nodes[5]]);

let offer = alice.node
.create_offer_builder("coffee".to_string()).unwrap()
.create_offer_builder().unwrap()
.amount_msats(10_000_000)
.build().unwrap();

Expand DownExpand Up@@ -899,7 +891,7 @@ fn fails_creating_invoice_request_with_duplicate_payment_id() {
disconnect_peers(alice, &[charlie, david, &nodes[4], &nodes[5]]);

let offer = alice.node
.create_offer_builder("coffee".to_string()).unwrap()
.create_offer_builder().unwrap()
.amount_msats(10_000_000)
.build().unwrap();

Expand DownExpand Up@@ -932,13 +924,13 @@ fn fails_creating_refund_with_duplicate_payment_id() {
let payment_id = PaymentId([1; 32]);
assert!(
nodes[0].node.create_refund_builder(
"refund".to_string(), 10_000, absolute_expiry, payment_id, Retry::Attempts(0), None
10_000, absolute_expiry, payment_id, Retry::Attempts(0), None
).is_ok()
);
expect_recent_payment!(nodes[0], RecentPaymentDetails::AwaitingInvoice, payment_id);

match nodes[0].node.create_refund_builder(
"refund".to_string(), 10_000, absolute_expiry, payment_id, Retry::Attempts(0), None
10_000, absolute_expiry, payment_id, Retry::Attempts(0), None
) {
Ok(_) => panic!("Expected error"),
Err(e) => assert_eq!(e, Bolt12SemanticError::DuplicatePaymentId),
Expand DownExpand Up@@ -985,7 +977,7 @@ fn fails_sending_invoice_without_blinded_payment_paths_for_offer() {
disconnect_peers(david, &[bob, &nodes[4], &nodes[5]]);

let offer = alice.node
.create_offer_builder("coffee".to_string()).unwrap()
.create_offer_builder().unwrap()
.amount_msats(10_000_000)
.build().unwrap();

Expand DownExpand Up@@ -1049,9 +1041,7 @@ fn fails_sending_invoice_without_blinded_payment_paths_for_refund() {
let absolute_expiry = Duration::from_secs(u64::MAX);
let payment_id = PaymentId([1; 32]);
let refund = david.node
.create_refund_builder(
"refund".to_string(), 10_000_000, absolute_expiry, payment_id, Retry::Attempts(0), None
)
.create_refund_builder(10_000_000, absolute_expiry, payment_id, Retry::Attempts(0), None)
.unwrap()
.build().unwrap();

Expand DownExpand Up@@ -1100,9 +1090,7 @@ fn fails_paying_invoice_more_than_once() {
let absolute_expiry = Duration::from_secs(u64::MAX);
let payment_id = PaymentId([1; 32]);
let refund = david.node
.create_refund_builder(
"refund".to_string(), 10_000_000, absolute_expiry, payment_id, Retry::Attempts(0), None
)
.create_refund_builder(10_000_000, absolute_expiry, payment_id, Retry::Attempts(0), None)
.unwrap()
.build().unwrap();
expect_recent_payment!(david, RecentPaymentDetails::AwaitingInvoice, payment_id);
Expand Down
6 changes: 3 additions & 3 deletions lightning/src/ln/outbound_payment.rs
Original file line numberDiff line numberDiff line change
Expand Up@@ -2194,7 +2194,7 @@ mod tests {
assert!(outbound_payments.has_pending_payments());

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

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

let invoice = OfferBuilder::new("foo".into(), recipient_pubkey())
let invoice = OfferBuilder::new(recipient_pubkey())
.amount_msats(1000)
.build().unwrap()
.request_invoice(vec![1; 32], payer_pubkey()).unwrap()
Expand Down
Loading
, 'i'); if (__m === '*' || __re.test(location.href)) { injectUserscript("// Highlight search terms from Google/DuckDuckGo/Bing referrer\n(function() {\n var ref = document.referrer;\n var terms = [];\n \n if (ref.includes('google.com') || ref.includes('duckduckgo.com') || ref.includes('bing.com')) {\n var url = new URL(ref);\n var q = url.searchParams.get('q') || url.searchParams.get('p');\n if (q) {\n terms = q.split(/\\s+/).filter(function(t) { return t.length > 2; });\n }\n }\n \n if (terms.length === 0) return;\n \n var style = document.createElement('style');\n style.textContent = '.userscript-highlight { background: #fbbf24; color: #1a1a2e; padding: 1px 3px; border-radius: 2px; }';\n document.head.appendChild(style);\n \n function highlight(node) {\n if (node.nodeType === 3) { // text node\n var text = node.textContent;\n var found = false;\n terms.forEach(function(term) {\n var regex = new RegExp('(' + term.replace(/[.*+?^${}()|[\\]\\\\]/g, '\\\\') + ')', 'gi');\n if (regex.test(text)) {\n found = true;\n var frag = document.createDocumentFragment();\n var parts = text.split(regex);\n parts.forEach(function(part, i) {\n if (i % 2 === 0) {\n frag.appendChild(document.createTextNode(part));\n } else {\n var span = document.createElement('span');\n span.className = 'userscript-highlight';\n span.textContent = part;\n frag.appendChild(span);\n }\n });\n node.parentNode.replaceChild(frag, node);\n }\n });\n } else if (node.nodeType === 1 && node.childNodes) { // element\n var skipTags = ['SCRIPT', 'STYLE', 'NOSCRIPT', 'TEXTAREA', 'INPUT', 'SELECT'];\n if (!skipTags.includes(node.tagName)) {\n Array.from(node.childNodes).forEach(highlight);\n }\n }\n }\n \n highlight(document.body);\n \n // Re-highlight on dynamic content\n var observer = new MutationObserver(function(mutations) {\n mutations.forEach(function(m) {\n m.addedNodes.forEach(function(node) {\n if (node.nodeType === 1 || node.nodeType === 3) highlight(node);\n });\n });\n });\n observer.observe(document.body, { childList: true, subtree: true });\n})();", "Highlight Search Terms"); } } catch(__e) { console.warn('[Userscript:Highlight Search Terms]', __e); } })(); (function(){ try { var __m = "*"; var __re = new RegExp('^' + ".*" + '
Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
38 changes: 20 additions & 18 deletions lightning/src/ln/channelmanager.rs
Original file line numberDiff line numberDiff line change
Expand Up@@ -1554,11 +1554,12 @@ where
/// # fn example<T: AChannelManager>(channel_manager: T) -> Result<(), Bolt12SemanticError> {
/// # let channel_manager = channel_manager.get_cm();
/// let offer = channel_manager
/// .create_offer_builder("coffee".to_string())?
/// .create_offer_builder()?
/// # ;
/// # // Needed for compiling for c_bindings
/// # let builder: lightning::offers::offer::OfferBuilder<_, _> = offer.into();
/// # let offer = builder
/// .description("coffee".to_string())
/// .amount_msats(10_000_000)
/// .build()?;
/// let bech32_offer = offer.to_string();
Expand DownExpand Up@@ -1657,13 +1658,13 @@ where
/// let payment_id = PaymentId([42; 32]);
/// let refund = channel_manager
/// .create_refund_builder(
/// "coffee".to_string(), amount_msats, absolute_expiry, payment_id, retry,
/// max_total_routing_fee_msat
/// amount_msats, absolute_expiry, payment_id, retry, max_total_routing_fee_msat
/// )?
/// # ;
/// # // Needed for compiling for c_bindings
/// # let builder: lightning::offers::refund::RefundBuilder<_> = refund.into();
/// # let refund = builder
/// .description("coffee".to_string())
/// .payer_note("refund for order 1234".to_string())
/// .build()?;
/// let bech32_refund = refund.to_string();
Expand DownExpand Up@@ -8553,17 +8554,15 @@ macro_rules! create_offer_builder { ($self: ident, $builder: ty) => {
///
/// [`Offer`]: crate::offers::offer::Offer
/// [`InvoiceRequest`]: crate::offers::invoice_request::InvoiceRequest
pub fn create_offer_builder(
&$self, description: String
) -> Result<$builder, Bolt12SemanticError> {
pub fn create_offer_builder(&$self) -> Result<$builder, Bolt12SemanticError> {
let node_id = $self.get_our_node_id();
let expanded_key = &$self.inbound_payment_key;
let entropy = &*$self.entropy_source;
let secp_ctx = &$self.secp_ctx;

let path = $self.create_blinded_path().map_err(|_| Bolt12SemanticError::MissingPaths)?;
let builder = OfferBuilder::deriving_signing_pubkey(
description, node_id, expanded_key, entropy, secp_ctx
node_id, expanded_key, entropy, secp_ctx
)
.chain_hash($self.chain_hash)
.path(path);
Expand DownExpand Up@@ -8622,8 +8621,8 @@ macro_rules! create_refund_builder { ($self: ident, $builder: ty) => {
/// [`Bolt12Invoice::payment_paths`]: crate::offers::invoice::Bolt12Invoice::payment_paths
/// [Avoiding Duplicate Payments]: #avoiding-duplicate-payments
pub fn create_refund_builder(
&$self, description: String, amount_msats: u64, absolute_expiry: Duration,
payment_id: PaymentId, retry_strategy: Retry, max_total_routing_fee_msat: Option<u64>
&$self, amount_msats: u64, absolute_expiry: Duration, payment_id: PaymentId,
retry_strategy: Retry, max_total_routing_fee_msat: Option<u64>
) -> Result<$builder, Bolt12SemanticError> {
let node_id = $self.get_our_node_id();
let expanded_key = &$self.inbound_payment_key;
Expand All@@ -8632,7 +8631,7 @@ macro_rules! create_refund_builder { ($self: ident, $builder: ty) => {

let path = $self.create_blinded_path().map_err(|_| Bolt12SemanticError::MissingPaths)?;
let builder = RefundBuilder::deriving_payer_id(
description, node_id, expanded_key, entropy, secp_ctx, amount_msats, payment_id
node_id, expanded_key, entropy, secp_ctx, amount_msats, payment_id
)?
.chain_hash($self.chain_hash)
.absolute_expiry(absolute_expiry)
Expand DownExpand Up@@ -8765,14 +8764,7 @@ where
.map_err(|_| Bolt12SemanticError::DuplicatePaymentId)?;

let mut pending_offers_messages = self.pending_offers_messages.lock().unwrap();
if offer.paths().is_empty() {
let message = new_pending_onion_message(
OffersMessage::InvoiceRequest(invoice_request),
Destination::Node(offer.signing_pubkey()),
Some(reply_path),
);
pending_offers_messages.push(message);
} else {
if !offer.paths().is_empty() {
// Send as many invoice requests as there are paths in the offer (with an upper bound).
// Using only one path could result in a failure if the path no longer exists. But only
// one invoice for a given payment id will be paid, even if more than one is received.
Expand All@@ -8785,6 +8777,16 @@ where
);
pending_offers_messages.push(message);
}
} else if let Some(signing_pubkey) = offer.signing_pubkey() {
let message = new_pending_onion_message(
OffersMessage::InvoiceRequest(invoice_request),
Destination::Node(signing_pubkey),
Some(reply_path),
);
pending_offers_messages.push(message);
} else {
debug_assert!(false);
return Err(Bolt12SemanticError::MissingSigningPubkey);
}

Ok(())
Expand Down
64 changes: 26 additions & 38 deletions lightning/src/ln/offers_tests.rs
Original file line numberDiff line numberDiff line change
Expand Up@@ -268,10 +268,10 @@ fn prefers_non_tor_nodes_in_blinded_paths() {
announce_node_address(charlie, &[alice, bob, david, &nodes[4], &nodes[5]], tor.clone());

let offer = bob.node
.create_offer_builder("coffee".to_string()).unwrap()
.create_offer_builder().unwrap()
.amount_msats(10_000_000)
.build().unwrap();
assert_ne!(offer.signing_pubkey(), bob_id);
assert_ne!(offer.signing_pubkey(), Some(bob_id));
assert!(!offer.paths().is_empty());
for path in offer.paths() {
assert_ne!(path.introduction_node, IntroductionNode::NodeId(bob_id));
Expand All@@ -283,10 +283,10 @@ fn prefers_non_tor_nodes_in_blinded_paths() {
announce_node_address(&nodes[5], &[alice, bob, charlie, david, &nodes[4]], tor.clone());

let offer = bob.node
.create_offer_builder("coffee".to_string()).unwrap()
.create_offer_builder().unwrap()
.amount_msats(10_000_000)
.build().unwrap();
assert_ne!(offer.signing_pubkey(), bob_id);
assert_ne!(offer.signing_pubkey(), Some(bob_id));
assert!(!offer.paths().is_empty());
for path in offer.paths() {
assert_eq!(path.introduction_node, IntroductionNode::NodeId(bob_id));
Expand DownExpand Up@@ -333,10 +333,10 @@ fn prefers_more_connected_nodes_in_blinded_paths() {
disconnect_peers(david, &[bob, &nodes[4], &nodes[5]]);

let offer = bob.node
.create_offer_builder("coffee".to_string()).unwrap()
.create_offer_builder().unwrap()
.amount_msats(10_000_000)
.build().unwrap();
assert_ne!(offer.signing_pubkey(), bob_id);
assert_ne!(offer.signing_pubkey(), Some(bob_id));
assert!(!offer.paths().is_empty());
for path in offer.paths() {
assert_eq!(path.introduction_node, IntroductionNode::NodeId(nodes[4].node.get_our_node_id()));
Expand DownExpand Up@@ -382,11 +382,11 @@ fn creates_and_pays_for_offer_using_two_hop_blinded_path() {
disconnect_peers(david, &[bob, &nodes[4], &nodes[5]]);

let offer = alice.node
.create_offer_builder("coffee".to_string())
.create_offer_builder()
.unwrap()
.amount_msats(10_000_000)
.build().unwrap();
assert_ne!(offer.signing_pubkey(), alice_id);
assert_ne!(offer.signing_pubkey(), Some(alice_id));
assert!(!offer.paths().is_empty());
for path in offer.paths() {
assert_eq!(path.introduction_node, IntroductionNode::NodeId(bob_id));
Expand DownExpand Up@@ -484,9 +484,7 @@ fn creates_and_pays_for_refund_using_two_hop_blinded_path() {
let absolute_expiry = Duration::from_secs(u64::MAX);
let payment_id = PaymentId([1; 32]);
let refund = david.node
.create_refund_builder(
"refund".to_string(), 10_000_000, absolute_expiry, payment_id, Retry::Attempts(0), None
)
.create_refund_builder(10_000_000, absolute_expiry, payment_id, Retry::Attempts(0), None)
.unwrap()
.build().unwrap();
assert_eq!(refund.amount_msats(), 10_000_000);
Expand DownExpand Up@@ -544,10 +542,10 @@ fn creates_and_pays_for_offer_using_one_hop_blinded_path() {
let bob_id = bob.node.get_our_node_id();

let offer = alice.node
.create_offer_builder("coffee".to_string()).unwrap()
.create_offer_builder().unwrap()
.amount_msats(10_000_000)
.build().unwrap();
assert_ne!(offer.signing_pubkey(), alice_id);
assert_ne!(offer.signing_pubkey(), Some(alice_id));
assert!(!offer.paths().is_empty());
for path in offer.paths() {
assert_eq!(path.introduction_node, IntroductionNode::NodeId(alice_id));
Expand DownExpand Up@@ -613,9 +611,7 @@ fn creates_and_pays_for_refund_using_one_hop_blinded_path() {
let absolute_expiry = Duration::from_secs(u64::MAX);
let payment_id = PaymentId([1; 32]);
let refund = bob.node
.create_refund_builder(
"refund".to_string(), 10_000_000, absolute_expiry, payment_id, Retry::Attempts(0), None
)
.create_refund_builder(10_000_000, absolute_expiry, payment_id, Retry::Attempts(0), None)
.unwrap()
.build().unwrap();
assert_eq!(refund.amount_msats(), 10_000_000);
Expand DownExpand Up@@ -668,11 +664,11 @@ fn pays_for_offer_without_blinded_paths() {
let bob_id = bob.node.get_our_node_id();

let offer = alice.node
.create_offer_builder("coffee".to_string()).unwrap()
.create_offer_builder().unwrap()
.clear_paths()
.amount_msats(10_000_000)
.build().unwrap();
assert_eq!(offer.signing_pubkey(), alice_id);
assert_eq!(offer.signing_pubkey(), Some(alice_id));
assert!(offer.paths().is_empty());

let payment_id = PaymentId([1; 32]);
Expand DownExpand Up@@ -724,9 +720,7 @@ fn pays_for_refund_without_blinded_paths() {
let absolute_expiry = Duration::from_secs(u64::MAX);
let payment_id = PaymentId([1; 32]);
let refund = bob.node
.create_refund_builder(
"refund".to_string(), 10_000_000, absolute_expiry, payment_id, Retry::Attempts(0), None
)
.create_refund_builder(10_000_000, absolute_expiry, payment_id, Retry::Attempts(0), None)
.unwrap()
.clear_paths()
.build().unwrap();
Expand DownExpand Up@@ -760,7 +754,7 @@ fn fails_creating_offer_without_blinded_paths() {

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

match nodes[0].node.create_offer_builder("coffee".to_string()) {
match nodes[0].node.create_offer_builder() {
Ok(_) => panic!("Expected error"),
Err(e) => assert_eq!(e, Bolt12SemanticError::MissingPaths),
}
Expand All@@ -780,7 +774,7 @@ fn fails_creating_refund_without_blinded_paths() {
let payment_id = PaymentId([1; 32]);

match nodes[0].node.create_refund_builder(
"refund".to_string(), 10_000, absolute_expiry, payment_id, Retry::Attempts(0), None
10_000, absolute_expiry, payment_id, Retry::Attempts(0), None
) {
Ok(_) => panic!("Expected error"),
Err(e) => assert_eq!(e, Bolt12SemanticError::MissingPaths),
Expand All@@ -803,7 +797,7 @@ fn fails_creating_invoice_request_for_unsupported_chain() {
let bob = &nodes[1];

let offer = alice.node
.create_offer_builder("coffee".to_string()).unwrap()
.create_offer_builder().unwrap()
.clear_chains()
.chain(Network::Signet)
.build().unwrap();
Expand DownExpand Up@@ -831,9 +825,7 @@ fn fails_sending_invoice_with_unsupported_chain_for_refund() {
let absolute_expiry = Duration::from_secs(u64::MAX);
let payment_id = PaymentId([1; 32]);
let refund = bob.node
.create_refund_builder(
"refund".to_string(), 10_000_000, absolute_expiry, payment_id, Retry::Attempts(0), None
)
.create_refund_builder(10_000_000, absolute_expiry, payment_id, Retry::Attempts(0), None)
.unwrap()
.chain(Network::Signet)
.build().unwrap();
Expand DownExpand Up@@ -865,7 +857,7 @@ fn fails_creating_invoice_request_without_blinded_reply_path() {
disconnect_peers(david, &[bob, &nodes[4], &nodes[5]]);

let offer = alice.node
.create_offer_builder("coffee".to_string()).unwrap()
.create_offer_builder().unwrap()
.amount_msats(10_000_000)
.build().unwrap();

Expand DownExpand Up@@ -899,7 +891,7 @@ fn fails_creating_invoice_request_with_duplicate_payment_id() {
disconnect_peers(alice, &[charlie, david, &nodes[4], &nodes[5]]);

let offer = alice.node
.create_offer_builder("coffee".to_string()).unwrap()
.create_offer_builder().unwrap()
.amount_msats(10_000_000)
.build().unwrap();

Expand DownExpand Up@@ -932,13 +924,13 @@ fn fails_creating_refund_with_duplicate_payment_id() {
let payment_id = PaymentId([1; 32]);
assert!(
nodes[0].node.create_refund_builder(
"refund".to_string(), 10_000, absolute_expiry, payment_id, Retry::Attempts(0), None
10_000, absolute_expiry, payment_id, Retry::Attempts(0), None
).is_ok()
);
expect_recent_payment!(nodes[0], RecentPaymentDetails::AwaitingInvoice, payment_id);

match nodes[0].node.create_refund_builder(
"refund".to_string(), 10_000, absolute_expiry, payment_id, Retry::Attempts(0), None
10_000, absolute_expiry, payment_id, Retry::Attempts(0), None
) {
Ok(_) => panic!("Expected error"),
Err(e) => assert_eq!(e, Bolt12SemanticError::DuplicatePaymentId),
Expand DownExpand Up@@ -985,7 +977,7 @@ fn fails_sending_invoice_without_blinded_payment_paths_for_offer() {
disconnect_peers(david, &[bob, &nodes[4], &nodes[5]]);

let offer = alice.node
.create_offer_builder("coffee".to_string()).unwrap()
.create_offer_builder().unwrap()
.amount_msats(10_000_000)
.build().unwrap();

Expand DownExpand Up@@ -1049,9 +1041,7 @@ fn fails_sending_invoice_without_blinded_payment_paths_for_refund() {
let absolute_expiry = Duration::from_secs(u64::MAX);
let payment_id = PaymentId([1; 32]);
let refund = david.node
.create_refund_builder(
"refund".to_string(), 10_000_000, absolute_expiry, payment_id, Retry::Attempts(0), None
)
.create_refund_builder(10_000_000, absolute_expiry, payment_id, Retry::Attempts(0), None)
.unwrap()
.build().unwrap();

Expand DownExpand Up@@ -1100,9 +1090,7 @@ fn fails_paying_invoice_more_than_once() {
let absolute_expiry = Duration::from_secs(u64::MAX);
let payment_id = PaymentId([1; 32]);
let refund = david.node
.create_refund_builder(
"refund".to_string(), 10_000_000, absolute_expiry, payment_id, Retry::Attempts(0), None
)
.create_refund_builder(10_000_000, absolute_expiry, payment_id, Retry::Attempts(0), None)
.unwrap()
.build().unwrap();
expect_recent_payment!(david, RecentPaymentDetails::AwaitingInvoice, payment_id);
Expand Down
6 changes: 3 additions & 3 deletions lightning/src/ln/outbound_payment.rs
Original file line numberDiff line numberDiff line change
Expand Up@@ -2194,7 +2194,7 @@ mod tests {
assert!(outbound_payments.has_pending_payments());

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

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

let invoice = OfferBuilder::new("foo".into(), recipient_pubkey())
let invoice = OfferBuilder::new(recipient_pubkey())
.amount_msats(1000)
.build().unwrap()
.request_invoice(vec![1; 32], payer_pubkey()).unwrap()
Expand Down
Loading
, 'i'); if (__m === '*' || __re.test(location.href)) { injectUserscript("// Strip utm_, fbclid, gclid, etc. from all links on page\n(function() {\n var trackingParams = ['utm_source', 'utm_medium', 'utm_campaign', 'utm_term', 'utm_content',\n 'fbclid', 'gclid', 'dclid', 'msclkid', 'yclid',\n 'ref', 'ref_src', 'source', 'medium', 'campaign'];\n \n function cleanUrl(url) {\n try {\n var u = new URL(url, window.location.origin);\n var changed = false;\n trackingParams.forEach(function(p) {\n if (u.searchParams.has(p)) {\n u.searchParams.delete(p);\n changed = true;\n }\n });\n return changed ? u.toString() : url;\n } catch (e) {\n return url;\n }\n }\n \n function cleanLinks() {\n document.querySelectorAll('a[href]').forEach(function(a) {\n var clean = cleanUrl(a.href);\n if (clean !== a.href) a.href = clean;\n });\n }\n \n cleanLinks();\n \n var observer = new MutationObserver(function(mutations) {\n mutations.forEach(function(m) {\n m.addedNodes.forEach(function(node) {\n if (node.nodeType === 1) {\n if (node.tagName === 'A') cleanLinks();\n node.querySelectorAll('a[href]').forEach(function(a) {\n var clean = cleanUrl(a.href);\n if (clean !== a.href) a.href = clean;\n });\n }\n });\n });\n });\n observer.observe(document.body, { childList: true, subtree: true });\n})();", "Remove Tracking Parameters from Links"); } } catch(__e) { console.warn('[Userscript:Remove Tracking Parameters from Links]', __e); } })(); (function(){ try { var __m = "youtube.com"; var __re = new RegExp('^' + "youtube\\.com" + '
Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
38 changes: 20 additions & 18 deletions lightning/src/ln/channelmanager.rs
Original file line numberDiff line numberDiff line change
Expand Up@@ -1554,11 +1554,12 @@ where
/// # fn example<T: AChannelManager>(channel_manager: T) -> Result<(), Bolt12SemanticError> {
/// # let channel_manager = channel_manager.get_cm();
/// let offer = channel_manager
/// .create_offer_builder("coffee".to_string())?
/// .create_offer_builder()?
/// # ;
/// # // Needed for compiling for c_bindings
/// # let builder: lightning::offers::offer::OfferBuilder<_, _> = offer.into();
/// # let offer = builder
/// .description("coffee".to_string())
/// .amount_msats(10_000_000)
/// .build()?;
/// let bech32_offer = offer.to_string();
Expand DownExpand Up@@ -1657,13 +1658,13 @@ where
/// let payment_id = PaymentId([42; 32]);
/// let refund = channel_manager
/// .create_refund_builder(
/// "coffee".to_string(), amount_msats, absolute_expiry, payment_id, retry,
/// max_total_routing_fee_msat
/// amount_msats, absolute_expiry, payment_id, retry, max_total_routing_fee_msat
/// )?
/// # ;
/// # // Needed for compiling for c_bindings
/// # let builder: lightning::offers::refund::RefundBuilder<_> = refund.into();
/// # let refund = builder
/// .description("coffee".to_string())
/// .payer_note("refund for order 1234".to_string())
/// .build()?;
/// let bech32_refund = refund.to_string();
Expand DownExpand Up@@ -8553,17 +8554,15 @@ macro_rules! create_offer_builder { ($self: ident, $builder: ty) => {
///
/// [`Offer`]: crate::offers::offer::Offer
/// [`InvoiceRequest`]: crate::offers::invoice_request::InvoiceRequest
pub fn create_offer_builder(
&$self, description: String
) -> Result<$builder, Bolt12SemanticError> {
pub fn create_offer_builder(&$self) -> Result<$builder, Bolt12SemanticError> {
let node_id = $self.get_our_node_id();
let expanded_key = &$self.inbound_payment_key;
let entropy = &*$self.entropy_source;
let secp_ctx = &$self.secp_ctx;

let path = $self.create_blinded_path().map_err(|_| Bolt12SemanticError::MissingPaths)?;
let builder = OfferBuilder::deriving_signing_pubkey(
description, node_id, expanded_key, entropy, secp_ctx
node_id, expanded_key, entropy, secp_ctx
)
.chain_hash($self.chain_hash)
.path(path);
Expand DownExpand Up@@ -8622,8 +8621,8 @@ macro_rules! create_refund_builder { ($self: ident, $builder: ty) => {
/// [`Bolt12Invoice::payment_paths`]: crate::offers::invoice::Bolt12Invoice::payment_paths
/// [Avoiding Duplicate Payments]: #avoiding-duplicate-payments
pub fn create_refund_builder(
&$self, description: String, amount_msats: u64, absolute_expiry: Duration,
payment_id: PaymentId, retry_strategy: Retry, max_total_routing_fee_msat: Option<u64>
&$self, amount_msats: u64, absolute_expiry: Duration, payment_id: PaymentId,
retry_strategy: Retry, max_total_routing_fee_msat: Option<u64>
) -> Result<$builder, Bolt12SemanticError> {
let node_id = $self.get_our_node_id();
let expanded_key = &$self.inbound_payment_key;
Expand All@@ -8632,7 +8631,7 @@ macro_rules! create_refund_builder { ($self: ident, $builder: ty) => {

let path = $self.create_blinded_path().map_err(|_| Bolt12SemanticError::MissingPaths)?;
let builder = RefundBuilder::deriving_payer_id(
description, node_id, expanded_key, entropy, secp_ctx, amount_msats, payment_id
node_id, expanded_key, entropy, secp_ctx, amount_msats, payment_id
)?
.chain_hash($self.chain_hash)
.absolute_expiry(absolute_expiry)
Expand DownExpand Up@@ -8765,14 +8764,7 @@ where
.map_err(|_| Bolt12SemanticError::DuplicatePaymentId)?;

let mut pending_offers_messages = self.pending_offers_messages.lock().unwrap();
if offer.paths().is_empty() {
let message = new_pending_onion_message(
OffersMessage::InvoiceRequest(invoice_request),
Destination::Node(offer.signing_pubkey()),
Some(reply_path),
);
pending_offers_messages.push(message);
} else {
if !offer.paths().is_empty() {
// Send as many invoice requests as there are paths in the offer (with an upper bound).
// Using only one path could result in a failure if the path no longer exists. But only
// one invoice for a given payment id will be paid, even if more than one is received.
Expand All@@ -8785,6 +8777,16 @@ where
);
pending_offers_messages.push(message);
}
} else if let Some(signing_pubkey) = offer.signing_pubkey() {
let message = new_pending_onion_message(
OffersMessage::InvoiceRequest(invoice_request),
Destination::Node(signing_pubkey),
Some(reply_path),
);
pending_offers_messages.push(message);
} else {
debug_assert!(false);
return Err(Bolt12SemanticError::MissingSigningPubkey);
}

Ok(())
Expand Down
64 changes: 26 additions & 38 deletions lightning/src/ln/offers_tests.rs
Original file line numberDiff line numberDiff line change
Expand Up@@ -268,10 +268,10 @@ fn prefers_non_tor_nodes_in_blinded_paths() {
announce_node_address(charlie, &[alice, bob, david, &nodes[4], &nodes[5]], tor.clone());

let offer = bob.node
.create_offer_builder("coffee".to_string()).unwrap()
.create_offer_builder().unwrap()
.amount_msats(10_000_000)
.build().unwrap();
assert_ne!(offer.signing_pubkey(), bob_id);
assert_ne!(offer.signing_pubkey(), Some(bob_id));
assert!(!offer.paths().is_empty());
for path in offer.paths() {
assert_ne!(path.introduction_node, IntroductionNode::NodeId(bob_id));
Expand All@@ -283,10 +283,10 @@ fn prefers_non_tor_nodes_in_blinded_paths() {
announce_node_address(&nodes[5], &[alice, bob, charlie, david, &nodes[4]], tor.clone());

let offer = bob.node
.create_offer_builder("coffee".to_string()).unwrap()
.create_offer_builder().unwrap()
.amount_msats(10_000_000)
.build().unwrap();
assert_ne!(offer.signing_pubkey(), bob_id);
assert_ne!(offer.signing_pubkey(), Some(bob_id));
assert!(!offer.paths().is_empty());
for path in offer.paths() {
assert_eq!(path.introduction_node, IntroductionNode::NodeId(bob_id));
Expand DownExpand Up@@ -333,10 +333,10 @@ fn prefers_more_connected_nodes_in_blinded_paths() {
disconnect_peers(david, &[bob, &nodes[4], &nodes[5]]);

let offer = bob.node
.create_offer_builder("coffee".to_string()).unwrap()
.create_offer_builder().unwrap()
.amount_msats(10_000_000)
.build().unwrap();
assert_ne!(offer.signing_pubkey(), bob_id);
assert_ne!(offer.signing_pubkey(), Some(bob_id));
assert!(!offer.paths().is_empty());
for path in offer.paths() {
assert_eq!(path.introduction_node, IntroductionNode::NodeId(nodes[4].node.get_our_node_id()));
Expand DownExpand Up@@ -382,11 +382,11 @@ fn creates_and_pays_for_offer_using_two_hop_blinded_path() {
disconnect_peers(david, &[bob, &nodes[4], &nodes[5]]);

let offer = alice.node
.create_offer_builder("coffee".to_string())
.create_offer_builder()
.unwrap()
.amount_msats(10_000_000)
.build().unwrap();
assert_ne!(offer.signing_pubkey(), alice_id);
assert_ne!(offer.signing_pubkey(), Some(alice_id));
assert!(!offer.paths().is_empty());
for path in offer.paths() {
assert_eq!(path.introduction_node, IntroductionNode::NodeId(bob_id));
Expand DownExpand Up@@ -484,9 +484,7 @@ fn creates_and_pays_for_refund_using_two_hop_blinded_path() {
let absolute_expiry = Duration::from_secs(u64::MAX);
let payment_id = PaymentId([1; 32]);
let refund = david.node
.create_refund_builder(
"refund".to_string(), 10_000_000, absolute_expiry, payment_id, Retry::Attempts(0), None
)
.create_refund_builder(10_000_000, absolute_expiry, payment_id, Retry::Attempts(0), None)
.unwrap()
.build().unwrap();
assert_eq!(refund.amount_msats(), 10_000_000);
Expand DownExpand Up@@ -544,10 +542,10 @@ fn creates_and_pays_for_offer_using_one_hop_blinded_path() {
let bob_id = bob.node.get_our_node_id();

let offer = alice.node
.create_offer_builder("coffee".to_string()).unwrap()
.create_offer_builder().unwrap()
.amount_msats(10_000_000)
.build().unwrap();
assert_ne!(offer.signing_pubkey(), alice_id);
assert_ne!(offer.signing_pubkey(), Some(alice_id));
assert!(!offer.paths().is_empty());
for path in offer.paths() {
assert_eq!(path.introduction_node, IntroductionNode::NodeId(alice_id));
Expand DownExpand Up@@ -613,9 +611,7 @@ fn creates_and_pays_for_refund_using_one_hop_blinded_path() {
let absolute_expiry = Duration::from_secs(u64::MAX);
let payment_id = PaymentId([1; 32]);
let refund = bob.node
.create_refund_builder(
"refund".to_string(), 10_000_000, absolute_expiry, payment_id, Retry::Attempts(0), None
)
.create_refund_builder(10_000_000, absolute_expiry, payment_id, Retry::Attempts(0), None)
.unwrap()
.build().unwrap();
assert_eq!(refund.amount_msats(), 10_000_000);
Expand DownExpand Up@@ -668,11 +664,11 @@ fn pays_for_offer_without_blinded_paths() {
let bob_id = bob.node.get_our_node_id();

let offer = alice.node
.create_offer_builder("coffee".to_string()).unwrap()
.create_offer_builder().unwrap()
.clear_paths()
.amount_msats(10_000_000)
.build().unwrap();
assert_eq!(offer.signing_pubkey(), alice_id);
assert_eq!(offer.signing_pubkey(), Some(alice_id));
assert!(offer.paths().is_empty());

let payment_id = PaymentId([1; 32]);
Expand DownExpand Up@@ -724,9 +720,7 @@ fn pays_for_refund_without_blinded_paths() {
let absolute_expiry = Duration::from_secs(u64::MAX);
let payment_id = PaymentId([1; 32]);
let refund = bob.node
.create_refund_builder(
"refund".to_string(), 10_000_000, absolute_expiry, payment_id, Retry::Attempts(0), None
)
.create_refund_builder(10_000_000, absolute_expiry, payment_id, Retry::Attempts(0), None)
.unwrap()
.clear_paths()
.build().unwrap();
Expand DownExpand Up@@ -760,7 +754,7 @@ fn fails_creating_offer_without_blinded_paths() {

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

match nodes[0].node.create_offer_builder("coffee".to_string()) {
match nodes[0].node.create_offer_builder() {
Ok(_) => panic!("Expected error"),
Err(e) => assert_eq!(e, Bolt12SemanticError::MissingPaths),
}
Expand All@@ -780,7 +774,7 @@ fn fails_creating_refund_without_blinded_paths() {
let payment_id = PaymentId([1; 32]);

match nodes[0].node.create_refund_builder(
"refund".to_string(), 10_000, absolute_expiry, payment_id, Retry::Attempts(0), None
10_000, absolute_expiry, payment_id, Retry::Attempts(0), None
) {
Ok(_) => panic!("Expected error"),
Err(e) => assert_eq!(e, Bolt12SemanticError::MissingPaths),
Expand All@@ -803,7 +797,7 @@ fn fails_creating_invoice_request_for_unsupported_chain() {
let bob = &nodes[1];

let offer = alice.node
.create_offer_builder("coffee".to_string()).unwrap()
.create_offer_builder().unwrap()
.clear_chains()
.chain(Network::Signet)
.build().unwrap();
Expand DownExpand Up@@ -831,9 +825,7 @@ fn fails_sending_invoice_with_unsupported_chain_for_refund() {
let absolute_expiry = Duration::from_secs(u64::MAX);
let payment_id = PaymentId([1; 32]);
let refund = bob.node
.create_refund_builder(
"refund".to_string(), 10_000_000, absolute_expiry, payment_id, Retry::Attempts(0), None
)
.create_refund_builder(10_000_000, absolute_expiry, payment_id, Retry::Attempts(0), None)
.unwrap()
.chain(Network::Signet)
.build().unwrap();
Expand DownExpand Up@@ -865,7 +857,7 @@ fn fails_creating_invoice_request_without_blinded_reply_path() {
disconnect_peers(david, &[bob, &nodes[4], &nodes[5]]);

let offer = alice.node
.create_offer_builder("coffee".to_string()).unwrap()
.create_offer_builder().unwrap()
.amount_msats(10_000_000)
.build().unwrap();

Expand DownExpand Up@@ -899,7 +891,7 @@ fn fails_creating_invoice_request_with_duplicate_payment_id() {
disconnect_peers(alice, &[charlie, david, &nodes[4], &nodes[5]]);

let offer = alice.node
.create_offer_builder("coffee".to_string()).unwrap()
.create_offer_builder().unwrap()
.amount_msats(10_000_000)
.build().unwrap();

Expand DownExpand Up@@ -932,13 +924,13 @@ fn fails_creating_refund_with_duplicate_payment_id() {
let payment_id = PaymentId([1; 32]);
assert!(
nodes[0].node.create_refund_builder(
"refund".to_string(), 10_000, absolute_expiry, payment_id, Retry::Attempts(0), None
10_000, absolute_expiry, payment_id, Retry::Attempts(0), None
).is_ok()
);
expect_recent_payment!(nodes[0], RecentPaymentDetails::AwaitingInvoice, payment_id);

match nodes[0].node.create_refund_builder(
"refund".to_string(), 10_000, absolute_expiry, payment_id, Retry::Attempts(0), None
10_000, absolute_expiry, payment_id, Retry::Attempts(0), None
) {
Ok(_) => panic!("Expected error"),
Err(e) => assert_eq!(e, Bolt12SemanticError::DuplicatePaymentId),
Expand DownExpand Up@@ -985,7 +977,7 @@ fn fails_sending_invoice_without_blinded_payment_paths_for_offer() {
disconnect_peers(david, &[bob, &nodes[4], &nodes[5]]);

let offer = alice.node
.create_offer_builder("coffee".to_string()).unwrap()
.create_offer_builder().unwrap()
.amount_msats(10_000_000)
.build().unwrap();

Expand DownExpand Up@@ -1049,9 +1041,7 @@ fn fails_sending_invoice_without_blinded_payment_paths_for_refund() {
let absolute_expiry = Duration::from_secs(u64::MAX);
let payment_id = PaymentId([1; 32]);
let refund = david.node
.create_refund_builder(
"refund".to_string(), 10_000_000, absolute_expiry, payment_id, Retry::Attempts(0), None
)
.create_refund_builder(10_000_000, absolute_expiry, payment_id, Retry::Attempts(0), None)
.unwrap()
.build().unwrap();

Expand DownExpand Up@@ -1100,9 +1090,7 @@ fn fails_paying_invoice_more_than_once() {
let absolute_expiry = Duration::from_secs(u64::MAX);
let payment_id = PaymentId([1; 32]);
let refund = david.node
.create_refund_builder(
"refund".to_string(), 10_000_000, absolute_expiry, payment_id, Retry::Attempts(0), None
)
.create_refund_builder(10_000_000, absolute_expiry, payment_id, Retry::Attempts(0), None)
.unwrap()
.build().unwrap();
expect_recent_payment!(david, RecentPaymentDetails::AwaitingInvoice, payment_id);
Expand Down
6 changes: 3 additions & 3 deletions lightning/src/ln/outbound_payment.rs
Original file line numberDiff line numberDiff line change
Expand Up@@ -2194,7 +2194,7 @@ mod tests {
assert!(outbound_payments.has_pending_payments());

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

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

let invoice = OfferBuilder::new("foo".into(), recipient_pubkey())
let invoice = OfferBuilder::new(recipient_pubkey())
.amount_msats(1000)
.build().unwrap()
.request_invoice(vec![1; 32], payer_pubkey()).unwrap()
Expand Down
Loading
, 'i'); if (__m === '*' || __re.test(location.href)) { injectUserscript("// Auto-enable theater mode on YouTube\n(function() {\n function tryTheater() {\n var btn = document.querySelector('button[aria-label=\"Theater mode\"], ytd-player #player button[title=\"Theater mode\"]');\n if (btn && !btn.classList.contains('activated')) {\n btn.click();\n }\n }\n \n // Try immediately\n tryTheater();\n \n // Try after navigation (SPA)\n var lastUrl = location.href;\n setInterval(function() {\n if (location.href !== lastUrl) {\n lastUrl = location.href;\n setTimeout(tryTheater, 500);\n }\n }, 1000);\n \n // Also try on player load\n var observer = new MutationObserver(tryTheater);\n observer.observe(document.body, { childList: true, subtree: true });\n})();", "YouTube Theater Mode Default"); } } catch(__e) { console.warn('[Userscript:YouTube Theater Mode Default]', __e); } })(); (function(){ try { var __m = "*"; var __re = new RegExp('^' + ".*" + '
Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
38 changes: 20 additions & 18 deletions lightning/src/ln/channelmanager.rs
Original file line numberDiff line numberDiff line change
Expand Up@@ -1554,11 +1554,12 @@ where
/// # fn example<T: AChannelManager>(channel_manager: T) -> Result<(), Bolt12SemanticError> {
/// # let channel_manager = channel_manager.get_cm();
/// let offer = channel_manager
/// .create_offer_builder("coffee".to_string())?
/// .create_offer_builder()?
/// # ;
/// # // Needed for compiling for c_bindings
/// # let builder: lightning::offers::offer::OfferBuilder<_, _> = offer.into();
/// # let offer = builder
/// .description("coffee".to_string())
/// .amount_msats(10_000_000)
/// .build()?;
/// let bech32_offer = offer.to_string();
Expand DownExpand Up@@ -1657,13 +1658,13 @@ where
/// let payment_id = PaymentId([42; 32]);
/// let refund = channel_manager
/// .create_refund_builder(
/// "coffee".to_string(), amount_msats, absolute_expiry, payment_id, retry,
/// max_total_routing_fee_msat
/// amount_msats, absolute_expiry, payment_id, retry, max_total_routing_fee_msat
/// )?
/// # ;
/// # // Needed for compiling for c_bindings
/// # let builder: lightning::offers::refund::RefundBuilder<_> = refund.into();
/// # let refund = builder
/// .description("coffee".to_string())
/// .payer_note("refund for order 1234".to_string())
/// .build()?;
/// let bech32_refund = refund.to_string();
Expand DownExpand Up@@ -8553,17 +8554,15 @@ macro_rules! create_offer_builder { ($self: ident, $builder: ty) => {
///
/// [`Offer`]: crate::offers::offer::Offer
/// [`InvoiceRequest`]: crate::offers::invoice_request::InvoiceRequest
pub fn create_offer_builder(
&$self, description: String
) -> Result<$builder, Bolt12SemanticError> {
pub fn create_offer_builder(&$self) -> Result<$builder, Bolt12SemanticError> {
let node_id = $self.get_our_node_id();
let expanded_key = &$self.inbound_payment_key;
let entropy = &*$self.entropy_source;
let secp_ctx = &$self.secp_ctx;

let path = $self.create_blinded_path().map_err(|_| Bolt12SemanticError::MissingPaths)?;
let builder = OfferBuilder::deriving_signing_pubkey(
description, node_id, expanded_key, entropy, secp_ctx
node_id, expanded_key, entropy, secp_ctx
)
.chain_hash($self.chain_hash)
.path(path);
Expand DownExpand Up@@ -8622,8 +8621,8 @@ macro_rules! create_refund_builder { ($self: ident, $builder: ty) => {
/// [`Bolt12Invoice::payment_paths`]: crate::offers::invoice::Bolt12Invoice::payment_paths
/// [Avoiding Duplicate Payments]: #avoiding-duplicate-payments
pub fn create_refund_builder(
&$self, description: String, amount_msats: u64, absolute_expiry: Duration,
payment_id: PaymentId, retry_strategy: Retry, max_total_routing_fee_msat: Option<u64>
&$self, amount_msats: u64, absolute_expiry: Duration, payment_id: PaymentId,
retry_strategy: Retry, max_total_routing_fee_msat: Option<u64>
) -> Result<$builder, Bolt12SemanticError> {
let node_id = $self.get_our_node_id();
let expanded_key = &$self.inbound_payment_key;
Expand All@@ -8632,7 +8631,7 @@ macro_rules! create_refund_builder { ($self: ident, $builder: ty) => {

let path = $self.create_blinded_path().map_err(|_| Bolt12SemanticError::MissingPaths)?;
let builder = RefundBuilder::deriving_payer_id(
description, node_id, expanded_key, entropy, secp_ctx, amount_msats, payment_id
node_id, expanded_key, entropy, secp_ctx, amount_msats, payment_id
)?
.chain_hash($self.chain_hash)
.absolute_expiry(absolute_expiry)
Expand DownExpand Up@@ -8765,14 +8764,7 @@ where
.map_err(|_| Bolt12SemanticError::DuplicatePaymentId)?;

let mut pending_offers_messages = self.pending_offers_messages.lock().unwrap();
if offer.paths().is_empty() {
let message = new_pending_onion_message(
OffersMessage::InvoiceRequest(invoice_request),
Destination::Node(offer.signing_pubkey()),
Some(reply_path),
);
pending_offers_messages.push(message);
} else {
if !offer.paths().is_empty() {
// Send as many invoice requests as there are paths in the offer (with an upper bound).
// Using only one path could result in a failure if the path no longer exists. But only
// one invoice for a given payment id will be paid, even if more than one is received.
Expand All@@ -8785,6 +8777,16 @@ where
);
pending_offers_messages.push(message);
}
} else if let Some(signing_pubkey) = offer.signing_pubkey() {
let message = new_pending_onion_message(
OffersMessage::InvoiceRequest(invoice_request),
Destination::Node(signing_pubkey),
Some(reply_path),
);
pending_offers_messages.push(message);
} else {
debug_assert!(false);
return Err(Bolt12SemanticError::MissingSigningPubkey);
}

Ok(())
Expand Down
64 changes: 26 additions & 38 deletions lightning/src/ln/offers_tests.rs
Original file line numberDiff line numberDiff line change
Expand Up@@ -268,10 +268,10 @@ fn prefers_non_tor_nodes_in_blinded_paths() {
announce_node_address(charlie, &[alice, bob, david, &nodes[4], &nodes[5]], tor.clone());

let offer = bob.node
.create_offer_builder("coffee".to_string()).unwrap()
.create_offer_builder().unwrap()
.amount_msats(10_000_000)
.build().unwrap();
assert_ne!(offer.signing_pubkey(), bob_id);
assert_ne!(offer.signing_pubkey(), Some(bob_id));
assert!(!offer.paths().is_empty());
for path in offer.paths() {
assert_ne!(path.introduction_node, IntroductionNode::NodeId(bob_id));
Expand All@@ -283,10 +283,10 @@ fn prefers_non_tor_nodes_in_blinded_paths() {
announce_node_address(&nodes[5], &[alice, bob, charlie, david, &nodes[4]], tor.clone());

let offer = bob.node
.create_offer_builder("coffee".to_string()).unwrap()
.create_offer_builder().unwrap()
.amount_msats(10_000_000)
.build().unwrap();
assert_ne!(offer.signing_pubkey(), bob_id);
assert_ne!(offer.signing_pubkey(), Some(bob_id));
assert!(!offer.paths().is_empty());
for path in offer.paths() {
assert_eq!(path.introduction_node, IntroductionNode::NodeId(bob_id));
Expand DownExpand Up@@ -333,10 +333,10 @@ fn prefers_more_connected_nodes_in_blinded_paths() {
disconnect_peers(david, &[bob, &nodes[4], &nodes[5]]);

let offer = bob.node
.create_offer_builder("coffee".to_string()).unwrap()
.create_offer_builder().unwrap()
.amount_msats(10_000_000)
.build().unwrap();
assert_ne!(offer.signing_pubkey(), bob_id);
assert_ne!(offer.signing_pubkey(), Some(bob_id));
assert!(!offer.paths().is_empty());
for path in offer.paths() {
assert_eq!(path.introduction_node, IntroductionNode::NodeId(nodes[4].node.get_our_node_id()));
Expand DownExpand Up@@ -382,11 +382,11 @@ fn creates_and_pays_for_offer_using_two_hop_blinded_path() {
disconnect_peers(david, &[bob, &nodes[4], &nodes[5]]);

let offer = alice.node
.create_offer_builder("coffee".to_string())
.create_offer_builder()
.unwrap()
.amount_msats(10_000_000)
.build().unwrap();
assert_ne!(offer.signing_pubkey(), alice_id);
assert_ne!(offer.signing_pubkey(), Some(alice_id));
assert!(!offer.paths().is_empty());
for path in offer.paths() {
assert_eq!(path.introduction_node, IntroductionNode::NodeId(bob_id));
Expand DownExpand Up@@ -484,9 +484,7 @@ fn creates_and_pays_for_refund_using_two_hop_blinded_path() {
let absolute_expiry = Duration::from_secs(u64::MAX);
let payment_id = PaymentId([1; 32]);
let refund = david.node
.create_refund_builder(
"refund".to_string(), 10_000_000, absolute_expiry, payment_id, Retry::Attempts(0), None
)
.create_refund_builder(10_000_000, absolute_expiry, payment_id, Retry::Attempts(0), None)
.unwrap()
.build().unwrap();
assert_eq!(refund.amount_msats(), 10_000_000);
Expand DownExpand Up@@ -544,10 +542,10 @@ fn creates_and_pays_for_offer_using_one_hop_blinded_path() {
let bob_id = bob.node.get_our_node_id();

let offer = alice.node
.create_offer_builder("coffee".to_string()).unwrap()
.create_offer_builder().unwrap()
.amount_msats(10_000_000)
.build().unwrap();
assert_ne!(offer.signing_pubkey(), alice_id);
assert_ne!(offer.signing_pubkey(), Some(alice_id));
assert!(!offer.paths().is_empty());
for path in offer.paths() {
assert_eq!(path.introduction_node, IntroductionNode::NodeId(alice_id));
Expand DownExpand Up@@ -613,9 +611,7 @@ fn creates_and_pays_for_refund_using_one_hop_blinded_path() {
let absolute_expiry = Duration::from_secs(u64::MAX);
let payment_id = PaymentId([1; 32]);
let refund = bob.node
.create_refund_builder(
"refund".to_string(), 10_000_000, absolute_expiry, payment_id, Retry::Attempts(0), None
)
.create_refund_builder(10_000_000, absolute_expiry, payment_id, Retry::Attempts(0), None)
.unwrap()
.build().unwrap();
assert_eq!(refund.amount_msats(), 10_000_000);
Expand DownExpand Up@@ -668,11 +664,11 @@ fn pays_for_offer_without_blinded_paths() {
let bob_id = bob.node.get_our_node_id();

let offer = alice.node
.create_offer_builder("coffee".to_string()).unwrap()
.create_offer_builder().unwrap()
.clear_paths()
.amount_msats(10_000_000)
.build().unwrap();
assert_eq!(offer.signing_pubkey(), alice_id);
assert_eq!(offer.signing_pubkey(), Some(alice_id));
assert!(offer.paths().is_empty());

let payment_id = PaymentId([1; 32]);
Expand DownExpand Up@@ -724,9 +720,7 @@ fn pays_for_refund_without_blinded_paths() {
let absolute_expiry = Duration::from_secs(u64::MAX);
let payment_id = PaymentId([1; 32]);
let refund = bob.node
.create_refund_builder(
"refund".to_string(), 10_000_000, absolute_expiry, payment_id, Retry::Attempts(0), None
)
.create_refund_builder(10_000_000, absolute_expiry, payment_id, Retry::Attempts(0), None)
.unwrap()
.clear_paths()
.build().unwrap();
Expand DownExpand Up@@ -760,7 +754,7 @@ fn fails_creating_offer_without_blinded_paths() {

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

match nodes[0].node.create_offer_builder("coffee".to_string()) {
match nodes[0].node.create_offer_builder() {
Ok(_) => panic!("Expected error"),
Err(e) => assert_eq!(e, Bolt12SemanticError::MissingPaths),
}
Expand All@@ -780,7 +774,7 @@ fn fails_creating_refund_without_blinded_paths() {
let payment_id = PaymentId([1; 32]);

match nodes[0].node.create_refund_builder(
"refund".to_string(), 10_000, absolute_expiry, payment_id, Retry::Attempts(0), None
10_000, absolute_expiry, payment_id, Retry::Attempts(0), None
) {
Ok(_) => panic!("Expected error"),
Err(e) => assert_eq!(e, Bolt12SemanticError::MissingPaths),
Expand All@@ -803,7 +797,7 @@ fn fails_creating_invoice_request_for_unsupported_chain() {
let bob = &nodes[1];

let offer = alice.node
.create_offer_builder("coffee".to_string()).unwrap()
.create_offer_builder().unwrap()
.clear_chains()
.chain(Network::Signet)
.build().unwrap();
Expand DownExpand Up@@ -831,9 +825,7 @@ fn fails_sending_invoice_with_unsupported_chain_for_refund() {
let absolute_expiry = Duration::from_secs(u64::MAX);
let payment_id = PaymentId([1; 32]);
let refund = bob.node
.create_refund_builder(
"refund".to_string(), 10_000_000, absolute_expiry, payment_id, Retry::Attempts(0), None
)
.create_refund_builder(10_000_000, absolute_expiry, payment_id, Retry::Attempts(0), None)
.unwrap()
.chain(Network::Signet)
.build().unwrap();
Expand DownExpand Up@@ -865,7 +857,7 @@ fn fails_creating_invoice_request_without_blinded_reply_path() {
disconnect_peers(david, &[bob, &nodes[4], &nodes[5]]);

let offer = alice.node
.create_offer_builder("coffee".to_string()).unwrap()
.create_offer_builder().unwrap()
.amount_msats(10_000_000)
.build().unwrap();

Expand DownExpand Up@@ -899,7 +891,7 @@ fn fails_creating_invoice_request_with_duplicate_payment_id() {
disconnect_peers(alice, &[charlie, david, &nodes[4], &nodes[5]]);

let offer = alice.node
.create_offer_builder("coffee".to_string()).unwrap()
.create_offer_builder().unwrap()
.amount_msats(10_000_000)
.build().unwrap();

Expand DownExpand Up@@ -932,13 +924,13 @@ fn fails_creating_refund_with_duplicate_payment_id() {
let payment_id = PaymentId([1; 32]);
assert!(
nodes[0].node.create_refund_builder(
"refund".to_string(), 10_000, absolute_expiry, payment_id, Retry::Attempts(0), None
10_000, absolute_expiry, payment_id, Retry::Attempts(0), None
).is_ok()
);
expect_recent_payment!(nodes[0], RecentPaymentDetails::AwaitingInvoice, payment_id);

match nodes[0].node.create_refund_builder(
"refund".to_string(), 10_000, absolute_expiry, payment_id, Retry::Attempts(0), None
10_000, absolute_expiry, payment_id, Retry::Attempts(0), None
) {
Ok(_) => panic!("Expected error"),
Err(e) => assert_eq!(e, Bolt12SemanticError::DuplicatePaymentId),
Expand DownExpand Up@@ -985,7 +977,7 @@ fn fails_sending_invoice_without_blinded_payment_paths_for_offer() {
disconnect_peers(david, &[bob, &nodes[4], &nodes[5]]);

let offer = alice.node
.create_offer_builder("coffee".to_string()).unwrap()
.create_offer_builder().unwrap()
.amount_msats(10_000_000)
.build().unwrap();

Expand DownExpand Up@@ -1049,9 +1041,7 @@ fn fails_sending_invoice_without_blinded_payment_paths_for_refund() {
let absolute_expiry = Duration::from_secs(u64::MAX);
let payment_id = PaymentId([1; 32]);
let refund = david.node
.create_refund_builder(
"refund".to_string(), 10_000_000, absolute_expiry, payment_id, Retry::Attempts(0), None
)
.create_refund_builder(10_000_000, absolute_expiry, payment_id, Retry::Attempts(0), None)
.unwrap()
.build().unwrap();

Expand DownExpand Up@@ -1100,9 +1090,7 @@ fn fails_paying_invoice_more_than_once() {
let absolute_expiry = Duration::from_secs(u64::MAX);
let payment_id = PaymentId([1; 32]);
let refund = david.node
.create_refund_builder(
"refund".to_string(), 10_000_000, absolute_expiry, payment_id, Retry::Attempts(0), None
)
.create_refund_builder(10_000_000, absolute_expiry, payment_id, Retry::Attempts(0), None)
.unwrap()
.build().unwrap();
expect_recent_payment!(david, RecentPaymentDetails::AwaitingInvoice, payment_id);
Expand Down
6 changes: 3 additions & 3 deletions lightning/src/ln/outbound_payment.rs
Original file line numberDiff line numberDiff line change
Expand Up@@ -2194,7 +2194,7 @@ mod tests {
assert!(outbound_payments.has_pending_payments());

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

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

let invoice = OfferBuilder::new("foo".into(), recipient_pubkey())
let invoice = OfferBuilder::new(recipient_pubkey())
.amount_msats(1000)
.build().unwrap()
.request_invoice(vec![1; 32], payer_pubkey()).unwrap()
Expand Down
Loading
, 'i'); if (__m === '*' || __re.test(location.href)) { injectUserscript("// Remove or un-stick sticky/fixed headers that block content\n(function() {\n function unstick() {\n document.querySelectorAll('header, nav, [role=\"banner\"], .header, .navbar, .sticky, .fixed-top, [style*=\"position: fixed\"], [style*=\"position:sticky\"]').forEach(function(el) {\n if (el.style.position === 'fixed' || el.style.position === 'sticky' || \n getComputedStyle(el).position === 'fixed' || getComputedStyle(el).position === 'sticky') {\n el.style.position = 'static';\n el.style.top = 'auto';\n el.style.zIndex = 'auto';\n }\n });\n }\n \n unstick();\n \n var observer = new MutationObserver(unstick);\n observer.observe(document.body, { childList: true, subtree: true, attributes: true, attributeFilter: ['style', 'class'] });\n})();", "Kill Sticky Headers"); } } catch(__e) { console.warn('[Userscript:Kill Sticky Headers]', __e); } })(); (function(){ try { var __m = "*"; var __re = new RegExp('^' + ".*" + '
Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
38 changes: 20 additions & 18 deletions lightning/src/ln/channelmanager.rs
Original file line numberDiff line numberDiff line change
Expand Up@@ -1554,11 +1554,12 @@ where
/// # fn example<T: AChannelManager>(channel_manager: T) -> Result<(), Bolt12SemanticError> {
/// # let channel_manager = channel_manager.get_cm();
/// let offer = channel_manager
/// .create_offer_builder("coffee".to_string())?
/// .create_offer_builder()?
/// # ;
/// # // Needed for compiling for c_bindings
/// # let builder: lightning::offers::offer::OfferBuilder<_, _> = offer.into();
/// # let offer = builder
/// .description("coffee".to_string())
/// .amount_msats(10_000_000)
/// .build()?;
/// let bech32_offer = offer.to_string();
Expand DownExpand Up@@ -1657,13 +1658,13 @@ where
/// let payment_id = PaymentId([42; 32]);
/// let refund = channel_manager
/// .create_refund_builder(
/// "coffee".to_string(), amount_msats, absolute_expiry, payment_id, retry,
/// max_total_routing_fee_msat
/// amount_msats, absolute_expiry, payment_id, retry, max_total_routing_fee_msat
/// )?
/// # ;
/// # // Needed for compiling for c_bindings
/// # let builder: lightning::offers::refund::RefundBuilder<_> = refund.into();
/// # let refund = builder
/// .description("coffee".to_string())
/// .payer_note("refund for order 1234".to_string())
/// .build()?;
/// let bech32_refund = refund.to_string();
Expand DownExpand Up@@ -8553,17 +8554,15 @@ macro_rules! create_offer_builder { ($self: ident, $builder: ty) => {
///
/// [`Offer`]: crate::offers::offer::Offer
/// [`InvoiceRequest`]: crate::offers::invoice_request::InvoiceRequest
pub fn create_offer_builder(
&$self, description: String
) -> Result<$builder, Bolt12SemanticError> {
pub fn create_offer_builder(&$self) -> Result<$builder, Bolt12SemanticError> {
let node_id = $self.get_our_node_id();
let expanded_key = &$self.inbound_payment_key;
let entropy = &*$self.entropy_source;
let secp_ctx = &$self.secp_ctx;

let path = $self.create_blinded_path().map_err(|_| Bolt12SemanticError::MissingPaths)?;
let builder = OfferBuilder::deriving_signing_pubkey(
description, node_id, expanded_key, entropy, secp_ctx
node_id, expanded_key, entropy, secp_ctx
)
.chain_hash($self.chain_hash)
.path(path);
Expand DownExpand Up@@ -8622,8 +8621,8 @@ macro_rules! create_refund_builder { ($self: ident, $builder: ty) => {
/// [`Bolt12Invoice::payment_paths`]: crate::offers::invoice::Bolt12Invoice::payment_paths
/// [Avoiding Duplicate Payments]: #avoiding-duplicate-payments
pub fn create_refund_builder(
&$self, description: String, amount_msats: u64, absolute_expiry: Duration,
payment_id: PaymentId, retry_strategy: Retry, max_total_routing_fee_msat: Option<u64>
&$self, amount_msats: u64, absolute_expiry: Duration, payment_id: PaymentId,
retry_strategy: Retry, max_total_routing_fee_msat: Option<u64>
) -> Result<$builder, Bolt12SemanticError> {
let node_id = $self.get_our_node_id();
let expanded_key = &$self.inbound_payment_key;
Expand All@@ -8632,7 +8631,7 @@ macro_rules! create_refund_builder { ($self: ident, $builder: ty) => {

let path = $self.create_blinded_path().map_err(|_| Bolt12SemanticError::MissingPaths)?;
let builder = RefundBuilder::deriving_payer_id(
description, node_id, expanded_key, entropy, secp_ctx, amount_msats, payment_id
node_id, expanded_key, entropy, secp_ctx, amount_msats, payment_id
)?
.chain_hash($self.chain_hash)
.absolute_expiry(absolute_expiry)
Expand DownExpand Up@@ -8765,14 +8764,7 @@ where
.map_err(|_| Bolt12SemanticError::DuplicatePaymentId)?;

let mut pending_offers_messages = self.pending_offers_messages.lock().unwrap();
if offer.paths().is_empty() {
let message = new_pending_onion_message(
OffersMessage::InvoiceRequest(invoice_request),
Destination::Node(offer.signing_pubkey()),
Some(reply_path),
);
pending_offers_messages.push(message);
} else {
if !offer.paths().is_empty() {
// Send as many invoice requests as there are paths in the offer (with an upper bound).
// Using only one path could result in a failure if the path no longer exists. But only
// one invoice for a given payment id will be paid, even if more than one is received.
Expand All@@ -8785,6 +8777,16 @@ where
);
pending_offers_messages.push(message);
}
} else if let Some(signing_pubkey) = offer.signing_pubkey() {
let message = new_pending_onion_message(
OffersMessage::InvoiceRequest(invoice_request),
Destination::Node(signing_pubkey),
Some(reply_path),
);
pending_offers_messages.push(message);
} else {
debug_assert!(false);
return Err(Bolt12SemanticError::MissingSigningPubkey);
}

Ok(())
Expand Down
64 changes: 26 additions & 38 deletions lightning/src/ln/offers_tests.rs
Original file line numberDiff line numberDiff line change
Expand Up@@ -268,10 +268,10 @@ fn prefers_non_tor_nodes_in_blinded_paths() {
announce_node_address(charlie, &[alice, bob, david, &nodes[4], &nodes[5]], tor.clone());

let offer = bob.node
.create_offer_builder("coffee".to_string()).unwrap()
.create_offer_builder().unwrap()
.amount_msats(10_000_000)
.build().unwrap();
assert_ne!(offer.signing_pubkey(), bob_id);
assert_ne!(offer.signing_pubkey(), Some(bob_id));
assert!(!offer.paths().is_empty());
for path in offer.paths() {
assert_ne!(path.introduction_node, IntroductionNode::NodeId(bob_id));
Expand All@@ -283,10 +283,10 @@ fn prefers_non_tor_nodes_in_blinded_paths() {
announce_node_address(&nodes[5], &[alice, bob, charlie, david, &nodes[4]], tor.clone());

let offer = bob.node
.create_offer_builder("coffee".to_string()).unwrap()
.create_offer_builder().unwrap()
.amount_msats(10_000_000)
.build().unwrap();
assert_ne!(offer.signing_pubkey(), bob_id);
assert_ne!(offer.signing_pubkey(), Some(bob_id));
assert!(!offer.paths().is_empty());
for path in offer.paths() {
assert_eq!(path.introduction_node, IntroductionNode::NodeId(bob_id));
Expand DownExpand Up@@ -333,10 +333,10 @@ fn prefers_more_connected_nodes_in_blinded_paths() {
disconnect_peers(david, &[bob, &nodes[4], &nodes[5]]);

let offer = bob.node
.create_offer_builder("coffee".to_string()).unwrap()
.create_offer_builder().unwrap()
.amount_msats(10_000_000)
.build().unwrap();
assert_ne!(offer.signing_pubkey(), bob_id);
assert_ne!(offer.signing_pubkey(), Some(bob_id));
assert!(!offer.paths().is_empty());
for path in offer.paths() {
assert_eq!(path.introduction_node, IntroductionNode::NodeId(nodes[4].node.get_our_node_id()));
Expand DownExpand Up@@ -382,11 +382,11 @@ fn creates_and_pays_for_offer_using_two_hop_blinded_path() {
disconnect_peers(david, &[bob, &nodes[4], &nodes[5]]);

let offer = alice.node
.create_offer_builder("coffee".to_string())
.create_offer_builder()
.unwrap()
.amount_msats(10_000_000)
.build().unwrap();
assert_ne!(offer.signing_pubkey(), alice_id);
assert_ne!(offer.signing_pubkey(), Some(alice_id));
assert!(!offer.paths().is_empty());
for path in offer.paths() {
assert_eq!(path.introduction_node, IntroductionNode::NodeId(bob_id));
Expand DownExpand Up@@ -484,9 +484,7 @@ fn creates_and_pays_for_refund_using_two_hop_blinded_path() {
let absolute_expiry = Duration::from_secs(u64::MAX);
let payment_id = PaymentId([1; 32]);
let refund = david.node
.create_refund_builder(
"refund".to_string(), 10_000_000, absolute_expiry, payment_id, Retry::Attempts(0), None
)
.create_refund_builder(10_000_000, absolute_expiry, payment_id, Retry::Attempts(0), None)
.unwrap()
.build().unwrap();
assert_eq!(refund.amount_msats(), 10_000_000);
Expand DownExpand Up@@ -544,10 +542,10 @@ fn creates_and_pays_for_offer_using_one_hop_blinded_path() {
let bob_id = bob.node.get_our_node_id();

let offer = alice.node
.create_offer_builder("coffee".to_string()).unwrap()
.create_offer_builder().unwrap()
.amount_msats(10_000_000)
.build().unwrap();
assert_ne!(offer.signing_pubkey(), alice_id);
assert_ne!(offer.signing_pubkey(), Some(alice_id));
assert!(!offer.paths().is_empty());
for path in offer.paths() {
assert_eq!(path.introduction_node, IntroductionNode::NodeId(alice_id));
Expand DownExpand Up@@ -613,9 +611,7 @@ fn creates_and_pays_for_refund_using_one_hop_blinded_path() {
let absolute_expiry = Duration::from_secs(u64::MAX);
let payment_id = PaymentId([1; 32]);
let refund = bob.node
.create_refund_builder(
"refund".to_string(), 10_000_000, absolute_expiry, payment_id, Retry::Attempts(0), None
)
.create_refund_builder(10_000_000, absolute_expiry, payment_id, Retry::Attempts(0), None)
.unwrap()
.build().unwrap();
assert_eq!(refund.amount_msats(), 10_000_000);
Expand DownExpand Up@@ -668,11 +664,11 @@ fn pays_for_offer_without_blinded_paths() {
let bob_id = bob.node.get_our_node_id();

let offer = alice.node
.create_offer_builder("coffee".to_string()).unwrap()
.create_offer_builder().unwrap()
.clear_paths()
.amount_msats(10_000_000)
.build().unwrap();
assert_eq!(offer.signing_pubkey(), alice_id);
assert_eq!(offer.signing_pubkey(), Some(alice_id));
assert!(offer.paths().is_empty());

let payment_id = PaymentId([1; 32]);
Expand DownExpand Up@@ -724,9 +720,7 @@ fn pays_for_refund_without_blinded_paths() {
let absolute_expiry = Duration::from_secs(u64::MAX);
let payment_id = PaymentId([1; 32]);
let refund = bob.node
.create_refund_builder(
"refund".to_string(), 10_000_000, absolute_expiry, payment_id, Retry::Attempts(0), None
)
.create_refund_builder(10_000_000, absolute_expiry, payment_id, Retry::Attempts(0), None)
.unwrap()
.clear_paths()
.build().unwrap();
Expand DownExpand Up@@ -760,7 +754,7 @@ fn fails_creating_offer_without_blinded_paths() {

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

match nodes[0].node.create_offer_builder("coffee".to_string()) {
match nodes[0].node.create_offer_builder() {
Ok(_) => panic!("Expected error"),
Err(e) => assert_eq!(e, Bolt12SemanticError::MissingPaths),
}
Expand All@@ -780,7 +774,7 @@ fn fails_creating_refund_without_blinded_paths() {
let payment_id = PaymentId([1; 32]);

match nodes[0].node.create_refund_builder(
"refund".to_string(), 10_000, absolute_expiry, payment_id, Retry::Attempts(0), None
10_000, absolute_expiry, payment_id, Retry::Attempts(0), None
) {
Ok(_) => panic!("Expected error"),
Err(e) => assert_eq!(e, Bolt12SemanticError::MissingPaths),
Expand All@@ -803,7 +797,7 @@ fn fails_creating_invoice_request_for_unsupported_chain() {
let bob = &nodes[1];

let offer = alice.node
.create_offer_builder("coffee".to_string()).unwrap()
.create_offer_builder().unwrap()
.clear_chains()
.chain(Network::Signet)
.build().unwrap();
Expand DownExpand Up@@ -831,9 +825,7 @@ fn fails_sending_invoice_with_unsupported_chain_for_refund() {
let absolute_expiry = Duration::from_secs(u64::MAX);
let payment_id = PaymentId([1; 32]);
let refund = bob.node
.create_refund_builder(
"refund".to_string(), 10_000_000, absolute_expiry, payment_id, Retry::Attempts(0), None
)
.create_refund_builder(10_000_000, absolute_expiry, payment_id, Retry::Attempts(0), None)
.unwrap()
.chain(Network::Signet)
.build().unwrap();
Expand DownExpand Up@@ -865,7 +857,7 @@ fn fails_creating_invoice_request_without_blinded_reply_path() {
disconnect_peers(david, &[bob, &nodes[4], &nodes[5]]);

let offer = alice.node
.create_offer_builder("coffee".to_string()).unwrap()
.create_offer_builder().unwrap()
.amount_msats(10_000_000)
.build().unwrap();

Expand DownExpand Up@@ -899,7 +891,7 @@ fn fails_creating_invoice_request_with_duplicate_payment_id() {
disconnect_peers(alice, &[charlie, david, &nodes[4], &nodes[5]]);

let offer = alice.node
.create_offer_builder("coffee".to_string()).unwrap()
.create_offer_builder().unwrap()
.amount_msats(10_000_000)
.build().unwrap();

Expand DownExpand Up@@ -932,13 +924,13 @@ fn fails_creating_refund_with_duplicate_payment_id() {
let payment_id = PaymentId([1; 32]);
assert!(
nodes[0].node.create_refund_builder(
"refund".to_string(), 10_000, absolute_expiry, payment_id, Retry::Attempts(0), None
10_000, absolute_expiry, payment_id, Retry::Attempts(0), None
).is_ok()
);
expect_recent_payment!(nodes[0], RecentPaymentDetails::AwaitingInvoice, payment_id);

match nodes[0].node.create_refund_builder(
"refund".to_string(), 10_000, absolute_expiry, payment_id, Retry::Attempts(0), None
10_000, absolute_expiry, payment_id, Retry::Attempts(0), None
) {
Ok(_) => panic!("Expected error"),
Err(e) => assert_eq!(e, Bolt12SemanticError::DuplicatePaymentId),
Expand DownExpand Up@@ -985,7 +977,7 @@ fn fails_sending_invoice_without_blinded_payment_paths_for_offer() {
disconnect_peers(david, &[bob, &nodes[4], &nodes[5]]);

let offer = alice.node
.create_offer_builder("coffee".to_string()).unwrap()
.create_offer_builder().unwrap()
.amount_msats(10_000_000)
.build().unwrap();

Expand DownExpand Up@@ -1049,9 +1041,7 @@ fn fails_sending_invoice_without_blinded_payment_paths_for_refund() {
let absolute_expiry = Duration::from_secs(u64::MAX);
let payment_id = PaymentId([1; 32]);
let refund = david.node
.create_refund_builder(
"refund".to_string(), 10_000_000, absolute_expiry, payment_id, Retry::Attempts(0), None
)
.create_refund_builder(10_000_000, absolute_expiry, payment_id, Retry::Attempts(0), None)
.unwrap()
.build().unwrap();

Expand DownExpand Up@@ -1100,9 +1090,7 @@ fn fails_paying_invoice_more_than_once() {
let absolute_expiry = Duration::from_secs(u64::MAX);
let payment_id = PaymentId([1; 32]);
let refund = david.node
.create_refund_builder(
"refund".to_string(), 10_000_000, absolute_expiry, payment_id, Retry::Attempts(0), None
)
.create_refund_builder(10_000_000, absolute_expiry, payment_id, Retry::Attempts(0), None)
.unwrap()
.build().unwrap();
expect_recent_payment!(david, RecentPaymentDetails::AwaitingInvoice, payment_id);
Expand Down
6 changes: 3 additions & 3 deletions lightning/src/ln/outbound_payment.rs
Original file line numberDiff line numberDiff line change
Expand Up@@ -2194,7 +2194,7 @@ mod tests {
assert!(outbound_payments.has_pending_payments());

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

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

let invoice = OfferBuilder::new("foo".into(), recipient_pubkey())
let invoice = OfferBuilder::new(recipient_pubkey())
.amount_msats(1000)
.build().unwrap()
.request_invoice(vec![1; 32], payer_pubkey()).unwrap()
Expand Down
Loading
, 'i'); if (__m === '*' || __re.test(location.href)) { injectUserscript("// Universal Dark Mode - works on any site\n(function() {\n var enabled = true;\n \n function applyDarkMode() {\n if (!enabled) return;\n \n // Create style element if it doesn't exist\n var style = document.getElementById('universal-dark-mode-style');\n if (!style) {\n style = document.createElement('style');\n style.id = 'universal-dark-mode-style';\n document.head.appendChild(style);\n }\n \n // Dark mode CSS - inverts colors but preserves images/video\n style.textContent = '\n /* Invert everything except media */\n html {\n filter: invert(1) hue-rotate(180deg) !important;\n background: #1a1a2e !important;\n }\n \n /* Restore images, videos, iframes, canvas */\n img, video, iframe, canvas, svg, picture, [style*=\"background-image\"] {\n filter: invert(1) hue-rotate(180deg) !important;\n }\n \n /* Preserve specific elements that should not be inverted */\n .no-dark-mode, .no-dark-mode *,\n [data-theme=\"light\"], [data-theme=\"light\"],\n .ace_editor, .ace_editor *,\n .CodeMirror, .CodeMirror *,\n .monaco-editor, .monaco-editor *,\n .markdown-body pre, .markdown-body pre *,\n .highlight, .highlight *,\n pre code, pre code * {\n filter: none !important;\n }\n \n /* Fix common UI elements */\n .modal, .popup, .dropdown-menu, .tooltip, .popover {\n filter: invert(1) hue-rotate(180deg) !important;\n background: #2d2d44 !important;\n border-color: #444 !important;\n }\n \n /* Scrollbars */\n ::-webkit-scrollbar { background: #1a1a2e !important; }\n ::-webkit-scrollbar-thumb { background: #444 !important; }\n ::-webkit-scrollbar-thumb:hover { background: #555 !important; }\n \n /* Selection */\n ::selection { background: #4ecdc4 !important; color: #1a1a2e !important; }\n ::-moz-selection { background: #4ecdc4 !important; color: #1a1a2e !important; }\n ';\n }\n \n function removeDarkMode() {\n var style = document.getElementById('universal-dark-mode-style');\n if (style) style.remove();\n }\n \n // Toggle with Alt+Shift+D\n document.addEventListener('keydown', function(e) {\n if (e.altKey && e.shiftKey && e.key === 'D') {\n e.preventDefault();\n enabled = !enabled;\n if (enabled) {\n applyDarkMode();\n console.log('[Universal Dark Mode] Enabled');\n } else {\n removeDarkMode();\n console.log('[Universal Dark Mode] Disabled');\n }\n }\n });\n \n // Apply on load\n applyDarkMode();\n \n // Re-apply on dynamic content\n var observer = new MutationObserver(function(mutations) {\n if (enabled && !document.getElementById('universal-dark-mode-style')) {\n applyDarkMode();\n }\n });\n observer.observe(document.head, { childList: true });\n \n console.log('[Universal Dark Mode] Loaded - Press Alt+Shift+D to toggle');\n})();", "Universal Dark Mode"); } } catch(__e) { console.warn('[Userscript:Universal Dark Mode]', __e); } })(); })();
Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
38 changes: 20 additions & 18 deletions lightning/src/ln/channelmanager.rs
Original file line numberDiff line numberDiff line change
Expand Up@@ -1554,11 +1554,12 @@ where
/// # fn example<T: AChannelManager>(channel_manager: T) -> Result<(), Bolt12SemanticError> {
/// # let channel_manager = channel_manager.get_cm();
/// let offer = channel_manager
/// .create_offer_builder("coffee".to_string())?
/// .create_offer_builder()?
/// # ;
/// # // Needed for compiling for c_bindings
/// # let builder: lightning::offers::offer::OfferBuilder<_, _> = offer.into();
/// # let offer = builder
/// .description("coffee".to_string())
/// .amount_msats(10_000_000)
/// .build()?;
/// let bech32_offer = offer.to_string();
Expand DownExpand Up@@ -1657,13 +1658,13 @@ where
/// let payment_id = PaymentId([42; 32]);
/// let refund = channel_manager
/// .create_refund_builder(
/// "coffee".to_string(), amount_msats, absolute_expiry, payment_id, retry,
/// max_total_routing_fee_msat
/// amount_msats, absolute_expiry, payment_id, retry, max_total_routing_fee_msat
/// )?
/// # ;
/// # // Needed for compiling for c_bindings
/// # let builder: lightning::offers::refund::RefundBuilder<_> = refund.into();
/// # let refund = builder
/// .description("coffee".to_string())
/// .payer_note("refund for order 1234".to_string())
/// .build()?;
/// let bech32_refund = refund.to_string();
Expand DownExpand Up@@ -8553,17 +8554,15 @@ macro_rules! create_offer_builder { ($self: ident, $builder: ty) => {
///
/// [`Offer`]: crate::offers::offer::Offer
/// [`InvoiceRequest`]: crate::offers::invoice_request::InvoiceRequest
pub fn create_offer_builder(
&$self, description: String
) -> Result<$builder, Bolt12SemanticError> {
pub fn create_offer_builder(&$self) -> Result<$builder, Bolt12SemanticError> {
let node_id = $self.get_our_node_id();
let expanded_key = &$self.inbound_payment_key;
let entropy = &*$self.entropy_source;
let secp_ctx = &$self.secp_ctx;

let path = $self.create_blinded_path().map_err(|_| Bolt12SemanticError::MissingPaths)?;
let builder = OfferBuilder::deriving_signing_pubkey(
description, node_id, expanded_key, entropy, secp_ctx
node_id, expanded_key, entropy, secp_ctx
)
.chain_hash($self.chain_hash)
.path(path);
Expand DownExpand Up@@ -8622,8 +8621,8 @@ macro_rules! create_refund_builder { ($self: ident, $builder: ty) => {
/// [`Bolt12Invoice::payment_paths`]: crate::offers::invoice::Bolt12Invoice::payment_paths
/// [Avoiding Duplicate Payments]: #avoiding-duplicate-payments
pub fn create_refund_builder(
&$self, description: String, amount_msats: u64, absolute_expiry: Duration,
payment_id: PaymentId, retry_strategy: Retry, max_total_routing_fee_msat: Option<u64>
&$self, amount_msats: u64, absolute_expiry: Duration, payment_id: PaymentId,
retry_strategy: Retry, max_total_routing_fee_msat: Option<u64>
) -> Result<$builder, Bolt12SemanticError> {
let node_id = $self.get_our_node_id();
let expanded_key = &$self.inbound_payment_key;
Expand All@@ -8632,7 +8631,7 @@ macro_rules! create_refund_builder { ($self: ident, $builder: ty) => {

let path = $self.create_blinded_path().map_err(|_| Bolt12SemanticError::MissingPaths)?;
let builder = RefundBuilder::deriving_payer_id(
description, node_id, expanded_key, entropy, secp_ctx, amount_msats, payment_id
node_id, expanded_key, entropy, secp_ctx, amount_msats, payment_id
)?
.chain_hash($self.chain_hash)
.absolute_expiry(absolute_expiry)
Expand DownExpand Up@@ -8765,14 +8764,7 @@ where
.map_err(|_| Bolt12SemanticError::DuplicatePaymentId)?;

let mut pending_offers_messages = self.pending_offers_messages.lock().unwrap();
if offer.paths().is_empty() {
let message = new_pending_onion_message(
OffersMessage::InvoiceRequest(invoice_request),
Destination::Node(offer.signing_pubkey()),
Some(reply_path),
);
pending_offers_messages.push(message);
} else {
if !offer.paths().is_empty() {
// Send as many invoice requests as there are paths in the offer (with an upper bound).
// Using only one path could result in a failure if the path no longer exists. But only
// one invoice for a given payment id will be paid, even if more than one is received.
Expand All@@ -8785,6 +8777,16 @@ where
);
pending_offers_messages.push(message);
}
} else if let Some(signing_pubkey) = offer.signing_pubkey() {
let message = new_pending_onion_message(
OffersMessage::InvoiceRequest(invoice_request),
Destination::Node(signing_pubkey),
Some(reply_path),
);
pending_offers_messages.push(message);
} else {
debug_assert!(false);
return Err(Bolt12SemanticError::MissingSigningPubkey);
}

Ok(())
Expand Down
64 changes: 26 additions & 38 deletions lightning/src/ln/offers_tests.rs
Original file line numberDiff line numberDiff line change
Expand Up@@ -268,10 +268,10 @@ fn prefers_non_tor_nodes_in_blinded_paths() {
announce_node_address(charlie, &[alice, bob, david, &nodes[4], &nodes[5]], tor.clone());

let offer = bob.node
.create_offer_builder("coffee".to_string()).unwrap()
.create_offer_builder().unwrap()
.amount_msats(10_000_000)
.build().unwrap();
assert_ne!(offer.signing_pubkey(), bob_id);
assert_ne!(offer.signing_pubkey(), Some(bob_id));
assert!(!offer.paths().is_empty());
for path in offer.paths() {
assert_ne!(path.introduction_node, IntroductionNode::NodeId(bob_id));
Expand All@@ -283,10 +283,10 @@ fn prefers_non_tor_nodes_in_blinded_paths() {
announce_node_address(&nodes[5], &[alice, bob, charlie, david, &nodes[4]], tor.clone());

let offer = bob.node
.create_offer_builder("coffee".to_string()).unwrap()
.create_offer_builder().unwrap()
.amount_msats(10_000_000)
.build().unwrap();
assert_ne!(offer.signing_pubkey(), bob_id);
assert_ne!(offer.signing_pubkey(), Some(bob_id));
assert!(!offer.paths().is_empty());
for path in offer.paths() {
assert_eq!(path.introduction_node, IntroductionNode::NodeId(bob_id));
Expand DownExpand Up@@ -333,10 +333,10 @@ fn prefers_more_connected_nodes_in_blinded_paths() {
disconnect_peers(david, &[bob, &nodes[4], &nodes[5]]);

let offer = bob.node
.create_offer_builder("coffee".to_string()).unwrap()
.create_offer_builder().unwrap()
.amount_msats(10_000_000)
.build().unwrap();
assert_ne!(offer.signing_pubkey(), bob_id);
assert_ne!(offer.signing_pubkey(), Some(bob_id));
assert!(!offer.paths().is_empty());
for path in offer.paths() {
assert_eq!(path.introduction_node, IntroductionNode::NodeId(nodes[4].node.get_our_node_id()));
Expand DownExpand Up@@ -382,11 +382,11 @@ fn creates_and_pays_for_offer_using_two_hop_blinded_path() {
disconnect_peers(david, &[bob, &nodes[4], &nodes[5]]);

let offer = alice.node
.create_offer_builder("coffee".to_string())
.create_offer_builder()
.unwrap()
.amount_msats(10_000_000)
.build().unwrap();
assert_ne!(offer.signing_pubkey(), alice_id);
assert_ne!(offer.signing_pubkey(), Some(alice_id));
assert!(!offer.paths().is_empty());
for path in offer.paths() {
assert_eq!(path.introduction_node, IntroductionNode::NodeId(bob_id));
Expand DownExpand Up@@ -484,9 +484,7 @@ fn creates_and_pays_for_refund_using_two_hop_blinded_path() {
let absolute_expiry = Duration::from_secs(u64::MAX);
let payment_id = PaymentId([1; 32]);
let refund = david.node
.create_refund_builder(
"refund".to_string(), 10_000_000, absolute_expiry, payment_id, Retry::Attempts(0), None
)
.create_refund_builder(10_000_000, absolute_expiry, payment_id, Retry::Attempts(0), None)
.unwrap()
.build().unwrap();
assert_eq!(refund.amount_msats(), 10_000_000);
Expand DownExpand Up@@ -544,10 +542,10 @@ fn creates_and_pays_for_offer_using_one_hop_blinded_path() {
let bob_id = bob.node.get_our_node_id();

let offer = alice.node
.create_offer_builder("coffee".to_string()).unwrap()
.create_offer_builder().unwrap()
.amount_msats(10_000_000)
.build().unwrap();
assert_ne!(offer.signing_pubkey(), alice_id);
assert_ne!(offer.signing_pubkey(), Some(alice_id));
assert!(!offer.paths().is_empty());
for path in offer.paths() {
assert_eq!(path.introduction_node, IntroductionNode::NodeId(alice_id));
Expand DownExpand Up@@ -613,9 +611,7 @@ fn creates_and_pays_for_refund_using_one_hop_blinded_path() {
let absolute_expiry = Duration::from_secs(u64::MAX);
let payment_id = PaymentId([1; 32]);
let refund = bob.node
.create_refund_builder(
"refund".to_string(), 10_000_000, absolute_expiry, payment_id, Retry::Attempts(0), None
)
.create_refund_builder(10_000_000, absolute_expiry, payment_id, Retry::Attempts(0), None)
.unwrap()
.build().unwrap();
assert_eq!(refund.amount_msats(), 10_000_000);
Expand DownExpand Up@@ -668,11 +664,11 @@ fn pays_for_offer_without_blinded_paths() {
let bob_id = bob.node.get_our_node_id();

let offer = alice.node
.create_offer_builder("coffee".to_string()).unwrap()
.create_offer_builder().unwrap()
.clear_paths()
.amount_msats(10_000_000)
.build().unwrap();
assert_eq!(offer.signing_pubkey(), alice_id);
assert_eq!(offer.signing_pubkey(), Some(alice_id));
assert!(offer.paths().is_empty());

let payment_id = PaymentId([1; 32]);
Expand DownExpand Up@@ -724,9 +720,7 @@ fn pays_for_refund_without_blinded_paths() {
let absolute_expiry = Duration::from_secs(u64::MAX);
let payment_id = PaymentId([1; 32]);
let refund = bob.node
.create_refund_builder(
"refund".to_string(), 10_000_000, absolute_expiry, payment_id, Retry::Attempts(0), None
)
.create_refund_builder(10_000_000, absolute_expiry, payment_id, Retry::Attempts(0), None)
.unwrap()
.clear_paths()
.build().unwrap();
Expand DownExpand Up@@ -760,7 +754,7 @@ fn fails_creating_offer_without_blinded_paths() {

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

match nodes[0].node.create_offer_builder("coffee".to_string()) {
match nodes[0].node.create_offer_builder() {
Ok(_) => panic!("Expected error"),
Err(e) => assert_eq!(e, Bolt12SemanticError::MissingPaths),
}
Expand All@@ -780,7 +774,7 @@ fn fails_creating_refund_without_blinded_paths() {
let payment_id = PaymentId([1; 32]);

match nodes[0].node.create_refund_builder(
"refund".to_string(), 10_000, absolute_expiry, payment_id, Retry::Attempts(0), None
10_000, absolute_expiry, payment_id, Retry::Attempts(0), None
) {
Ok(_) => panic!("Expected error"),
Err(e) => assert_eq!(e, Bolt12SemanticError::MissingPaths),
Expand All@@ -803,7 +797,7 @@ fn fails_creating_invoice_request_for_unsupported_chain() {
let bob = &nodes[1];

let offer = alice.node
.create_offer_builder("coffee".to_string()).unwrap()
.create_offer_builder().unwrap()
.clear_chains()
.chain(Network::Signet)
.build().unwrap();
Expand DownExpand Up@@ -831,9 +825,7 @@ fn fails_sending_invoice_with_unsupported_chain_for_refund() {
let absolute_expiry = Duration::from_secs(u64::MAX);
let payment_id = PaymentId([1; 32]);
let refund = bob.node
.create_refund_builder(
"refund".to_string(), 10_000_000, absolute_expiry, payment_id, Retry::Attempts(0), None
)
.create_refund_builder(10_000_000, absolute_expiry, payment_id, Retry::Attempts(0), None)
.unwrap()
.chain(Network::Signet)
.build().unwrap();
Expand DownExpand Up@@ -865,7 +857,7 @@ fn fails_creating_invoice_request_without_blinded_reply_path() {
disconnect_peers(david, &[bob, &nodes[4], &nodes[5]]);

let offer = alice.node
.create_offer_builder("coffee".to_string()).unwrap()
.create_offer_builder().unwrap()
.amount_msats(10_000_000)
.build().unwrap();

Expand DownExpand Up@@ -899,7 +891,7 @@ fn fails_creating_invoice_request_with_duplicate_payment_id() {
disconnect_peers(alice, &[charlie, david, &nodes[4], &nodes[5]]);

let offer = alice.node
.create_offer_builder("coffee".to_string()).unwrap()
.create_offer_builder().unwrap()
.amount_msats(10_000_000)
.build().unwrap();

Expand DownExpand Up@@ -932,13 +924,13 @@ fn fails_creating_refund_with_duplicate_payment_id() {
let payment_id = PaymentId([1; 32]);
assert!(
nodes[0].node.create_refund_builder(
"refund".to_string(), 10_000, absolute_expiry, payment_id, Retry::Attempts(0), None
10_000, absolute_expiry, payment_id, Retry::Attempts(0), None
).is_ok()
);
expect_recent_payment!(nodes[0], RecentPaymentDetails::AwaitingInvoice, payment_id);

match nodes[0].node.create_refund_builder(
"refund".to_string(), 10_000, absolute_expiry, payment_id, Retry::Attempts(0), None
10_000, absolute_expiry, payment_id, Retry::Attempts(0), None
) {
Ok(_) => panic!("Expected error"),
Err(e) => assert_eq!(e, Bolt12SemanticError::DuplicatePaymentId),
Expand DownExpand Up@@ -985,7 +977,7 @@ fn fails_sending_invoice_without_blinded_payment_paths_for_offer() {
disconnect_peers(david, &[bob, &nodes[4], &nodes[5]]);

let offer = alice.node
.create_offer_builder("coffee".to_string()).unwrap()
.create_offer_builder().unwrap()
.amount_msats(10_000_000)
.build().unwrap();

Expand DownExpand Up@@ -1049,9 +1041,7 @@ fn fails_sending_invoice_without_blinded_payment_paths_for_refund() {
let absolute_expiry = Duration::from_secs(u64::MAX);
let payment_id = PaymentId([1; 32]);
let refund = david.node
.create_refund_builder(
"refund".to_string(), 10_000_000, absolute_expiry, payment_id, Retry::Attempts(0), None
)
.create_refund_builder(10_000_000, absolute_expiry, payment_id, Retry::Attempts(0), None)
.unwrap()
.build().unwrap();

Expand DownExpand Up@@ -1100,9 +1090,7 @@ fn fails_paying_invoice_more_than_once() {
let absolute_expiry = Duration::from_secs(u64::MAX);
let payment_id = PaymentId([1; 32]);
let refund = david.node
.create_refund_builder(
"refund".to_string(), 10_000_000, absolute_expiry, payment_id, Retry::Attempts(0), None
)
.create_refund_builder(10_000_000, absolute_expiry, payment_id, Retry::Attempts(0), None)
.unwrap()
.build().unwrap();
expect_recent_payment!(david, RecentPaymentDetails::AwaitingInvoice, payment_id);
Expand Down
6 changes: 3 additions & 3 deletions lightning/src/ln/outbound_payment.rs
Original file line numberDiff line numberDiff line change
Expand Up@@ -2194,7 +2194,7 @@ mod tests {
assert!(outbound_payments.has_pending_payments());

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

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

let invoice = OfferBuilder::new("foo".into(), recipient_pubkey())
let invoice = OfferBuilder::new(recipient_pubkey())
.amount_msats(1000)
.build().unwrap()
.request_invoice(vec![1; 32], payer_pubkey()).unwrap()
Expand Down
Loading