user323: Given a Tx message, how does one calculate how big a fee one paid for the transaction?

user575: Use the following pseudocode:
TotalOutputValue = 0
For each Output in tx_out array
  TotalOutputValue += Output[value]
TotalInputValue = 0
For each Input in tx_in array
  PreviousOutput = Input[previous_output]
  PreviousTransaction = PreviousOutput[hash]
  OutputIndex = PreviousOutput[index]
  Look up the transaction with hash PreviousTransaction
  Output = The output with index OutputIndex in that transaction
  TotalInputValue += Output[value]
Fee = TotalInputValue - TotalOutputValue


323: <p>Given a <a href="https://en.bitcoin.it/wiki/Protocol_specification#tx">Tx message</a>, how does one calculate how big a fee one paid for the transaction?</p>
 575: <p>Use the following pseudocode:</p>

<pre><code>TotalOutputValue = 0
For each Output in tx_out array
  TotalOutputValue += Output[value]
TotalInputValue = 0
For each Input in tx_in array
  PreviousOutput = Input[previous_output]
  PreviousTransaction = PreviousOutput[hash]
  OutputIndex = PreviousOutput[index]
  Look up the transaction with hash PreviousTransaction
  Output = The output with index OutputIndex in that transaction
  TotalInputValue += Output[value]
Fee = TotalInputValue - TotalOutputValue
</code></pre>
