1 use chain::chaininterface;
2 use chain::chaininterface::ConfirmationTarget;
3 use chain::transaction::OutPoint;
4 use ln::channelmonitor;
6 use ln::msgs::{HandleError};
9 use bitcoin::blockdata::transaction::Transaction;
11 use secp256k1::PublicKey;
13 use std::sync::{Arc,Mutex};
16 pub struct TestFeeEstimator {
17 pub sat_per_vbyte: u64,
19 impl chaininterface::FeeEstimator for TestFeeEstimator {
20 fn get_est_sat_per_vbyte(&self, _confirmation_target: ConfirmationTarget) -> u64 {
25 pub struct TestChannelMonitor {
26 pub added_monitors: Mutex<Vec<(OutPoint, channelmonitor::ChannelMonitor)>>,
27 pub simple_monitor: Arc<channelmonitor::SimpleManyChannelMonitor<OutPoint>>,
29 impl TestChannelMonitor {
30 pub fn new(chain_monitor: Arc<chaininterface::ChainWatchInterface>, broadcaster: Arc<chaininterface::BroadcasterInterface>) -> Self {
32 added_monitors: Mutex::new(Vec::new()),
33 simple_monitor: channelmonitor::SimpleManyChannelMonitor::new(chain_monitor, broadcaster),
37 impl channelmonitor::ManyChannelMonitor for TestChannelMonitor {
38 fn add_update_monitor(&self, funding_txo: OutPoint, monitor: channelmonitor::ChannelMonitor) -> Result<(), channelmonitor::ChannelMonitorUpdateErr> {
39 // At every point where we get a monitor update, we should be able to send a useful monitor
40 // to a watchtower and disk...
41 assert!(channelmonitor::ChannelMonitor::deserialize(&monitor.serialize_for_disk()[..]).unwrap() == monitor);
42 monitor.serialize_for_watchtower(); // This at least shouldn't crash...
43 self.added_monitors.lock().unwrap().push((funding_txo, monitor.clone()));
44 self.simple_monitor.add_update_monitor(funding_txo, monitor)
48 pub struct TestBroadcaster {
49 pub txn_broadcasted: Mutex<Vec<Transaction>>,
51 impl chaininterface::BroadcasterInterface for TestBroadcaster {
52 fn broadcast_transaction(&self, tx: &Transaction) {
53 self.txn_broadcasted.lock().unwrap().push(tx.clone());
57 pub struct TestChannelMessageHandler {
58 pub pending_events: Mutex<Vec<events::Event>>,
61 impl TestChannelMessageHandler {
62 pub fn new() -> Self {
63 TestChannelMessageHandler {
64 pending_events: Mutex::new(Vec::new()),
69 impl msgs::ChannelMessageHandler for TestChannelMessageHandler {
71 fn handle_open_channel(&self, _their_node_id: &PublicKey, _msg: &msgs::OpenChannel) -> Result<msgs::AcceptChannel, HandleError> {
72 Err(HandleError { err: "", action: None })
74 fn handle_accept_channel(&self, _their_node_id: &PublicKey, _msg: &msgs::AcceptChannel) -> Result<(), HandleError> {
75 Err(HandleError { err: "", action: None })
77 fn handle_funding_created(&self, _their_node_id: &PublicKey, _msg: &msgs::FundingCreated) -> Result<msgs::FundingSigned, HandleError> {
78 Err(HandleError { err: "", action: None })
80 fn handle_funding_signed(&self, _their_node_id: &PublicKey, _msg: &msgs::FundingSigned) -> Result<(), HandleError> {
81 Err(HandleError { err: "", action: None })
83 fn handle_funding_locked(&self, _their_node_id: &PublicKey, _msg: &msgs::FundingLocked) -> Result<Option<msgs::AnnouncementSignatures>, HandleError> {
84 Err(HandleError { err: "", action: None })
86 fn handle_shutdown(&self, _their_node_id: &PublicKey, _msg: &msgs::Shutdown) -> Result<(Option<msgs::Shutdown>, Option<msgs::ClosingSigned>), HandleError> {
87 Err(HandleError { err: "", action: None })
89 fn handle_closing_signed(&self, _their_node_id: &PublicKey, _msg: &msgs::ClosingSigned) -> Result<Option<msgs::ClosingSigned>, HandleError> {
90 Err(HandleError { err: "", action: None })
92 fn handle_update_add_htlc(&self, _their_node_id: &PublicKey, _msg: &msgs::UpdateAddHTLC) -> Result<(), HandleError> {
93 Err(HandleError { err: "", action: None })
95 fn handle_update_fulfill_htlc(&self, _their_node_id: &PublicKey, _msg: &msgs::UpdateFulfillHTLC) -> Result<(), HandleError> {
96 Err(HandleError { err: "", action: None })
98 fn handle_update_fail_htlc(&self, _their_node_id: &PublicKey, _msg: &msgs::UpdateFailHTLC) -> Result<Option<msgs::HTLCFailChannelUpdate>, HandleError> {
99 Err(HandleError { err: "", action: None })
101 fn handle_update_fail_malformed_htlc(&self, _their_node_id: &PublicKey, _msg: &msgs::UpdateFailMalformedHTLC) -> Result<(), HandleError> {
102 Err(HandleError { err: "", action: None })
104 fn handle_commitment_signed(&self, _their_node_id: &PublicKey, _msg: &msgs::CommitmentSigned) -> Result<(msgs::RevokeAndACK, Option<msgs::CommitmentSigned>), HandleError> {
105 Err(HandleError { err: "", action: None })
107 fn handle_revoke_and_ack(&self, _their_node_id: &PublicKey, _msg: &msgs::RevokeAndACK) -> Result<Option<msgs::CommitmentUpdate>, HandleError> {
108 Err(HandleError { err: "", action: None })
110 fn handle_update_fee(&self, _their_node_id: &PublicKey, _msg: &msgs::UpdateFee) -> Result<(), HandleError> {
111 Err(HandleError { err: "", action: None })
113 fn handle_announcement_signatures(&self, _their_node_id: &PublicKey, _msg: &msgs::AnnouncementSignatures) -> Result<(), HandleError> {
114 Err(HandleError { err: "", action: None })
116 fn peer_disconnected(&self, _their_node_id: &PublicKey, _no_connection_possible: bool) {}
119 impl events::EventsProvider for TestChannelMessageHandler {
120 fn get_and_clear_pending_events(&self) -> Vec<events::Event> {
121 let mut pending_events = self.pending_events.lock().unwrap();
122 let mut ret = Vec::new();
123 mem::swap(&mut ret, &mut *pending_events);
128 pub struct TestRoutingMessageHandler {}
130 impl TestRoutingMessageHandler {
131 pub fn new() -> Self {
132 TestRoutingMessageHandler {}
136 impl msgs::RoutingMessageHandler for TestRoutingMessageHandler {
137 fn handle_node_announcement(&self, _msg: &msgs::NodeAnnouncement) -> Result<(), HandleError> {
138 Err(HandleError { err: "", action: None })
140 fn handle_channel_announcement(&self, _msg: &msgs::ChannelAnnouncement) -> Result<bool, HandleError> {
141 Err(HandleError { err: "", action: None })
143 fn handle_channel_update(&self, _msg: &msgs::ChannelUpdate) -> Result<(), HandleError> {
144 Err(HandleError { err: "", action: None })
146 fn handle_htlc_fail_channel_update(&self, _update: &msgs::HTLCFailChannelUpdate) {}