5

The IDs of the unspent transactions are stored in the UTXO database. I assume that it's generated like this by the client:

for block in blocks:
    for transaction in block:
        utxo.remove(transaction.input)
        utxo.add(transaction)

However, I have some doubts: What else is stored in the UTXO database? Does it store the actual amount of unspent coins for each transaction (which would seem necessary for the verification of the uncomfirmed transactions)?

1 Answer 1

8

The UTXO database starts empty and then is updated while the blockchain is parsed in the manner that you described. Only, there can be more than one input and more than one output for a transaction, so I'd put it like this:

for block in blocks:
    for transaction in block:
        for(input in transaction):
            utxoset.remove(input)
        for(output in transaction):
            utxoset.add(output)

Obviously, the block is checked for validity and therefore we know that the inputs and outputs are legit.

The UTXO set then stores the UTXOs referenced by outpoints as key, where an outpoint consists of:

  • TXID: Unique hash identifier of the transaction that created the output
  • index: the position of the output in the transaction's output list

And the information stored in the Transaction Outputs is:

  • value: number of satoshis the output is good for
  • pubkey script: the conditions the output can be spent under

Finally, for each block undo data is generated, in the case that a reorganization occurs.

0

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.