From: 志宇 Date: Thu, 28 Dec 2023 04:49:04 +0000 (+0800) Subject: fix(example): bitcoind_rpc_polling now initializes local_chain properly X-Git-Tag: v1.0.0-alpha.3~5^2~2 X-Git-Url: http://internal-gitweb-vhost/script/%22https:/enum.FileStoreError.html?a=commitdiff_plain;h=bc796f412acdc3d2cd96f7aec0f24fa47c1fe889;p=bdk fix(example): bitcoind_rpc_polling now initializes local_chain properly Previously, the genesis block is not initialized properly. Thank you @notmandatory for identifying this bug. --- diff --git a/example-crates/example_bitcoind_rpc_polling/src/main.rs b/example-crates/example_bitcoind_rpc_polling/src/main.rs index 93ef53f2..449242e4 100644 --- a/example-crates/example_bitcoind_rpc_polling/src/main.rs +++ b/example-crates/example_bitcoind_rpc_polling/src/main.rs @@ -12,7 +12,7 @@ use bdk_bitcoind_rpc::{ Emitter, }; use bdk_chain::{ - bitcoin::{Block, Transaction}, + bitcoin::{constants::genesis_block, Block, Transaction}, indexed_tx_graph, keychain, local_chain::{self, CheckPoint, LocalChain}, ConfirmationTimeHeightAnchor, IndexedTxGraph, @@ -117,10 +117,11 @@ fn main() -> anyhow::Result<()> { "[{:>10}s] loaded initial changeset from db", start.elapsed().as_secs_f32() ); + let (init_chain_changeset, init_graph_changeset) = init_changeset; let graph = Mutex::new({ let mut graph = IndexedTxGraph::new(index); - graph.apply_changeset(init_changeset.1); + graph.apply_changeset(init_graph_changeset); graph }); println!( @@ -128,7 +129,16 @@ fn main() -> anyhow::Result<()> { start.elapsed().as_secs_f32() ); - let chain = Mutex::new(LocalChain::from_changeset(init_changeset.0)?); + let chain = Mutex::new(if init_chain_changeset.is_empty() { + let genesis_hash = genesis_block(args.network).block_hash(); + let (chain, chain_changeset) = LocalChain::from_genesis_hash(genesis_hash); + let mut db = db.lock().unwrap(); + db.stage((chain_changeset, Default::default())); + db.commit()?; + chain + } else { + LocalChain::from_changeset(init_chain_changeset)? + }); println!( "[{:>10}s] loaded local chain from changeset", start.elapsed().as_secs_f32()