mirror of
https://github.com/bigchaindb/bigchaindb.git
synced 2024-10-13 13:34:05 +00:00
Problem: transaction parameter are not required anymore
Solution: remove transaction parameter
This commit is contained in:
parent
2066450f98
commit
5695672cca
@ -45,13 +45,13 @@ class Transaction(Transaction):
|
|||||||
# transactions in current round
|
# transactions in current round
|
||||||
if ctxn.id == input_txid:
|
if ctxn.id == input_txid:
|
||||||
input_tx = ctxn
|
input_tx = ctxn
|
||||||
status = bigchain.TX_VALID
|
status = 'valid'
|
||||||
|
|
||||||
if input_tx is None:
|
if input_tx is None:
|
||||||
raise InputDoesNotExist("input `{}` doesn't exist"
|
raise InputDoesNotExist("input `{}` doesn't exist"
|
||||||
.format(input_txid))
|
.format(input_txid))
|
||||||
|
|
||||||
if status != bigchain.TX_VALID:
|
if status != 'valid':
|
||||||
raise TransactionNotInValidBlock(
|
raise TransactionNotInValidBlock(
|
||||||
'input `{}` does not exist in a valid block'.format(
|
'input `{}` does not exist in a valid block'.format(
|
||||||
input_txid))
|
input_txid))
|
||||||
|
|||||||
@ -35,12 +35,6 @@ class BigchainDB(object):
|
|||||||
Create, read, sign, write transactions to the database
|
Create, read, sign, write transactions to the database
|
||||||
"""
|
"""
|
||||||
|
|
||||||
TX_VALID = 'valid'
|
|
||||||
"""return if a tx is in valid block"""
|
|
||||||
|
|
||||||
TX_UNDECIDED = 'undecided'
|
|
||||||
"""return if tx is in undecided block"""
|
|
||||||
|
|
||||||
def __init__(self, connection=None):
|
def __init__(self, connection=None):
|
||||||
"""Initialize the Bigchain instance
|
"""Initialize the Bigchain instance
|
||||||
|
|
||||||
@ -265,19 +259,15 @@ class BigchainDB(object):
|
|||||||
transaction = Transaction.from_dict(transaction)
|
transaction = Transaction.from_dict(transaction)
|
||||||
|
|
||||||
if include_status:
|
if include_status:
|
||||||
return transaction, self.TX_VALID if transaction else None
|
return transaction, 'valid' if transaction else None
|
||||||
else:
|
else:
|
||||||
return transaction
|
return transaction
|
||||||
|
|
||||||
def get_transactions_filtered(self, asset_id, operation=None):
|
def get_transactions_filtered(self, asset_id, operation=None):
|
||||||
"""Get a list of transactions filtered on some criteria
|
"""Get a list of transactions filtered on some criteria
|
||||||
"""
|
"""
|
||||||
txids = backend.query.get_txids_filtered(self.connection, asset_id,
|
return backend.query.get_txids_filtered(self.connection, asset_id,
|
||||||
operation)
|
operation)
|
||||||
for txid in txids:
|
|
||||||
tx, status = self.get_transaction(txid, True)
|
|
||||||
if status == self.TX_VALID:
|
|
||||||
yield tx
|
|
||||||
|
|
||||||
def get_outputs_filtered(self, owner, spent=None):
|
def get_outputs_filtered(self, owner, spent=None):
|
||||||
"""Get a list of output links filtered on some criteria
|
"""Get a list of output links filtered on some criteria
|
||||||
@ -416,17 +406,9 @@ class BigchainDB(object):
|
|||||||
Returns:
|
Returns:
|
||||||
iter: An iterator of assets that match the text search.
|
iter: An iterator of assets that match the text search.
|
||||||
"""
|
"""
|
||||||
objects = backend.query.text_search(self.connection, search, limit=limit,
|
return backend.query.text_search(self.connection, search, limit=limit,
|
||||||
table=table)
|
table=table)
|
||||||
|
|
||||||
# TODO: This is not efficient. There may be a more efficient way to
|
|
||||||
# query by storing block ids with the assets and using fastquery.
|
|
||||||
# See https://github.com/bigchaindb/bigchaindb/issues/1496
|
|
||||||
for obj in objects:
|
|
||||||
tx, status = self.get_transaction(obj['id'], True)
|
|
||||||
if status == self.TX_VALID:
|
|
||||||
yield obj
|
|
||||||
|
|
||||||
def get_assets(self, asset_ids):
|
def get_assets(self, asset_ids):
|
||||||
"""Return a list of assets that match the asset_ids
|
"""Return a list of assets that match the asset_ids
|
||||||
|
|
||||||
|
|||||||
@ -30,7 +30,7 @@ class TransactionApi(Resource):
|
|||||||
with pool() as bigchain:
|
with pool() as bigchain:
|
||||||
tx, status = bigchain.get_transaction(tx_id, include_status=True)
|
tx, status = bigchain.get_transaction(tx_id, include_status=True)
|
||||||
|
|
||||||
if not tx or status is not bigchain.TX_VALID:
|
if not tx:
|
||||||
return make_error(404)
|
return make_error(404)
|
||||||
|
|
||||||
return tx.to_dict()
|
return tx.to_dict()
|
||||||
|
|||||||
@ -313,7 +313,6 @@ class TestBigchainApi(object):
|
|||||||
response, status = b.get_transaction(tx.id, include_status=True)
|
response, status = b.get_transaction(tx.id, include_status=True)
|
||||||
# add validity information, which will be returned
|
# add validity information, which will be returned
|
||||||
assert tx.to_dict() == response.to_dict()
|
assert tx.to_dict() == response.to_dict()
|
||||||
assert status == b.TX_UNDECIDED
|
|
||||||
|
|
||||||
@pytest.mark.usefixtures('inputs')
|
@pytest.mark.usefixtures('inputs')
|
||||||
def test_read_transaction_invalid_block(self, b, user_pk, user_sk):
|
def test_read_transaction_invalid_block(self, b, user_pk, user_sk):
|
||||||
|
|||||||
@ -402,25 +402,6 @@ def test_transactions_get_list_bad(client):
|
|||||||
assert client.get(url).status_code == 400
|
assert client.get(url).status_code == 400
|
||||||
|
|
||||||
|
|
||||||
@pytest.mark.tendermint
|
|
||||||
def test_return_only_valid_transaction(client):
|
|
||||||
from bigchaindb.tendermint import BigchainDB
|
|
||||||
|
|
||||||
def get_transaction_patched(status):
|
|
||||||
def inner(self, tx_id, include_status):
|
|
||||||
return {}, status
|
|
||||||
return inner
|
|
||||||
|
|
||||||
# NOTE: `get_transaction` only returns a transaction if it's included in a
|
|
||||||
# VALID block.
|
|
||||||
# As the endpoint uses `get_transaction`, we don't have to test
|
|
||||||
# against invalid transactions here.
|
|
||||||
with patch('bigchaindb.tendermint.BigchainDB.get_transaction',
|
|
||||||
get_transaction_patched(BigchainDB.TX_UNDECIDED)):
|
|
||||||
url = '{}{}'.format(TX_ENDPOINT, '123')
|
|
||||||
assert client.get(url).status_code == 404
|
|
||||||
|
|
||||||
|
|
||||||
@pytest.mark.tendermint
|
@pytest.mark.tendermint
|
||||||
@patch('requests.post')
|
@patch('requests.post')
|
||||||
@pytest.mark.parametrize('mode', [
|
@pytest.mark.parametrize('mode', [
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user