Skip to content

Commit

Permalink
example: Simplify signet example
Browse files Browse the repository at this point in the history
which seemed redundant when applying updates.
This change also reflected in crate docs
  • Loading branch information
ValuedMammal committed Sep 13, 2024
1 parent 419a615 commit f398d28
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 21 deletions.
23 changes: 10 additions & 13 deletions examples/signet.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
use bdk_wallet::chain::Merge;
use std::collections::HashSet;
use std::net::{IpAddr, Ipv4Addr};
use std::str::FromStr;
Expand All @@ -24,18 +23,18 @@ const TARGET_INDEX: u32 = 20;
async fn main() -> anyhow::Result<()> {
let secp = Secp256k1::new();

let desc = "tr([7d94197e/86'/1'/0']tpubDCyQVJj8KzjiQsFjmb3KwECVXPvMwvAxxZGCP9XmWSopmjW3bCV3wD7TgxrUhiGSueDS1MU5X1Vb1YjYcp8jitXc5fXfdC1z68hDDEyKRNr/0/*)";
let change_desc = "tr([7d94197e/86'/1'/0']tpubDCyQVJj8KzjiQsFjmb3KwECVXPvMwvAxxZGCP9XmWSopmjW3bCV3wD7TgxrUhiGSueDS1MU5X1Vb1YjYcp8jitXc5fXfdC1z68hDDEyKRNr/1/*)";
let desc = "tr([83737d5e/86'/1'/0']tpubDDR5GgtoxS8fJyjjvdahN4VzV5DV6jtbcyvVXhEKq2XtpxjxBXmxH3r8QrNbQqHg4bJM1EGkxi7Pjfkgnui9jQWqS7kxHvX6rhUeriLDKxz/0/*)";
let change_desc = "tr([83737d5e/86'/1'/0']tpubDDR5GgtoxS8fJyjjvdahN4VzV5DV6jtbcyvVXhEKq2XtpxjxBXmxH3r8QrNbQqHg4bJM1EGkxi7Pjfkgnui9jQWqS7kxHvX6rhUeriLDKxz/1/*)";
let (descriptor, _) = Descriptor::parse_descriptor(&secp, desc)?;
let (change_descriptor, _) = Descriptor::parse_descriptor(&secp, change_desc)?;

let g = genesis_block(Network::Signet).block_hash();
let (mut chain, _) = LocalChain::from_genesis_hash(g);
let genesis_hash = genesis_block(Network::Signet).block_hash();
let (mut chain, _) = LocalChain::from_genesis_hash(genesis_hash);

let mut graph = IndexedTxGraph::new({
let mut index = KeychainTxOutIndex::default();
let _ = index.insert_descriptor(0usize, descriptor);
let _ = index.insert_descriptor(1, change_descriptor);
let _ = index.insert_descriptor("external", descriptor);
let _ = index.insert_descriptor("internal", change_descriptor);
index
});

Expand All @@ -57,9 +56,9 @@ async fn main() -> anyhow::Result<()> {
.add_peers(peers.into_iter().map(|ip| (ip, None).into()).collect())
.add_scripts(spks_to_watch)
.anchor_checkpoint(HeaderCheckpoint::new(
170_000,
205_000,
BlockHash::from_str(
"00000041c812a89f084f633e4cf47e819a2f6b1c0a15162355a930410522c99d",
"0000002bd0f82f8c0c0f1e19128f84c938763641dba85c44bdb6aed1678d16cb",
)?,
))
.num_required_peers(2)
Expand All @@ -76,12 +75,10 @@ async fn main() -> anyhow::Result<()> {
let logger = PrintLogger::new();
if let Some(update) = client.update(&logger).await {
let _ = chain.apply_update(update.chain_update.unwrap())?;
let mut indexed_tx_graph_changeset = graph.apply_update(update.tx_update);
let index_changeset = graph
let _ = graph.apply_update(update.tx_update);
let _ = graph
.index
.reveal_to_target_multi(&update.last_active_indices);
indexed_tx_graph_changeset.merge(index_changeset.into());
graph.apply_changeset(indexed_tx_graph_changeset);
}

// Shutdown
Expand Down
14 changes: 6 additions & 8 deletions src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -70,13 +70,13 @@
//! let (descriptor, _) = Descriptor::parse_descriptor(&secp, &RECEIVE)?;
//! let (change_descriptor, _) = Descriptor::parse_descriptor(&secp, &CHANGE)?;
//!
//! let g = genesis_block(Network::Signet).block_hash();
//! let (mut chain, _) = LocalChain::from_genesis_hash(g);
//! let genesis_hash = genesis_block(Network::Signet).block_hash();
//! let (mut chain, _) = LocalChain::from_genesis_hash(genesis_hash);
//!
//! let mut graph = IndexedTxGraph::new({
//! let mut index = KeychainTxOutIndex::default();
//! let _ = index.insert_descriptor(0usize, descriptor);
//! let _ = index.insert_descriptor(1, change_descriptor);
//! let _ = index.insert_descriptor("external", descriptor);
//! let _ = index.insert_descriptor("internal", change_descriptor);
//! index
//! });
//!
Expand Down Expand Up @@ -112,12 +112,10 @@
//! let logger = PrintLogger::new();
//! if let Some(update) = client.update(&logger).await {
//! let _ = chain.apply_update(update.chain_update.unwrap())?;
//! let mut indexed_tx_graph_changeset = graph.apply_update(update.tx_update);
//! let index_changeset = graph
//! let _ = graph.apply_update(update.tx_update);
//! let _ = graph
//! .index
//! .reveal_to_target_multi(&update.last_active_indices);
//! indexed_tx_graph_changeset.merge(index_changeset.into());
//! let _ = graph.apply_changeset(indexed_tx_graph_changeset);
//! }
//! client.shutdown().await?;
//! Ok(())
Expand Down

0 comments on commit f398d28

Please sign in to comment.