2 use chain::transaction::OutPoint;
4 use bitcoin::blockdata::script::Script;
6 use secp256k1::key::PublicKey;
8 use std::time::Instant;
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
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
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.
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.
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).
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
52 payment_preimage: [u8; 32],
54 /// Indicates an outbound payment we made failed. Probably some intermediary node dropped
55 /// something. You may wish to retry with a different route.
57 /// The hash which was given to ChannelManager::send_payment.
58 payment_hash: [u8; 32],
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,
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.
73 /// The node_id of the node which should receive this message
75 /// The message which should be sent.
76 msg: msgs::OpenChannel,
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.
81 /// The node_id of the node which should receive this message
83 /// The message which should be sent.
84 msg: msgs::FundingCreated,
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.
89 /// The node_id of the node which should receive these message(s)
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>,
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.
100 /// The node_id of the node which should receive these message(s)
102 /// The update messages which should be sent. ALL messages in the struct should be sent!
103 updates: msgs::CommitmentUpdate,
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.
108 /// The node_id of the node which should receive this message
110 /// The message which should be sent.
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,
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,
130 /// Broadcast an error downstream to be handled
131 /// This event is handled by PeerManager::process_events if you are using a PeerManager.
133 /// The node_id of the node which should receive this message
135 /// The action which should be taken.
136 action: Option<msgs::ErrorAction>
140 pub trait EventsProvider {
141 fn get_and_clear_pending_events(&self) -> Vec<Event>;