diff --git a/example-crates/example_bitcoind_rpc_polling/src/main.rs b/example-crates/example_bitcoind_rpc_polling/src/main.rs index 49fce4d9e..88b83067b 100644 --- a/example-crates/example_bitcoind_rpc_polling/src/main.rs +++ b/example-crates/example_bitcoind_rpc_polling/src/main.rs @@ -110,9 +110,13 @@ enum RpcCommands { fn main() -> anyhow::Result<()> { let start = Instant::now(); - - let (args, keymap, index, db, init_changeset) = - example_cli::init::(DB_MAGIC, DB_PATH)?; + let example_cli::Init { + args, + keymap, + index, + db, + init_changeset, + } = example_cli::init::(DB_MAGIC, DB_PATH)?; println!( "[{:>10}s] loaded initial changeset from db", start.elapsed().as_secs_f32() diff --git a/example-crates/example_cli/src/lib.rs b/example-crates/example_cli/src/lib.rs index 4b3ece51f..4989c08c6 100644 --- a/example-crates/example_cli/src/lib.rs +++ b/example-crates/example_cli/src/lib.rs @@ -656,19 +656,26 @@ where } } -// Alias the `Result` of `init` -pub type InitialState = ( - Args, - KeyMap, - KeychainTxOutIndex, - Mutex>, - C, -); +/// The initial state returned by [`init`]. +pub struct Init { + /// Arguments parsed by the cli. + pub args: Args, + /// Descriptor keymap. + pub keymap: KeyMap, + /// Keychain-txout index. + pub index: KeychainTxOutIndex, + /// Persistence backend. + pub db: Mutex>, + /// Initial changeset. + pub init_changeset: C, +} +/// Parses command line arguments and initializes all components, creating +/// a file store with the given parameters, or loading one if it exists. pub fn init( db_magic: &[u8], db_default_path: &str, -) -> anyhow::Result> +) -> anyhow::Result> where C: Default + Append + Serialize + DeserializeOwned, { @@ -702,11 +709,11 @@ where let init_changeset = db_backend.load_from_persistence()?.unwrap_or_default(); - Ok(( + Ok(Init { args, keymap, index, - Mutex::new(Database::new(db_backend)), + db: Mutex::new(Database::new(db_backend)), init_changeset, - )) + }) } diff --git a/example-crates/example_electrum/src/main.rs b/example-crates/example_electrum/src/main.rs index ccd17a704..df34795bd 100644 --- a/example-crates/example_electrum/src/main.rs +++ b/example-crates/example_electrum/src/main.rs @@ -103,8 +103,15 @@ type ChangeSet = ( ); fn main() -> anyhow::Result<()> { - let (args, keymap, index, db, (disk_local_chain, disk_tx_graph)) = - example_cli::init::(DB_MAGIC, DB_PATH)?; + let example_cli::Init { + args, + keymap, + index, + db, + init_changeset, + } = example_cli::init::(DB_MAGIC, DB_PATH)?; + + let (disk_local_chain, disk_tx_graph) = init_changeset; let graph = Mutex::new({ let mut graph = IndexedTxGraph::new(index); diff --git a/example-crates/example_esplora/src/main.rs b/example-crates/example_esplora/src/main.rs index b4dabea7a..e92205706 100644 --- a/example-crates/example_esplora/src/main.rs +++ b/example-crates/example_esplora/src/main.rs @@ -99,8 +99,13 @@ pub struct ScanOptions { } fn main() -> anyhow::Result<()> { - let (args, keymap, index, db, init_changeset) = - example_cli::init::(DB_MAGIC, DB_PATH)?; + let example_cli::Init { + args, + keymap, + index, + db, + init_changeset, + } = example_cli::init::(DB_MAGIC, DB_PATH)?; let genesis_hash = genesis_block(args.network).block_hash();