@@ -57,8 +57,11 @@ use crate::ln::outbound_payment::{Bolt12PaymentError, OutboundPayments, PaymentA
57
57
use crate::ln::wire::Encode;
58
58
use crate::offers::invoice::{Bolt12Invoice, DEFAULT_RELATIVE_EXPIRY, DerivedSigningPubkey, InvoiceBuilder};
59
59
use crate::offers::invoice_error::InvoiceError;
60
+ use crate::offers::invoice_request::{DerivedPayerId, InvoiceRequestBuilder};
60
61
use crate::offers::merkle::SignError;
62
+ use crate::offers::offer::{DerivedMetadata, Offer, OfferBuilder};
61
63
use crate::offers::parse::Bolt12SemanticError;
64
+ use crate::offers::refund::RefundBuilder;
62
65
use crate::onion_message::{OffersMessage, OffersMessageHandler};
63
66
use crate::sign::{EntropySource, KeysManager, NodeSigner, Recipient, SignerProvider, WriteableEcdsaChannelSigner};
64
67
use crate::util::config::{UserConfig, ChannelConfig, ChannelConfigUpdate};
@@ -6585,6 +6588,74 @@ where
6585
6588
}
6586
6589
}
6587
6590
6591
+ /// Creates an [`OfferBuilder`] such that the [`Offer`] it builds is recognized by the
6592
+ /// [`ChannelManager`] when handling [`InvoiceRequest`] messages for the offer.
6593
+ ///
6594
+ /// [`Offer`]: crate::offers::offer::Offer
6595
+ /// [`InvoiceRequest`]: crate::offers::invoice_request::InvoiceRequest
6596
+ pub fn create_offer_builder(
6597
+ &self, description: String
6598
+ ) -> OfferBuilder<DerivedMetadata, secp256k1::All> {
6599
+ let node_id = self.get_our_node_id();
6600
+ let expanded_key = &self.inbound_payment_key;
6601
+ let entropy = &*self.entropy_source;
6602
+ let secp_ctx = &self.secp_ctx;
6603
+
6604
+ // TODO: Set blinded paths
6605
+ OfferBuilder::deriving_signing_pubkey(description, node_id, expanded_key, entropy, secp_ctx)
6606
+ }
6607
+
6608
+ /// Creates a [`RefundBuilder`] such that the [`Refund`] it builds is recognized by the
6609
+ /// [`ChannelManager`] when handling [`Bolt12Invoice`] messages for the refund.
6610
+ ///
6611
+ /// The provided `payment_id` is used to ensure that only one invoice is paid for the refund.
6612
+ ///
6613
+ /// [`Refund`]: crate::offers::refund::Refund
6614
+ /// [`Bolt12Invoice`]: crate::offers::invoice::Bolt12Invoice
6615
+ pub fn create_refund_builder(
6616
+ &self, description: String, amount_msats: u64, payment_id: PaymentId, retry_strategy: Retry
6617
+ ) -> Result<RefundBuilder<secp256k1::All>, Bolt12SemanticError> {
6618
+ let node_id = self.get_our_node_id();
6619
+ let expanded_key = &self.inbound_payment_key;
6620
+ let entropy = &*self.entropy_source;
6621
+ let secp_ctx = &self.secp_ctx;
6622
+
6623
+ // TODO: Set blinded paths
6624
+ let builder = RefundBuilder::deriving_payer_id(
6625
+ description, node_id, expanded_key, entropy, secp_ctx, amount_msats, payment_id
6626
+ )?;
6627
+ self.pending_outbound_payments
6628
+ .add_new_awaiting_invoice(payment_id, retry_strategy)
6629
+ .map_err(|_| Bolt12SemanticError::DuplicatePaymentId)?;
6630
+
6631
+ Ok(builder)
6632
+ }
6633
+
6634
+ /// Creates an [`InvoiceRequestBuilder`] such that the [`InvoiceRequest`] it builds is
6635
+ /// recognized by the [`ChannelManager`] when handling [`Bolt12Invoice`] messages for the
6636
+ /// request.
6637
+ ///
6638
+ /// The provided `payment_id` is used to ensure that only one invoice is paid for the request.
6639
+ ///
6640
+ /// [`InvoiceRequest`]: crate::offers::invoice_request::InvoiceRequest
6641
+ /// [`Bolt12Invoice`]: crate::offers::invoice::Bolt12Invoice
6642
+ pub fn create_invoice_request_builder<'a, 'b>(
6643
+ &'b self, offer: &'a Offer, payment_id: PaymentId, retry_strategy: Retry
6644
+ ) -> Result<InvoiceRequestBuilder<'a, 'b, DerivedPayerId, secp256k1::All>, Bolt12SemanticError> {
6645
+ let expanded_key = &self.inbound_payment_key;
6646
+ let entropy = &*self.entropy_source;
6647
+ let secp_ctx = &self.secp_ctx;
6648
+
6649
+ let builder = offer.request_invoice_deriving_payer_id(
6650
+ expanded_key, entropy, secp_ctx, payment_id
6651
+ )?;
6652
+ self.pending_outbound_payments
6653
+ .add_new_awaiting_invoice(payment_id, retry_strategy)
6654
+ .map_err(|_| Bolt12SemanticError::DuplicatePaymentId)?;
6655
+
6656
+ Ok(builder)
6657
+ }
6658
+
6588
6659
/// Gets a payment secret and payment hash for use in an invoice given to a third party wishing
6589
6660
/// to pay us.
6590
6661
///
0 commit comments