changed get transaction list api point to use comma separated txids

Signed-off-by: Lorenz Herzberger <lorenzherzberger@gmail.com>
This commit is contained in:
Lorenz Herzberger 2022-05-03 16:11:09 +02:00
parent 99b5313981
commit d723f87308
No known key found for this signature in database
GPG Key ID: FA5EE906EB55316A
5 changed files with 19 additions and 13 deletions

View File

@ -75,9 +75,9 @@ lint: check-deps ## Lint the project
test: check-deps test-unit test-acceptance ## Run unit and acceptance tests test: check-deps test-unit test-acceptance ## Run unit and acceptance tests
test-unit: check-deps ## Run all tests once test-unit: check-deps ## Run all tests once or specify a file/test with TEST=tests/file.py::Class::test
@$(DC) up -d bdb @$(DC) up -d bdb
@$(DC) exec planetmint pytest @$(DC) exec planetmint pytest ${TEST}
test-unit-watch: check-deps ## Run all tests and wait. Every time you change code, tests will be run again test-unit-watch: check-deps ## Run all tests and wait. Every time you change code, tests will be run again
@$(DC) run --rm --no-deps planetmint pytest -f @$(DC) run --rm --no-deps planetmint pytest -f

View File

@ -263,11 +263,10 @@ class Planetmint(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)
# TODO: change this to asset_ids, check references of function def get_transactions_filtered(self, asset_ids, operation=None, last_tx=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_ids,
operation, last_tx) operation, last_tx)
for txid in txids: for txid in txids:
yield self.get_transaction(txid) yield self.get_transaction(txid)

View File

@ -13,6 +13,13 @@ def valid_txid(txid):
return txid.lower() return txid.lower()
raise ValueError('Invalid hash') raise ValueError('Invalid hash')
def valid_txid_list(txids):
txids = txids.split(',')
r = re.compile('^[a-fA-F0-9]{64}$')
valid_txids = list(filter(r.match, txids))
if not len(txids) == len(valid_txids):
raise ValueError('List contains invalid hash')
return [txid.lower() for txid in valid_txids]
def valid_bool(val): def valid_bool(val):
val = val.lower() val = val.lower()

View File

@ -47,7 +47,7 @@ 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_ids', type=parameters.valid_txid_list,
required=True) required=True)
parser.add_argument('last_tx', type=parameters.valid_bool, parser.add_argument('last_tx', type=parameters.valid_bool,
required=False) required=False)

View File

@ -369,24 +369,24 @@ def test_transactions_get_list_good(client):
return [type('', (), {'to_dict': partial(lambda a: a, arg)}) return [type('', (), {'to_dict': partial(lambda a: a, arg)})
for arg in sorted(args.items())] for arg in sorted(args.items())]
asset_id = '1' * 64 asset_ids = ['1' * 64]
with patch('planetmint.Planetmint.get_transactions_filtered', get_txs_patched): with patch('planetmint.Planetmint.get_transactions_filtered', get_txs_patched):
url = TX_ENDPOINT + '?asset_id=' + asset_id url = TX_ENDPOINT + '?asset_ids=' + ','.join(asset_ids)
assert client.get(url).json == [ assert client.get(url).json == [
['asset_id', asset_id], ['asset_ids', asset_ids],
['last_tx', None], ['last_tx', None],
['operation', None] ['operation', None]
] ]
url = TX_ENDPOINT + '?asset_id=' + asset_id + '&operation=CREATE' url = TX_ENDPOINT + '?asset_ids=' + ','.join(asset_ids) + '&operation=CREATE'
assert client.get(url).json == [ assert client.get(url).json == [
['asset_id', asset_id], ['asset_ids', asset_ids],
['last_tx', None], ['last_tx', None],
['operation', 'CREATE'] ['operation', 'CREATE']
] ]
url = TX_ENDPOINT + '?asset_id=' + asset_id + '&last_tx=true' url = TX_ENDPOINT + '?asset_ids=' + ','.join(asset_ids) + '&last_tx=true'
assert client.get(url).json == [ assert client.get(url).json == [
['asset_id', asset_id], ['asset_ids', asset_ids],
['last_tx', True], ['last_tx', True],
['operation', None] ['operation', None]
] ]