Skip to content

Commit 9ea5264

Browse files
committed
Add FilledTransaction methods
1 parent cb2e1e2 commit 9ea5264

File tree

1 file changed

+24
-0
lines changed

1 file changed

+24
-0
lines changed

types/src/types.rs

+24
Original file line numberDiff line numberDiff line change
@@ -96,6 +96,30 @@ pub struct FilledTransaction<C> {
9696
pub spent_utxos: Vec<Output<C>>,
9797
}
9898

99+
impl<C: GetValue> FilledTransaction<C> {
100+
pub fn get_value_in(&self) -> u64 {
101+
self.spent_utxos.iter().map(GetValue::get_value).sum()
102+
}
103+
104+
pub fn get_value_out(&self) -> u64 {
105+
self.transaction
106+
.outputs
107+
.iter()
108+
.map(GetValue::get_value)
109+
.sum()
110+
}
111+
112+
pub fn get_fee(&self) -> Option<u64> {
113+
let value_in = self.get_value_in();
114+
let value_out = self.get_value_out();
115+
if value_in < value_out {
116+
None
117+
} else {
118+
Some(value_in - value_out)
119+
}
120+
}
121+
}
122+
99123
#[derive(Debug, Clone, Serialize, Deserialize)]
100124
pub struct AuthorizedTransaction<A, C> {
101125
pub transaction: Transaction<C>,

0 commit comments

Comments
 (0)