diff --git a/planetmint/backend/tarantool/query.py b/planetmint/backend/tarantool/query.py index 39dc0a8..8eae34a 100644 --- a/planetmint/backend/tarantool/query.py +++ b/planetmint/backend/tarantool/query.py @@ -192,22 +192,22 @@ def store_block(connection, block: dict): @register_query(TarantoolDBConnection) def get_txids_filtered( - connection, asset_id: str, operation: str = None, last_tx: any = None + connection, asset_ids: list[str], operation: str = None, last_tx: any = None ): # TODO here is used 'OR' operator actions = { - "CREATE": {"sets": ["CREATE", asset_id], "index": "transaction_search"}, + "CREATE": {"sets": ["CREATE", asset_ids], "index": "transaction_search"}, # 1 - operation, 2 - id (only in transactions) + - "TRANSFER": {"sets": ["TRANSFER", asset_id], "index": "transaction_search"}, + "TRANSFER": {"sets": ["TRANSFER", asset_ids], "index": "transaction_search"}, # 1 - operation, 2 - asset.id (linked mode) + OPERATOR OR - None: {"sets": [asset_id, asset_id]}, + None: {"sets": [asset_ids, asset_ids]}, }[operation] _transactions = [] if actions["sets"][0] == "CREATE": # + _transactions = connection.run( - connection.space("transactions").select([operation, asset_id], index=actions["index"]) + connection.space("transactions").select([operation, asset_ids[0]], index=actions["index"]) ) elif actions["sets"][0] == "TRANSFER": # + - _assets = connection.run(connection.space("assets").select([asset_id], index="only_asset_search")) + _assets = connection.run(connection.space("assets").select(asset_ids, index="only_asset_search")) for asset in _assets: _txid = asset[1] @@ -217,8 +217,8 @@ def get_txids_filtered( if len(_tmp_transactions) != 0: _transactions.extend(_tmp_transactions) else: - _tx_ids = connection.run(connection.space("transactions").select([asset_id], index="id_search")) - _assets_ids = connection.run(connection.space("assets").select([asset_id], index="only_asset_search")) + _tx_ids = connection.run(connection.space("transactions").select(asset_ids, index="id_search")) + _assets_ids = connection.run(connection.space("assets").select(asset_ids, index="only_asset_search")) return tuple(set([sublist[1] for sublist in _assets_ids] + [sublist[0] for sublist in _tx_ids])) if last_tx: diff --git a/planetmint/web/websocket_dispatcher.py b/planetmint/web/websocket_dispatcher.py index 3f423f1..8bf5aae 100644 --- a/planetmint/web/websocket_dispatcher.py +++ b/planetmint/web/websocket_dispatcher.py @@ -57,11 +57,11 @@ class Dispatcher: @staticmethod def eventify_block(block): for tx in block["transactions"]: - if tx.asset: - asset_id = tx.asset.get("id", tx.id) + if tx.assets: + asset_ids = [asset.get("id", tx.id) for asset in tx.assets] else: - asset_id = tx.id - yield {"height": block["height"], "asset_id": asset_id, "transaction_id": tx.id} + asset_ids = [tx.id] + yield {"height": block["height"], "asset_ids": asset_ids, "transaction_id": tx.id} async def publish(self): """Publish new events to the subscribers.""" diff --git a/tests/backend/tarantool/test_queries.py b/tests/backend/tarantool/test_queries.py index 32c310e..74e6041 100644 --- a/tests/backend/tarantool/test_queries.py +++ b/tests/backend/tarantool/test_queries.py @@ -28,15 +28,15 @@ def test_get_txids_filtered(signed_create_tx, signed_transfer_tx, db_conn): asset_id = Transaction.get_asset_id([signed_create_tx, signed_transfer_tx]) # Test get by just asset id - txids = set(query.get_txids_filtered(connection=db_conn, asset_id=asset_id)) + txids = set(query.get_txids_filtered(connection=db_conn, asset_ids=[asset_id])) assert txids == {signed_create_tx.id, signed_transfer_tx.id} # Test get by asset and CREATE - txids = set(query.get_txids_filtered(connection=db_conn, asset_id=asset_id, operation=Transaction.CREATE)) + txids = set(query.get_txids_filtered(connection=db_conn, asset_ids=[asset_id], operation=Transaction.CREATE)) assert txids == {signed_create_tx.id} # Test get by asset and TRANSFER - txids = set(query.get_txids_filtered(connection=db_conn, asset_id=asset_id, operation=Transaction.TRANSFER)) + txids = set(query.get_txids_filtered(connection=db_conn, asset_ids=[asset_id], operation=Transaction.TRANSFER)) assert txids == {signed_transfer_tx.id} diff --git a/tests/web/test_transactions.py b/tests/web/test_transactions.py index 5fae4e3..998fd24 100644 --- a/tests/web/test_transactions.py +++ b/tests/web/test_transactions.py @@ -397,13 +397,13 @@ def test_transactions_get_list_good(client): ["last_tx", None], ["operation", None], ] - url = TX_ENDPOINT + "?asset_id=" + ','.join(asset_ids) + "&operation=CREATE" + url = TX_ENDPOINT + "?asset_ids=" + ','.join(asset_ids) + "&operation=CREATE" assert client.get(url).json == [ ["asset_ids", asset_ids], ["last_tx", None], ["operation", "CREATE"], ] - url = TX_ENDPOINT + "?asset_id=" + ','.join(asset_ids) + "&last_tx=true" + url = TX_ENDPOINT + "?asset_ids=" + ','.join(asset_ids) + "&last_tx=true" assert client.get(url).json == [ ["asset_ids", asset_ids], ["last_tx", True], diff --git a/tests/web/test_websocket_server.py b/tests/web/test_websocket_server.py index 6d577f6..454a868 100644 --- a/tests/web/test_websocket_server.py +++ b/tests/web/test_websocket_server.py @@ -37,8 +37,8 @@ def test_eventify_block_works_with_any_transaction(): block = {"height": 1, "transactions": [tx, tx_transfer]} expected_events = [ - {"height": 1, "asset_id": tx.id, "transaction_id": tx.id}, - {"height": 1, "asset_id": tx_transfer.assets[0]["id"], "transaction_id": tx_transfer.id}, + {"height": 1, "asset_ids": [tx.id], "transaction_id": tx.id}, + {"height": 1, "asset_ids": [tx_transfer.assets[0]["id"]], "transaction_id": tx_transfer.id}, ] for event, expected in zip(Dispatcher.eventify_block(block), expected_events): @@ -192,7 +192,7 @@ async def test_websocket_transaction_event(aiohttp_client, event_loop): json_result = json.loads(result.data) assert json_result["transaction_id"] == tx.id # Since the transactions are all CREATEs, asset id == transaction id - assert json_result["asset_id"] == tx.id + assert json_result["asset_ids"] == [tx.id] assert json_result["height"] == block["height"] await tx_source.put(events.POISON_PILL)