Document all the fields in Errors
[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                 /// The random channel_id we picked which you'll need to pass into
17                 /// ChannelManager::funding_transaction_generated.
18                 temporary_channel_id: [u8; 32],
19                 /// The value, in satoshis, that the output should have.
20                 channel_value_satoshis: u64,
21                 /// The script which should be used in the transaction output.
22                 output_script: Script,
23                 /// The value passed in to ChannelManager::create_channel
24                 user_channel_id: u64,
25         },
26         /// Used to indicate that the client may now broadcast the funding transaction it created for a
27         /// channel. Broadcasting such a transaction prior to this event may lead to our counterparty
28         /// trivially stealing all funds in the funding transaction!
29         FundingBroadcastSafe {
30                 /// The output, which was passed to ChannelManager::funding_transaction_generated, which is
31                 /// now safe to broadcast.
32                 funding_txo: OutPoint,
33                 /// The value passed in to ChannelManager::create_channel
34                 user_channel_id: u64,
35         },
36         /// Indicates we've received money! Just gotta dig out that payment preimage and feed it to
37         /// ChannelManager::claim_funds to get it....
38         /// Note that if the preimage is not known, you must call ChannelManager::fail_htlc_backwards
39         /// to free up resources for this HTLC.
40         PaymentReceived {
41                 /// The hash for which the preimage should be handed to the ChannelManager.
42                 payment_hash: [u8; 32],
43                 /// The value, in thousandths of a satoshi, that this payment is for.
44                 amt: u64,
45         },
46         /// Indicates an outbound payment we made succeeded (ie it made it all the way to its target
47         /// and we got back the payment preimage for it).
48         PaymentSent {
49                 /// The preimage to the hash given to ChannelManager::send_payment.
50                 /// Note that this serves as a payment receipt, if you wish to have such a thing, you must
51                 /// store it somehow!
52                 payment_preimage: [u8; 32],
53         },
54         /// Indicates an outbound payment we made failed. Probably some intermediary node dropped
55         /// something. You may wish to retry with a different route.
56         PaymentFailed {
57                 /// The hash which was given to ChannelManager::send_payment.
58                 payment_hash: [u8; 32],
59         },
60         /// Used to indicate that ChannelManager::process_pending_htlc_forwards should be called at a
61         /// time in the future.
62         PendingHTLCsForwardable {
63                 /// The earliest time at which process_pending_htlc_forwards should be called.
64                 time_forwardable: Instant,
65         },
66
67         // Events indicating the network loop should send a message to a peer:
68         // TODO: Move these into a separate struct and make a top-level enum
69         /// Used to indicate that we've initialted a channel open and should send the open_channel
70         /// message provided to the given peer.
71         /// This event is handled by PeerManager::process_events if you are using a PeerManager.
72         SendOpenChannel {
73                 /// The node_id of the node which should receive this message
74                 node_id: PublicKey,
75                 /// The message which should be sent.
76                 msg: msgs::OpenChannel,
77         },
78         /// Used to indicate that a funding_created message should be sent to the peer with the given node_id.
79         /// This event is handled by PeerManager::process_events if you are using a PeerManager.
80         SendFundingCreated {
81                 /// The node_id of the node which should receive this message
82                 node_id: PublicKey,
83                 /// The message which should be sent.
84                 msg: msgs::FundingCreated,
85         },
86         /// Used to indicate that a funding_locked message should be sent to the peer with the given node_id.
87         /// This event is handled by PeerManager::process_events if you are using a PeerManager.
88         SendFundingLocked {
89                 /// The node_id of the node which should receive these message(s)
90                 node_id: PublicKey,
91                 /// The funding_locked message which should be sent.
92                 msg: msgs::FundingLocked,
93                 /// An optional additional announcement_signatures message which should be sent.
94                 announcement_sigs: Option<msgs::AnnouncementSignatures>,
95         },
96         /// Used to indicate that a series of HTLC update messages, as well as a commitment_signed
97         /// message should be sent to the peer with the given node_id.
98         /// This event is handled by PeerManager::process_events if you are using a PeerManager.
99         UpdateHTLCs {
100                 /// The node_id of the node which should receive these message(s)
101                 node_id: PublicKey,
102                 /// The update messages which should be sent. ALL messages in the struct should be sent!
103                 updates: msgs::CommitmentUpdate,
104         },
105         /// Used to indicate that a shutdown message should be sent to the peer with the given node_id.
106         /// This event is handled by PeerManager::process_events if you are using a PeerManager.
107         SendShutdown {
108                 /// The node_id of the node which should receive this message
109                 node_id: PublicKey,
110                 /// The message which should be sent.
111                 msg: msgs::Shutdown,
112         },
113         /// Used to indicate that a channel_announcement and channel_update should be broadcast to all
114         /// peers (except the peer with node_id either msg.contents.node_id_1 or msg.contents.node_id_2).
115         /// This event is handled by PeerManager::process_events if you are using a PeerManager.
116         BroadcastChannelAnnouncement {
117                 /// The channel_announcement which should be sent.
118                 msg: msgs::ChannelAnnouncement,
119                 /// The followup channel_update which should be sent.
120                 update_msg: msgs::ChannelUpdate,
121         },
122         /// Used to indicate that a channel_update should be broadcast to all peers.
123         /// This event is handled by PeerManager::process_events if you are using a PeerManager.
124         BroadcastChannelUpdate {
125                 /// The channel_update which should be sent.
126                 msg: msgs::ChannelUpdate,
127         },
128
129         //Error handling
130         /// Broadcast an error downstream to be handled
131         /// This event is handled by PeerManager::process_events if you are using a PeerManager.
132         HandleError {
133                 /// The node_id of the node which should receive this message
134                 node_id: PublicKey,
135                 /// The action which should be taken.
136                 action: Option<msgs::ErrorAction>
137         }
138 }
139
140 pub trait EventsProvider {
141         fn get_and_clear_pending_events(&self) -> Vec<Event>;
142 }