From 5da76608fcd5e0ae340010f19a778750a68a86e1 Mon Sep 17 00:00:00 2001 From: Vihiga Tyonum Date: Wed, 8 Jul 2026 16:22:46 +0100 Subject: [PATCH] feat(handlers): mv feats into subdirs in handlers --- src/error.rs | 2 +- .../dns}/dns_payment_instructions.rs | 0 src/handlers/{dns.rs => dns/mod.rs} | 8 +++++--- src/handlers/key.rs | 16 ++++++---------- src/handlers/mod.rs | 7 +++++++ src/handlers/offline.rs | 3 +-- src/handlers/online.rs | 14 +++++++------- src/{ => handlers}/payjoin/db.rs | 5 +++-- src/{ => handlers}/payjoin/mod.rs | 8 ++++---- src/{ => handlers}/payjoin/ohttp.rs | 0 src/main.rs | 10 ---------- 11 files changed, 34 insertions(+), 39 deletions(-) rename src/{ => handlers/dns}/dns_payment_instructions.rs (100%) rename src/handlers/{dns.rs => dns/mod.rs} (98%) rename src/{ => handlers}/payjoin/db.rs (99%) rename src/{ => handlers}/payjoin/mod.rs (99%) rename src/{ => handlers}/payjoin/ohttp.rs (100%) diff --git a/src/error.rs b/src/error.rs index dbdc7b8..7f7eab0 100644 --- a/src/error.rs +++ b/src/error.rs @@ -154,7 +154,7 @@ pub enum BDKCliError { #[cfg(feature = "payjoin")] #[error("Payjoin database error: {0}")] - PayjoinDb(#[from] crate::payjoin::db::Error), + PayjoinDb(#[from] crate::handlers::payjoin::db::Error), #[cfg(feature = "bip322")] #[error("BIP-322 error: {0}")] diff --git a/src/dns_payment_instructions.rs b/src/handlers/dns/dns_payment_instructions.rs similarity index 100% rename from src/dns_payment_instructions.rs rename to src/handlers/dns/dns_payment_instructions.rs diff --git a/src/handlers/dns.rs b/src/handlers/dns/mod.rs similarity index 98% rename from src/handlers/dns.rs rename to src/handlers/dns/mod.rs index 18e127b..6e682bc 100644 --- a/src/handlers/dns.rs +++ b/src/handlers/dns/mod.rs @@ -1,7 +1,9 @@ -use crate::dns_payment_instructions::{ +mod dns_payment_instructions; + +use crate::error::BDKCliError as Error; +use crate::handlers::dns::dns_payment_instructions::{ parse_dns_instructions, process_instructions, resolve_dns_recipient, }; -use crate::error::BDKCliError as Error; use crate::handlers::{AppContext, AsyncAppCommand, Init, OfflineOperations}; use crate::utils::types::{PsbtResult, StatusResult}; use crate::utils::{parse_dns_recipient, parse_outpoint, parse_recipient}; @@ -168,6 +170,6 @@ impl AsyncAppCommand>> for CreateDnsTxCommand { } let psbt = tx_builder.finish()?; - Ok(PsbtResult::new(&psbt, false, Some(false))) + Ok(PsbtResult::new(&psbt, Some(false))) } } diff --git a/src/handlers/key.rs b/src/handlers/key.rs index ce8c844..c1a9e76 100644 --- a/src/handlers/key.rs +++ b/src/handlers/key.rs @@ -1,17 +1,13 @@ use crate::commands::KeySubCommand; use crate::error::BDKCliError as Error; -use crate::handlers::Init; -use crate::handlers::{AppCommand, AppContext}; -use crate::utils::output::FormatOutput; -use crate::utils::types::KeyResult; +use crate::handlers::{AppCommand, AppContext, Init}; +use crate::utils::{output::FormatOutput, types::KeyResult}; use bdk_wallet::bip39::{Language, Mnemonic}; -use bdk_wallet::bitcoin::bip32::DerivationPath; -use bdk_wallet::bitcoin::bip32::KeySource; -use bdk_wallet::bitcoin::bip32::Xpriv; +use bdk_wallet::bitcoin::bip32::{DerivationPath, KeySource, Xpriv}; use bdk_wallet::bitcoin::key::Secp256k1; -use bdk_wallet::keys::bip39::WordCount; -use bdk_wallet::keys::{DerivableKey, GeneratableKey}; -use bdk_wallet::keys::{DescriptorKey, ExtendedKey, GeneratedKey}; +use bdk_wallet::keys::{ + DerivableKey, DescriptorKey, ExtendedKey, GeneratableKey, GeneratedKey, bip39::WordCount, +}; use bdk_wallet::miniscript::{self, Segwitv0}; use clap::Parser; diff --git a/src/handlers/mod.rs b/src/handlers/mod.rs index 113398b..a2c4ad5 100644 --- a/src/handlers/mod.rs +++ b/src/handlers/mod.rs @@ -5,6 +5,13 @@ pub mod dns; pub mod key; pub mod offline; pub mod online; +#[cfg(any( + feature = "electrum", + feature = "esplora", + feature = "cbf", + feature = "rpc" +))] +pub mod payjoin; pub mod repl; #[cfg(any( diff --git a/src/handlers/offline.rs b/src/handlers/offline.rs index d536e18..7490d80 100644 --- a/src/handlers/offline.rs +++ b/src/handlers/offline.rs @@ -84,8 +84,7 @@ impl OfflineWalletSubCommand { .write_out(std::io::stdout()), #[cfg(feature = "dns_payment")] Self::CreateDnsTx(_) => Err(Error::Generic( - "CreateDnsTx is dispatched asynchronously through main" - .to_string(), + "CreateDnsTx is dispatched asynchronously through main".to_string(), )), } } diff --git a/src/handlers/online.rs b/src/handlers/online.rs index f520451..bf84dc0 100644 --- a/src/handlers/online.rs +++ b/src/handlers/online.rs @@ -2,14 +2,13 @@ use clap::Parser; #[cfg(feature = "electrum")] use crate::client::BlockchainClient::Electrum; -#[cfg(feature = "rpc")] -use crate::client::BlockchainClient::RpcClient; #[cfg(feature = "cbf")] use crate::client::{BlockchainClient::KyotoClient, sync_kyoto_client}; #[cfg(feature = "esplora")] use {crate::client::BlockchainClient::Esplora, bdk_esplora::EsploraAsyncExt}; #[cfg(feature = "rpc")] use { + crate::client::BlockchainClient::RpcClient, bdk_bitcoind_rpc::{Emitter, NO_EXPECTED_MEMPOOL_TXS, bitcoincore_rpc::RpcApi}, bdk_wallet::chain::{BlockId, CanonicalizationParams, CheckPoint}, }; @@ -27,11 +26,12 @@ use crate::utils::print_wallet_events; use { crate::commands::OnlineWalletSubCommand, crate::error::BDKCliError as Error, - crate::handlers::{AppContext, AsyncAppCommand, OnlineOperations}, - crate::payjoin::PayjoinManager, - crate::utils::is_final, - crate::utils::output::FormatOutput, - crate::utils::types::{StatusResult, TransactionResult}, + crate::handlers::{AppContext, AsyncAppCommand, OnlineOperations, payjoin::PayjoinManager}, + crate::utils::{ + is_final, + output::FormatOutput, + types::{StatusResult, TransactionResult}, + }, bdk_wallet::bitcoin::{ Psbt, Transaction, Txid, base64::Engine, base64::prelude::BASE64_STANDARD, consensus::Decodable, hex::FromHex, diff --git a/src/payjoin/db.rs b/src/handlers/payjoin/db.rs similarity index 99% rename from src/payjoin/db.rs rename to src/handlers/payjoin/db.rs index f21524d..dd64e4d 100644 --- a/src/payjoin/db.rs +++ b/src/handlers/payjoin/db.rs @@ -814,8 +814,9 @@ mod tests { .get_inactive_recv_session_ids() .expect("inactive receiver ids should load"); - let table = crate::payjoin::PayjoinManager::history(Some(datadir.clone()), wallet_name) - .expect("history should render"); + let table = + crate::handlers::payjoin::PayjoinManager::history(Some(datadir.clone()), wallet_name) + .expect("history should render"); assert!(table.contains("Sender")); assert!(table.contains("Receiver")); diff --git a/src/payjoin/mod.rs b/src/handlers/payjoin/mod.rs similarity index 99% rename from src/payjoin/mod.rs rename to src/handlers/payjoin/mod.rs index 11e09a0..7a2fe36 100644 --- a/src/payjoin/mod.rs +++ b/src/handlers/payjoin/mod.rs @@ -24,8 +24,8 @@ use payjoin::{HpkePublicKey, ImplementationError, UriExt}; use serde_json::{json, to_string_pretty}; use std::{path::PathBuf, sync::Arc}; -use crate::payjoin::db::{ReceiverPersister, SenderPersister, open_payjoin_db}; -use crate::payjoin::ohttp::RelayManager; +use crate::handlers::payjoin::db::{ReceiverPersister, SenderPersister, open_payjoin_db}; +use crate::handlers::payjoin::ohttp::RelayManager; pub mod db; pub mod ohttp; @@ -38,7 +38,7 @@ pub mod ohttp; pub(crate) struct PayjoinManager<'a> { wallet: &'a mut Wallet, relay_manager: RelayManager, - db: Arc, + db: Arc, } trait StatusText { @@ -136,7 +136,7 @@ impl<'a> PayjoinManager<'a> { self.relay_manager.configure(ohttp_relays)?; let ohttp_keys = self.relay_manager.fetch_ohttp_keys(&directory).await?; - let persister = crate::payjoin::db::ReceiverPersister::new(self.db.clone())?; + let persister = crate::handlers::payjoin::db::ReceiverPersister::new(self.db.clone())?; let checked_max_fee_rate = max_fee_rate .map(FeeRate::from_sat_per_kwu) diff --git a/src/payjoin/ohttp.rs b/src/handlers/payjoin/ohttp.rs similarity index 100% rename from src/payjoin/ohttp.rs rename to src/handlers/payjoin/ohttp.rs diff --git a/src/main.rs b/src/main.rs index 8ee07f6..a79492e 100644 --- a/src/main.rs +++ b/src/main.rs @@ -15,19 +15,9 @@ mod commands; mod config; mod error; mod handlers; -#[cfg(any( - feature = "electrum", - feature = "esplora", - feature = "cbf", - feature = "rpc" -))] -mod payjoin; mod persister; mod utils; -#[cfg(feature = "dns_payment")] -mod dns_payment_instructions; - use bdk_wallet::bitcoin::Network; use log::{debug, warn}; -- 2.49.0