Problem: Spending transaction doesn't return properly (#2318)

Solution: Differentiate between stored spent txns and current spending txns
This commit is contained in:
Vanshdeep Singh 2018-05-29 17:43:42 +02:00 committed by vrde
parent 340d0a2ea1
commit a2aa4554c0
2 changed files with 7 additions and 2 deletions

View File

@ -249,17 +249,20 @@ class BigchainDB(Bigchain):
'`{}` was spent more than once. There is a problem'
' with the chain'.format(txid))
current_spent_transactions = []
for ctxn in current_transactions:
for ctxn_input in ctxn.inputs:
if ctxn_input.fulfills.txid == txid and\
ctxn_input.fulfills.output == output:
transactions.append(ctxn.to_dict())
current_spent_transactions.append(ctxn)
transaction = None
if len(transactions) > 1:
if len(transactions) + len(current_spent_transactions) > 1:
raise DoubleSpend('tx "{}" spends inputs twice'.format(txid))
elif transactions:
transaction = Transaction.from_db(self, transactions[0])
elif current_spent_transactions:
transaction = current_spent_transactions[0]
return transaction

View File

@ -377,6 +377,8 @@ def test_get_spent_transaction_critical_double_spend(b, alice, bob, carol):
b.store_bulk_transactions([tx])
assert b.get_spent(tx.id, tx_transfer.inputs[0].fulfills.output, [tx_transfer])
with pytest.raises(DoubleSpend):
b.get_spent(tx.id, tx_transfer.inputs[0].fulfills.output,
[tx_transfer, double_spend])