@@ -57,8 +57,11 @@ use crate::ln::outbound_payment::{OutboundPayments, PaymentAttempts, PendingOutb
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};
@@ -6579,6 +6582,74 @@ where
6579
6582
}
6580
6583
}
6581
6584
6585
+ /// Creates an [`OfferBuilder`] such that the [`Offer`] it builds is recognized by the
6586
+ /// [`ChannelManager`] when handling [`InvoiceRequest`] messages for the offer.
6587
+ ///
6588
+ /// [`Offer`]: crate::offers::offer::Offer
6589
+ /// [`InvoiceRequest`]: crate::offers::invoice_request::InvoiceRequest
6590
+ pub fn create_offer_builder(
6591
+ &self, description: String
6592
+ ) -> OfferBuilder<DerivedMetadata, secp256k1::All> {
6593
+ let node_id = self.get_our_node_id();
6594
+ let expanded_key = &self.inbound_payment_key;
6595
+ let entropy = &*self.entropy_source;
6596
+ let secp_ctx = &self.secp_ctx;
6597
+
6598
+ // TODO: Set blinded paths
6599
+ OfferBuilder::deriving_signing_pubkey(description, node_id, expanded_key, entropy, secp_ctx)
6600
+ }
6601
+
6602
+ /// Creates a [`RefundBuilder`] such that the [`Refund`] it builds is recognized by the
6603
+ /// [`ChannelManager`] when handling [`Bolt12Invoice`] messages for the refund.
6604
+ ///
6605
+ /// The provided `payment_id` is used to ensure that only one invoice is paid for the refund.
6606
+ ///
6607
+ /// [`Refund`]: crate::offers::refund::Refund
6608
+ /// [`Bolt12Invoice`]: crate::offers::invoice::Bolt12Invoice
6609
+ pub fn create_refund_builder(
6610
+ &self, description: String, amount_msats: u64, payment_id: PaymentId
6611
+ ) -> Result<RefundBuilder<secp256k1::All>, Bolt12SemanticError> {
6612
+ let node_id = self.get_our_node_id();
6613
+ let expanded_key = &self.inbound_payment_key;
6614
+ let entropy = &*self.entropy_source;
6615
+ let secp_ctx = &self.secp_ctx;
6616
+
6617
+ // TODO: Set blinded paths
6618
+ let builder = RefundBuilder::deriving_payer_id(
6619
+ description, node_id, expanded_key, entropy, secp_ctx, amount_msats, payment_id
6620
+ )?;
6621
+ self.pending_outbound_payments
6622
+ .add_new_awaiting_invoice(payment_id)
6623
+ .map_err(|_| Bolt12SemanticError::DuplicatePaymentId)?;
6624
+
6625
+ Ok(builder)
6626
+ }
6627
+
6628
+ /// Creates an [`InvoiceRequestBuilder`] such that the [`InvoiceRequest`] it builds is
6629
+ /// recognized by the [`ChannelManager`] when handling [`Bolt12Invoice`] messages for the
6630
+ /// request.
6631
+ ///
6632
+ /// The provided `payment_id` is used to ensure that only one invoice is paid for the request.
6633
+ ///
6634
+ /// [`InvoiceRequest`]: crate::offers::invoice_request::InvoiceRequest
6635
+ /// [`Bolt12Invoice`]: crate::offers::invoice::Bolt12Invoice
6636
+ pub fn create_invoice_request_builder<'a, 'b>(
6637
+ &'b self, offer: &'a Offer, payment_id: PaymentId
6638
+ ) -> Result<InvoiceRequestBuilder<'a, 'b, DerivedPayerId, secp256k1::All>, Bolt12SemanticError> {
6639
+ let expanded_key = &self.inbound_payment_key;
6640
+ let entropy = &*self.entropy_source;
6641
+ let secp_ctx = &self.secp_ctx;
6642
+
6643
+ let builder = offer.request_invoice_deriving_payer_id(
6644
+ expanded_key, entropy, secp_ctx, payment_id
6645
+ )?;
6646
+ self.pending_outbound_payments
6647
+ .add_new_awaiting_invoice(payment_id)
6648
+ .map_err(|_| Bolt12SemanticError::DuplicatePaymentId)?;
6649
+
6650
+ Ok(builder)
6651
+ }
6652
+
6582
6653
/// Gets a payment secret and payment hash for use in an invoice given to a third party wishing
6583
6654
/// to pay us.
6584
6655
///
0 commit comments