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

Method boot

src/app.rs:45–136  ·  view source on GitHub ↗

Start up bwt, run the initial sync and start the configured service(s) To abort during initialization, disconnect the progress_tx channel. To shutdown after initialization was completed, drop the App.

(config: Config, progress_tx: Option<mpsc::Sender<Progress>>)

Source from the content-addressed store, hash-verified

43 /// To abort during initialization, disconnect the progress_tx channel.
44 /// To shutdown after initialization was completed, drop the App.
45 pub fn boot(config: Config, progress_tx: Option<mpsc::Sender<Progress>>) -> Result<Self> {
46 debug!(target: LT, "{}", scrub_config(&config));
47
48 let watcher = WalletWatcher::from_config(&config)?;
49 let rpc = Arc::new(RpcClient::new(
50 config.bitcoind_url(),
51 config.bitcoind_auth()?,
52 )?);
53 let indexer = Arc::new(RwLock::new(Indexer::new(rpc.clone(), watcher)?));
54 let query = Arc::new(Query::new((&config).into(), rpc.clone(), indexer.clone()));
55
56 // wait for bitcoind to load up and initialize the wallet
57 init_bitcoind(rpc.clone(), &config, progress_tx.clone())?;
58
59 if config.startup_banner {
60 println!("{}", banner::get_welcome_banner(&query, false)?);
61 }
62
63 // do an initial sync without keeping track of updates
64 indexer.write().unwrap().initial_sync(progress_tx.clone())?;
65
66 // abort if the progress channel was shutdown
67 if let Some(progress_tx) = progress_tx {
68 if progress_tx.send(Progress::Done).is_err() {
69 bail!(BwtError::Canceled);
70 }
71 }
72
73 // prepare access token (user-provided, cookie file or ephemeral)
74 let access_token = config.auth_method()?.get_token()?;
75 if config.print_token {
76 if let Some(token) = &access_token {
77 info!(target: "bwt::auth", "Your SECRET access token is: {}", token);
78 }
79 }
80
81 // channel for triggering real-time index sync
82 // throttled to avoid excessive indexing when bitcoind catches up
83 let (sync_tx, sync_rx) = mpsc::channel();
84 #[cfg(any(feature = "http", unix))]
85 let throttled_sync_tx = throttle_sender(sync_tx.clone(), THROTTLE_SEC);
86
87 #[cfg(feature = "electrum")]
88 let electrum = config.electrum_addr().map(|addr| {
89 ElectrumServer::start(
90 addr,
91 iif!(config.electrum_socks_auth, access_token.clone(), None),
92 config.electrum_skip_merkle,
93 query.clone(),
94 )
95 });
96
97 #[cfg(feature = "http")]
98 let http = config.http_addr().map(|addr| {
99 HttpServer::start(
100 addr,
101 access_token.clone(),
102 config.http_cors.clone(),

Callers

nothing calls this directly

Calls 12

init_bitcoindFunction · 0.85
throttle_senderFunction · 0.85
startFunction · 0.85
bitcoind_urlMethod · 0.80
bitcoind_authMethod · 0.80
intoMethod · 0.80
initial_syncMethod · 0.80
get_tokenMethod · 0.80
auth_methodMethod · 0.80
electrum_addrMethod · 0.45
http_addrMethod · 0.45

Tested by

no test coverage detected