-
-/// Used to give chain error details upstream
-pub enum ChainError {
- /// Client doesn't support UTXO lookup (but the chain hash matches our genesis block hash)
- NotSupported,
- /// Chain isn't the one watched
- NotWatched,
- /// Tx doesn't exist or is unconfirmed
- UnknownTx,
-}
-
-/// An interface to request notification of certain scripts as they appear the
-/// chain.
-///
-/// Note that all of the functions implemented here *must* be reentrant-safe (obviously - they're
-/// called from inside the library in response to ChainListener events, P2P events, or timer
-/// events).
-pub trait ChainWatchInterface: Sync + Send {
- /// Provides a txid/random-scriptPubKey-in-the-tx which much be watched for.
- fn install_watch_tx(&self, txid: &Sha256dHash, script_pub_key: &Script);
-
- /// Provides an outpoint which must be watched for, providing any transactions which spend the
- /// given outpoint.
- fn install_watch_outpoint(&self, outpoint: (Sha256dHash, u32), out_script: &Script);
-
- /// Indicates that a listener needs to see all transactions.
- fn watch_all_txn(&self);
-
- /// Gets the script and value in satoshis for a given unspent transaction output given a
- /// short_channel_id (aka unspent_tx_output_identier). For BTC/tBTC channels the top three
- /// bytes are the block height, the next 3 the transaction index within the block, and the
- /// final two the output within the transaction.
- fn get_chain_utxo(&self, genesis_hash: Sha256dHash, unspent_tx_output_identifier: u64) -> Result<(Script, u64), ChainError>;
-
- /// Gets the list of transactions and transaction indices that the ChainWatchInterface is
- /// watching for.
- fn filter_block<'a>(&self, block: &'a Block) -> (Vec<&'a Transaction>, Vec<u32>);
-
- /// Returns a usize that changes when the ChainWatchInterface's watched data is modified.
- /// Users of `filter_block` should pre-save a copy of `reentered`'s return value and use it to
- /// determine whether they need to re-filter a given block.
- fn reentered(&self) -> usize;
-}