adjusted get_txids_filtered for new indexes

Signed-off-by: Lorenz Herzberger <lorenzherzberger@gmail.com>
This commit is contained in:
Lorenz Herzberger 2022-12-07 15:45:11 +01:00
parent c623a9fe6c
commit aeb2bba61b
No known key found for this signature in database
GPG Key ID: FA5EE906EB55316A
4 changed files with 29 additions and 33 deletions

View File

@ -13,8 +13,8 @@ class Asset:
data: str = ""
@staticmethod
def from_dict(asset_tuple: dict) -> Asset:
return Asset(asset_tuple["data"])
def from_dict(asset_dict: dict) -> Asset:
return Asset(asset_dict["data"]) if "data" in asset_dict.keys() else Asset(asset_dict["id"])
def to_dict(self) -> dict:
return {

View File

@ -46,6 +46,14 @@ function init()
{ field = 'inputs[*].fulfills["transaction_id"]', type = 'string', is_nullable = true },
{ field = 'inputs[*].fulfills["output_index"]', type = 'unsigned', is_nullable = true }
}})
transactions:create_index('transactions_by_id_and_operation', {
if_not_exists = true,
parts = {
{ field = 'id', type = 'string' },
{ field = 'operation', type = 'string' },
{ field = 'assets[*].id', type = 'string', is_nullable = true }
}
})
-- Outputs

View File

@ -160,42 +160,30 @@ def store_block(connection, block: dict):
@register_query(TarantoolDBConnection)
def get_txids_filtered(
connection, asset_ids: list[str], operation: str = None, last_tx: any = None
): # TODO here is used 'OR' operator
actions = {
"CREATE": {"sets": ["CREATE", asset_ids], "index": "transaction_search"},
# 1 - operation, 2 - id (only in transactions) +
"TRANSFER": {"sets": ["TRANSFER", asset_ids], "index": "transaction_search"},
# 1 - operation, 2 - asset.id (linked mode) + OPERATOR OR
None: {"sets": [asset_ids, asset_ids]},
}[operation]
_transactions = []
if actions["sets"][0] == "CREATE": # +
_transactions = connection.run(
connection.space(TARANT_TABLE_TRANSACTION).select([operation, asset_ids[0]], index=actions["index"])
def get_txids_filtered(connection, asset_ids: list[str], operation: str = "", last_tx: bool = False):
transactions = []
if operation == "CREATE":
transactions = connection.run(
connection.space(TARANT_TABLE_TRANSACTION).select([asset_ids[0], operation], index="transactions_by_id_and_operation")
)
elif actions["sets"][0] == "TRANSFER": # +
_assets = connection.run(connection.space(TARANT_TABLE_ASSETS).select(asset_ids, index="only_asset_search"))
for asset in _assets:
_txid = asset[1]
_tmp_transactions = connection.run(
connection.space(TARANT_TABLE_TRANSACTION).select([operation, _txid], index=actions["index"])
elif operation == "TRANSFER":
transactions = connection.run(
connection.space(TARANT_TABLE_TRANSACTION).select(["", operation, asset_ids], index="transactions_by_id_and_operation")
)
if len(_tmp_transactions) != 0:
_transactions.extend(_tmp_transactions)
else:
_tx_ids = connection.run(connection.space(TARANT_TABLE_TRANSACTION).select(asset_ids, index=TARANT_ID_SEARCH))
_assets_ids = connection.run(
connection.space(TARANT_TABLE_ASSETS).select(asset_ids, index="only_asset_search")
txs = connection.run(connection.space(TARANT_TABLE_TRANSACTION).select(asset_ids, index=TARANT_ID_SEARCH))
asset_txs = connection.run(
connection.space(TARANT_TABLE_TRANSACTION).select(asset_ids, index="transactions_by_asset")
)
return tuple(set([sublist[1] for sublist in _assets_ids] + [sublist[0] for sublist in _tx_ids]))
transactions = txs + asset_txs
ids = tuple([tx[0] for tx in transactions])
# NOTE: check when and where this is used and remove if not
if last_tx:
return tuple(next(iter(_transactions)))
return ids[0]
return tuple([elem[0] for elem in _transactions])
return ids
@register_query(TarantoolDBConnection)

View File

@ -233,7 +233,7 @@ class Planetmint(object):
def get_transactions(self, txn_ids):
return backend.query.get_transactions(self.connection, txn_ids)
def get_transactions_filtered(self, asset_ids, operation=None, last_tx=None):
def get_transactions_filtered(self, asset_ids, operation=None, last_tx=False):
"""Get a list of transactions filtered on some criteria"""
txids = backend.query.get_txids_filtered(self.connection, asset_ids, operation, last_tx)
for txid in txids: