Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

add balance command #1047

Merged
merged 4 commits into from
Dec 23, 2022
Merged
Show file tree
Hide file tree
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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(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) => balance.run(options),
rot13maxi marked this conversation as resolved.
Show resolved Hide resolved
Self::Create(create) => create.run(options),
Self::Inscribe(inscribe) => inscribe.run(options),
Self::Inscriptions(inscriptions) => inscriptions.run(options),
Expand Down
20 changes: 20 additions & 0 deletions src/subcommand/wallet/balance.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
use super::*;

#[derive(Debug, Parser)]
pub(crate) struct Balance {}

impl Balance {
pub(crate) fn run(self, options: Options) -> Result {
println!(
"{}",
options
.bitcoin_rpc_client_for_wallet_command("ord wallet balance")?
.get_balances()?
.mine
.trusted
.to_sat()
);

Ok(())
}
}
rot13maxi marked this conversation as resolved.
Show resolved Hide resolved
18 changes: 18 additions & 0 deletions tests/wallet.rs
Original file line number Diff line number Diff line change
Expand Up @@ -688,3 +688,21 @@ 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();

let coinbase_tx = &rpc_server.mine_blocks_with_subsidy(1, 1_000_000)[0].txdata[0];
let amount = coinbase_tx.output[0].value;

CommandBuilder::new("--regtest wallet balance")
.rpc_server(&rpc_server)
.expected_stdout(format!("{amount}\n"))
rot13maxi marked this conversation as resolved.
Show resolved Hide resolved
.run();
}