|
| 1 | +#![allow(unused)] |
1 | 2 | use bdk_bitcoind_rpc::{
|
2 | 3 | bitcoincore_rpc::{Auth, Client, RpcApi},
|
3 | 4 | Emitter, MempoolEvent,
|
@@ -84,125 +85,125 @@ enum Emission {
|
84 | 85 | }
|
85 | 86 |
|
86 | 87 | fn main() -> anyhow::Result<()> {
|
87 |
| - let args = Args::parse(); |
| 88 | + // let args = Args::parse(); |
88 | 89 |
|
89 |
| - let rpc_client = Arc::new(args.client()?); |
90 |
| - println!( |
91 |
| - "Connected to Bitcoin Core RPC at {:?}", |
92 |
| - rpc_client.get_blockchain_info().unwrap() |
93 |
| - ); |
| 90 | + // let rpc_client = Arc::new(args.client()?); |
| 91 | + // println!( |
| 92 | + // "Connected to Bitcoin Core RPC at {:?}", |
| 93 | + // rpc_client.get_blockchain_info().unwrap() |
| 94 | + // ); |
94 | 95 |
|
95 |
| - let start_load_wallet = Instant::now(); |
96 |
| - let mut db = Connection::open(args.db_path)?; |
97 |
| - let wallet_opt = Wallet::load() |
98 |
| - .descriptor(KeychainKind::External, Some(args.descriptor.clone())) |
99 |
| - .descriptor(KeychainKind::Internal, args.change_descriptor.clone()) |
100 |
| - .extract_keys() |
101 |
| - .check_network(args.network) |
102 |
| - .load_wallet(&mut db)?; |
103 |
| - let mut wallet = match wallet_opt { |
104 |
| - Some(wallet) => wallet, |
105 |
| - None => match &args.change_descriptor { |
106 |
| - Some(change_desc) => Wallet::create(args.descriptor.clone(), change_desc.clone()) |
107 |
| - .network(args.network) |
108 |
| - .create_wallet(&mut db)?, |
109 |
| - None => Wallet::create_single(args.descriptor.clone()) |
110 |
| - .network(args.network) |
111 |
| - .create_wallet(&mut db)?, |
112 |
| - }, |
113 |
| - }; |
114 |
| - println!( |
115 |
| - "Loaded wallet in {}s", |
116 |
| - start_load_wallet.elapsed().as_secs_f32() |
117 |
| - ); |
| 96 | + // let start_load_wallet = Instant::now(); |
| 97 | + // let mut db = Connection::open(args.db_path)?; |
| 98 | + // let wallet_opt = Wallet::load() |
| 99 | + // .descriptor(KeychainKind::External, Some(args.descriptor.clone())) |
| 100 | + // .descriptor(KeychainKind::Internal, args.change_descriptor.clone()) |
| 101 | + // .extract_keys() |
| 102 | + // .check_network(args.network) |
| 103 | + // .load_wallet(&mut db)?; |
| 104 | + // let mut wallet = match wallet_opt { |
| 105 | + // Some(wallet) => wallet, |
| 106 | + // None => match &args.change_descriptor { |
| 107 | + // Some(change_desc) => Wallet::create(args.descriptor.clone(), change_desc.clone()) |
| 108 | + // .network(args.network) |
| 109 | + // .create_wallet(&mut db)?, |
| 110 | + // None => Wallet::create_single(args.descriptor.clone()) |
| 111 | + // .network(args.network) |
| 112 | + // .create_wallet(&mut db)?, |
| 113 | + // }, |
| 114 | + // }; |
| 115 | + // println!( |
| 116 | + // "Loaded wallet in {}s", |
| 117 | + // start_load_wallet.elapsed().as_secs_f32() |
| 118 | + // ); |
118 | 119 |
|
119 |
| - let address = wallet.reveal_next_address(KeychainKind::External).address; |
120 |
| - println!("Wallet address: {address}"); |
| 120 | + // let address = wallet.reveal_next_address(KeychainKind::External).address; |
| 121 | + // println!("Wallet address: {address}"); |
121 | 122 |
|
122 |
| - let balance = wallet.balance(); |
123 |
| - println!("Wallet balance before syncing: {}", balance.total()); |
| 123 | + // let balance = wallet.balance(); |
| 124 | + // println!("Wallet balance before syncing: {}", balance.total()); |
124 | 125 |
|
125 |
| - let wallet_tip = wallet.latest_checkpoint(); |
126 |
| - println!( |
127 |
| - "Wallet tip: {} at height {}", |
128 |
| - wallet_tip.hash(), |
129 |
| - wallet_tip.height() |
130 |
| - ); |
| 126 | + // let wallet_tip = wallet.latest_checkpoint(); |
| 127 | + // println!( |
| 128 | + // "Wallet tip: {} at height {}", |
| 129 | + // wallet_tip.hash(), |
| 130 | + // wallet_tip.height() |
| 131 | + // ); |
131 | 132 |
|
132 |
| - let (sender, receiver) = sync_channel::<Emission>(21); |
| 133 | + // let (sender, receiver) = sync_channel::<Emission>(21); |
133 | 134 |
|
134 |
| - let signal_sender = sender.clone(); |
135 |
| - let _ = ctrlc::set_handler(move || { |
136 |
| - signal_sender |
137 |
| - .send(Emission::SigTerm) |
138 |
| - .expect("failed to send sigterm") |
139 |
| - }); |
| 135 | + // let signal_sender = sender.clone(); |
| 136 | + // let _ = ctrlc::set_handler(move || { |
| 137 | + // signal_sender |
| 138 | + // .send(Emission::SigTerm) |
| 139 | + // .expect("failed to send sigterm") |
| 140 | + // }); |
140 | 141 |
|
141 |
| - let mut emitter = Emitter::new( |
142 |
| - rpc_client, |
143 |
| - wallet_tip, |
144 |
| - args.start_height, |
145 |
| - wallet |
146 |
| - .transactions() |
147 |
| - .filter(|tx| tx.chain_position.is_unconfirmed()), |
148 |
| - ); |
149 |
| - spawn(move || -> Result<(), anyhow::Error> { |
150 |
| - while let Some(emission) = emitter.next_block()? { |
151 |
| - sender.send(Emission::Block(emission))?; |
152 |
| - } |
153 |
| - sender.send(Emission::Mempool(emitter.mempool()?))?; |
154 |
| - Ok(()) |
155 |
| - }); |
| 142 | + // let mut emitter = Emitter::new( |
| 143 | + // rpc_client, |
| 144 | + // wallet_tip, |
| 145 | + // args.start_height, |
| 146 | + // wallet |
| 147 | + // .transactions() |
| 148 | + // .filter(|tx| tx.chain_position.is_unconfirmed()), |
| 149 | + // ); |
| 150 | + // spawn(move || -> Result<(), anyhow::Error> { |
| 151 | + // while let Some(emission) = emitter.next_block()? { |
| 152 | + // sender.send(Emission::Block(emission))?; |
| 153 | + // } |
| 154 | + // sender.send(Emission::Mempool(emitter.mempool()?))?; |
| 155 | + // Ok(()) |
| 156 | + // }); |
156 | 157 |
|
157 |
| - let mut blocks_received = 0_usize; |
158 |
| - for emission in receiver { |
159 |
| - match emission { |
160 |
| - Emission::SigTerm => { |
161 |
| - println!("Sigterm received, exiting..."); |
162 |
| - break; |
163 |
| - } |
164 |
| - Emission::Block(block_emission) => { |
165 |
| - blocks_received += 1; |
166 |
| - let height = block_emission.block_height(); |
167 |
| - let hash = block_emission.block_hash(); |
168 |
| - let connected_to = block_emission.connected_to(); |
169 |
| - let start_apply_block = Instant::now(); |
170 |
| - wallet.apply_block_connected_to(&block_emission.block, height, connected_to)?; |
171 |
| - wallet.persist(&mut db)?; |
172 |
| - let elapsed = start_apply_block.elapsed().as_secs_f32(); |
173 |
| - println!("Applied block {hash} at height {height} in {elapsed}s"); |
174 |
| - } |
175 |
| - Emission::Mempool(event) => { |
176 |
| - let start_apply_mempool = Instant::now(); |
177 |
| - wallet.apply_evicted_txs(event.evicted); |
178 |
| - wallet.apply_unconfirmed_txs(event.update); |
179 |
| - wallet.persist(&mut db)?; |
180 |
| - println!( |
181 |
| - "Applied unconfirmed transactions in {}s", |
182 |
| - start_apply_mempool.elapsed().as_secs_f32() |
183 |
| - ); |
184 |
| - break; |
185 |
| - } |
186 |
| - } |
187 |
| - } |
188 |
| - let wallet_tip_end = wallet.latest_checkpoint(); |
189 |
| - let balance = wallet.balance(); |
190 |
| - println!( |
191 |
| - "Synced {} blocks in {}s", |
192 |
| - blocks_received, |
193 |
| - start_load_wallet.elapsed().as_secs_f32(), |
194 |
| - ); |
195 |
| - println!( |
196 |
| - "Wallet tip is '{}:{}'", |
197 |
| - wallet_tip_end.height(), |
198 |
| - wallet_tip_end.hash() |
199 |
| - ); |
200 |
| - println!("Wallet balance is {}", balance.total()); |
201 |
| - println!( |
202 |
| - "Wallet has {} transactions and {} utxos", |
203 |
| - wallet.transactions().count(), |
204 |
| - wallet.list_unspent().count() |
205 |
| - ); |
| 158 | + // let mut blocks_received = 0_usize; |
| 159 | + // for emission in receiver { |
| 160 | + // match emission { |
| 161 | + // Emission::SigTerm => { |
| 162 | + // println!("Sigterm received, exiting..."); |
| 163 | + // break; |
| 164 | + // } |
| 165 | + // Emission::Block(block_emission) => { |
| 166 | + // blocks_received += 1; |
| 167 | + // let height = block_emission.block_height(); |
| 168 | + // let hash = block_emission.block_hash(); |
| 169 | + // let connected_to = block_emission.connected_to(); |
| 170 | + // let start_apply_block = Instant::now(); |
| 171 | + // wallet.apply_block_connected_to(&block_emission.block, height, connected_to)?; |
| 172 | + // wallet.persist(&mut db)?; |
| 173 | + // let elapsed = start_apply_block.elapsed().as_secs_f32(); |
| 174 | + // println!("Applied block {hash} at height {height} in {elapsed}s"); |
| 175 | + // } |
| 176 | + // Emission::Mempool(event) => { |
| 177 | + // let start_apply_mempool = Instant::now(); |
| 178 | + // wallet.apply_evicted_txs(event.evicted); |
| 179 | + // wallet.apply_unconfirmed_txs(event.update); |
| 180 | + // wallet.persist(&mut db)?; |
| 181 | + // println!( |
| 182 | + // "Applied unconfirmed transactions in {}s", |
| 183 | + // start_apply_mempool.elapsed().as_secs_f32() |
| 184 | + // ); |
| 185 | + // break; |
| 186 | + // } |
| 187 | + // } |
| 188 | + // } |
| 189 | + // let wallet_tip_end = wallet.latest_checkpoint(); |
| 190 | + // let balance = wallet.balance(); |
| 191 | + // println!( |
| 192 | + // "Synced {} blocks in {}s", |
| 193 | + // blocks_received, |
| 194 | + // start_load_wallet.elapsed().as_secs_f32(), |
| 195 | + // ); |
| 196 | + // println!( |
| 197 | + // "Wallet tip is '{}:{}'", |
| 198 | + // wallet_tip_end.height(), |
| 199 | + // wallet_tip_end.hash() |
| 200 | + // ); |
| 201 | + // println!("Wallet balance is {}", balance.total()); |
| 202 | + // println!( |
| 203 | + // "Wallet has {} transactions and {} utxos", |
| 204 | + // wallet.transactions().count(), |
| 205 | + // wallet.list_unspent().count() |
| 206 | + // ); |
206 | 207 |
|
207 | 208 | Ok(())
|
208 | 209 | }
|
0 commit comments