|
10 | 10 | //! Provides data structures and functions for creating and managing Offers messages,
|
11 | 11 | //! facilitating communication, and handling Bolt12 messages and payments.
|
12 | 12 |
|
| 13 | +use crate::blinded_path::message::{ |
| 14 | + BlindedMessagePath, MessageContext, MessageForwardNode, OffersContext, |
| 15 | +}; |
| 16 | +use crate::blinded_path::payment::BlindedPaymentPath; |
| 17 | +use crate::ln::channelmanager::PaymentId; |
13 | 18 | use crate::ln::inbound_payment;
|
| 19 | +use crate::offers::invoice::{Bolt12Invoice, DerivedSigningPubkey, InvoiceBuilder}; |
| 20 | +use crate::offers::invoice_request::{InvoiceRequest, InvoiceRequestBuilder}; |
| 21 | +use crate::offers::nonce::Nonce; |
| 22 | +use crate::offers::offer::{DerivedMetadata, Offer, OfferBuilder}; |
| 23 | +use crate::offers::parse::Bolt12SemanticError; |
| 24 | +use crate::offers::refund::{Refund, RefundBuilder}; |
14 | 25 | use crate::onion_message::async_payments::AsyncPaymentsMessage;
|
15 |
| -use crate::onion_message::messenger::{MessageRouter, MessageSendInstructions}; |
| 26 | +use crate::onion_message::dns_resolution::{DNSSECQuery, HumanReadableName}; |
| 27 | +use crate::onion_message::messenger::{Destination, MessageRouter, MessageSendInstructions}; |
16 | 28 | use crate::onion_message::offers::OffersMessage;
|
17 | 29 | use crate::sign::EntropySource;
|
18 | 30 | use crate::sync::Mutex;
|
19 | 31 | use bitcoin::constants::ChainHash;
|
20 | 32 | use bitcoin::secp256k1::{PublicKey, Secp256k1};
|
21 | 33 | use bitcoin::{secp256k1, Network};
|
| 34 | +use types::payment::PaymentHash; |
22 | 35 |
|
23 | 36 | use core::ops::Deref;
|
24 | 37 | use core::sync::atomic::AtomicUsize;
|
| 38 | +use core::time::Duration; |
25 | 39 |
|
26 | 40 | #[cfg(feature = "dnssec")]
|
27 | 41 | use crate::onion_message::dns_resolution::DNSResolverMessage;
|
28 | 42 |
|
| 43 | +pub trait Flow { |
| 44 | + fn create_offer_builder( |
| 45 | + &self, nonce: Nonce, |
| 46 | + ) -> Result<OfferBuilder<DerivedMetadata, secp256k1::All>, Bolt12SemanticError>; |
| 47 | + |
| 48 | + fn create_refund_builder( |
| 49 | + &self, amount_msats: u64, absolute_expiry: Duration, payment_id: PaymentId, nonce: Nonce, |
| 50 | + ) -> Result<RefundBuilder<secp256k1::All>, Bolt12SemanticError>; |
| 51 | + |
| 52 | + fn create_invoice_request_builder<'a>( |
| 53 | + &'a self, offer: &'a Offer, nonce: Nonce, quantity: Option<u64>, amount_msats: Option<u64>, |
| 54 | + payer_note: Option<String>, human_readable_name: Option<HumanReadableName>, |
| 55 | + payment_id: PaymentId, |
| 56 | + ) -> Result<InvoiceRequestBuilder<'a, 'a, secp256k1::All>, Bolt12SemanticError>; |
| 57 | + |
| 58 | + fn create_invoice_builder<'a>( |
| 59 | + &'a self, refund: &'a Refund, payment_paths: Vec<BlindedPaymentPath>, |
| 60 | + payment_hash: PaymentHash, |
| 61 | + ) -> Result<InvoiceBuilder<'a, DerivedSigningPubkey>, Bolt12SemanticError>; |
| 62 | + |
| 63 | + fn create_blinded_paths( |
| 64 | + &self, peers: Vec<MessageForwardNode>, context: MessageContext, |
| 65 | + ) -> Result<Vec<BlindedMessagePath>, ()>; |
| 66 | + |
| 67 | + fn create_compact_blinded_paths( |
| 68 | + &self, peers: Vec<MessageForwardNode>, context: OffersContext, |
| 69 | + ) -> Result<Vec<BlindedMessagePath>, ()>; |
| 70 | + |
| 71 | + fn create_blinded_paths_using_absolute_expiry( |
| 72 | + &self, peers: Vec<MessageForwardNode>, context: OffersContext, |
| 73 | + absolute_expiry: Option<Duration>, |
| 74 | + ) -> Result<Vec<BlindedMessagePath>, ()>; |
| 75 | + |
| 76 | + fn enqueue_invoice_request( |
| 77 | + &self, invoice_request: InvoiceRequest, reply_paths: Vec<BlindedMessagePath>, |
| 78 | + ) -> Result<(), Bolt12SemanticError>; |
| 79 | + |
| 80 | + fn enqueue_invoice( |
| 81 | + &self, invoice: Bolt12Invoice, refund: &Refund, reply_paths: Vec<BlindedMessagePath>, |
| 82 | + ) -> Result<(), Bolt12SemanticError>; |
| 83 | + |
| 84 | + #[cfg(feature = "dnssec")] |
| 85 | + fn enqueue_dns_onion_message( |
| 86 | + &self, message: DNSSECQuery, dns_resolvers: Vec<Destination>, |
| 87 | + reply_paths: Vec<BlindedMessagePath>, |
| 88 | + ) -> Result<(), Bolt12SemanticError>; |
| 89 | + |
| 90 | + fn get_and_clear_pending_offers_messages( |
| 91 | + &self, |
| 92 | + ) -> Vec<(OffersMessage, MessageSendInstructions)>; |
| 93 | + |
| 94 | + fn get_and_clear_pending_async_messages( |
| 95 | + &self, |
| 96 | + ) -> Vec<(AsyncPaymentsMessage, MessageSendInstructions)>; |
| 97 | + |
| 98 | + #[cfg(feature = "dnssec")] |
| 99 | + fn get_and_clear_pending_dns_messages( |
| 100 | + &self, |
| 101 | + ) -> Vec<(DNSResolverMessage, MessageSendInstructions)>; |
| 102 | +} |
| 103 | + |
29 | 104 | pub struct OffersMessageFlow<ES: Deref, MR: Deref>
|
30 | 105 | where
|
31 | 106 | ES::Target: EntropySource,
|
|
0 commit comments