Skip to content

Commit 92cdd27

Browse files
committed
transaction: Add utxo handler.
1 parent 35ca36f commit 92cdd27

File tree

1 file changed

+16
-0
lines changed

1 file changed

+16
-0
lines changed

Diff for: src/ledger/transactions.rs

+16
Original file line numberDiff line numberDiff line change
@@ -57,6 +57,8 @@ impl Ledger {
5757

5858
self.add_mempool_transaction(txid)?;
5959

60+
self.handle_transaction_utxos(&transaction)?;
61+
6062
Ok(txid)
6163
}
6264

@@ -267,6 +269,20 @@ impl Ledger {
267269
amount
268270
}
269271

272+
/// Removes inputs from UTXOs and adds outputs to UTXOs.
273+
pub fn handle_transaction_utxos(&self, transaction: &Transaction) -> Result<(), LedgerError> {
274+
for input in &transaction.input {
275+
self.remove_utxo(input.previous_output)?;
276+
}
277+
278+
let txid = transaction.compute_txid();
279+
for vout in 0..(transaction.output.len() as u32) {
280+
self.add_utxo(OutPoint { txid, vout })?;
281+
}
282+
283+
Ok(())
284+
}
285+
270286
/// Creates a `TxIn` with some defaults.
271287
pub fn create_txin(&self, txid: Txid, vout: u32) -> TxIn {
272288
TxIn {

0 commit comments

Comments
 (0)