From 772d76a8e5ff2cf8fe457e91e7d58d79d11e5a51 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Ceyhun=20=C5=9Een?= Date: Fri, 7 Jun 2024 12:54:25 +0300 Subject: [PATCH] ledger: Return new Ledger after a add_utxo call. --- src/ledger/mod.rs | 10 +++++++--- 1 file changed, 7 insertions(+), 3 deletions(-) diff --git a/src/ledger/mod.rs b/src/ledger/mod.rs index 3b8b1cf..e5149bf 100644 --- a/src/ledger/mod.rs +++ b/src/ledger/mod.rs @@ -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. @@ -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));