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
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,