@@ -40,6 +40,7 @@ use core::fmt;
40
40
use core:: ops:: Deref ;
41
41
use miniscript:: psbt:: { PsbtExt , PsbtInputExt , PsbtInputSatisfier } ;
42
42
43
+ use bdk_chain:: request:: { ScanRequest , SyncRequest } ;
43
44
use bdk_chain:: tx_graph:: CalculateFeeError ;
44
45
#[ allow( unused_imports) ]
45
46
use log:: { debug, error, info, trace} ;
@@ -113,9 +114,20 @@ pub struct Update {
113
114
pub chain : Option < local_chain:: Update > ,
114
115
}
115
116
116
- impl From < ( BTreeMap < KeychainKind , u32 > , TxGraph < ConfirmationTimeAnchor > , local_chain:: Update ) > for Update
117
+ impl
118
+ From < (
119
+ BTreeMap < KeychainKind , u32 > ,
120
+ TxGraph < ConfirmationTimeAnchor > ,
121
+ local_chain:: Update ,
122
+ ) > for Update
117
123
{
118
- fn from ( ( last_active_indices, graph, chain) : ( BTreeMap < KeychainKind , u32 > , TxGraph < ConfirmationTimeAnchor > , local_chain:: Update ) ) -> Self {
124
+ fn from (
125
+ ( last_active_indices, graph, chain) : (
126
+ BTreeMap < KeychainKind , u32 > ,
127
+ TxGraph < ConfirmationTimeAnchor > ,
128
+ local_chain:: Update ,
129
+ ) ,
130
+ ) -> Self {
119
131
Self {
120
132
last_active_indices,
121
133
graph,
@@ -124,8 +136,7 @@ impl From<(BTreeMap<KeychainKind, u32>, TxGraph<ConfirmationTimeAnchor>, local_c
124
136
}
125
137
}
126
138
127
- impl From < ( TxGraph < ConfirmationTimeAnchor > , local_chain:: Update ) > for Update
128
- {
139
+ impl From < ( TxGraph < ConfirmationTimeAnchor > , local_chain:: Update ) > for Update {
129
140
fn from ( ( graph, chain) : ( TxGraph < ConfirmationTimeAnchor > , local_chain:: Update ) ) -> Self {
130
141
Self {
131
142
graph,
@@ -2013,54 +2024,59 @@ impl<D> Wallet<D> {
2013
2024
///
2014
2025
/// Collect the wallet keychain script pub keys, local chain, and previous chain tip data needed
2015
2026
/// to start a blockchain scan.
2016
- pub fn start_scan ( & self ) -> ( BTreeMap < KeychainKind , impl Iterator < Item = ( u32 , ScriptBuf ) > + Clone > ,
2017
- & LocalChain , Option < CheckPoint > ) {
2018
-
2019
- let keychain_spks = self . spks_of_all_keychains ( ) ;
2020
- let local_chain = self . local_chain ( ) ;
2021
- let prev_tip = self . latest_checkpoint ( ) ;
2027
+ pub fn start_scan (
2028
+ & self ,
2029
+ ) -> ScanRequest < KeychainKind , impl Iterator < Item = ( u32 , ScriptBuf ) > + Clone > {
2030
+ let spks_by_keychain = self . spks_of_all_keychains ( ) ;
2031
+ let checkpoint = self . latest_checkpoint ( ) ;
2022
2032
2023
- ( keychain_spks, local_chain, prev_tip)
2033
+ ScanRequest {
2034
+ spks_by_keychain,
2035
+ checkpoint,
2036
+ }
2024
2037
}
2025
2038
2026
2039
/// Get data needed to start a wallet sync
2027
2040
///
2028
2041
/// Collect the wallet keychain script pub keys, local chain, previous chain tip, UTXOs, and
2029
2042
/// unconfirmed transaction id data needed to start a blockchain sync.
2030
- pub fn start_sync ( & self , unused_spks_only : bool ) -> ( Vec < ScriptBuf > , & LocalChain , Option < CheckPoint > , Vec < OutPoint > , Vec < Txid > ) {
2031
-
2032
- let local_chain = self . local_chain ( ) ;
2033
- let prev_tip = self . latest_checkpoint ( ) ;
2043
+ pub fn start_sync ( & self , unused_spks_only : bool ) -> SyncRequest {
2044
+ let checkpoint = self . latest_checkpoint ( ) ;
2034
2045
2035
2046
// Sync only unused SPKs
2036
2047
let spks = if unused_spks_only {
2037
- self . spk_index ( )
2038
- . unused_spks ( ..)
2039
- . map ( |( ( _keychain, _index) , script) | ScriptBuf :: from ( script) )
2040
- . collect :: < Vec < ScriptBuf > > ( )
2041
- }
2042
- // Sync all SPKs
2043
- else {
2044
- self . spk_index ( )
2045
- . all_spks ( )
2046
- . into_iter ( )
2047
- . map ( |( ( _keychain, _index) , script) | ( * script) . clone ( ) )
2048
- . collect :: < Vec < ScriptBuf > > ( )
2049
- } ;
2048
+ self . spk_index ( )
2049
+ . unused_spks ( ..)
2050
+ . map ( |( ( _keychain, _index) , script) | ScriptBuf :: from ( script) )
2051
+ . collect :: < Vec < ScriptBuf > > ( )
2052
+ }
2053
+ // Sync all SPKs
2054
+ else {
2055
+ self . spk_index ( )
2056
+ . all_spks ( )
2057
+ . into_iter ( )
2058
+ . map ( |( ( _keychain, _index) , script) | ( * script) . clone ( ) )
2059
+ . collect :: < Vec < ScriptBuf > > ( )
2060
+ } ;
2050
2061
2051
- // Sync UTXOs
2052
- // We want to search for whether our UTXOs are spent, and spent by which transaction.
2053
- let outpoints: Vec < OutPoint > = self . list_unspent ( ) . map ( |utxo| utxo. outpoint ) . collect ( ) ;
2062
+ // Sync UTXOs
2063
+ // We want to search for whether our UTXOs are spent, and spent by which transaction.
2064
+ let outpoints: Vec < OutPoint > = self . list_unspent ( ) . map ( |utxo| utxo. outpoint ) . collect ( ) ;
2054
2065
2055
- // Sync unconfirmed TX
2056
- // We want to search for whether our unconfirmed transactions are now confirmed.
2057
- let txids: Vec < Txid > = self
2058
- . transactions ( )
2059
- . filter ( |canonical_tx| !canonical_tx. chain_position . is_confirmed ( ) )
2060
- . map ( |canonical_tx| canonical_tx. tx_node . txid )
2061
- . collect ( ) ;
2066
+ // Sync unconfirmed TX
2067
+ // We want to search for whether our unconfirmed transactions are now confirmed.
2068
+ let txids: Vec < Txid > = self
2069
+ . transactions ( )
2070
+ . filter ( |canonical_tx| !canonical_tx. chain_position . is_confirmed ( ) )
2071
+ . map ( |canonical_tx| canonical_tx. tx_node . txid )
2072
+ . collect ( ) ;
2062
2073
2063
- ( spks, local_chain, prev_tip, outpoints, txids)
2074
+ SyncRequest {
2075
+ spks,
2076
+ txids,
2077
+ outpoints,
2078
+ checkpoint,
2079
+ }
2064
2080
}
2065
2081
}
2066
2082
0 commit comments