Skip to content

Commit 772d76a

Browse files
committed
ledger: Return new Ledger after a add_utxo call.
1 parent 397ac4e commit 772d76a

File tree

1 file changed

+7
-3
lines changed

1 file changed

+7
-3
lines changed

src/ledger/mod.rs

+7-3
Original file line numberDiff line numberDiff line change
@@ -22,8 +22,12 @@ impl Ledger {
2222
}
2323

2424
/// Adds a new UTXO to user's UTXO's.
25-
pub fn add_utxo(&mut self, utxo: TxOut) {
26-
self.utxos.push(utxo);
25+
pub fn add_utxo(&self, utxo: TxOut) -> Self {
26+
let mut ledger = self.clone().to_owned();
27+
28+
ledger.utxos.push(utxo);
29+
30+
ledger
2731
}
2832

2933
/// Adds a new address for user.
@@ -80,7 +84,7 @@ mod tests {
8084
value: Amount::from_sat(0x45),
8185
script_pubkey: ledger.addresses[0].script_pubkey(),
8286
};
83-
ledger.add_utxo(utxo);
87+
ledger = ledger.add_utxo(utxo);
8488

8589
assert_eq!(ledger.utxos.len(), 1);
8690
assert_eq!(ledger.utxos[0].value, Amount::from_sat(0x45));

0 commit comments

Comments
 (0)