Skip to content

Commit 98c2551

Browse files
committed
SIS sep file
1 parent e2f293b commit 98c2551

File tree

3 files changed

+45
-37
lines changed

3 files changed

+45
-37
lines changed

src/event.rs

Lines changed: 11 additions & 37 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@
55
// http://opensource.org/licenses/MIT>, at your option. You may not use this file except in
66
// accordance with one or both of these licenses.
77

8+
use crate::static_invoice_store::StaticInvoiceStore;
89
use crate::types::{CustomTlvRecord, DynStore, PaymentStore, Sweeper, Wallet};
910

1011
use crate::{
@@ -37,8 +38,6 @@ use lightning::events::{Event as LdkEvent, PaymentFailureReason};
3738
use lightning::impl_writeable_tlv_based_enum;
3839
use lightning::ln::channelmanager::PaymentId;
3940
use lightning::ln::types::ChannelId;
40-
use lightning::offers::static_invoice::StaticInvoice;
41-
use lightning::onion_message::messenger::Responder;
4241
use lightning::routing::gossip::NodeId;
4342
use lightning::util::config::{
4443
ChannelConfigOverrides, ChannelConfigUpdate, ChannelHandshakeConfigUpdate,
@@ -58,7 +57,7 @@ use rand::{thread_rng, Rng};
5857

5958
use core::future::Future;
6059
use core::task::{Poll, Waker};
61-
use std::collections::{HashMap, VecDeque};
60+
use std::collections::VecDeque;
6261
use std::ops::Deref;
6362
use std::sync::{Arc, Condvar, Mutex};
6463

@@ -463,31 +462,6 @@ where
463462
static_invoice_store: StaticInvoiceStore,
464463
}
465464

466-
struct StaticInvoiceStore {
467-
pub static_invoices: Mutex<HashMap<(Vec<u8>, u16), StaticInvoice>>,
468-
}
469-
470-
impl StaticInvoiceStore {
471-
fn new() -> Self {
472-
Self { static_invoices: Mutex::new(HashMap::new()) }
473-
}
474-
475-
fn handle_static_invoice_requested(
476-
&self, recipient_id: Vec<u8>, invoice_slot: u16,
477-
) -> Option<StaticInvoice> {
478-
let map = self.static_invoices.lock().unwrap();
479-
480-
map.get(&(recipient_id.clone(), invoice_slot)).cloned()
481-
}
482-
483-
fn handle_persist_static_invoice(
484-
&self, invoice: StaticInvoice, invoice_slot: u16, recipient_id: Vec<u8>,
485-
) {
486-
let mut map = self.static_invoices.lock().unwrap();
487-
map.insert((recipient_id, invoice_slot), invoice);
488-
}
489-
}
490-
491465
impl<L: Deref + Clone + Sync + Send + 'static> EventHandler<L>
492466
where
493467
L::Target: LdkLogger,
@@ -498,8 +472,9 @@ where
498472
channel_manager: Arc<ChannelManager>, connection_manager: Arc<ConnectionManager<L>>,
499473
output_sweeper: Arc<Sweeper>, network_graph: Arc<Graph>,
500474
liquidity_source: Option<Arc<LiquiditySource<Arc<Logger>>>>,
501-
payment_store: Arc<PaymentStore>, peer_store: Arc<PeerStore<L>>, runtime: Arc<Runtime>,
502-
logger: L, config: Arc<Config>,
475+
payment_store: Arc<PaymentStore>, peer_store: Arc<PeerStore<L>>,
476+
static_invoice_store: StaticInvoiceStore, runtime: Arc<Runtime>, logger: L,
477+
config: Arc<Config>,
503478
) -> Self {
504479
Self {
505480
event_queue,
@@ -515,7 +490,7 @@ where
515490
logger,
516491
runtime,
517492
config,
518-
static_invoice_store: StaticInvoiceStore::new(),
493+
static_invoice_store,
519494
}
520495
}
521496

@@ -1530,18 +1505,17 @@ where
15301505
recipient_id,
15311506
invoice_persisted_path,
15321507
} => {
1533-
self.static_invoice_store.handle_persist_static_invoice(
1534-
invoice,
1535-
invoice_slot,
1536-
recipient_id,
1537-
);
1508+
self.static_invoice_store
1509+
.handle_persist_static_invoice(invoice, invoice_slot, recipient_id)
1510+
.await;
15381511

15391512
self.channel_manager.static_invoice_persisted(invoice_persisted_path);
15401513
},
15411514
LdkEvent::StaticInvoiceRequested { recipient_id, invoice_slot, reply_path } => {
15421515
let invoice = self
15431516
.static_invoice_store
1544-
.handle_static_invoice_requested(recipient_id, invoice_slot);
1517+
.handle_static_invoice_requested(recipient_id, invoice_slot)
1518+
.await;
15451519

15461520
if let Some(invoice) = invoice {
15471521
match self.channel_manager.send_static_invoice(invoice, reply_path) {

src/lib.rs

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -95,6 +95,7 @@ mod message_handler;
9595
pub mod payment;
9696
mod peer_store;
9797
mod runtime;
98+
mod static_invoice_store;
9899
mod tx_broadcaster;
99100
mod types;
100101
mod wallet;
@@ -171,6 +172,8 @@ use std::sync::atomic::{AtomicBool, Ordering};
171172
use std::sync::{Arc, Mutex, RwLock};
172173
use std::time::{Duration, Instant, SystemTime, UNIX_EPOCH};
173174

175+
use crate::static_invoice_store::StaticInvoiceStore;
176+
174177
#[cfg(feature = "uniffi")]
175178
uniffi::include_scaffolding!("ldk_node");
176179

@@ -498,6 +501,8 @@ impl Node {
498501
Arc::clone(&self.logger),
499502
));
500503

504+
let static_invoice_store = StaticInvoiceStore::new();
505+
501506
let event_handler = Arc::new(EventHandler::new(
502507
Arc::clone(&self.event_queue),
503508
Arc::clone(&self.wallet),
@@ -509,6 +514,7 @@ impl Node {
509514
self.liquidity_source.clone(),
510515
Arc::clone(&self.payment_store),
511516
Arc::clone(&self.peer_store),
517+
static_invoice_store,
512518
Arc::clone(&self.runtime),
513519
Arc::clone(&self.logger),
514520
Arc::clone(&self.config),

src/static_invoice_store.rs

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
use std::{collections::HashMap, sync::Mutex};
2+
3+
use lightning::offers::static_invoice::StaticInvoice;
4+
5+
pub(crate) struct StaticInvoiceStore {
6+
pub static_invoices: Mutex<HashMap<(Vec<u8>, u16), StaticInvoice>>,
7+
}
8+
9+
impl StaticInvoiceStore {
10+
pub(crate) fn new() -> Self {
11+
Self { static_invoices: Mutex::new(HashMap::new()) }
12+
}
13+
14+
pub(crate) async fn handle_static_invoice_requested(
15+
&self, recipient_id: Vec<u8>, invoice_slot: u16,
16+
) -> Option<StaticInvoice> {
17+
let map = self.static_invoices.lock().unwrap();
18+
19+
map.get(&(recipient_id.clone(), invoice_slot)).cloned()
20+
}
21+
22+
pub(crate) async fn handle_persist_static_invoice(
23+
&self, invoice: StaticInvoice, invoice_slot: u16, recipient_id: Vec<u8>,
24+
) {
25+
let mut map = self.static_invoices.lock().unwrap();
26+
map.insert((recipient_id, invoice_slot), invoice);
27+
}
28+
}

0 commit comments

Comments
 (0)