Replace use of ChainWatchInterface with WatchEvent
[rust-lightning] / lightning / src / chain / mod.rs
1 // This file is Copyright its original authors, visible in version control
2 // history.
3 //
4 // This file is licensed under the Apache License, Version 2.0 <LICENSE-APACHE
5 // or http://www.apache.org/licenses/LICENSE-2.0> or the MIT license
6 // <LICENSE-MIT or http://opensource.org/licenses/MIT>, at your option.
7 // You may not use this file except in accordance with one or both of these
8 // licenses.
9
10 //! Structs and traits which allow other parts of rust-lightning to interact with the blockchain.
11
12 use bitcoin::blockdata::script::Script;
13 use bitcoin::hash_types::Txid;
14
15 use chain::transaction::OutPoint;
16
17 pub mod chaininterface;
18 pub mod transaction;
19 pub mod keysinterface;
20
21 /// An interface for providing [`WatchEvent`]s.
22 ///
23 /// [`WatchEvent`]: enum.WatchEvent.html
24 pub trait WatchEventProvider {
25         /// Releases events produced since the last call. Subsequent calls must only return new events.
26         fn release_pending_watch_events(&self) -> Vec<WatchEvent>;
27 }
28
29 /// An event indicating on-chain activity to watch for pertaining to a channel.
30 pub enum WatchEvent {
31         /// Watch for a transaction with `txid` and having an output with `script_pubkey` as a spending
32         /// condition.
33         WatchTransaction {
34                 /// Identifier of the transaction.
35                 txid: Txid,
36
37                 /// Spending condition for an output of the transaction.
38                 script_pubkey: Script,
39         },
40         /// Watch for spends of a transaction output identified by `outpoint` having `script_pubkey` as
41         /// the spending condition.
42         WatchOutput {
43                 /// Identifier for the output.
44                 outpoint: OutPoint,
45
46                 /// Spending condition for the output.
47                 script_pubkey: Script,
48         }
49 }