MCPcopy Create free account
hub / github.com/bwt-dev/bwt / main

Function main

examples/use-from-rust.rs:4–36  ·  view source on GitHub ↗
()

Source from the content-addressed store, hash-verified

2use bwt::{App, Config, Result};
3
4fn main() -> Result<()> {
5 let my_desc = "wpkh(tpubD6NzVbkrYhZ4Ya1aR2od7JTGK6b44cwKhWzrvrTeTWFrzGokdAGHrZLK6BdYwpx9K7EoY38LzHva3SWwF8yRrXM9x9DQ3jCGKZKt1nQEz7n/0/*)";
6
7 // Initialize the config
8 let config = Config {
9 network: bitcoin::Network::Regtest,
10 bitcoind_dir: Some("/home/satoshi/.bitcoin".into()),
11 bitcoind_wallet: Some("bwt".into()),
12 electrum_addr: Some("127.0.0.1:0".parse().unwrap()),
13 descriptors: vec![my_desc.parse().unwrap()],
14 rescan_since: RescanSince::Now,
15 verbose: 2,
16 ..Default::default()
17 };
18 config.setup_logger(); // optional
19
20 // Boot up bwt. The thread will be blocked until the initial sync is completed
21 let app = App::boot(config, None)?;
22
23 // The index is now ready for querying
24 let query = app.query();
25 log::info!("synced up to {:?}", query.get_tip()?);
26 log::info!("utxos: {:?}", query.list_unspent(None, 0, None)?);
27 log::info!("electrum running on {}", app.electrum_addr().unwrap());
28
29 // Start syncing new blocks/transactions in the background
30 let shutdown_tx = app.sync_background();
31
32 // To shutdown the syncing thread, send a message to `shutdown_tx` or let it drop out of scope
33 shutdown_tx.send(()).unwrap();
34
35 Ok(())
36}

Callers

nothing calls this directly

Calls 4

intoMethod · 0.80
setup_loggerMethod · 0.80
queryMethod · 0.80
sync_backgroundMethod · 0.80

Tested by

no test coverage detected