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

add balance command #1047

merged 4 commits into from
Dec 23, 2022

Conversation

rot13maxi
Copy link
Contributor

@rot13maxi rot13maxi commented Dec 22, 2022

Add a simple balance command. Here's what it looks like:

$ ./target/debug/ord --signet wallet balance
0.0099852 BTC

closes #1036

@casey
Copy link
Collaborator

casey commented Dec 23, 2022

Nice! Don't worry about rebasing. I'll just squash at the end.

I'm leaning towards displaying the balance in sats:

  • BTC are enormous, so probably too large to be useful, and people aren't good at reading long decimals.
  • The rest of the commands are sat oriented.
  • If we accept BTC amounts as input, I'd rather avoid floating point numbers.
  • Everything is pretty sat-oriented.

What do you think?

This could use an integration test in tests/wallets.rs. It should run ord wallet balance, get a zero balance, mine some coins to the wallet, and then run the command again and see a nonzero balance. I'm not sure if we'll need to implement a new test RPC server command, but we can cross that bridge when we get to it.

@rot13maxi
Copy link
Contributor Author

ended up doing a rebase anyway.
Now displays balance in sats, and there's an integration test. Let me know if there's anything else you want to see in here

Copy link
Collaborator

@casey casey left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looking good, a few minor comments.

src/subcommand/wallet.rs Outdated Show resolved Hide resolved
src/subcommand/wallet/balance.rs Outdated Show resolved Hide resolved
tests/wallet.rs Outdated Show resolved Hide resolved
@rot13maxi rot13maxi requested a review from casey December 23, 2022 21:55
Copy link
Collaborator

@casey casey left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

vv minor changes

tests/wallet.rs Outdated
.expected_stdout("0\n")
.run();

let _ = &rpc_server.mine_blocks(1);
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

You can just do:

Suggested change
let _ = &rpc_server.mine_blocks(1);
rpc_server.mine_blocks(1);

let _ = is only needed when ignoring a type that has #[must_use] on it, like Result.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

right you are

tests/wallet.rs Outdated

CommandBuilder::new("--regtest wallet balance")
.rpc_server(&rpc_server)
.expected_stdout(format!("5000000000\n"))
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Since this doesn't have any interpolations, format is unnecessary:

Suggested change
.expected_stdout(format!("5000000000\n"))
.expected_stdout("5000000000\n")

There's a just recipe for running some of the checks that run on ci, try just ci, or look for the ci recipe in the justfile to find the commands to run. CI runs clippy (which would complain about this), checks formatting, and runs bin/forbid, which forbids certain strings from appearing in the codebase.

bin/forbid is actually quite useful. It forbids the string todo, so if you want to make sure you don't forget something before comitting, write todo: I need to do blah blah blah and CI will complain, so you don't need to worry about forgetting it.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

ah! I haven't used just before. I'll check that out so you don't have to keep commenting on things that the linter would check. thanks!

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

No worries! just is kind of like make, but only for saving and running commands, and less weird.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

yeah, this is great. should be a lot easier to make sure im conforming to style, etc. for future PRs :)

Copy link
Collaborator

@casey casey left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM!

@casey casey merged commit 751d9bd into ordinals:master Dec 23, 2022
@rot13maxi rot13maxi deleted the balance-command branch December 25, 2022 21:39
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Add wallet balance command
2 participants