@@ -4,17 +4,18 @@ use crate::logger::{
4
4
log_error, log_given_level, log_info, log_internal, log_trace, log_warn, FilesystemLogger ,
5
5
Logger ,
6
6
} ;
7
+ use crate :: { scid_utils, LdkLiteConfig } ;
7
8
8
9
use lightning:: chain:: chaininterface:: { BroadcasterInterface , ConfirmationTarget , FeeEstimator } ;
9
10
use lightning:: chain:: WatchedOutput ;
10
- use lightning:: chain:: { Confirm , Filter } ;
11
+ use lightning:: chain:: { Access , AccessError , Confirm , Filter } ;
11
12
12
13
use bdk:: blockchain:: { Blockchain , EsploraBlockchain , GetBlockHash , GetHeight , GetTx } ;
13
14
use bdk:: database:: BatchDatabase ;
14
15
use bdk:: wallet:: AddressIndex ;
15
16
use bdk:: { SignOptions , SyncOptions } ;
16
17
17
- use bitcoin:: { BlockHash , Script , Transaction , Txid } ;
18
+ use bitcoin:: { BlockHash , Script , Transaction , TxOut , Txid } ;
18
19
19
20
use std:: sync:: { Arc , Mutex } ;
20
21
29
30
queued_outputs : Mutex < Vec < WatchedOutput > > ,
30
31
watched_outputs : Mutex < Vec < WatchedOutput > > ,
31
32
last_sync_height : Mutex < Option < u32 > > ,
33
+ config : Arc < LdkLiteConfig > ,
32
34
logger : Arc < FilesystemLogger > ,
33
35
}
34
36
37
39
D : BatchDatabase ,
38
40
{
39
41
pub ( crate ) fn new (
40
- blockchain : EsploraBlockchain , wallet : bdk:: Wallet < D > , logger : Arc < FilesystemLogger > ,
42
+ blockchain : EsploraBlockchain , wallet : bdk:: Wallet < D > , config : Arc < LdkLiteConfig > ,
43
+ logger : Arc < FilesystemLogger > ,
41
44
) -> Self {
42
45
let wallet = Mutex :: new ( wallet) ;
43
46
let watched_transactions = Mutex :: new ( Vec :: new ( ) ) ;
53
56
queued_outputs,
54
57
watched_outputs,
55
58
last_sync_height,
59
+ config,
56
60
logger,
57
61
}
58
62
}
@@ -275,6 +279,44 @@ where
275
279
}
276
280
}
277
281
282
+ impl < D > Access for LdkLiteChainAccess < D >
283
+ where
284
+ D : BatchDatabase ,
285
+ {
286
+ fn get_utxo (
287
+ & self , genesis_hash : & BlockHash , short_channel_id : u64 ,
288
+ ) -> Result < TxOut , AccessError > {
289
+ if genesis_hash
290
+ != & bitcoin:: blockdata:: constants:: genesis_block ( self . config . network )
291
+ . header
292
+ . block_hash ( )
293
+ {
294
+ return Err ( AccessError :: UnknownChain ) ;
295
+ }
296
+
297
+ let block_height = scid_utils:: block_from_scid ( & short_channel_id) ;
298
+ let tx_index = scid_utils:: tx_index_from_scid ( & short_channel_id) ;
299
+ let vout = scid_utils:: vout_from_scid ( & short_channel_id) ;
300
+
301
+ let client = & * self . blockchain ;
302
+ let block_hash = self
303
+ . blockchain
304
+ . get_block_hash ( block_height. into ( ) )
305
+ . map_err ( |_| AccessError :: UnknownTx ) ?;
306
+ let txid = client
307
+ . get_txid_at_block_index ( & block_hash, tx_index as usize )
308
+ . map_err ( |_| AccessError :: UnknownTx ) ?
309
+ . ok_or ( AccessError :: UnknownTx ) ?;
310
+ let tx = client
311
+ . get_tx ( & txid)
312
+ . map_err ( |_| AccessError :: UnknownTx ) ?
313
+ . ok_or ( AccessError :: UnknownTx ) ?;
314
+ let tx_out = tx. output . get ( vout as usize ) . ok_or ( AccessError :: UnknownTx ) ?;
315
+
316
+ Ok ( tx_out. clone ( ) )
317
+ }
318
+ }
319
+
278
320
impl < D > Filter for LdkLiteChainAccess < D >
279
321
where
280
322
D : BatchDatabase ,
0 commit comments