@@ -11,14 +11,12 @@ use std::sync::atomic::{AtomicUsize, Ordering};
11
11
12
12
/// Used to give chain error details upstream
13
13
pub enum ChainError {
14
- /// Chain isn 't supported
14
+ /// Client doesn 't support UTXO lookup (but the chain hash matches our genesis block hash)
15
15
NotSupported ,
16
16
/// Chain isn't the one watched
17
17
NotWatched ,
18
- /// Tx isn 't there
18
+ /// Tx doesn 't exist or is unconfirmed
19
19
UnknownTx ,
20
- /// Tx isn't confirmed
21
- UnconfirmedTx ,
22
20
}
23
21
24
22
/// An interface to request notification of certain scripts as they appear the
@@ -40,14 +38,11 @@ pub trait ChainWatchInterface: Sync + Send {
40
38
fn register_listener ( & self , listener : Weak < ChainListener > ) ;
41
39
//TODO: unregister
42
40
43
- /// Gets the chain currently watched
44
- fn get_network ( & self ) -> Network ;
45
-
46
- /// Gets the script and value in satoshis for a given txid and outpoint index
47
- fn get_chain_txo ( & self , genesis_hash : Sha256dHash , txid : Sha256dHash , output_index : u16 ) -> Result < ( Script , u64 ) , ChainError > ;
48
-
49
- /// Gets if outpoint is among UTXO
50
- fn get_spendable_outpoint ( & self , genesis_hash : Sha256dHash , txid : Sha256dHash , output_index : u16 ) -> Result < bool , ChainError > ;
41
+ /// Gets the script and value in satoshis for a given unspent transaction output given a
42
+ /// short_channel_id (aka unspent_tx_output_identier). For BTC/tBTC channels the top three
43
+ /// bytes are the block height, the next 3 the transaction index within the block, and the
44
+ /// final two the output within the transaction.
45
+ fn get_chain_utxo ( & self , genesis_hash : Sha256dHash , unspent_tx_output_identifier : u64 ) -> Result < ( Script , u64 ) , ChainError > ;
51
46
}
52
47
53
48
/// An interface to send a transaction to the Bitcoin network.
@@ -100,14 +95,6 @@ pub struct ChainWatchInterfaceUtil {
100
95
logger : Arc < Logger > ,
101
96
}
102
97
103
- macro_rules! watched_chain {
104
- ( $self: ident, $hash: expr) => {
105
- if $hash != genesis_block( $self. get_network( ) ) . header. bitcoin_hash( ) {
106
- return Err ( ChainError :: NotWatched ) ;
107
- }
108
- }
109
- }
110
-
111
98
/// Register listener
112
99
impl ChainWatchInterface for ChainWatchInterfaceUtil {
113
100
fn install_watch_script ( & self , script_pub_key : & Script ) {
@@ -133,23 +120,11 @@ impl ChainWatchInterface for ChainWatchInterfaceUtil {
133
120
vec. push ( listener) ;
134
121
}
135
122
136
- fn get_network ( & self ) -> Network {
137
- self . network
138
- }
139
-
140
-
141
- fn get_chain_txo ( & self , genesis_hash : Sha256dHash , _txid : Sha256dHash , _output_index : u16 ) -> Result < ( Script , u64 ) , ChainError > {
142
- watched_chain ! ( self , genesis_hash) ;
143
-
144
- //TODO: self.BlockchainStore.get_txo(txid, output_index)
145
- Err ( ChainError :: UnknownTx )
146
- }
147
-
148
- fn get_spendable_outpoint ( & self , genesis_hash : Sha256dHash , _txid : Sha256dHash , _output_index : u16 ) -> Result < bool , ChainError > {
149
- watched_chain ! ( self , genesis_hash) ;
150
-
151
- //TODO: self.BlockchainStore.is_utxo(txid, output_index)
152
- Err ( ChainError :: UnknownTx )
123
+ fn get_chain_utxo ( & self , genesis_hash : Sha256dHash , _unspent_tx_output_identifier : u64 ) -> Result < ( Script , u64 ) , ChainError > {
124
+ if genesis_hash != genesis_block ( self . network ) . header . bitcoin_hash ( ) {
125
+ return Err ( ChainError :: NotWatched ) ;
126
+ }
127
+ Err ( ChainError :: NotSupported )
153
128
}
154
129
}
155
130
0 commit comments