mirror of
https://github.com/bigchaindb/bigchaindb.git
synced 2024-10-13 13:34:05 +00:00
added last_tx switch to the TX get query to only get the latest TX for a given asset.
Signed-off-by: Juergen Eckel <juergen@riddleandcode.com>
This commit is contained in:
parent
c801c833fc
commit
a9476719a8
@ -261,7 +261,7 @@ class BigchainDB(object):
|
|||||||
def get_transactions(self, txn_ids):
|
def get_transactions(self, txn_ids):
|
||||||
return backend.query.get_transactions(self.connection, txn_ids)
|
return backend.query.get_transactions(self.connection, txn_ids)
|
||||||
|
|
||||||
def get_transactions_filtered(self, asset_id, operation=None):
|
def get_transactions_filtered(self, asset_id, operation=None, last_tx=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,
|
txids = backend.query.get_txids_filtered(self.connection, asset_id,
|
||||||
|
|||||||
@ -41,19 +41,31 @@ class TransactionApi(Resource):
|
|||||||
|
|
||||||
return tx.to_dict()
|
return tx.to_dict()
|
||||||
|
|
||||||
|
|
||||||
class TransactionListApi(Resource):
|
class TransactionListApi(Resource):
|
||||||
|
|
||||||
def get(self):
|
def get(self):
|
||||||
parser = reqparse.RequestParser()
|
parser = reqparse.RequestParser()
|
||||||
parser.add_argument('operation', type=parameters.valid_operation)
|
parser.add_argument('operation', type=parameters.valid_operation)
|
||||||
parser.add_argument('asset_id', type=parameters.valid_txid,
|
parser.add_argument('asset_id', type=parameters.valid_txid,
|
||||||
required=True)
|
required=True)
|
||||||
|
parser.add_argument('last_tx', type=parameters.valid_bool,
|
||||||
|
required=False)
|
||||||
args = parser.parse_args()
|
args = parser.parse_args()
|
||||||
|
|
||||||
with current_app.config['bigchain_pool']() as bigchain:
|
with current_app.config['bigchain_pool']() as bigchain:
|
||||||
txs = bigchain.get_transactions_filtered(**args)
|
txs = bigchain.get_transactions_filtered(**args)
|
||||||
|
print( txs )
|
||||||
|
if args['last_tx'] and args['last_tx']==True:
|
||||||
|
lastTX = None
|
||||||
|
for x in txs:
|
||||||
|
lastTX = x
|
||||||
|
|
||||||
return [tx.to_dict() for tx in txs]
|
if lastTX:
|
||||||
|
return [ lastTX.to_dict() ]
|
||||||
|
else:
|
||||||
|
return []
|
||||||
|
else:
|
||||||
|
return [tx.to_dict() for tx in txs]
|
||||||
|
|
||||||
def post(self):
|
def post(self):
|
||||||
"""API endpoint to push transactions to the Federation.
|
"""API endpoint to push transactions to the Federation.
|
||||||
|
|||||||
@ -91,7 +91,7 @@ Transactions
|
|||||||
Requests to the ``/api/v1/transactions`` endpoint
|
Requests to the ``/api/v1/transactions`` endpoint
|
||||||
without any query parameters will get a response status code ``400 Bad Request``.
|
without any query parameters will get a response status code ``400 Bad Request``.
|
||||||
|
|
||||||
.. http:get:: /api/v1/transactions?asset_id={asset_id}&operation={CREATE|TRANSFER}
|
.. http:get:: /api/v1/transactions?asset_id={asset_id}&operation={CREATE|TRANSFER}&last_tx={true|false}
|
||||||
|
|
||||||
Get a list of transactions that use an asset with the ID ``asset_id``.
|
Get a list of transactions that use an asset with the ID ``asset_id``.
|
||||||
|
|
||||||
@ -106,12 +106,18 @@ Transactions
|
|||||||
If ``operation`` is not included, then *every* transaction involving
|
If ``operation`` is not included, then *every* transaction involving
|
||||||
the asset with ID ``asset_id`` will be returned.
|
the asset with ID ``asset_id`` will be returned.
|
||||||
|
|
||||||
|
if ``last_tx`` is set to ``true``, only the last transaction is returned
|
||||||
|
instead of all transactions with the given ``asset_id``.
|
||||||
|
|
||||||
This endpoint returns transactions only if they are in committed blocks.
|
This endpoint returns transactions only if they are in committed blocks.
|
||||||
|
|
||||||
:query string operation: (Optional) ``CREATE`` or ``TRANSFER``.
|
:query string operation: (Optional) ``CREATE`` or ``TRANSFER``.
|
||||||
|
|
||||||
:query string asset_id: asset ID.
|
:query string asset_id: asset ID.
|
||||||
|
|
||||||
|
:query string last_tx: (Optional) ``true`` or ``false``.
|
||||||
|
|
||||||
|
|
||||||
**Example request**:
|
**Example request**:
|
||||||
|
|
||||||
.. literalinclude:: http-samples/get-tx-by-asset-request.http
|
.. literalinclude:: http-samples/get-tx-by-asset-request.http
|
||||||
@ -141,7 +147,7 @@ Transactions
|
|||||||
Otherwise, the node will send the transaction to Tendermint (in the same node) using the
|
Otherwise, the node will send the transaction to Tendermint (in the same node) using the
|
||||||
`Tendermint broadcast API
|
`Tendermint broadcast API
|
||||||
<https://tendermint.com/docs/tendermint-core/using-tendermint.html#broadcast-api>`_.
|
<https://tendermint.com/docs/tendermint-core/using-tendermint.html#broadcast-api>`_.
|
||||||
|
|
||||||
The meaning of the ``mode`` query parameter is inherited from the mode parameter in
|
The meaning of the ``mode`` query parameter is inherited from the mode parameter in
|
||||||
`Tendermint's broadcast API
|
`Tendermint's broadcast API
|
||||||
<https://tendermint.com/docs/tendermint-core/using-tendermint.html#broadcast-api>`_.
|
<https://tendermint.com/docs/tendermint-core/using-tendermint.html#broadcast-api>`_.
|
||||||
@ -191,7 +197,7 @@ Transactions
|
|||||||
:resheader Content-Type: ``application/json``
|
:resheader Content-Type: ``application/json``
|
||||||
|
|
||||||
:statuscode 202: The meaning of this response depends on the value
|
:statuscode 202: The meaning of this response depends on the value
|
||||||
of the ``mode`` parameter. See above.
|
of the ``mode`` parameter. See above.
|
||||||
|
|
||||||
:statuscode 400: The posted transaction was invalid.
|
:statuscode 400: The posted transaction was invalid.
|
||||||
|
|
||||||
@ -347,14 +353,14 @@ Assets
|
|||||||
.. http:get:: /api/v1/assets/?search={search}
|
.. http:get:: /api/v1/assets/?search={search}
|
||||||
|
|
||||||
Return all assets that match a given text search.
|
Return all assets that match a given text search.
|
||||||
|
|
||||||
.. note::
|
.. note::
|
||||||
|
|
||||||
The ``id`` of the asset
|
The ``id`` of the asset
|
||||||
is the same ``id`` of the CREATE transaction that created the asset.
|
is the same ``id`` of the CREATE transaction that created the asset.
|
||||||
|
|
||||||
.. note::
|
.. note::
|
||||||
|
|
||||||
You can use ``assets/?search`` or ``assets?search``.
|
You can use ``assets/?search`` or ``assets?search``.
|
||||||
|
|
||||||
If no assets match the text search it returns an empty list.
|
If no assets match the text search it returns an empty list.
|
||||||
@ -471,14 +477,14 @@ Transaction Metadata
|
|||||||
.. http:get:: /api/v1/metadata/?search={search}
|
.. http:get:: /api/v1/metadata/?search={search}
|
||||||
|
|
||||||
Return all metadata objects that match a given text search.
|
Return all metadata objects that match a given text search.
|
||||||
|
|
||||||
.. note::
|
.. note::
|
||||||
|
|
||||||
The ``id`` of the metadata
|
The ``id`` of the metadata
|
||||||
is the same ``id`` of the transaction where it was defined.
|
is the same ``id`` of the transaction where it was defined.
|
||||||
|
|
||||||
.. note::
|
.. note::
|
||||||
|
|
||||||
You can use ``metadata/?search`` or ``metadata?search``.
|
You can use ``metadata/?search`` or ``metadata?search``.
|
||||||
|
|
||||||
If no metadata objects match the text search it returns an empty list.
|
If no metadata objects match the text search it returns an empty list.
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user