Skip to content

Commit

Permalink
transaction: Add utxo handler.
Browse files Browse the repository at this point in the history
  • Loading branch information
ceyhunsen committed Sep 3, 2024
1 parent 35ca36f commit 92cdd27
Showing 1 changed file with 16 additions and 0 deletions.
16 changes: 16 additions & 0 deletions src/ledger/transactions.rs
Original file line number Diff line number Diff line change
Expand Up @@ -57,6 +57,8 @@ impl Ledger {

self.add_mempool_transaction(txid)?;

self.handle_transaction_utxos(&transaction)?;

Ok(txid)
}

Expand Down Expand Up @@ -267,6 +269,20 @@ impl Ledger {
amount
}

/// Removes inputs from UTXOs and adds outputs to UTXOs.
pub fn handle_transaction_utxos(&self, transaction: &Transaction) -> Result<(), LedgerError> {
for input in &transaction.input {
self.remove_utxo(input.previous_output)?;
}

let txid = transaction.compute_txid();
for vout in 0..(transaction.output.len() as u32) {
self.add_utxo(OutPoint { txid, vout })?;
}

Ok(())
}

/// Creates a `TxIn` with some defaults.
pub fn create_txin(&self, txid: Txid, vout: u32) -> TxIn {
TxIn {
Expand Down

0 comments on commit 92cdd27

Please sign in to comment.