Skip to content

Commit

Permalink
fix(example): bitcoind_rpc_polling now initializes local_chain properly
Browse files Browse the repository at this point in the history
Previously, the genesis block is not initialized properly. Thank you
@notmandatory for identifying this bug.
  • Loading branch information
evanlinjin committed Dec 28, 2023
1 parent 4fd539b commit bc796f4
Showing 1 changed file with 13 additions and 3 deletions.
16 changes: 13 additions & 3 deletions example-crates/example_bitcoind_rpc_polling/src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down Expand Up @@ -117,18 +117,28 @@ 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!(
"[{:>10}s] loaded indexed tx graph from changeset",
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()
Expand Down

0 comments on commit bc796f4

Please sign in to comment.