Skip to content

Commit

Permalink
ledger: Return new Ledger after a add_utxo call.
Browse files Browse the repository at this point in the history
  • Loading branch information
ceyhunsen committed Jun 7, 2024
1 parent 397ac4e commit 772d76a
Showing 1 changed file with 7 additions and 3 deletions.
10 changes: 7 additions & 3 deletions src/ledger/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -22,8 +22,12 @@ impl Ledger {
}

/// Adds a new UTXO to user's UTXO's.
pub fn add_utxo(&mut self, utxo: TxOut) {
self.utxos.push(utxo);
pub fn add_utxo(&self, utxo: TxOut) -> Self {
let mut ledger = self.clone().to_owned();

ledger.utxos.push(utxo);

ledger
}

/// Adds a new address for user.
Expand Down Expand Up @@ -80,7 +84,7 @@ mod tests {
value: Amount::from_sat(0x45),
script_pubkey: ledger.addresses[0].script_pubkey(),
};
ledger.add_utxo(utxo);
ledger = ledger.add_utxo(utxo);

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

0 comments on commit 772d76a

Please sign in to comment.