Merge bitcoindevkit/bdk#1084: Enhance bdk chain structures
1ff806c67ffix(chain)!: rm weird `From` impl (志宇)d43ae0231frefactor: improve docs, cleanup unnecessary types and improve code (Vladimir Fomene)4104206980feat: impl Append for lots of tuples (LLFourn)c56728ff13refactor: Remove `scan` and `scan_txout` from SpkTxoutIndex and KeychainTxoutIndex (Vladimir Fomene)32c40ac939feat(electrum)!: change signature of `ElectrumExt` (志宇)a28748c339refactor: Implement Default for WalletUpdate (Vladimir Fomene)f42f8b8ff1refactor: Allow for no chain update (Vladimir Fomene)68572bfd2erefactor: move WalletChangeset to wallet module (Vladimir Fomene)2392e50fd9refactor: Move WalletUpdate to wallet module (Vladimir Fomene)7c12dc9942refactor: Remove ForEachTxout trait (Vladimir Fomene)6bcbb93233refactor: Edit ElectrumExt not to use WalletUpdate (Vladimir Fomene) Pull request description: ### Description Fixes #1061 ### Changelog notice - Move WalletUpdate to the wallet module - Remove ForEachTxout trait completely - Refactor ElectrumExt to not use WalletUpdate. ### Checklists #### All Submissions: * [x] I've signed all my commits * [x] I followed the [contribution guidelines](https://github.com/bitcoindevkit/bdk/blob/master/CONTRIBUTING.md) * [x] I ran `cargo fmt` and `cargo clippy` before committing ACKs for top commit: evanlinjin: ACK1ff806c67fTree-SHA512: 05349713af9d2efa14a522ceaabb7513bb437d786adf2f93055765589a67e4eb68bda36ff415aeba07816c4d30988d4d55bac018e7697019270a219105ed65a2
This commit is contained in:
@@ -6,9 +6,9 @@ use std::{
|
||||
|
||||
use bdk_chain::{
|
||||
bitcoin::{Address, Network, OutPoint, ScriptBuf, Txid},
|
||||
indexed_tx_graph::IndexedTxGraph,
|
||||
keychain::WalletChangeSet,
|
||||
local_chain::{CheckPoint, LocalChain},
|
||||
indexed_tx_graph::{self, IndexedTxGraph},
|
||||
keychain,
|
||||
local_chain::{self, CheckPoint, LocalChain},
|
||||
Append, ConfirmationTimeAnchor,
|
||||
};
|
||||
|
||||
@@ -23,6 +23,11 @@ use example_cli::{
|
||||
const DB_MAGIC: &[u8] = b"bdk_example_esplora";
|
||||
const DB_PATH: &str = ".bdk_esplora_example.db";
|
||||
|
||||
type ChangeSet = (
|
||||
local_chain::ChangeSet,
|
||||
indexed_tx_graph::ChangeSet<ConfirmationTimeAnchor, keychain::ChangeSet<Keychain>>,
|
||||
);
|
||||
|
||||
#[derive(Subcommand, Debug, Clone)]
|
||||
enum EsploraCommands {
|
||||
/// Scans the addresses in the wallet using the esplora API.
|
||||
@@ -60,22 +65,22 @@ pub struct ScanOptions {
|
||||
}
|
||||
|
||||
fn main() -> anyhow::Result<()> {
|
||||
let (args, keymap, index, db, init_changeset) = example_cli::init::<
|
||||
EsploraCommands,
|
||||
WalletChangeSet<Keychain, ConfirmationTimeAnchor>,
|
||||
>(DB_MAGIC, DB_PATH)?;
|
||||
let (args, keymap, index, db, init_changeset) =
|
||||
example_cli::init::<EsploraCommands, ChangeSet>(DB_MAGIC, DB_PATH)?;
|
||||
|
||||
let (init_chain_changeset, init_indexed_tx_graph_changeset) = init_changeset;
|
||||
|
||||
// Contruct `IndexedTxGraph` and `LocalChain` with our initial changeset. They are wrapped in
|
||||
// `Mutex` to display how they can be used in a multithreaded context. Technically the mutexes
|
||||
// aren't strictly needed here.
|
||||
let graph = Mutex::new({
|
||||
let mut graph = IndexedTxGraph::new(index);
|
||||
graph.apply_changeset(init_changeset.indexed_tx_graph);
|
||||
graph.apply_changeset(init_indexed_tx_graph_changeset);
|
||||
graph
|
||||
});
|
||||
let chain = Mutex::new({
|
||||
let mut chain = LocalChain::default();
|
||||
chain.apply_changeset(&init_changeset.chain);
|
||||
chain.apply_changeset(&init_chain_changeset);
|
||||
chain
|
||||
});
|
||||
|
||||
@@ -303,18 +308,17 @@ fn main() -> anyhow::Result<()> {
|
||||
println!("missing block heights: {:?}", missing_block_heights);
|
||||
|
||||
// Here, we actually fetch the missing blocks and create a `local_chain::Update`.
|
||||
let chain_update = client
|
||||
.update_local_chain(tip, missing_block_heights)
|
||||
.context("scanning for blocks")?;
|
||||
|
||||
println!("new tip: {}", chain_update.tip.height());
|
||||
let chain_changeset = {
|
||||
let chain_update = client
|
||||
.update_local_chain(tip, missing_block_heights)
|
||||
.context("scanning for blocks")?;
|
||||
println!("new tip: {}", chain_update.tip.height());
|
||||
chain.lock().unwrap().apply_update(chain_update)?
|
||||
};
|
||||
|
||||
// We persist the changes
|
||||
let mut db = db.lock().unwrap();
|
||||
db.stage(WalletChangeSet {
|
||||
chain: chain.lock().unwrap().apply_update(chain_update)?,
|
||||
indexed_tx_graph: indexed_tx_graph_changeset,
|
||||
});
|
||||
db.stage((chain_changeset, indexed_tx_graph_changeset));
|
||||
db.commit()?;
|
||||
Ok(())
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user