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

Get balance in categories #640

Merged
merged 1 commit into from
Aug 4, 2022

Conversation

wszdexdrf
Copy link
Contributor

@wszdexdrf wszdexdrf commented Jun 23, 2022

Description

This changes get_balance() function so that it returns balance separated in 4 categories:

  • available
  • trusted-pending
  • untrusted-pending
  • immature

Fixes #238

Notes to the reviewers

Based on #614

Checklists

All Submissions:

  • I've signed all my commits
  • I followed the contribution guidelines
  • I ran cargo fmt and cargo clippy before committing

New Features:

  • I've updated tests for the new feature
  • I've added docs for the new feature
  • I've updated CHANGELOG.md

@wszdexdrf
Copy link
Contributor Author

I have not added tests since I feel that existing test should be fine. I can add some if need be.
Regarding the code, I went with the rule "add instead of change"

@wszdexdrf wszdexdrf marked this pull request as ready for review June 23, 2022 16:12
Copy link
Member

@danielabrozzoni danielabrozzoni left a comment

Choose a reason for hiding this comment

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

Concept ACK

  • Some tests are failing, run them with cargo test --features test-electrum and cargo test --features test-rpc
  • You should update the CHANGELOG.md
  • You should add tests! Some ideas:
    • Receive a transaction, check that the output values get counted in the untrusted_pending, get it confirmed, check that now the amount is in available
    • Make a transaction, check that the change value is counted in trusted_pending, get it confirmed, check that now the amount is in available

src/types.rs Outdated Show resolved Hide resolved
src/types.rs Outdated Show resolved Hide resolved
src/types.rs Show resolved Hide resolved
src/wallet/mod.rs Outdated Show resolved Hide resolved
src/wallet/mod.rs Outdated Show resolved Hide resolved
src/wallet/mod.rs Outdated Show resolved Hide resolved
src/wallet/mod.rs Show resolved Hide resolved
@wszdexdrf wszdexdrf force-pushed the get_balance_in_categories branch 3 times, most recently from 7e7d25a to ae5271a Compare June 25, 2022 15:06
@danielabrozzoni
Copy link
Member

Can you rebase to pick up the CI fixes (#638)? Thanks :)

@wszdexdrf wszdexdrf force-pushed the get_balance_in_categories branch 5 times, most recently from d91b8fa to 4f052fe Compare June 30, 2022 13:45
src/wallet/mod.rs Outdated Show resolved Hide resolved
src/types.rs Outdated Show resolved Hide resolved
src/types.rs Outdated Show resolved Hide resolved
src/types.rs Show resolved Hide resolved
src/types.rs Show resolved Hide resolved
src/wallet/mod.rs Show resolved Hide resolved
@notmandatory notmandatory added the new feature New feature or request label Jul 4, 2022
Copy link
Member

@evanlinjin evanlinjin left a comment

Choose a reason for hiding this comment

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

Concept ACK

I'm very excited for these changes, and great work!

I just have some thoughts on naming conventions and some changes in logic. Haven't really gone through everything yet though.

In regards to naming conventions, may need various second opinions.

src/types.rs Outdated Show resolved Hide resolved
#[derive(Serialize, Deserialize, Debug, PartialEq, Eq, Clone, Default)]
pub struct Balance {
/// All coinbase outputs not yet matured
pub immature: u64,
Copy link
Member

Choose a reason for hiding this comment

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

Would immature_coinbase be clearer? Or too wordy? 😅

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I feel immature coins are only ever meant in regards to coinbase coins, so I think it would be a bit too wordy. I thought of these names as if they had a imaginary "balance" or "coins" added at the end of them.

Copy link
Member

Choose a reason for hiding this comment

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

That's an interesting point. If a coin is un-spendable due to a script-level timelock (such as OP_CLTV or OP_CSV) would we also use the term immature?

Copy link
Member

Choose a reason for hiding this comment

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

That's an interesting point. If a coin is un-spendable due to a script-level timelock (such as OP_CLTV or OP_CSV) would we also use the term immature?

Not at the moment! But I should open an issue to remember this. Also see #640 (comment)

Copy link
Member

@danielabrozzoni danielabrozzoni Jul 6, 2022

Choose a reason for hiding this comment

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

......which means that maybe immature coinbase is clearer...

src/types.rs Outdated Show resolved Hide resolved
src/wallet/mod.rs Show resolved Hide resolved
src/wallet/mod.rs Outdated Show resolved Hide resolved
@afilini
Copy link
Member

afilini commented Jul 5, 2022

FYI: #614 got merged, so you can rebase on master to pickup the latest changes.

It also looks like there are some conflicts, so during the rebase you'll get a chance to fix them as well.

EDIT: I think the conflicts mostly come from the two commits you have in your branch from the old version of #614, so just dropping those and rebasing on master should fix everything.

@wszdexdrf wszdexdrf force-pushed the get_balance_in_categories branch 4 times, most recently from 4ec63e4 to 74def0a Compare July 6, 2022 10:30
Copy link
Member

@danielabrozzoni danielabrozzoni left a comment

Choose a reason for hiding this comment

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

tACK 74def0a

src/wallet/mod.rs Outdated Show resolved Hide resolved
Copy link
Member

@afilini afilini left a comment

Choose a reason for hiding this comment

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

I hate to make you go through another round of fixing and rebasing but I swear, this is gonna be the last one!

The code looked great to me now, no complains there.

CHANGELOG.md Outdated Show resolved Hide resolved
@wszdexdrf wszdexdrf force-pushed the get_balance_in_categories branch 2 times, most recently from bde59df to 62e6b04 Compare July 6, 2022 15:21
Copy link
Member

@afilini afilini left a comment

Choose a reason for hiding this comment

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

ACK 62e6b04

Copy link
Member

@evanlinjin evanlinjin left a comment

Choose a reason for hiding this comment

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

ACK 62e6b04

However, just a thought...

For tests that require checking balance, would it make sense to compare with the whole Balance struct?

For example:

assert_eq!(wallet.get_balance().unwrap(), Balance{ .. })

But I hate to be the one that delays merging, maybe we can have this as another task for another PR?

Otherwise, I've gone through everything and it all looks dandy to me :)

@danielabrozzoni
Copy link
Member

This needs rebasing to fix the conflicts.

One small note: please, when you've updated the code, can you click "resolve conversation" under the comments? This way the whole PR is way more readable. I've done it for you this time, I hope I didn't accidentally solve something that wasn't solved...

Copy link
Member

@danielabrozzoni danielabrozzoni left a comment

Choose a reason for hiding this comment

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

Just a tiny nit. Me and Alekos have been recently talking about lacking test coverage (mainly after we discovered #666 😈 ), and we realize that we should definitely be more nit-picker on tests. Sorry to delay merging even more, but I promise we're close!

src/wallet/mod.rs Outdated Show resolved Hide resolved
src/testutils/blockchain_tests.rs Outdated Show resolved Hide resolved
src/testutils/blockchain_tests.rs Outdated Show resolved Hide resolved
@wszdexdrf wszdexdrf force-pushed the get_balance_in_categories branch 2 times, most recently from f3bb345 to b86b3aa Compare July 31, 2022 11:29
@wszdexdrf wszdexdrf force-pushed the get_balance_in_categories branch 7 times, most recently from 34fce23 to fb7845c Compare August 3, 2022 18:42
Add type balance with add, display traits. Change affected tests.
Update `CHANGELOG.md`
@danielabrozzoni
Copy link
Member

Rebased

Copy link
Member

@afilini afilini left a comment

Choose a reason for hiding this comment

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

ACK 0f03831

@afilini afilini merged commit 03d3c78 into bitcoindevkit:master Aug 4, 2022
notmandatory added a commit to bitcoindevkit/bdk-ffi that referenced this pull request Sep 8, 2022
3c6075a Add Balance struct and conversion from BdkBalance (thunderbiscuit)
4e15bad Update BDK to version 0.22 (thunderbiscuit)

Pull request description:

  The bindings do not build when attempting this upgrade because `get_balance()` now returns a `Balance` struct (this was merged in bitcoindevkit/bdk#640)

  ```sh
  error[E0308]: mismatched types
     --> src/lib.rs:433:9
      |
  432 |     fn get_balance(&self) -> Result<u64, Error> {
      |                              ------------------ expected `Result<u64, bdk::Error>` because of return type
  433 |         self.get_wallet().get_balance()
      |         ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ expected `u64`, found struct `Balance`
      |
      = note: expected enum `Result<u64, _>`
                 found enum `Result<Balance, _>`

  For more information about this error, try `rustc --explain E0308`.
  error: could not compile `bdk-ffi` due to previous error
  ```

  When we upgrade to `0.22.0` we could decide to add the `Balance` struct to the bindings, or simply return the total by calling `get_total()`, which returns a `u64` (same as we have now).

ACKs for top commit:
  notmandatory:
    ACK 3c6075a

Tree-SHA512: 13d2f83f992735f4f9619ae339d7834df08385129edf06bac830c298b433571af3f211e92a6da1f4f9646dec27dbd2c6133a035f26eac8757b7a1c94b54b463d
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
new feature New feature or request
Projects
Archived in project
Development

Successfully merging this pull request may close these issues.

feature request: unconfirmed balances
5 participants