Skip to main content

Validate Bitcoin Transactions

HardPremium

Blockchains like Bitcoin use the UTXO (Unspent Transaction Outputs) model to track ownership of coins. In this model, each transaction consumes UTXOs as inputs and creates new UTXOs as outputs. However, there can be invalid transactions where:

  1. The sender does not own the UTXO they're trying to spend.
  2. The same UTXO has already been used as input in another transaction.

You're given the following tables:

  1. transactions table:
    • transaction_id (unique identifier for each transaction)
    • sender (address of the person initiating the transaction)
    • timestamp (time when the transaction was created)
  2. transaction_inputs table:
    • input_id (unique identifier for each input within a transaction)
    • transaction_id (foreign key referencing transactions)
    • utxo_id (foreign key indicating which UTXO is being consumed by this input)
  3. utxo table:
    • utxo_id (unique identifier for the UTXO)
    • address (owner of the UTXO)
    • amount (amount of cryptocurrency represented by the UTXO)

Given these tables, write a SQL query to identify transactions that are potentially invalid based on the above conditions. Your output should have the following column: InvalidTransactionId.