1 // This file is Copyright its original authors, visible in version control
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
10 //! Structs and traits which allow other parts of rust-lightning to interact with the blockchain.
12 use bitcoin::blockdata::script::Script;
13 use bitcoin::blockdata::transaction::TxOut;
14 use bitcoin::hash_types::{BlockHash, Txid};
16 use chain::transaction::OutPoint;
18 pub mod chaininterface;
20 pub mod keysinterface;
22 /// The `Access` trait defines behavior for accessing chain data and state, such as blocks and
24 pub trait Access: Send + Sync {
25 /// Returns the transaction output of a funding transaction encoded by [`short_channel_id`].
26 /// Returns an error if `genesis_hash` is for a different chain or if such a transaction output
29 /// [`short_channel_id`]: https://github.com/lightningnetwork/lightning-rfc/blob/master/07-routing-gossip.md#definition-of-short_channel_id
30 fn get_utxo(&self, genesis_hash: &BlockHash, short_channel_id: u64) -> Result<TxOut, AccessError>;
33 /// An error when accessing the chain via [`Access`].
35 /// [`Access`]: trait.Access.html
37 pub enum AccessError {
38 /// The requested chain is unknown.
41 /// The requested transaction doesn't exist or hasn't confirmed.
45 /// An interface for providing [`WatchEvent`]s.
47 /// [`WatchEvent`]: enum.WatchEvent.html
48 pub trait WatchEventProvider {
49 /// Releases events produced since the last call. Subsequent calls must only return new events.
50 fn release_pending_watch_events(&self) -> Vec<WatchEvent>;
53 /// An event indicating on-chain activity to watch for pertaining to a channel.
55 /// Watch for a transaction with `txid` and having an output with `script_pubkey` as a spending
58 /// Identifier of the transaction.
61 /// Spending condition for an output of the transaction.
62 script_pubkey: Script,
64 /// Watch for spends of a transaction output identified by `outpoint` having `script_pubkey` as
65 /// the spending condition.
67 /// Identifier for the output.
70 /// Spending condition for the output.
71 script_pubkey: Script,