Merge HTLC-update events, remove FailHTLC ErrorAction
[rust-lightning] / src / util / events.rs
1 use ln::msgs;
2 use chain::transaction::OutPoint;
3
4 use bitcoin::blockdata::script::Script;
5
6 use secp256k1::key::PublicKey;
7
8 use std::time::Instant;
9
10 pub enum Event {
11         // Events a user will probably have to handle
12         /// Used to indicate that the client should generate a funding transaction with the given
13         /// parameters and then call ChannelManager::funding_transaction_generated.
14         /// Generated in ChannelManager message handling.
15         FundingGenerationReady {
16                 temporary_channel_id: [u8; 32],
17                 channel_value_satoshis: u64,
18                 output_script: Script,
19                 /// The value passed in to ChannelManager::create_channel
20                 user_channel_id: u64,
21         },
22         /// Used to indicate that the client may now broadcast the funding transaction it created for a
23         /// channel. Broadcasting such a transaction prior to this event may lead to our counterparty
24         /// trivially stealing all funds in the funding transaction!
25         FundingBroadcastSafe {
26                 funding_txo: OutPoint,
27                 /// The value passed in to ChannelManager::create_channel
28                 user_channel_id: u64,
29         },
30         /// Indicates we've received money! Just gotta dig out that payment preimage and feed it to
31         /// ChannelManager::claim_funds to get it....
32         /// Note that if the preimage is not known, you must call ChannelManager::fail_htlc_backwards
33         /// to free up resources for this HTLC.
34         PaymentReceived {
35                 payment_hash: [u8; 32],
36                 amt: u64,
37         },
38         /// Indicates an outbound payment we made succeeded (ie it made it all the way to its target
39         /// and we got back the payment preimage for it). payment_preimage serves as a payment receipt,
40         /// if you wish to have such a thing, you must store it somehow!
41         PaymentSent {
42                 payment_preimage: [u8; 32],
43         },
44         /// Indicates an outbound payment we made failed. Probably some intermediary node dropped
45         /// something. You may wish to retry with a different route.
46         PaymentFailed {
47                 payment_hash: [u8; 32],
48         },
49         /// Used to indicate that ChannelManager::process_pending_htlc_forwards should be called at a
50         /// time in the future.
51         PendingHTLCsForwardable {
52                 time_forwardable: Instant,
53         },
54
55         // Events indicating the network loop should send a message to a peer:
56         /// Used to indicate that we've initialted a channel open and should send the open_channel
57         /// message provided to the given peer
58         SendOpenChannel {
59                 node_id: PublicKey,
60                 msg: msgs::OpenChannel,
61         },
62         /// Used to indicate that a funding_created message should be sent to the peer with the given node_id.
63         SendFundingCreated {
64                 node_id: PublicKey,
65                 msg: msgs::FundingCreated,
66         },
67         /// Used to indicate that a funding_locked message should be sent to the peer with the given node_id.
68         SendFundingLocked {
69                 node_id: PublicKey,
70                 msg: msgs::FundingLocked,
71                 announcement_sigs: Option<msgs::AnnouncementSignatures>,
72         },
73         /// Used to indicate that a series of HTLC update messages, as well as a commitment_signed
74         /// message should be sent to the peer with the given node_id.
75         UpdateHTLCs {
76                 node_id: PublicKey,
77                 updates: msgs::CommitmentUpdate,
78         },
79         /// Used to indicate that a shutdown message should be sent to the peer with the given node_id.
80         SendShutdown {
81                 node_id: PublicKey,
82                 msg: msgs::Shutdown,
83         },
84         /// Used to indicate that a channel_announcement and channel_update should be broadcast to all
85         /// peers (except the peer with node_id either msg.contents.node_id_1 or msg.contents.node_id_2).
86         BroadcastChannelAnnouncement {
87                 msg: msgs::ChannelAnnouncement,
88                 update_msg: msgs::ChannelUpdate,
89         },
90         /// Used to indicate that a channel_update should be broadcast to all peers.
91         BroadcastChannelUpdate {
92                 msg: msgs::ChannelUpdate,
93         },
94
95         //Error handling
96         /// Broadcast an error downstream to be handled
97         HandleError {
98                 node_id: PublicKey,
99                 action: Option<msgs::ErrorAction>
100         }
101 }
102
103 pub trait EventsProvider {
104         fn get_and_clear_pending_events(&self) -> Vec<Event>;
105 }