Skip to content

Commit e1bba3a

Browse files
committed
Introduce OffersMessageFlow
1 parent 1610854 commit e1bba3a

File tree

2 files changed

+93
-0
lines changed

2 files changed

+93
-0
lines changed

lightning/src/offers/flow.rs

+92
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,92 @@
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+
use bitcoin::constants::ChainHash;
14+
use bitcoin::secp256k1::{Secp256k1, PublicKey};
15+
use bitcoin::{secp256k1, Network};
16+
use crate::ln::inbound_payment;
17+
use crate::sign::EntropySource;
18+
use crate::onion_message::messenger::{MessageRouter, MessageSendInstructions};
19+
use crate::onion_message::offers::OffersMessage;
20+
use crate::onion_message::async_payments::AsyncPaymentsMessage;
21+
use crate::sync::Mutex;
22+
23+
use core::ops::Deref;
24+
use core::sync::atomic::AtomicUsize;
25+
26+
#[cfg(feature = "dnssec")]
27+
use crate::onion_message::dns_resolution::DNSResolverMessage;
28+
29+
pub struct OffersMessageFlow<ES: Deref, MR: Deref>
30+
where
31+
ES::Target: EntropySource,
32+
MR::Target: MessageRouter,
33+
{
34+
chain_hash: ChainHash,
35+
message_router: MR,
36+
37+
our_network_pubkey: PublicKey,
38+
highest_seen_timestamp: AtomicUsize,
39+
inbound_payment_key: inbound_payment::ExpandedKey,
40+
41+
secp_ctx: Secp256k1<secp256k1::All>,
42+
entropy_source: ES,
43+
44+
#[cfg(not(any(test, feature = "_test_utils")))]
45+
pending_offers_messages: Mutex<Vec<(OffersMessage, MessageSendInstructions)>>,
46+
#[cfg(any(test, feature = "_test_utils"))]
47+
pub(crate) pending_offers_messages: Mutex<Vec<(OffersMessage, MessageSendInstructions)>>,
48+
49+
pending_async_payments_messages: Mutex<Vec<(AsyncPaymentsMessage, MessageSendInstructions)>>,
50+
51+
#[cfg(feature = "dnssec")]
52+
pending_dns_onion_messages: Mutex<Vec<(DNSResolverMessage, MessageSendInstructions)>>,
53+
}
54+
55+
impl<ES: Deref, MR: Deref> OffersMessageFlow<ES, MR>
56+
where
57+
ES::Target: EntropySource,
58+
MR::Target: MessageRouter,
59+
{
60+
/// Creates a new [`OffersMessageFlow`]
61+
pub fn new(
62+
network: Network, message_router: MR, our_network_pubkey: PublicKey,
63+
current_timestamp: u32, inbound_payment_key: inbound_payment::ExpandedKey,
64+
entropy_source: ES,
65+
66+
) -> Self {
67+
let mut secp_ctx = Secp256k1::new();
68+
secp_ctx.seeded_randomize(&entropy_source.get_secure_random_bytes());
69+
70+
Self {
71+
chain_hash: ChainHash::using_genesis_block(network),
72+
message_router,
73+
74+
our_network_pubkey,
75+
highest_seen_timestamp: AtomicUsize::new(current_timestamp as usize),
76+
inbound_payment_key,
77+
78+
secp_ctx,
79+
entropy_source,
80+
81+
pending_offers_messages: Mutex::new(Vec::new()),
82+
pending_async_payments_messages: Mutex::new(Vec::new()),
83+
#[cfg(feature = "dnssec")]
84+
pending_dns_onion_messages: Mutex::new(Vec::new()),
85+
}
86+
}
87+
88+
/// Gets the node_id held by this OffersMessageFlow
89+
pub fn get_our_node_id(&self) -> PublicKey {
90+
self.our_network_pubkey
91+
}
92+
}

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)