Finalize Transaction

From Open Transactions
Revision as of 10:23, 23 October 2014 by GuilhermeSalgado (talk | contribs)
Jump to navigation Jump to search

Initial Conditions

  • An unfinished transaction is ready for processing.
    • The transaction may or may not have have a useful (non-change) output
    • The transaction is valid
      • Not too big
      • Inputs are sufficient to cover outputs and required fees
    • A change output may exist in the transaction
      • If a change output exists, it has a nil position and a nil value.

Sequence

  1. If the transaction only contains a change output and no inputs, then it may be discarded.
  2. The change amount is calculated by: Σ(txin) - ( Σ(txout) + fees )
    1. If the change amount is greater than zero:
      1. Set the value of the output
      2. Set the position of the output to the next unused value after the last non-change output.
    2. If the change amount is zero, then the change output is removed from the transaction.
  3. Calculate an ntxid for the transaction for tracking purposes.
  4. Loop through every (non-change) output in the transaction and update the withdrawal status object for the corresponding output.
    1. The withdrawal status object contain an entry for every output in the transaction, where each entry has an outpoints object containing a nil ntxid, an index matching the output position index, and a matching amount.
    2. Update the ntxid value from nil to the ntxid for the transaction.
  5. Add the fees from this transaction to the fees property of the withdrawal status object.
  6. Move the transaction to the finished transaction list.