feat(electrum)!: change signature of ElectrumExt

We remove `ElectrumUpdate` and return tuples instead for `ElectrumExt`
methods. We introduce the `IncompleteTxGraph` structure to specifically
hodl the incomplete `TxGraph`.

This change is motivated by @LLFourn's comment: 794bf37e63 (r1305432603)
This commit is contained in:
志宇
2023-08-26 20:29:46 +08:00
parent a28748c339
commit 32c40ac939
4 changed files with 93 additions and 103 deletions

View File

@@ -13,7 +13,7 @@ use bdk_chain::{
};
use bdk_electrum::{
electrum_client::{self, ElectrumApi},
ElectrumExt, ElectrumUpdate,
ElectrumExt,
};
use example_cli::{
anyhow::{self, Context},
@@ -251,20 +251,18 @@ fn main() -> anyhow::Result<()> {
// drop lock on graph and chain
drop((graph, chain));
let update = client
let (chain_update, graph_update) = client
.scan_without_keychain(tip, spks, txids, outpoints, scan_options.batch_size)
.context("scanning the blockchain")?;
ElectrumUpdate {
graph_update: update.graph_update,
new_tip: update.new_tip,
keychain_update: BTreeMap::new(),
}
(chain_update, graph_update, BTreeMap::new())
}
};
let (chain_update, incomplete_graph_update, keychain_update) = response;
let missing_txids = {
let graph = &*graph.lock().unwrap();
response.missing_full_txs(graph.graph())
incomplete_graph_update.missing_full_txs(graph.graph())
};
let now = std::time::UNIX_EPOCH
@@ -272,17 +270,13 @@ fn main() -> anyhow::Result<()> {
.expect("must get time")
.as_secs();
let (graph_update, keychain_update, update_tip) =
response.finalize(&client, Some(now), missing_txids)?;
let graph_update = incomplete_graph_update.finalize(&client, Some(now), missing_txids)?;
let db_changeset = {
let mut chain = chain.lock().unwrap();
let mut graph = graph.lock().unwrap();
let chain = chain.apply_update(local_chain::Update {
tip: update_tip,
introduce_older_blocks: true,
})?;
let chain = chain.apply_update(chain_update)?;
let indexed_tx_graph = {
let mut changeset =

View File

@@ -7,9 +7,9 @@ use std::io::Write;
use std::str::FromStr;
use bdk::bitcoin::Address;
use bdk::wallet::WalletUpdate;
use bdk::SignOptions;
use bdk::{bitcoin::Network, wallet::WalletUpdate, Wallet};
use bdk_electrum::bdk_chain::local_chain;
use bdk::{bitcoin::Network, Wallet};
use bdk_electrum::electrum_client::{self, ElectrumApi};
use bdk_electrum::ElectrumExt;
use bdk_file_store::Store;
@@ -53,21 +53,19 @@ fn main() -> Result<(), Box<dyn std::error::Error>> {
})
.collect();
let electrum_update = client.scan(prev_tip, keychain_spks, None, None, STOP_GAP, BATCH_SIZE)?;
let (chain_update, incomplete_graph_update, keychain_update) =
client.scan(prev_tip, keychain_spks, None, None, STOP_GAP, BATCH_SIZE)?;
println!();
let missing = electrum_update.missing_full_txs(wallet.as_ref());
let (graph_update, keychain_update, update_tip) =
electrum_update.finalize_as_confirmation_time(&client, None, missing)?;
let missing = incomplete_graph_update.missing_full_txs(wallet.as_ref());
let graph_update =
incomplete_graph_update.finalize_with_confirmation_time(&client, None, missing)?;
let wallet_update = WalletUpdate {
last_active_indices: keychain_update,
graph: graph_update,
chain: Some(local_chain::Update {
tip: update_tip,
introduce_older_blocks: true,
}),
chain: Some(chain_update),
};
wallet.apply_update(wallet_update)?;
wallet.commit()?;