@@ -7,6 +7,7 @@ use bdk_core::{
7
7
BlockId , CheckPoint , ConfirmationBlockTime , TxUpdate ,
8
8
} ;
9
9
use electrum_client:: { ElectrumApi , Error , HeaderNotification } ;
10
+ use std:: convert:: TryInto ;
10
11
use std:: sync:: { Arc , Mutex } ;
11
12
12
13
/// We include a chain suffix of a certain length for the purpose of robustness.
@@ -37,8 +38,24 @@ impl<E: ElectrumApi> BdkElectrumClient<E> {
37
38
}
38
39
}
39
40
40
- /// Inserts transactions into the transaction cache so that the client will not fetch these
41
- /// transactions.
41
+ /// Insert anchors into the anchor cache so that the client will not re-fetch them.
42
+ ///
43
+ /// Typically used to pre-populate the cache from an existing `TxGraph`.
44
+ pub fn populate_anchor_cache (
45
+ & self ,
46
+ tx_anchors : impl IntoIterator < Item = ( Txid , impl IntoIterator < Item = ConfirmationBlockTime > ) > ,
47
+ ) {
48
+ let mut cache = self . anchor_cache . lock ( ) . unwrap ( ) ;
49
+ for ( txid, anchors) in tx_anchors {
50
+ for anchor in anchors {
51
+ cache. insert ( ( txid, anchor. block_id . hash ) , anchor) ;
52
+ }
53
+ }
54
+ }
55
+
56
+ /// Insert transactions into the transaction cache so that the client will not re-fetch them.
57
+ ///
58
+ /// Typically used to pre-populate the cache from an existing `TxGraph`.
42
59
pub fn populate_tx_cache ( & self , txs : impl IntoIterator < Item = impl Into < Arc < Transaction > > > ) {
43
60
let mut tx_cache = self . tx_cache . lock ( ) . unwrap ( ) ;
44
61
for tx in txs {
0 commit comments