The double-spendable transaction is a transaction with the same value as the first transaction but with a different recipient address. The fund transfer is reversed by addressing the entire fund back to the attacker. All the transaction outputs except the transaction output carrying change are removed from the transaction. Since the change transaction output is addressed to the attacker, the entire fund value is assigned to this output transaction.
A similar process is used as before to calculate the fee for the entire transaction. A higher transaction fee per byte, feeperbyte2, is used when calculating the fee for the transaction:
tx.vout = tx.vout[0:1] change_txout = tx.vout[0] value_out = value_in ...