@@ -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,61 @@ 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 > ) {
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 ( ) ;
2018
2032
2019
- let keychain_spks = self . spks_of_all_keychains ( ) ;
2020
2033
let local_chain = self . local_chain ( ) ;
2021
- let prev_tip = self . latest_checkpoint ( ) ;
2022
2034
2023
- ( keychain_spks, local_chain, prev_tip)
2035
+ ScanRequest {
2036
+ spks_by_keychain,
2037
+ checkpoint,
2038
+ }
2024
2039
}
2025
2040
2026
2041
/// Get data needed to start a wallet sync
2027
2042
///
2028
2043
/// Collect the wallet keychain script pub keys, local chain, previous chain tip, UTXOs, and
2029
2044
/// 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 ( ) ;
2045
+ pub fn start_sync ( & self , unused_spks_only : bool ) -> SyncRequest {
2046
+ let checkpoint = self . latest_checkpoint ( ) ;
2034
2047
2035
2048
// Sync only unused SPKs
2036
2049
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
- } ;
2050
+ self . spk_index ( )
2051
+ . unused_spks ( ..)
2052
+ . map ( |( ( _keychain, _index) , script) | ScriptBuf :: from ( script) )
2053
+ . collect :: < Vec < ScriptBuf > > ( )
2054
+ }
2055
+ // Sync all SPKs
2056
+ else {
2057
+ self . spk_index ( )
2058
+ . all_spks ( )
2059
+ . into_iter ( )
2060
+ . map ( |( ( _keychain, _index) , script) | ( * script) . clone ( ) )
2061
+ . collect :: < Vec < ScriptBuf > > ( )
2062
+ } ;
2050
2063
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 ( ) ;
2064
+ // Sync UTXOs
2065
+ // We want to search for whether our UTXOs are spent, and spent by which transaction.
2066
+ let outpoints: Vec < OutPoint > = self . list_unspent ( ) . map ( |utxo| utxo. outpoint ) . collect ( ) ;
2054
2067
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 ( ) ;
2068
+ // Sync unconfirmed TX
2069
+ // We want to search for whether our unconfirmed transactions are now confirmed.
2070
+ let txids: Vec < Txid > = self
2071
+ . transactions ( )
2072
+ . filter ( |canonical_tx| !canonical_tx. chain_position . is_confirmed ( ) )
2073
+ . map ( |canonical_tx| canonical_tx. tx_node . txid )
2074
+ . collect ( ) ;
2062
2075
2063
- ( spks, local_chain, prev_tip, outpoints, txids)
2076
+ SyncRequest {
2077
+ spks,
2078
+ txids,
2079
+ outpoints,
2080
+ checkpoint,
2081
+ }
2064
2082
}
2065
2083
}
2066
2084
0 commit comments