Skip to content

Commit 287c932

Browse files
committed
Introduce Flow trait
1 parent 1610854 commit 287c932

File tree

2 files changed

+137
-0
lines changed

2 files changed

+137
-0
lines changed

lightning/src/offers/flow.rs

+136
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,136 @@
1+
// This file is Copyright its original authors, visible in version control
2+
// history.
3+
//
4+
// This file is licensed under the Apache License, Version 2.0 <LICENSE-APACHE
5+
// or http://www.apache.org/licenses/LICENSE-2.0> or the MIT license
6+
// <LICENSE-MIT or http://opensource.org/licenses/MIT>, at your option.
7+
// You may not use this file except in accordance with one or both of these
8+
// licenses.
9+
10+
//! Provides data structures and functions for creating and managing Offers messages,
11+
//! facilitating communication, and handling Bolt12 messages and payments.
12+
13+
14+
use core::ops::Deref;
15+
use core::time::Duration;
16+
17+
use bitcoin::secp256k1;
18+
19+
use crate::blinded_path::message::{AsyncPaymentsContext, BlindedMessagePath, OffersContext};
20+
use crate::blinded_path::payment::{BlindedPaymentPath, PaymentContext};
21+
use crate::chain;
22+
use crate::ln::channelmanager::PaymentId;
23+
use crate::offers::invoice::{Bolt12Invoice, DerivedSigningPubkey, InvoiceBuilder};
24+
use crate::offers::invoice_error::InvoiceError;
25+
use crate::offers::invoice_request::{InvoiceRequest, InvoiceRequestBuilder, VerifiedInvoiceRequest};
26+
use crate::offers::nonce::Nonce;
27+
use crate::offers::offer::{DerivedMetadata, Offer, OfferBuilder};
28+
use crate::offers::parse::Bolt12SemanticError;
29+
use crate::offers::refund::{Refund, RefundBuilder};
30+
use crate::onion_message::async_payments::AsyncPaymentsMessage;
31+
use crate::onion_message::dns_resolution::HumanReadableName;
32+
use crate::onion_message::messenger::{Destination, MessageSendInstructions};
33+
use crate::onion_message::offers::OffersMessage;
34+
use crate::sign::NodeSigner;
35+
use crate::types::payment::{PaymentHash, PaymentSecret};
36+
37+
#[cfg(async_payments)]
38+
use {
39+
crate::blinded_path::message::MessageContext,
40+
crate::offers::static_invoice::{StaticInvoice, StaticInvoiceBuilder},
41+
};
42+
43+
#[cfg(feature = "dnssec")]
44+
use {
45+
crate::blinded_path::message::DNSResolverContext,
46+
crate::onion_message::dns_resolution::{DNSResolverMessage, DNSSECQuery},
47+
};
48+
49+
pub trait Flow: chain::Listen {
50+
fn verify_invoice_request(&self, invoice_request: InvoiceRequest, context: Option<OffersContext>) -> Result<VerifiedInvoiceRequest, ()>;
51+
52+
fn verify_bolt12_invoice(&self, invoice: &Bolt12Invoice, context: Option<&OffersContext>) -> Result<PaymentId, ()>;
53+
54+
#[cfg(async_payments)]
55+
fn verify_async_context(&self, context: AsyncPaymentsContext) -> Result<Option<PaymentId>, ()>;
56+
57+
fn create_offer_builder<F>(
58+
&self, absolute_expiry: Option<Duration>, paths: F,
59+
) -> Result<OfferBuilder<DerivedMetadata, secp256k1::All>, Bolt12SemanticError>
60+
where
61+
F: Fn(OffersContext) -> Result<Vec<BlindedMessagePath>, ()>;
62+
63+
fn create_refund_builder<F>(
64+
&self, amount_msats: u64, absolute_expiry: Duration, payment_id: PaymentId, paths: F,
65+
) -> Result<RefundBuilder<secp256k1::All>, Bolt12SemanticError>
66+
where
67+
F: Fn(OffersContext) -> Result<Vec<BlindedMessagePath>, ()>;
68+
69+
fn create_invoice_request_builder<'a>(
70+
&'a self, offer: &'a Offer, nonce: Nonce, quantity: Option<u64>, amount_msats: Option<u64>,
71+
payer_note: Option<String>, human_readable_name: Option<HumanReadableName>,
72+
payment_id: PaymentId,
73+
) -> Result<InvoiceRequestBuilder<'a, 'a, secp256k1::All>, Bolt12SemanticError>;
74+
75+
#[cfg(async_payments)]
76+
fn create_static_invoice_builder<'a, F1, F2>(
77+
&'a self, offer: &'a Offer, offer_nonce: Nonce, relative_expiry: Option<Duration>, payment_paths: F1, receive_paths: F2
78+
) -> Result<StaticInvoiceBuilder<'a>, Bolt12SemanticError>
79+
where
80+
F1: Fn(Option<u64>, PaymentSecret, PaymentContext, u32) -> Result<Vec<BlindedPaymentPath>, ()>,
81+
F2: Fn(MessageContext) -> Result<Vec<BlindedMessagePath>, ()>;
82+
83+
fn create_invoice_builder_from_refund<'a, F>(
84+
&'a self, refund: &'a Refund, payment_hash: PaymentHash, payment_paths: F,
85+
) -> Result<InvoiceBuilder<'a, DerivedSigningPubkey>, Bolt12SemanticError>
86+
where
87+
F: Fn(PaymentContext) -> Result<Vec<BlindedPaymentPath>, ()>;
88+
89+
fn create_invoice_from_invoice_request<NS: Deref, F>(
90+
self, signer: NS, invoice_request: VerifiedInvoiceRequest, payment_hash: PaymentHash, payment_paths: F,
91+
) -> Result<Bolt12Invoice, InvoiceError>
92+
where
93+
NS::Target: NodeSigner,
94+
F: Fn(PaymentContext) -> Result<Vec<BlindedPaymentPath>, ()>;
95+
96+
fn enqueue_invoice_request<F>(
97+
&self, invoice_request: InvoiceRequest, payment_id: PaymentId, nonce: Option<Nonce>, reply_paths: F,
98+
) -> Result<(), Bolt12SemanticError>
99+
where
100+
F: Fn(MessageContext) -> Result<Vec<BlindedMessagePath>, ()>;
101+
102+
fn enqueue_invoice<F>(
103+
&self, invoice: Bolt12Invoice, refund: &Refund, payment_hash: PaymentHash, reply_paths: F,
104+
) -> Result<(), Bolt12SemanticError>
105+
where
106+
F: Fn(MessageContext) -> Result<Vec<BlindedMessagePath>, ()>;
107+
108+
#[cfg(async_payments)]
109+
fn enqueue_async_payment_messages<F>(
110+
&self, invoice: &StaticInvoice, payment_id: PaymentId, reply_paths: F,
111+
) -> Result<(), Bolt12SemanticError>
112+
where
113+
F: Fn(MessageContext) -> Result<Vec<BlindedMessagePath>, ()>;
114+
115+
#[cfg(feature = "dnssec")]
116+
fn enqueue_dns_onion_message<F>(
117+
&self, message: DNSSECQuery, context: DNSResolverContext, dns_resolvers: Vec<Destination>,
118+
reply_paths: F,
119+
) -> Result<(), Bolt12SemanticError>
120+
where
121+
F: Fn(DNSResolverContext) -> Result<Vec<BlindedMessagePath>, ()>;
122+
123+
fn get_and_clear_pending_offers_messages(
124+
&self,
125+
) -> Vec<(OffersMessage, MessageSendInstructions)>;
126+
127+
#[cfg(async_payments)]
128+
fn get_and_clear_pending_async_messages(
129+
&self,
130+
) -> Vec<(AsyncPaymentsMessage, MessageSendInstructions)>;
131+
132+
#[cfg(feature = "dnssec")]
133+
fn get_and_clear_pending_dns_messages(
134+
&self,
135+
) -> Vec<(DNSResolverMessage, MessageSendInstructions)>;
136+
}

lightning/src/offers/mod.rs

+1
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@
1414
1515
#[macro_use]
1616
pub mod offer;
17+
pub mod flow;
1718

1819
pub mod invoice;
1920
pub mod invoice_error;

0 commit comments

Comments
 (0)