Skip to content

feat(chain): derive Copy and implement AddAssign, Sub, SubAssign, Sum for Balance - #2367

Open
bhuvan-somisetty wants to merge 1 commit into
bitcoindevkit:masterfrom
bhuvan-somisetty:feat-balance-copy-and-ops
Open

bhuvan-somisetty wants to merge 1 commit into
bitcoindevkit:masterfrom
bhuvan-somisetty:feat-balance-copy-and-ops

Conversation

@bhuvan-somisetty

Copy link
Copy Markdown
Contributor

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::Add implementations for reference combinations (&Balance + &Balance, Balance + &Balance, &Balance + Balance).
  • core::ops::AddAssign (Balance += Balance, Balance += &Balance).
  • core::ops::Sub and core::ops::SubAssign (Balance - Balance, Balance -= Balance, etc.).
  • core::iter::Sum for both Balance and &Balance.
  • Unit tests covering all the new operations and Copy behavior.

Closes #2366.

Notes to the reviewers

  • All operations mirror the standard arithmetic conventions of bitcoin::Amount.
  • Non-breaking ergonomic addition.

Changelog notice

Checklists

All Submissions:

New Features:

  • I've added tests for the new feature
  • I've added docs for the new feature

… for Balance

Derive `Copy` on `Balance` and implement `Add` for reference combinations,
`AddAssign`, `Sub`, `SubAssign`, and `Sum` (by value and by reference).

Fixes bitcoindevkit#2366.

Signed-off-by: bhuvan-somisetty <somisettybhuvan5@gmail.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

Status: Triage

Development

Successfully merging this pull request may close these issues.

feat(chain): derive Copy and implement AddAssign, Sub, SubAssign, Sum for Balance

1 participant