-
Notifications
You must be signed in to change notification settings - Fork 474
Expand file tree
/
Copy pathtest_persister.rs
More file actions
47 lines (42 loc) · 1.63 KB
/
Copy pathtest_persister.rs
File metadata and controls
47 lines (42 loc) · 1.63 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
use lightning::chain;
use lightning::chain::{chainmonitor, channelmonitor};
use lightning::ln::types::ChannelId;
use lightning::util::persist::MonitorName;
use lightning::util::test_channel_signer::TestChannelSigner;
use std::collections::HashMap;
use std::sync::Mutex;
pub struct TestPersister {
pub update_ret: Mutex<chain::ChannelMonitorUpdateStatus>,
latest_monitors: Mutex<HashMap<ChannelId, channelmonitor::ChannelMonitor<TestChannelSigner>>>,
}
impl TestPersister {
pub fn new(update_ret: chain::ChannelMonitorUpdateStatus) -> Self {
Self {
update_ret: Mutex::new(update_ret),
latest_monitors: Mutex::new(HashMap::new()),
}
}
pub fn take_latest_monitor(
&self, channel_id: &ChannelId,
) -> channelmonitor::ChannelMonitor<TestChannelSigner> {
self.latest_monitors.lock().unwrap().remove(channel_id)
.expect("Persister should have monitor for channel")
}
}
impl chainmonitor::Persist<TestChannelSigner> for TestPersister {
fn persist_new_channel(
&self, _monitor_name: MonitorName,
data: &channelmonitor::ChannelMonitor<TestChannelSigner>,
) -> chain::ChannelMonitorUpdateStatus {
self.latest_monitors.lock().unwrap().insert(data.channel_id(), data.clone());
self.update_ret.lock().unwrap().clone()
}
fn update_persisted_channel(
&self, _monitor_name: MonitorName, _update: Option<&channelmonitor::ChannelMonitorUpdate>,
data: &channelmonitor::ChannelMonitor<TestChannelSigner>,
) -> chain::ChannelMonitorUpdateStatus {
self.latest_monitors.lock().unwrap().insert(data.channel_id(), data.clone());
self.update_ret.lock().unwrap().clone()
}
fn archive_persisted_channel(&self, _monitor_name: MonitorName) {}
}