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 wallet balance subcommand #271

Merged
merged 76 commits into from
Aug 9, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
76 commits
Select commit Hold shift + click to select a range
3e13678
Add wallet utxos subcommand
terror Jul 20, 2022
f8b6915
Merge branch 'master' into utxos
terror Jul 21, 2022
ed59bd2
Semi-working
terror Jul 21, 2022
0b7ac8f
Merge remote-tracking branch 'refs/remotes/origin/utxos' into utxos
terror Jul 21, 2022
3dba2af
Initial work
terror Jul 22, 2022
79ad708
Get first_coinbase_transaction working
terror Jul 22, 2022
646c9ee
Fix two more list tests
terror Jul 25, 2022
c3c418c
Fix a few find tests
terror Jul 25, 2022
5e43541
Get 4th list test working
terror Jul 26, 2022
9f498b7
Start adding bdk wallet in tests
terror Jul 27, 2022
6cfd1f4
Cleanup
terror Jul 27, 2022
b3f39c5
Merge branch 'master' into regtest
terror Jul 27, 2022
6e6b1d0
Semi-working
terror Jul 27, 2022
1fdbc82
Clearer output
terror Jul 27, 2022
be6fb0e
Get first part of split_ranges_are_tracked_correctly working
terror Jul 27, 2022
1ad4cc2
Fix merge_ranges test
terror Jul 28, 2022
041695d
Fix fee_paying_transaction_range
terror Jul 28, 2022
2868785
Small refactors
terror Jul 29, 2022
94f84fb
Fix null_output test
terror Jul 29, 2022
01417c3
Use git dependency
terror Jul 29, 2022
c9fc017
Fix two_fee test
terror Jul 29, 2022
380c647
Fix null_input test
terror Jul 29, 2022
5aa0cde
Get all list tests to pass invidiually
terror Jul 29, 2022
c8cc1df
Fix find tests
terror Jul 29, 2022
f106d2a
Fix info and index tests
terror Jul 29, 2022
efcfcc2
Get server tests to pass
terror Jul 29, 2022
26b67cc
Only kill process if healthy
terror Jul 30, 2022
353b78f
Get all non-ignored tests to pass
terror Aug 1, 2022
8447056
Merge branch 'master' into regtest
terror Aug 1, 2022
0ad28c0
Make tests slightly faster
terror Aug 1, 2022
1eca6dc
Add our own bitcoind wrapper
casey Aug 1, 2022
8219df5
Merge branch 'master' into regtest
terror Aug 1, 2022
10f92cc
Remove todo's
terror Aug 1, 2022
85e95ec
Merge branch 'master' into utxos
terror Aug 2, 2022
ff89123
Add logging
terror Aug 2, 2022
f268fea
Get tests to pass individually again
terror Aug 2, 2022
32d8b36
Merge branch 'regtest' into utxos
terror Aug 2, 2022
ce154d2
Small refactors
terror Aug 2, 2022
295c19f
Refactor to use State object
casey Aug 2, 2022
9443fe9
Use unwrap
casey Aug 2, 2022
eae8092
Move state and test into own files
casey Aug 2, 2022
bba0e9d
More stuff
casey Aug 2, 2022
28f033b
Fix
casey Aug 2, 2022
4590aa6
Stuff
casey Aug 2, 2022
6c21615
Get first server test working
casey Aug 2, 2022
1624643
Get tests to pass
terror Aug 2, 2022
f16a003
Strip suffix error
terror Aug 2, 2022
30b5dfd
Generate 101 blocks, output txid:vout
terror Aug 3, 2022
75e960f
Add balance subcommand
terror Aug 2, 2022
e66cdf8
Generate 101 blocks
terror Aug 3, 2022
14f13ed
Try not to leak write transactions
casey Aug 4, 2022
e2a620b
Try updating dependencies
casey Aug 4, 2022
ef09f26
Initialize logger in state
casey Aug 4, 2022
0a88ec1
Increase redb database size
casey Aug 4, 2022
f5cbdae
Merge branch 'master' into regtest
terror Aug 8, 2022
5d0b30c
Fix more tests
terror Aug 8, 2022
6c563ea
Fix outputs
terror Aug 8, 2022
f9fbb79
Transactions still broken
terror Aug 8, 2022
557d5bd
All server tests pass
terror Aug 8, 2022
09895ba
Fix ci breakage
terror Aug 8, 2022
2e31c18
Run with a single test thread
terror Aug 8, 2022
c37b945
Install bitcoind
terror Aug 8, 2022
f8b84bf
Bitcoin -> Bitcoind
terror Aug 8, 2022
0da8ce7
Install sqlite
terror Aug 8, 2022
e3fd7e3
Load server on first request
terror Aug 9, 2022
f11f0a6
Merge branch 'regtest' into utxos
terror Aug 9, 2022
ee58902
Fix import errors
terror Aug 9, 2022
77aa8c5
Fix regex
terror Aug 9, 2022
b4dce90
Merge branch 'utxos' into balance
terror Aug 9, 2022
0958999
Clippy
terror Aug 9, 2022
c8a21a6
Install bitcoin from release on linux
casey Aug 9, 2022
76c7c41
Merge branch 'regtest' into balance
terror Aug 9, 2022
580331c
Merge branch 'master' into balance
terror Aug 9, 2022
85b52d2
Use latest index_ranges
terror Aug 9, 2022
70b6557
More
terror Aug 9, 2022
b5aaf64
Test for 0 balance
terror Aug 9, 2022
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
7 changes: 5 additions & 2 deletions src/subcommand/wallet.rs
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
use super::*;

mod balance;
mod fund;
mod init;
mod utxos;
Expand Down Expand Up @@ -54,16 +55,18 @@ fn get_wallet(options: Options) -> Result<bdk::wallet::Wallet<SqliteDatabase>> {

#[derive(Debug, Parser)]
pub(crate) enum Wallet {
Init,
Balance,
Fund,
Init,
Utxos,
}

impl Wallet {
pub(crate) fn run(self, options: Options) -> Result {
match self {
Self::Init => init::run(options),
Self::Balance => balance::run(options),
Self::Fund => fund::run(options),
Self::Init => init::run(options),
Self::Utxos => utxos::run(options),
}
}
Expand Down
6 changes: 6 additions & 0 deletions src/subcommand/wallet/balance.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
use super::*;

pub(crate) fn run(options: Options) -> Result {
println!("{}", get_wallet(options)?.get_balance()?);
Ok(())
}
44 changes: 44 additions & 0 deletions tests/wallet.rs
Original file line number Diff line number Diff line change
Expand Up @@ -140,3 +140,47 @@ fn utxos() {
.stdout_regex("^[[:xdigit:]]{64}:0 5000000000\n")
.run()
}

#[test]
fn balance() {
let state = Test::new()
.command("--network regtest wallet init")
.expected_status(0)
.expected_stderr("Wallet initialized.\n")
.output()
.state;

let state = Test::with_state(state)
.command("--network regtest wallet balance")
.expected_status(0)
.expected_stdout("0\n")
.output()
.state;

let output = Test::with_state(state)
.command("--network regtest wallet fund")
.stdout_regex("^bcrt1.*\n")
.output();

output
.state
.client
.generate_to_address(
101,
&Address::from_str(
output
.stdout
.strip_suffix('\n')
.ok_or("Failed to strip suffix")
.unwrap(),
)
.unwrap(),
)
.unwrap();

Test::with_state(output.state)
.command("--network regtest wallet balance")
.expected_status(0)
.expected_stdout("5000000000\n")
.run()
}