mirror of
https://github.com/bigchaindb/bigchaindb.git
synced 2024-10-13 13:34:05 +00:00
Problem: Spending transaction doesn't return properly (#2318)
Solution: Differentiate between stored spent txns and current spending txns
This commit is contained in:
parent
340d0a2ea1
commit
a2aa4554c0
@ -249,17 +249,20 @@ class BigchainDB(Bigchain):
|
|||||||
'`{}` was spent more than once. There is a problem'
|
'`{}` was spent more than once. There is a problem'
|
||||||
' with the chain'.format(txid))
|
' with the chain'.format(txid))
|
||||||
|
|
||||||
|
current_spent_transactions = []
|
||||||
for ctxn in current_transactions:
|
for ctxn in current_transactions:
|
||||||
for ctxn_input in ctxn.inputs:
|
for ctxn_input in ctxn.inputs:
|
||||||
if ctxn_input.fulfills.txid == txid and\
|
if ctxn_input.fulfills.txid == txid and\
|
||||||
ctxn_input.fulfills.output == output:
|
ctxn_input.fulfills.output == output:
|
||||||
transactions.append(ctxn.to_dict())
|
current_spent_transactions.append(ctxn)
|
||||||
|
|
||||||
transaction = None
|
transaction = None
|
||||||
if len(transactions) > 1:
|
if len(transactions) + len(current_spent_transactions) > 1:
|
||||||
raise DoubleSpend('tx "{}" spends inputs twice'.format(txid))
|
raise DoubleSpend('tx "{}" spends inputs twice'.format(txid))
|
||||||
elif transactions:
|
elif transactions:
|
||||||
transaction = Transaction.from_db(self, transactions[0])
|
transaction = Transaction.from_db(self, transactions[0])
|
||||||
|
elif current_spent_transactions:
|
||||||
|
transaction = current_spent_transactions[0]
|
||||||
|
|
||||||
return transaction
|
return transaction
|
||||||
|
|
||||||
|
@ -377,6 +377,8 @@ def test_get_spent_transaction_critical_double_spend(b, alice, bob, carol):
|
|||||||
|
|
||||||
b.store_bulk_transactions([tx])
|
b.store_bulk_transactions([tx])
|
||||||
|
|
||||||
|
assert b.get_spent(tx.id, tx_transfer.inputs[0].fulfills.output, [tx_transfer])
|
||||||
|
|
||||||
with pytest.raises(DoubleSpend):
|
with pytest.raises(DoubleSpend):
|
||||||
b.get_spent(tx.id, tx_transfer.inputs[0].fulfills.output,
|
b.get_spent(tx.id, tx_transfer.inputs[0].fulfills.output,
|
||||||
[tx_transfer, double_spend])
|
[tx_transfer, double_spend])
|
||||||
|
Loading…
x
Reference in New Issue
Block a user