mirror of
https://github.com/planetmint/planetmint.git
synced 2025-11-24 14:35:45 +00:00
Fix more tests
Signed-off-by: cybnon <stefan.weber93@googlemail.com>
This commit is contained in:
parent
3edd365646
commit
ba37a68a3a
@ -100,6 +100,19 @@ def get_asset(connection, asset_id) -> Asset:
|
|||||||
|
|
||||||
raise NotImplementedError
|
raise NotImplementedError
|
||||||
|
|
||||||
|
@singledispatch
|
||||||
|
def get_assets_by_tx_id(connection, tx_id: str) -> list[Asset]:
|
||||||
|
"""Get assets by transaction id.
|
||||||
|
|
||||||
|
Args:
|
||||||
|
tx_id (str): the id of the transaction.
|
||||||
|
|
||||||
|
Returns:
|
||||||
|
The result of the operation.
|
||||||
|
"""
|
||||||
|
|
||||||
|
raise NotImplementedError
|
||||||
|
|
||||||
|
|
||||||
@singledispatch
|
@singledispatch
|
||||||
def get_spent(connection, transaction_id, condition_id):
|
def get_spent(connection, transaction_id, condition_id):
|
||||||
|
|||||||
@ -33,7 +33,7 @@ def _group_transaction_by_ids(connection, txids: list):
|
|||||||
_txinputs = get_inputs_by_tx_id(connection, txid)
|
_txinputs = get_inputs_by_tx_id(connection, txid)
|
||||||
_txoutputs = get_outputs_by_tx_id(connection, txid)
|
_txoutputs = get_outputs_by_tx_id(connection, txid)
|
||||||
_txkeys = get_keys_by_tx_id(connection, txid)
|
_txkeys = get_keys_by_tx_id(connection, txid)
|
||||||
_txassets = get_assets(connection, [txid])
|
_txassets = get_assets_by_tx_id(connection, txid)
|
||||||
_txmeta = get_metadata_by_tx_id(connection, txid)
|
_txmeta = get_metadata_by_tx_id(connection, txid)
|
||||||
_txscript = get_script_by_tx_id(connection, txid)
|
_txscript = get_script_by_tx_id(connection, txid)
|
||||||
|
|
||||||
@ -243,12 +243,28 @@ def get_assets(connection, assets_ids: list) -> list[Asset]:
|
|||||||
_returned_data = []
|
_returned_data = []
|
||||||
for _id in list(set(assets_ids)):
|
for _id in list(set(assets_ids)):
|
||||||
res = connection.run(connection.space(TARANT_TABLE_ASSETS).select(_id, index=TARANT_TX_ID_SEARCH))
|
res = connection.run(connection.space(TARANT_TABLE_ASSETS).select(_id, index=TARANT_TX_ID_SEARCH))
|
||||||
|
if len(res) is 0:
|
||||||
|
continue
|
||||||
_returned_data.append(res[0])
|
_returned_data.append(res[0])
|
||||||
|
|
||||||
sorted_assets = sorted(_returned_data, key=lambda k: k[1], reverse=False)
|
sorted_assets = sorted(_returned_data, key=lambda k: k[1], reverse=False)
|
||||||
return [Asset.from_tuple(asset) for asset in sorted_assets]
|
return [Asset.from_tuple(asset) for asset in sorted_assets]
|
||||||
|
|
||||||
|
|
||||||
|
@register_query(TarantoolDBConnection)
|
||||||
|
def get_assets_by_tx_id(connection, tx_id: str) -> list[Asset]:
|
||||||
|
res = connection.run(connection.space(TARANT_TABLE_ASSETS).select(tx_id, index=TARANT_TX_ID_SEARCH))
|
||||||
|
if len(res) > 1:
|
||||||
|
return _from_tuple_list_to_asset_list(res)
|
||||||
|
|
||||||
|
sorted_assets = sorted(res, key=lambda k: k[1], reverse=False)
|
||||||
|
return _from_tuple_list_to_asset_list(sorted_assets)
|
||||||
|
|
||||||
|
|
||||||
|
def _from_tuple_list_to_asset_list(_data: list) -> list[Asset]:
|
||||||
|
return [Asset.from_tuple(asset) for asset in _data]
|
||||||
|
|
||||||
|
|
||||||
@register_query(TarantoolDBConnection)
|
@register_query(TarantoolDBConnection)
|
||||||
def get_spent(connection, fullfil_transaction_id: str, fullfil_output_index: str):
|
def get_spent(connection, fullfil_transaction_id: str, fullfil_output_index: str):
|
||||||
_inputs = connection.run(
|
_inputs = connection.run(
|
||||||
|
|||||||
@ -18,7 +18,7 @@ class FastQuery:
|
|||||||
"""Get outputs for a public key"""
|
"""Get outputs for a public key"""
|
||||||
txs = list(query.get_owned_ids(self.connection, public_key))
|
txs = list(query.get_owned_ids(self.connection, public_key))
|
||||||
return [
|
return [
|
||||||
TransactionLink(tx["id"], index)
|
TransactionLink(tx["transactions"].id, index)
|
||||||
for tx in txs
|
for tx in txs
|
||||||
for index, output in enumerate(tx["outputs"])
|
for index, output in enumerate(tx["outputs"])
|
||||||
if condition_details_has_owner(output["condition"]["details"], public_key)
|
if condition_details_has_owner(output["condition"]["details"], public_key)
|
||||||
|
|||||||
@ -262,7 +262,6 @@ class Planetmint(object):
|
|||||||
|
|
||||||
def get_spent(self, txid, output, current_transactions=[]):
|
def get_spent(self, txid, output, current_transactions=[]):
|
||||||
transactions = backend.query.get_spent(self.connection, txid, output)
|
transactions = backend.query.get_spent(self.connection, txid, output)
|
||||||
transactions = list(transactions) if transactions else []
|
|
||||||
if len(transactions) > 1:
|
if len(transactions) > 1:
|
||||||
raise core_exceptions.CriticalDoubleSpend(
|
raise core_exceptions.CriticalDoubleSpend(
|
||||||
"`{}` was spent more than once. There is a problem" " with the chain".format(txid)
|
"`{}` was spent more than once. There is a problem" " with the chain".format(txid)
|
||||||
@ -278,10 +277,10 @@ class Planetmint(object):
|
|||||||
if len(transactions) + len(current_spent_transactions) > 1:
|
if len(transactions) + len(current_spent_transactions) > 1:
|
||||||
raise DoubleSpend('tx "{}" spends inputs twice'.format(txid))
|
raise DoubleSpend('tx "{}" spends inputs twice'.format(txid))
|
||||||
elif transactions:
|
elif transactions:
|
||||||
transaction = backend.query.get_transaction(self.connection, transactions[0]["id"])
|
tx_id = transactions[0]["transactions"].id
|
||||||
assets = backend.query.get_assets(self.connection, [transaction["id"]])
|
tx = backend.query.get_transaction(self.connection, tx_id)
|
||||||
transaction["assets"] = [asset.data for asset in assets]
|
assets = backend.query.get_assets_by_tx_id(self.connection, tx_id)
|
||||||
transaction = Transaction.from_dict(transaction, False)
|
transaction = {"transactions": tx} | {"assets": [asset.data for asset in assets]}
|
||||||
elif current_spent_transactions:
|
elif current_spent_transactions:
|
||||||
transaction = current_spent_transactions[0]
|
transaction = current_spent_transactions[0]
|
||||||
|
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user