@@ -57,8 +57,11 @@ use crate::ln::outbound_payment::{Bolt12PaymentError, OutboundPayments, PaymentA
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};
@@ -6702,6 +6705,74 @@ where
67026705 }
67036706 }
67046707
6708+ /// Creates an [`OfferBuilder`] such that the [`Offer`] it builds is recognized by the
6709+ /// [`ChannelManager`] when handling [`InvoiceRequest`] messages for the offer.
6710+ ///
6711+ /// [`Offer`]: crate::offers::offer::Offer
6712+ /// [`InvoiceRequest`]: crate::offers::invoice_request::InvoiceRequest
6713+ pub fn create_offer_builder(
6714+ &self, description: String
6715+ ) -> OfferBuilder<DerivedMetadata, secp256k1::All> {
6716+ let node_id = self.get_our_node_id();
6717+ let expanded_key = &self.inbound_payment_key;
6718+ let entropy = &*self.entropy_source;
6719+ let secp_ctx = &self.secp_ctx;
6720+
6721+ // TODO: Set blinded paths
6722+ OfferBuilder::deriving_signing_pubkey(description, node_id, expanded_key, entropy, secp_ctx)
6723+ }
6724+
6725+ /// Creates a [`RefundBuilder`] such that the [`Refund`] it builds is recognized by the
6726+ /// [`ChannelManager`] when handling [`Bolt12Invoice`] messages for the refund.
6727+ ///
6728+ /// The provided `payment_id` is used to ensure that only one invoice is paid for the refund.
6729+ ///
6730+ /// [`Refund`]: crate::offers::refund::Refund
6731+ /// [`Bolt12Invoice`]: crate::offers::invoice::Bolt12Invoice
6732+ pub fn create_refund_builder(
6733+ &self, description: String, amount_msats: u64, payment_id: PaymentId, retry_strategy: Retry
6734+ ) -> Result<RefundBuilder<secp256k1::All>, Bolt12SemanticError> {
6735+ let node_id = self.get_our_node_id();
6736+ let expanded_key = &self.inbound_payment_key;
6737+ let entropy = &*self.entropy_source;
6738+ let secp_ctx = &self.secp_ctx;
6739+
6740+ // TODO: Set blinded paths
6741+ let builder = RefundBuilder::deriving_payer_id(
6742+ description, node_id, expanded_key, entropy, secp_ctx, amount_msats, payment_id
6743+ )?;
6744+ self.pending_outbound_payments
6745+ .add_new_awaiting_invoice(payment_id, retry_strategy)
6746+ .map_err(|_| Bolt12SemanticError::DuplicatePaymentId)?;
6747+
6748+ Ok(builder)
6749+ }
6750+
6751+ /// Creates an [`InvoiceRequestBuilder`] such that the [`InvoiceRequest`] it builds is
6752+ /// recognized by the [`ChannelManager`] when handling [`Bolt12Invoice`] messages for the
6753+ /// request.
6754+ ///
6755+ /// The provided `payment_id` is used to ensure that only one invoice is paid for the request.
6756+ ///
6757+ /// [`InvoiceRequest`]: crate::offers::invoice_request::InvoiceRequest
6758+ /// [`Bolt12Invoice`]: crate::offers::invoice::Bolt12Invoice
6759+ pub fn create_invoice_request_builder<'a, 'b>(
6760+ &'b self, offer: &'a Offer, payment_id: PaymentId, retry_strategy: Retry
6761+ ) -> Result<InvoiceRequestBuilder<'a, 'b, DerivedPayerId, secp256k1::All>, Bolt12SemanticError> {
6762+ let expanded_key = &self.inbound_payment_key;
6763+ let entropy = &*self.entropy_source;
6764+ let secp_ctx = &self.secp_ctx;
6765+
6766+ let builder = offer.request_invoice_deriving_payer_id(
6767+ expanded_key, entropy, secp_ctx, payment_id
6768+ )?;
6769+ self.pending_outbound_payments
6770+ .add_new_awaiting_invoice(payment_id, retry_strategy)
6771+ .map_err(|_| Bolt12SemanticError::DuplicatePaymentId)?;
6772+
6773+ Ok(builder)
6774+ }
6775+
67056776 /// Gets a payment secret and payment hash for use in an invoice given to a third party wishing
67066777 /// to pay us.
67076778 ///
0 commit comments