initial checkin
[rust-lightning] / src / util / events.rs
1 use ln::msgs;
2
3 use bitcoin::blockdata::script::Script;
4 use bitcoin::util::uint::Uint256;
5 use bitcoin::util::hash::Sha256dHash;
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: (Sha256dHash, u16),
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         PaymentReceived {
34                 payment_hash: [u8; 32],
35                 amt: u64,
36         },
37
38         // Events indicating the network loop should send a message to a peer:
39         /// Used to indicate that ChannelManager::process_pending_htlc_forwards should be called at a
40         /// time in the future.
41         PendingHTLCsForwardable {
42                 time_forwardable: Instant,
43         },
44         /// Used to indicate that a funding_created message should be sent to the peer with the given node_id.
45         SendFundingCreated {
46                 node_id: PublicKey,
47                 msg: msgs::FundingCreated,
48         },
49         /// Used to indicate that a funding_locked message should be sent to the peer with the given node_id.
50         SendFundingLocked {
51                 node_id: PublicKey,
52                 msg: msgs::FundingLocked,
53                 announcement_sigs: Option<msgs::AnnouncementSignatures>,
54         },
55         /// Used to indicate that a series of update_add_htlc messages, as well as a commitment_signed
56         /// message should be sent to the peer with the given node_id.
57         SendHTLCs {
58                 node_id: PublicKey,
59                 msgs: Vec<msgs::UpdateAddHTLC>,
60                 commitment_msg: msgs::CommitmentSigned,
61         },
62         /// Used to indicate that we're ready to fulfill an htlc from the peer with the given node_id.
63         SendFulfillHTLC {
64                 node_id: PublicKey,
65                 msg: msgs::UpdateFulfillHTLC,
66         },
67         /// Used to indicate that a channel_announcement and channel_update should be broadcast to all
68         /// peers (except the peer with node_id either msg.contents.node_id_1 or msg.contents.node_id_2).
69         BroadcastChannelAnnouncement {
70                 msg: msgs::ChannelAnnouncement,
71                 update_msg: msgs::ChannelUpdate,
72         },
73 }
74
75 pub trait EventsProvider {
76         fn get_and_clear_pending_events(&self) -> Vec<Event>;
77 }