]> Untitled Git - bdk/commitdiff
Merge bitcoindevkit/bdk#2367: feat(chain): derive Copy and implement AddAssign, Sum... master github/master
authormerge-script <hello@evanlinjin.me>
Mon, 19 Oct 2026 23:53:34 +0000 (10:53 +1100)
committermerge-script <hello@evanlinjin.me>
Mon, 19 Oct 2026 23:53:34 +0000 (10:53 +1100)
55aba974b4399516f3ad05ffdb92fcea029ec826 feat(chain): derive Copy and implement AddAssign, Sum for Balance (bhuvan-somisetty)

Pull request description:

  ### Description

  `bdk_chain::Balance` contains four `bitcoin::Amount` fields (`immature`, `trusted_pending`, `untrusted_pending`, `confirmed`). Since `Amount` is `Copy`, `Balance` can also derive `Copy`.

  This PR adds:
  - `Copy` derive for `Balance`.
  - `core::ops::AddAssign` for `Balance`.
  - `core::iter::Sum` for `Balance`.
  - Unit test covering `+=` and `sum`.

  Closes #2366.

  ### Notes to the reviewers

  - Non-breaking ergonomic addition.

  ### Changelog notice

  ### Added
  - `bdk_chain`: `Balance` now derives `Copy` and implements `AddAssign` and `Sum`. #2367

  ### Checklists

  #### All Submissions:

  * [x] I followed the [contribution guidelines](https://github.com/bitcoindevkit/bdk/blob/master/CONTRIBUTING.md)

  #### New Features:

  * [x] I've added tests for the new feature
  * [ ] I've added docs for the new feature

  #### Bugfixes:

  * [ ] This pull request breaks the existing API
  * [ ] I've added tests to reproduce the issue which are now passing
  * [x] I'm linking the issue being fixed by this PR

Signed-off-by: bhuvan-somisetty <somisettybhuvan5@gmail.com>
ACKs for top commit:
  evanlinjin:
    ACK 55aba974b4399516f3ad05ffdb92fcea029ec826

Tree-SHA512: 3a3fc3662a2ba79770de98877108e2c042db6966b509729972b61109ae548d971f481c59f0857da6c7ea2ef1973747643e393b97005e202a404b602ba52620da

1  2 
crates/chain/src/balance.rs

index d062b93a4bd4b800f1b3d6971afbe468ba89b35f,dc4db823c970a2b5f88223ecd7cd65f0c1debb8b..b0170538ee93ea48b809e50b2b593f405351a0f7
@@@ -1,11 -1,10 +1,11 @@@
  use bitcoin::Amount;
  
  /// Balance, differentiated into various categories.
- #[derive(Debug, PartialEq, Eq, Clone, Default)]
+ #[derive(Debug, PartialEq, Eq, Clone, Copy, Default)]
  #[cfg_attr(feature = "serde", derive(serde::Deserialize, serde::Serialize))]
  pub struct Balance {
 -    /// All coinbase outputs not yet matured
 +    /// Outputs not yet spendable by consensus (immature coinbase or unmet timelock), confirmed or
 +    /// not.
      pub immature: Amount,
      /// Unconfirmed UTXOs generated by a wallet tx
      pub trusted_pending: Amount,