1use bitcoin::Amount;
2
3#[derive(Debug, PartialEq, Eq, Clone, Default)]
5#[cfg_attr(feature = "serde", derive(serde::Deserialize, serde::Serialize))]
6pub struct Balance {
7 pub immature: Amount,
9 pub trusted_pending: Amount,
11 pub untrusted_pending: Amount,
13 pub confirmed: Amount,
15}
16
17impl Balance {
18 pub fn trusted_spendable(&self) -> Amount {
23 self.confirmed + self.trusted_pending
24 }
25
26 pub fn total(&self) -> Amount {
28 self.confirmed + self.trusted_pending + self.untrusted_pending + self.immature
29 }
30}
31
32impl core::fmt::Display for Balance {
33 fn fmt(&self, f: &mut core::fmt::Formatter<'_>) -> core::fmt::Result {
34 write!(
35 f,
36 "{{ immature: {}, trusted_pending: {}, untrusted_pending: {}, confirmed: {} }}",
37 self.immature, self.trusted_pending, self.untrusted_pending, self.confirmed
38 )
39 }
40}
41
42impl core::ops::Add for Balance {
43 type Output = Self;
44
45 fn add(self, other: Self) -> Self {
46 Self {
47 immature: self.immature + other.immature,
48 trusted_pending: self.trusted_pending + other.trusted_pending,
49 untrusted_pending: self.untrusted_pending + other.untrusted_pending,
50 confirmed: self.confirmed + other.confirmed,
51 }
52 }
53}