Skip to content

misleading spendable balance #797

@zoedberg

Description

@zoedberg

Describe the bug

I've noticed a strange behaviour of the get_balance API.

To Reproduce

Creating a new wallet and sending some funds to it produces the following balance:

spendable: 0
total: 10000
immature: 0
confirmed: 0
trusted pending: 0
untrusted pending: 10000

Since the spendable balance is 0 I assumed it was not possible to send funds, but still I've been able to spend the funds and bdk now reports the following balance:

spendable: 8859
total: 8859
immature: 0
confirmed: 0
trusted pending: 8859
untrusted pending: 0

Maybe this is not a bug and is just a matter of naming, but to me spendable should reflect the amount of funds that is possible to spend.

Expected behavior

I see that you documented spendable as the "sum of trusted_pending and confirmed coins", so IMO a more fitting name could be safe_to_spend balance.

Moreover we probably need also a spendable balance defined as the sum of funds that can be spent, that I think will be the sum of all balances except the immature one.

Build environment

  • BDK tag/commit: v0.24.0
  • OS+version: debian 11
  • Rust/Cargo version: 1.65.0
  • Rust/Cargo target: x86_64-unknown-linux-gnu

Metadata

Metadata

Assignees

No one assigned

    Labels

    apiA breaking API changebugSomething isn't workingmodule-wallet

    Type

    No type

    Projects

    Status

    Done

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions