2023-11-30 04:59:15 -08:00
|
|
|
//! Initializing the scanner.
|
|
|
|
|
|
|
|
use color_eyre::Report;
|
|
|
|
use tokio::task::JoinHandle;
|
|
|
|
use tracing::Instrument;
|
|
|
|
|
2023-11-30 13:27:46 -08:00
|
|
|
use zebra_chain::{diagnostic::task::WaitForPanics, parameters::Network};
|
2023-11-30 04:59:15 -08:00
|
|
|
|
|
|
|
use crate::{scan, storage::Storage, Config};
|
|
|
|
|
2023-11-30 13:27:46 -08:00
|
|
|
/// Initialize the scanner based on its config, and spawn a task for it.
|
|
|
|
///
|
|
|
|
/// TODO: add a test for this function.
|
|
|
|
pub fn spawn_init(
|
2023-11-30 04:59:15 -08:00
|
|
|
config: &Config,
|
|
|
|
network: Network,
|
|
|
|
state: scan::State,
|
|
|
|
) -> JoinHandle<Result<(), Report>> {
|
2023-11-30 13:27:46 -08:00
|
|
|
let config = config.clone();
|
|
|
|
tokio::spawn(init(config, network, state).in_current_span())
|
|
|
|
}
|
|
|
|
|
|
|
|
/// Initialize the scanner based on its config.
|
|
|
|
///
|
|
|
|
/// TODO: add a test for this function.
|
|
|
|
pub async fn init(config: Config, network: Network, state: scan::State) -> Result<(), Report> {
|
|
|
|
let storage = tokio::task::spawn_blocking(move || Storage::new(&config, network))
|
|
|
|
.wait_for_panics()
|
|
|
|
.await;
|
2023-11-30 04:59:15 -08:00
|
|
|
|
|
|
|
// TODO: add more tasks here?
|
2023-11-30 13:27:46 -08:00
|
|
|
scan::start(state, storage).await
|
2023-11-30 04:59:15 -08:00
|
|
|
}
|