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