Merge bitcoindevkit/bdk#1453: refactor(electrum) put the tx cache in electrum
2d2656acfafeat(electrum): re-export `transaction_broadcast` method (志宇)53fa35096frefactor(electrum)!: put the tx cache in electrum (LLFourn) Pull request description: Previously there was a `TxCache` that you passed in as part of the sync request. There are lots of downsides to this: 1. If the user forgets to do this you cache nothing 2. where are you meant to keep this cache? The example shows it being recreated every time which seems very suboptimal. 3. More API and documentation surface area. Instead just do a plain old simple cache inside the electrum client. This way at least you only download transactions once. You can pre-populate the cache with a method also and I did this in the examples. * [x] This pull request breaks the existing API ACKs for top commit: evanlinjin: self-ACK2d2656acfanotmandatory: ACK2d2656acfaTree-SHA512: 6c29fd4f99ea5bd66234d5cdaf4b157a192ddd3baacc91076e402d8df0de7010bc482e24895e85fcb2f805ec6d1ce6cdb7654f8f552c90ba75ed35f80a00b856
This commit is contained in:
@@ -14,7 +14,7 @@ use bdk_chain::{
|
||||
};
|
||||
use bdk_electrum::{
|
||||
electrum_client::{self, Client, ElectrumApi},
|
||||
ElectrumExt,
|
||||
BdkElectrumClient,
|
||||
};
|
||||
use example_cli::{
|
||||
anyhow::{self, Context},
|
||||
@@ -146,7 +146,10 @@ fn main() -> anyhow::Result<()> {
|
||||
}
|
||||
};
|
||||
|
||||
let client = electrum_cmd.electrum_args().client(args.network)?;
|
||||
let client = BdkElectrumClient::new(electrum_cmd.electrum_args().client(args.network)?);
|
||||
|
||||
// Tell the electrum client about the txs we've already got locally so it doesn't re-download them
|
||||
client.populate_tx_cache(&*graph.lock().unwrap());
|
||||
|
||||
let (chain_update, mut graph_update, keychain_update) = match electrum_cmd.clone() {
|
||||
ElectrumCommands::Scan {
|
||||
@@ -159,7 +162,6 @@ fn main() -> anyhow::Result<()> {
|
||||
let chain = &*chain.lock().unwrap();
|
||||
|
||||
FullScanRequest::from_chain_tip(chain.tip())
|
||||
.cache_graph_txs(graph.graph())
|
||||
.set_spks_for_keychain(
|
||||
Keychain::External,
|
||||
graph
|
||||
@@ -220,8 +222,7 @@ fn main() -> anyhow::Result<()> {
|
||||
}
|
||||
|
||||
let chain_tip = chain.tip();
|
||||
let mut request =
|
||||
SyncRequest::from_chain_tip(chain_tip.clone()).cache_graph_txs(graph.graph());
|
||||
let mut request = SyncRequest::from_chain_tip(chain_tip.clone());
|
||||
|
||||
if all_spks {
|
||||
let all_spks = graph
|
||||
|
||||
@@ -6,10 +6,8 @@ const BATCH_SIZE: usize = 5;
|
||||
use std::io::Write;
|
||||
use std::str::FromStr;
|
||||
|
||||
use bdk_electrum::{
|
||||
electrum_client::{self, ElectrumApi},
|
||||
ElectrumExt,
|
||||
};
|
||||
use bdk_electrum::electrum_client;
|
||||
use bdk_electrum::BdkElectrumClient;
|
||||
use bdk_file_store::Store;
|
||||
use bdk_wallet::bitcoin::{Address, Amount};
|
||||
use bdk_wallet::chain::collections::HashSet;
|
||||
@@ -37,7 +35,13 @@ fn main() -> Result<(), anyhow::Error> {
|
||||
println!("Wallet balance before syncing: {} sats", balance.total());
|
||||
|
||||
print!("Syncing...");
|
||||
let client = electrum_client::Client::new("ssl://electrum.blockstream.info:60002")?;
|
||||
let client = BdkElectrumClient::new(electrum_client::Client::new(
|
||||
"ssl://electrum.blockstream.info:60002",
|
||||
)?);
|
||||
|
||||
// Populate the electrum client's transaction cache so it doesn't redownload transaction we
|
||||
// already have.
|
||||
client.populate_tx_cache(&wallet);
|
||||
|
||||
let request = wallet
|
||||
.start_full_scan()
|
||||
|
||||
Reference in New Issue
Block a user