@@ -57,8 +57,11 @@ use crate::ln::outbound_payment::{OutboundPayments, PaymentAttempts, PendingOutb
5757use crate::ln::wire::Encode;
5858use crate::offers::invoice::{Bolt12Invoice, DEFAULT_RELATIVE_EXPIRY, DerivedSigningPubkey, InvoiceBuilder};
5959use crate::offers::invoice_error::InvoiceError;
60+ use crate::offers::invoice_request::{DerivedPayerId, InvoiceRequestBuilder};
6061use crate::offers::merkle::SignError;
62+ use crate::offers::offer::{DerivedMetadata, Offer, OfferBuilder};
6163use crate::offers::parse::Bolt12SemanticError;
64+ use crate::offers::refund::RefundBuilder;
6265use crate::onion_message::{OffersMessage, OffersMessageHandler};
6366use crate::sign::{EntropySource, KeysManager, NodeSigner, Recipient, SignerProvider, WriteableEcdsaChannelSigner};
6467use crate::util::config::{UserConfig, ChannelConfig, ChannelConfigUpdate};
@@ -6579,6 +6582,74 @@ where
65796582 }
65806583 }
65816584
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+
65826653 /// Gets a payment secret and payment hash for use in an invoice given to a third party wishing
65836654 /// to pay us.
65846655 ///
0 commit comments