Skip to content

Commit

Permalink
Add ord wallet balance (ordinals#1047)
Browse files Browse the repository at this point in the history
  • Loading branch information
rot13maxi authored Dec 23, 2022
1 parent 1af3abe commit ffb7524
Show file tree
Hide file tree
Showing 3 changed files with 36 additions and 0 deletions.
4 changes: 4 additions & 0 deletions src/subcommand/wallet.rs
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
use {super::*, transaction_builder::TransactionBuilder};

mod balance;
mod create;
mod inscribe;
mod inscriptions;
Expand All @@ -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")]
Expand All @@ -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),
Expand Down
15 changes: 15 additions & 0 deletions src/subcommand/wallet/balance.rs
Original file line number Diff line number Diff line change
@@ -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(())
}
17 changes: 17 additions & 0 deletions tests/wallet.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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();
}

0 comments on commit ffb7524

Please sign in to comment.