@@ -44,7 +44,7 @@ fn main() -> Result<(), anyhow::Error> {
44
44
let balance = wallet. balance ( ) ;
45
45
println ! ( "Wallet balance before syncing: {}" , balance. total( ) ) ;
46
46
47
- print ! ( "Syncing... " ) ;
47
+ println ! ( "=== Performing Full Sync === " ) ;
48
48
let client = BdkElectrumClient :: new ( electrum_client:: Client :: new ( ELECTRUM_URL ) ?) ;
49
49
50
50
// Populate the electrum client's transaction cache so it doesn't redownload transaction we
@@ -71,7 +71,12 @@ fn main() -> Result<(), anyhow::Error> {
71
71
wallet. persist ( & mut db) ?;
72
72
73
73
let balance = wallet. balance ( ) ;
74
- println ! ( "Wallet balance after syncing: {}" , balance. total( ) ) ;
74
+ println ! ( "Wallet balance after full sync: {}" , balance. total( ) ) ;
75
+ println ! (
76
+ "Wallet has {} transactions and {} utxos after full sync" ,
77
+ wallet. transactions( ) . count( ) ,
78
+ wallet. list_unspent( ) . count( )
79
+ ) ;
75
80
76
81
if balance. total ( ) < SEND_AMOUNT {
77
82
println ! (
@@ -92,5 +97,29 @@ fn main() -> Result<(), anyhow::Error> {
92
97
client. transaction_broadcast ( & tx) ?;
93
98
println ! ( "Tx broadcasted! Txid: {}" , tx. compute_txid( ) ) ;
94
99
100
+ println ! ( "=== Performing Partial Sync ===" ) ;
101
+ std:: io:: stdout ( ) . flush ( ) . expect ( "must flush" ) ;
102
+ let sync_request =
103
+ wallet
104
+ . start_sync_with_revealed_spks ( )
105
+ . inspect ( |sync_item, sync_progress| {
106
+ let progress_percent =
107
+ ( 100 * sync_progress. consumed ( ) ) as f32 / sync_progress. total ( ) as f32 ;
108
+ eprintln ! ( "[ SCANNING {:03.0}%] {}" , progress_percent, sync_item)
109
+ } ) ;
110
+
111
+ client. populate_tx_cache ( wallet. tx_graph ( ) . full_txs ( ) . map ( |tx_node| tx_node. tx ) ) ;
112
+
113
+ let sync_update = client. sync ( sync_request, BATCH_SIZE , false ) ?;
114
+ wallet. apply_update ( sync_update) ?;
115
+
116
+ let balance_after_sync = wallet. balance ( ) ;
117
+ println ! ( "Wallet balance after sync: {}" , balance_after_sync. total( ) ) ;
118
+ println ! (
119
+ "Wallet has {} transactions and {} utxos after partial sync" ,
120
+ wallet. transactions( ) . count( ) ,
121
+ wallet. list_unspent( ) . count( )
122
+ ) ;
123
+
95
124
Ok ( ( ) )
96
125
}
0 commit comments