MCPcopy Create free account
hub / github.com/bitcoindevkit/bdk-cli / handle_command

Function handle_command

src/handlers.rs:1199–1439  ·  view source on GitHub ↗

The global top level handler.

(cli_opts: CliOpts)

Source from the content-addressed store, hash-verified

1197
1198/// The global top level handler.
1199pub(crate) async fn handle_command(cli_opts: CliOpts) -> Result<String, Error> {
1200 let pretty = cli_opts.pretty;
1201 let subcommand = cli_opts.subcommand.clone();
1202
1203 let result: Result<String, Error> = match subcommand {
1204 #[cfg(any(
1205 feature = "electrum",
1206 feature = "esplora",
1207 feature = "cbf",
1208 feature = "rpc"
1209 ))]
1210 CliSubCommand::Wallet {
1211 wallet,
1212 subcommand: WalletSubCommand::OnlineWalletSubCommand(online_subcommand),
1213 } => {
1214 let home_dir = prepare_home_dir(cli_opts.datadir)?;
1215
1216 let (wallet_opts, network) = load_wallet_config(&home_dir, &wallet)?;
1217
1218 let database_path = prepare_wallet_db_dir(&home_dir, &wallet)?;
1219
1220 #[cfg(any(feature = "sqlite", feature = "redb"))]
1221 let result = {
1222 let mut persister: Persister = match &wallet_opts.database_type {
1223 #[cfg(feature = "sqlite")]
1224 DatabaseType::Sqlite => {
1225 let db_file = database_path.join("wallet.sqlite");
1226 let connection = Connection::open(db_file)?;
1227 log::debug!("Sqlite database opened successfully");
1228 Persister::Connection(connection)
1229 }
1230 #[cfg(feature = "redb")]
1231 DatabaseType::Redb => {
1232 let wallet_name = &wallet_opts.wallet;
1233 let db = Arc::new(bdk_redb::redb::Database::create(
1234 home_dir.join("wallet.redb"),
1235 )?);
1236 let store = RedbStore::new(
1237 db,
1238 wallet_name.as_deref().unwrap_or("wallet").to_string(),
1239 )?;
1240 log::debug!("Redb database opened successfully");
1241 Persister::RedbStore(store)
1242 }
1243 };
1244
1245 let mut wallet = new_persisted_wallet(network, &mut persister, &wallet_opts)?;
1246 let blockchain_client =
1247 new_blockchain_client(&wallet_opts, &wallet, database_path)?;
1248
1249 let result = handle_online_wallet_subcommand(
1250 &mut wallet,
1251 &blockchain_client,
1252 online_subcommand,
1253 )
1254 .await?;
1255 wallet.persist(&mut persister)?;
1256 result

Callers 1

mainFunction · 0.85

Calls 15

prepare_home_dirFunction · 0.85
load_wallet_configFunction · 0.85
prepare_wallet_db_dirFunction · 0.85
new_persisted_walletFunction · 0.85
new_blockchain_clientFunction · 0.85
new_walletFunction · 0.85
handle_config_subcommandFunction · 0.85
handle_key_subcommandFunction · 0.85

Tested by

no test coverage detected