Skip to content

Commit e812422

Browse files
committed
Move create_async_receive_offer_builder to flow.rs
1 parent f7a21d3 commit e812422

File tree

3 files changed

+39
-38
lines changed

3 files changed

+39
-38
lines changed

lightning/src/ln/async_payments_tests.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -49,7 +49,7 @@ fn create_static_invoice<T: secp256k1::Signing + secp256k1::Verification>(
4949
)
5050
.unwrap();
5151
let (offer_builder, offer_nonce) = recipient
52-
.node
52+
.offers_handler
5353
.create_async_receive_offer_builder(blinded_paths_to_always_online_node)
5454
.unwrap();
5555
let offer = offer_builder.build().unwrap();
@@ -155,7 +155,7 @@ fn static_invoice_unknown_required_features() {
155155
)
156156
.unwrap();
157157
let (offer_builder, nonce) = nodes[2]
158-
.node
158+
.offers_handler
159159
.create_async_receive_offer_builder(blinded_paths_to_always_online_node)
160160
.unwrap();
161161
let offer = offer_builder.build().unwrap();

lightning/src/ln/channelmanager.rs

Lines changed: 4 additions & 36 deletions
Original file line numberDiff line numberDiff line change
@@ -88,7 +88,7 @@ use crate::util::logger::{Level, Logger, WithContext};
8888
use crate::util::errors::APIError;
8989
#[cfg(async_payments)] use {
9090
crate::blinded_path::payment::AsyncBolt12OfferContext,
91-
crate::offers::offer::{Amount, DerivedMetadata, OfferBuilder},
91+
crate::offers::offer::Amount,
9292
crate::offers::static_invoice::{DEFAULT_RELATIVE_EXPIRY as STATIC_INVOICE_DEFAULT_RELATIVE_EXPIRY, StaticInvoice, StaticInvoiceBuilder},
9393
};
9494

@@ -9678,43 +9678,11 @@ where
96789678
MR::Target: MessageRouter,
96799679
L::Target: Logger,
96809680
{
9681-
9682-
/// Create an offer for receiving async payments as an often-offline recipient.
9683-
///
9684-
/// Because we may be offline when the payer attempts to request an invoice, you MUST:
9685-
/// 1. Provide at least 1 [`BlindedMessagePath`] terminating at an always-online node that will
9686-
/// serve the [`StaticInvoice`] created from this offer on our behalf.
9687-
/// 2. Use [`Self::create_static_invoice_builder`] to create a [`StaticInvoice`] from this
9688-
/// [`Offer`] plus the returned [`Nonce`], and provide the static invoice to the
9689-
/// aforementioned always-online node.
9690-
#[cfg(async_payments)]
9691-
pub fn create_async_receive_offer_builder(
9692-
&self, message_paths_to_always_online_node: Vec<BlindedMessagePath>
9693-
) -> Result<(OfferBuilder<DerivedMetadata, secp256k1::All>, Nonce), Bolt12SemanticError> {
9694-
if message_paths_to_always_online_node.is_empty() {
9695-
return Err(Bolt12SemanticError::MissingPaths)
9696-
}
9697-
9698-
let node_id = self.get_our_node_id();
9699-
let expanded_key = &self.inbound_payment_key;
9700-
let entropy = &*self.entropy_source;
9701-
let secp_ctx = &self.secp_ctx;
9702-
9703-
let nonce = Nonce::from_entropy_source(entropy);
9704-
let mut builder = OfferBuilder::deriving_signing_pubkey(
9705-
node_id, expanded_key, nonce, secp_ctx
9706-
).chain_hash(self.chain_hash);
9707-
9708-
for path in message_paths_to_always_online_node {
9709-
builder = builder.path(path);
9710-
}
9711-
9712-
Ok((builder.into(), nonce))
9713-
}
9714-
97159681
/// Creates a [`StaticInvoiceBuilder`] from the corresponding [`Offer`] and [`Nonce`] that were
9716-
/// created via [`Self::create_async_receive_offer_builder`]. If `relative_expiry` is unset, the
9682+
/// created via [`create_async_receive_offer_builder`]. If `relative_expiry` is unset, the
97179683
/// invoice's expiry will default to [`STATIC_INVOICE_DEFAULT_RELATIVE_EXPIRY`].
9684+
///
9685+
/// [`create_async_receive_offer_builder`]: crate::offers::flow::create_async_receive_offer_builder
97189686
#[cfg(async_payments)]
97199687
pub fn create_static_invoice_builder<'a>(
97209688
&self, offer: &'a Offer, offer_nonce: Nonce, relative_expiry: Option<Duration>

lightning/src/offers/flow.rs

Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -922,4 +922,37 @@ where
922922

923923
#[cfg(c_bindings)]
924924
create_refund_builder!(self, RefundMaybeWithDerivedMetadataBuilder);
925+
926+
/// Create an offer for receiving async payments as an often-offline recipient.
927+
///
928+
/// Because we may be offline when the payer attempts to request an invoice, you MUST:
929+
/// 1. Provide at least 1 [`BlindedMessagePath`] terminating at an always-online node that will
930+
/// serve the [`StaticInvoice`] created from this offer on our behalf.
931+
/// 2. Use [`Self::create_static_invoice_builder`] to create a [`StaticInvoice`] from this
932+
/// [`Offer`] plus the returned [`Nonce`], and provide the static invoice to the
933+
/// aforementioned always-online node.
934+
#[cfg(async_payments)]
935+
pub fn create_async_receive_offer_builder(
936+
&self, message_paths_to_always_online_node: Vec<BlindedMessagePath>,
937+
) -> Result<(OfferBuilder<DerivedMetadata, secp256k1::All>, Nonce), Bolt12SemanticError> {
938+
if message_paths_to_always_online_node.is_empty() {
939+
return Err(Bolt12SemanticError::MissingPaths);
940+
}
941+
942+
let node_id = self.get_our_node_id();
943+
let expanded_key = &self.inbound_payment_key;
944+
let entropy = &*self.entropy_source;
945+
let secp_ctx = &self.secp_ctx;
946+
947+
let nonce = Nonce::from_entropy_source(entropy);
948+
let mut builder =
949+
OfferBuilder::deriving_signing_pubkey(node_id, expanded_key, nonce, secp_ctx)
950+
.chain_hash(self.commons.get_chain_hash());
951+
952+
for path in message_paths_to_always_online_node {
953+
builder = builder.path(path);
954+
}
955+
956+
Ok((builder.into(), nonce))
957+
}
925958
}

0 commit comments

Comments
 (0)