diff --git a/src/subcommand/wallet.rs b/src/subcommand/wallet.rs index 93be1f67e5..e09fead4cd 100644 --- a/src/subcommand/wallet.rs +++ b/src/subcommand/wallet.rs @@ -1,5 +1,6 @@ use {super::*, transaction_builder::TransactionBuilder}; +mod balance; mod create; mod inscribe; mod inscriptions; @@ -12,6 +13,8 @@ mod utxos; #[derive(Debug, Parser)] pub(crate) enum Wallet { + #[clap(about = "Get wallet balance")] + Balance, #[clap(about = "Create a new wallet")] Create(create::Create), #[clap(about = "Create an inscription")] @@ -33,6 +36,7 @@ pub(crate) enum Wallet { impl Wallet { pub(crate) fn run(self, options: Options) -> Result { match self { + Self::Balance => balance::run(options), Self::Create(create) => create.run(options), Self::Inscribe(inscribe) => inscribe.run(options), Self::Inscriptions(inscriptions) => inscriptions.run(options), diff --git a/src/subcommand/wallet/balance.rs b/src/subcommand/wallet/balance.rs new file mode 100644 index 0000000000..f375fc8981 --- /dev/null +++ b/src/subcommand/wallet/balance.rs @@ -0,0 +1,15 @@ +use super::*; + +pub(crate) fn run(options: Options) -> Result { + println!( + "{}", + options + .bitcoin_rpc_client()? + .get_balances()? + .mine + .trusted + .to_sat() + ); + + Ok(()) +} diff --git a/tests/wallet.rs b/tests/wallet.rs index 15a8a9e299..f871c6692f 100644 --- a/tests/wallet.rs +++ b/tests/wallet.rs @@ -688,3 +688,20 @@ fn inscribe_gif() { ), ) } + +#[test] +fn wallet_balance() { + let rpc_server = test_bitcoincore_rpc::spawn_with(Network::Regtest, "ord"); + + CommandBuilder::new("--regtest wallet balance") + .rpc_server(&rpc_server) + .expected_stdout("0\n") + .run(); + + rpc_server.mine_blocks(1); + + CommandBuilder::new("--regtest wallet balance") + .rpc_server(&rpc_server) + .expected_stdout("5000000000\n") + .run(); +}