mirror of
https://github.com/planetmint/planetmint.git
synced 2025-11-24 14:35:45 +00:00
Format file
This commit is contained in:
parent
ba37a68a3a
commit
50ca7982ed
@ -16,37 +16,41 @@ class Block:
|
|||||||
app_hash: str = None
|
app_hash: str = None
|
||||||
height: int = None
|
height: int = None
|
||||||
|
|
||||||
|
|
||||||
@dataclass
|
@dataclass
|
||||||
class Script:
|
class Script:
|
||||||
id: str = None
|
id: str = None
|
||||||
script = None
|
script = None
|
||||||
|
|
||||||
|
|
||||||
@dataclass
|
@dataclass
|
||||||
class UTXO:
|
class UTXO:
|
||||||
id: str = None
|
id: str = None
|
||||||
output_index: int = None
|
output_index: int = None
|
||||||
utxo: dict = None
|
utxo: dict = None
|
||||||
|
|
||||||
|
|
||||||
@dataclass
|
@dataclass
|
||||||
class Transaction:
|
class Transaction:
|
||||||
id: str = None
|
id: str = None
|
||||||
assets: list[Asset] = None
|
assets: list[Asset] = None
|
||||||
metadata: MetaData = None
|
metadata: MetaData = None
|
||||||
version: str = None # TODO: make enum
|
version: str = None # TODO: make enum
|
||||||
operation: str = None # TODO: make enum
|
operation: str = None # TODO: make enum
|
||||||
inputs: list[Input] = None
|
inputs: list[Input] = None
|
||||||
outputs: list[Output] = None
|
outputs: list[Output] = None
|
||||||
script: str = None
|
script: str = None
|
||||||
|
|
||||||
|
|
||||||
@dataclass
|
@dataclass
|
||||||
class Validator:
|
class Validator:
|
||||||
id: str = None
|
id: str = None
|
||||||
height: int = None
|
height: int = None
|
||||||
validators = None
|
validators = None
|
||||||
|
|
||||||
|
|
||||||
@dataclass
|
@dataclass
|
||||||
class ABCIChain:
|
class ABCIChain:
|
||||||
height: str = None
|
height: str = None
|
||||||
is_synced: bool = None
|
is_synced: bool = None
|
||||||
chain_id: str = None
|
chain_id: str = None
|
||||||
|
|
||||||
|
|||||||
@ -7,6 +7,7 @@ from __future__ import annotations
|
|||||||
import json
|
import json
|
||||||
from dataclasses import dataclass
|
from dataclasses import dataclass
|
||||||
|
|
||||||
|
|
||||||
@dataclass
|
@dataclass
|
||||||
class Asset:
|
class Asset:
|
||||||
id: str = ""
|
id: str = ""
|
||||||
|
|||||||
@ -5,6 +5,7 @@
|
|||||||
|
|
||||||
from dataclasses import dataclass
|
from dataclasses import dataclass
|
||||||
|
|
||||||
|
|
||||||
@dataclass
|
@dataclass
|
||||||
class Fulfills:
|
class Fulfills:
|
||||||
transaction_id: str = ""
|
transaction_id: str = ""
|
||||||
|
|||||||
@ -9,6 +9,7 @@ from typing import Optional
|
|||||||
|
|
||||||
from .fulfills import Fulfills
|
from .fulfills import Fulfills
|
||||||
|
|
||||||
|
|
||||||
@dataclass
|
@dataclass
|
||||||
class Input:
|
class Input:
|
||||||
tx_id: str = ""
|
tx_id: str = ""
|
||||||
@ -21,10 +22,7 @@ class Input:
|
|||||||
fulfills = None
|
fulfills = None
|
||||||
|
|
||||||
if input_dict["fulfills"]:
|
if input_dict["fulfills"]:
|
||||||
fulfills = Fulfills(
|
fulfills = Fulfills(input_dict["fulfills"]["transaction_id"], input_dict["fulfills"]["output_index"])
|
||||||
input_dict["fulfills"]["transaction_id"],
|
|
||||||
input_dict["fulfills"]["output_index"]
|
|
||||||
)
|
|
||||||
|
|
||||||
return Input(tx_id, fulfills, input_dict["owners_before"], input_dict["fulfillment"])
|
return Input(tx_id, fulfills, input_dict["owners_before"], input_dict["fulfillment"])
|
||||||
|
|
||||||
@ -43,13 +41,10 @@ class Input:
|
|||||||
return Input(tx_id, fulfills, owners_before, fulfillment)
|
return Input(tx_id, fulfills, owners_before, fulfillment)
|
||||||
|
|
||||||
def to_dict(self) -> dict:
|
def to_dict(self) -> dict:
|
||||||
fulfills = {
|
fulfills = (
|
||||||
"transaction_id": self.fulfills.transaction_id,
|
{"transaction_id": self.fulfills.transaction_id, "output_index": self.fulfills.output_index}
|
||||||
"output_index": self.fulfills.output_index
|
if self.fulfills
|
||||||
} if self.fulfills else None
|
else None
|
||||||
|
)
|
||||||
|
|
||||||
return {
|
return {"fulfills": fulfills, "fulfillment": self.fulfillment, "owners_before": self.owners_before}
|
||||||
"fulfills": fulfills,
|
|
||||||
"fulfillment": self.fulfillment,
|
|
||||||
"owners_before": self.owners_before
|
|
||||||
}
|
|
||||||
|
|||||||
@ -7,6 +7,7 @@ from __future__ import annotations
|
|||||||
from dataclasses import dataclass, field
|
from dataclasses import dataclass, field
|
||||||
from typing import Optional
|
from typing import Optional
|
||||||
|
|
||||||
|
|
||||||
@dataclass
|
@dataclass
|
||||||
class Keys:
|
class Keys:
|
||||||
tx_id: str = ""
|
tx_id: str = ""
|
||||||
@ -20,7 +21,6 @@ class Keys:
|
|||||||
public_keys=output["public_keys"],
|
public_keys=output["public_keys"],
|
||||||
)
|
)
|
||||||
|
|
||||||
|
|
||||||
@staticmethod
|
@staticmethod
|
||||||
def from_tuple(output: tuple) -> Keys:
|
def from_tuple(output: tuple) -> Keys:
|
||||||
return Keys(
|
return Keys(
|
||||||
|
|||||||
@ -8,6 +8,7 @@ import json
|
|||||||
from dataclasses import dataclass
|
from dataclasses import dataclass
|
||||||
from typing import Optional
|
from typing import Optional
|
||||||
|
|
||||||
|
|
||||||
@dataclass
|
@dataclass
|
||||||
class MetaData:
|
class MetaData:
|
||||||
id: str = ""
|
id: str = ""
|
||||||
|
|||||||
@ -114,13 +114,8 @@ def output_with_sub_conditions(output, tx_id) -> Output:
|
|||||||
type=sub_condition["type"],
|
type=sub_condition["type"],
|
||||||
public_key=sub_condition["public_key"],
|
public_key=sub_condition["public_key"],
|
||||||
)
|
)
|
||||||
for sub_condition in output["condition"]["details"][
|
for sub_condition in output["condition"]["details"]["subconditions"]
|
||||||
"subconditions"
|
|
||||||
]
|
|
||||||
],
|
],
|
||||||
),
|
),
|
||||||
),
|
),
|
||||||
)
|
)
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|||||||
@ -7,6 +7,7 @@ from __future__ import annotations
|
|||||||
from dataclasses import dataclass
|
from dataclasses import dataclass
|
||||||
from typing import Optional
|
from typing import Optional
|
||||||
|
|
||||||
|
|
||||||
@dataclass
|
@dataclass
|
||||||
class Script:
|
class Script:
|
||||||
id: str = ""
|
id: str = ""
|
||||||
@ -15,5 +16,3 @@ class Script:
|
|||||||
@staticmethod
|
@staticmethod
|
||||||
def from_tuple(script_tuple: tuple) -> Script:
|
def from_tuple(script_tuple: tuple) -> Script:
|
||||||
return Script(script_tuple[0], script_tuple[1])
|
return Script(script_tuple[0], script_tuple[1])
|
||||||
|
|
||||||
|
|
||||||
|
|||||||
@ -7,6 +7,7 @@ from __future__ import annotations
|
|||||||
from dataclasses import dataclass, field
|
from dataclasses import dataclass, field
|
||||||
from typing import Optional
|
from typing import Optional
|
||||||
|
|
||||||
|
|
||||||
@dataclass
|
@dataclass
|
||||||
class Transaction:
|
class Transaction:
|
||||||
id: str = ""
|
id: str = ""
|
||||||
@ -23,7 +24,6 @@ class Transaction:
|
|||||||
raw_transaction=transaction["transaction"],
|
raw_transaction=transaction["transaction"],
|
||||||
)
|
)
|
||||||
|
|
||||||
|
|
||||||
@staticmethod
|
@staticmethod
|
||||||
def from_tuple(transaction: tuple) -> Transaction:
|
def from_tuple(transaction: tuple) -> Transaction:
|
||||||
return Transaction(
|
return Transaction(
|
||||||
@ -33,7 +33,6 @@ class Transaction:
|
|||||||
raw_transaction=transaction[3],
|
raw_transaction=transaction[3],
|
||||||
)
|
)
|
||||||
|
|
||||||
|
|
||||||
def to_dict(self) -> dict:
|
def to_dict(self) -> dict:
|
||||||
return {
|
return {
|
||||||
"id": self.id,
|
"id": self.id,
|
||||||
|
|||||||
@ -59,6 +59,7 @@ def store_transactions(connection, signed_transactions):
|
|||||||
|
|
||||||
raise NotImplementedError
|
raise NotImplementedError
|
||||||
|
|
||||||
|
|
||||||
@singledispatch
|
@singledispatch
|
||||||
def store_transaction(connection, transaction):
|
def store_transaction(connection, transaction):
|
||||||
"""Store a single transaction."""
|
"""Store a single transaction."""
|
||||||
@ -100,6 +101,7 @@ def get_asset(connection, asset_id) -> Asset:
|
|||||||
|
|
||||||
raise NotImplementedError
|
raise NotImplementedError
|
||||||
|
|
||||||
|
|
||||||
@singledispatch
|
@singledispatch
|
||||||
def get_assets_by_tx_id(connection, tx_id: str) -> list[Asset]:
|
def get_assets_by_tx_id(connection, tx_id: str) -> list[Asset]:
|
||||||
"""Get assets by transaction id.
|
"""Get assets by transaction id.
|
||||||
@ -188,6 +190,7 @@ def get_block_with_transaction(connection, txid):
|
|||||||
|
|
||||||
raise NotImplementedError
|
raise NotImplementedError
|
||||||
|
|
||||||
|
|
||||||
@singledispatch
|
@singledispatch
|
||||||
def get_metadata_by_tx_id(connection, transaction_id: str) -> MetaData:
|
def get_metadata_by_tx_id(connection, transaction_id: str) -> MetaData:
|
||||||
"""Get metadata from the metadata table containing `transaction_id`.
|
"""Get metadata from the metadata table containing `transaction_id`.
|
||||||
@ -201,6 +204,7 @@ def get_metadata_by_tx_id(connection, transaction_id: str) -> MetaData:
|
|||||||
"""
|
"""
|
||||||
raise NotImplementedError
|
raise NotImplementedError
|
||||||
|
|
||||||
|
|
||||||
@singledispatch
|
@singledispatch
|
||||||
def store_transaction_outputs_and_keys(connection, output: Output, index: int):
|
def store_transaction_outputs_and_keys(connection, output: Output, index: int):
|
||||||
"""Store the transaction outputs.
|
"""Store the transaction outputs.
|
||||||
@ -222,6 +226,7 @@ def store_transaction_outputs(connection, output: Output, index: int):
|
|||||||
"""
|
"""
|
||||||
raise NotImplementedError
|
raise NotImplementedError
|
||||||
|
|
||||||
|
|
||||||
@singledispatch
|
@singledispatch
|
||||||
def store_transaction_keys(connection, keys: [Keys], output_id: str, index: int):
|
def store_transaction_keys(connection, keys: [Keys], output_id: str, index: int):
|
||||||
"""Store the transaction keys.
|
"""Store the transaction keys.
|
||||||
@ -493,21 +498,25 @@ def get_latest_abci_chain(conn):
|
|||||||
"""
|
"""
|
||||||
raise NotImplementedError
|
raise NotImplementedError
|
||||||
|
|
||||||
|
|
||||||
@singledispatch
|
@singledispatch
|
||||||
def get_inputs_by_tx_id(connection, tx_id) -> list[Input]:
|
def get_inputs_by_tx_id(connection, tx_id) -> list[Input]:
|
||||||
"""Retrieve inputs for a transaction by its id"""
|
"""Retrieve inputs for a transaction by its id"""
|
||||||
raise NotImplementedError
|
raise NotImplementedError
|
||||||
|
|
||||||
|
|
||||||
@singledispatch
|
@singledispatch
|
||||||
def store_transaction_inputs(connection, inputs: list[Input]):
|
def store_transaction_inputs(connection, inputs: list[Input]):
|
||||||
"""Store inputs for a transaction"""
|
"""Store inputs for a transaction"""
|
||||||
raise NotImplementedError
|
raise NotImplementedError
|
||||||
|
|
||||||
|
|
||||||
@singledispatch
|
@singledispatch
|
||||||
def _group_transaction_by_ids(txids: list, connection):
|
def _group_transaction_by_ids(txids: list, connection):
|
||||||
"""Returns the transactions object (JSON TYPE), from list of ids."""
|
"""Returns the transactions object (JSON TYPE), from list of ids."""
|
||||||
raise NotImplementedError
|
raise NotImplementedError
|
||||||
|
|
||||||
|
|
||||||
@singledispatch
|
@singledispatch
|
||||||
def get_script_by_tx_id(connection, tx_id: str) -> Script:
|
def get_script_by_tx_id(connection, tx_id: str) -> Script:
|
||||||
"""Retrieve script for a transaction by its id"""
|
"""Retrieve script for a transaction by its id"""
|
||||||
@ -519,6 +528,7 @@ def get_outputs_by_tx_id(connection, tx_id: str) -> list[Output]:
|
|||||||
"""Retrieve outputs for a transaction by its id"""
|
"""Retrieve outputs for a transaction by its id"""
|
||||||
raise NotImplementedError
|
raise NotImplementedError
|
||||||
|
|
||||||
|
|
||||||
@singledispatch
|
@singledispatch
|
||||||
def get_keys_by_tx_id(connection, tx_id: str) -> list[Keys]:
|
def get_keys_by_tx_id(connection, tx_id: str) -> list[Keys]:
|
||||||
"""Retrieve keys for a transaction by its id"""
|
"""Retrieve keys for a transaction by its id"""
|
||||||
|
|||||||
@ -12,9 +12,17 @@ from tarantool.error import DatabaseError
|
|||||||
from planetmint.backend import query
|
from planetmint.backend import query
|
||||||
from planetmint.backend.models.keys import Keys
|
from planetmint.backend.models.keys import Keys
|
||||||
from planetmint.backend.models.transaction import Transaction
|
from planetmint.backend.models.transaction import Transaction
|
||||||
from planetmint.backend.tarantool.const import TARANT_TABLE_META_DATA, TARANT_TABLE_ASSETS, TARANT_TABLE_KEYS, \
|
from planetmint.backend.tarantool.const import (
|
||||||
TARANT_TABLE_TRANSACTION, TARANT_TABLE_INPUT, TARANT_TABLE_OUTPUT, TARANT_TABLE_SCRIPT, TARANT_TX_ID_SEARCH, \
|
TARANT_TABLE_META_DATA,
|
||||||
TARANT_ID_SEARCH
|
TARANT_TABLE_ASSETS,
|
||||||
|
TARANT_TABLE_KEYS,
|
||||||
|
TARANT_TABLE_TRANSACTION,
|
||||||
|
TARANT_TABLE_INPUT,
|
||||||
|
TARANT_TABLE_OUTPUT,
|
||||||
|
TARANT_TABLE_SCRIPT,
|
||||||
|
TARANT_TX_ID_SEARCH,
|
||||||
|
TARANT_ID_SEARCH,
|
||||||
|
)
|
||||||
from planetmint.backend.utils import module_dispatch_registrar
|
from planetmint.backend.utils import module_dispatch_registrar
|
||||||
from planetmint.backend.models import Asset, MetaData, Input, Script, Output
|
from planetmint.backend.models import Asset, MetaData, Input, Script, Output
|
||||||
from planetmint.backend.tarantool.connection import TarantoolDBConnection
|
from planetmint.backend.tarantool.connection import TarantoolDBConnection
|
||||||
@ -74,16 +82,20 @@ def get_keys_by_tx_id(connection, tx_id: str) -> list[Keys]:
|
|||||||
|
|
||||||
@register_query(TarantoolDBConnection)
|
@register_query(TarantoolDBConnection)
|
||||||
def store_transaction_inputs(connection, input: Input, index: int):
|
def store_transaction_inputs(connection, input: Input, index: int):
|
||||||
connection.run(connection.space(TARANT_TABLE_INPUT).insert((
|
connection.run(
|
||||||
input.tx_id,
|
connection.space(TARANT_TABLE_INPUT).insert(
|
||||||
input.fulfillment,
|
(
|
||||||
input.owners_before,
|
input.tx_id,
|
||||||
input.fulfills.transaction_id if input.fulfills else "",
|
input.fulfillment,
|
||||||
# TODO: the output_index should be an unsigned int
|
input.owners_before,
|
||||||
str(input.fulfills.output_index) if input.fulfills else "",
|
input.fulfills.transaction_id if input.fulfills else "",
|
||||||
uuid4().hex,
|
# TODO: the output_index should be an unsigned int
|
||||||
index
|
str(input.fulfills.output_index) if input.fulfills else "",
|
||||||
)))
|
uuid4().hex,
|
||||||
|
index,
|
||||||
|
)
|
||||||
|
)
|
||||||
|
)
|
||||||
|
|
||||||
|
|
||||||
@register_query(TarantoolDBConnection)
|
@register_query(TarantoolDBConnection)
|
||||||
@ -119,22 +131,14 @@ def store_transaction_outputs(connection, output: Output, index: int) -> str:
|
|||||||
index,
|
index,
|
||||||
)
|
)
|
||||||
|
|
||||||
connection.run(connection.space(TARANT_TABLE_OUTPUT).insert((
|
connection.run(connection.space(TARANT_TABLE_OUTPUT).insert((tmp_output)))
|
||||||
tmp_output
|
|
||||||
)))
|
|
||||||
return output_id
|
return output_id
|
||||||
|
|
||||||
|
|
||||||
@register_query(TarantoolDBConnection)
|
@register_query(TarantoolDBConnection)
|
||||||
def store_transaction_keys(connection, keys: Keys, output_id: str, index: int):
|
def store_transaction_keys(connection, keys: Keys, output_id: str, index: int):
|
||||||
for key in keys.public_keys:
|
for key in keys.public_keys:
|
||||||
connection.run(connection.space(TARANT_TABLE_KEYS).insert((
|
connection.run(connection.space(TARANT_TABLE_KEYS).insert((uuid4().hex, keys.tx_id, output_id, key, index)))
|
||||||
uuid4().hex,
|
|
||||||
keys.tx_id,
|
|
||||||
output_id,
|
|
||||||
key,
|
|
||||||
index
|
|
||||||
)))
|
|
||||||
|
|
||||||
|
|
||||||
@register_query(TarantoolDBConnection)
|
@register_query(TarantoolDBConnection)
|
||||||
@ -142,12 +146,17 @@ def store_transactions(connection, signed_transactions: list):
|
|||||||
for transaction in signed_transactions:
|
for transaction in signed_transactions:
|
||||||
store_transaction(connection, transaction)
|
store_transaction(connection, transaction)
|
||||||
|
|
||||||
[store_transaction_inputs(connection, Input.from_dict(input, transaction["id"]), index) for
|
[
|
||||||
index, input in enumerate(transaction[TARANT_TABLE_INPUT])]
|
store_transaction_inputs(connection, Input.from_dict(input, transaction["id"]), index)
|
||||||
|
for index, input in enumerate(transaction[TARANT_TABLE_INPUT])
|
||||||
|
]
|
||||||
|
|
||||||
[store_transaction_outputs_and_keys(connection, Output.outputs_and_keys_dict(output, transaction["id"]), index)
|
[
|
||||||
for index, output in
|
store_transaction_outputs_and_keys(
|
||||||
enumerate(transaction[TARANT_TABLE_OUTPUT])]
|
connection, Output.outputs_and_keys_dict(output, transaction["id"]), index
|
||||||
|
)
|
||||||
|
for index, output in enumerate(transaction[TARANT_TABLE_OUTPUT])
|
||||||
|
]
|
||||||
|
|
||||||
store_metadatas(connection, [MetaData(transaction["id"], transaction["metadata"])])
|
store_metadatas(connection, [MetaData(transaction["id"], transaction["metadata"])])
|
||||||
|
|
||||||
@ -160,17 +169,14 @@ def store_transactions(connection, signed_transactions: list):
|
|||||||
if TARANT_TABLE_SCRIPT in transaction:
|
if TARANT_TABLE_SCRIPT in transaction:
|
||||||
connection.run(
|
connection.run(
|
||||||
connection.space(TARANT_TABLE_SCRIPT).insert((transaction["id"], transaction[TARANT_TABLE_SCRIPT])),
|
connection.space(TARANT_TABLE_SCRIPT).insert((transaction["id"], transaction[TARANT_TABLE_SCRIPT])),
|
||||||
only_data=False)
|
only_data=False,
|
||||||
|
)
|
||||||
|
|
||||||
|
|
||||||
@register_query(TarantoolDBConnection)
|
@register_query(TarantoolDBConnection)
|
||||||
def store_transaction(connection, transaction):
|
def store_transaction(connection, transaction):
|
||||||
tx = (transaction["id"], transaction["operation"], transaction["version"],
|
tx = (transaction["id"], transaction["operation"], transaction["version"], transaction)
|
||||||
transaction)
|
connection.run(connection.space(TARANT_TABLE_TRANSACTION).insert(tx), only_data=False)
|
||||||
connection.run(connection.space(TARANT_TABLE_TRANSACTION).insert(
|
|
||||||
tx
|
|
||||||
),
|
|
||||||
only_data=False)
|
|
||||||
|
|
||||||
|
|
||||||
@register_query(TarantoolDBConnection)
|
@register_query(TarantoolDBConnection)
|
||||||
@ -191,9 +197,7 @@ def get_transactions(connection, transactions_ids: list) -> list[Transaction]:
|
|||||||
def store_metadatas(connection, metadata: list[MetaData]):
|
def store_metadatas(connection, metadata: list[MetaData]):
|
||||||
for meta in metadata:
|
for meta in metadata:
|
||||||
connection.run(
|
connection.run(
|
||||||
connection.space(TARANT_TABLE_META_DATA).insert(
|
connection.space(TARANT_TABLE_META_DATA).insert((meta.id, json.dumps(meta.metadata))) # noqa: E713
|
||||||
(meta.id, json.dumps(meta.metadata))
|
|
||||||
) # noqa: E713
|
|
||||||
)
|
)
|
||||||
|
|
||||||
|
|
||||||
@ -268,8 +272,9 @@ def _from_tuple_list_to_asset_list(_data: list) -> list[Asset]:
|
|||||||
@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(
|
||||||
connection.space(TARANT_TABLE_INPUT).select([fullfil_transaction_id, str(fullfil_output_index)],
|
connection.space(TARANT_TABLE_INPUT).select(
|
||||||
index="spent_search")
|
[fullfil_transaction_id, str(fullfil_output_index)], index="spent_search"
|
||||||
|
)
|
||||||
)
|
)
|
||||||
_transactions = _group_transaction_by_ids(txids=[inp[0] for inp in _inputs], connection=connection)
|
_transactions = _group_transaction_by_ids(txids=[inp[0] for inp in _inputs], connection=connection)
|
||||||
return _transactions
|
return _transactions
|
||||||
@ -304,7 +309,7 @@ def store_block(connection, block: dict):
|
|||||||
|
|
||||||
@register_query(TarantoolDBConnection)
|
@register_query(TarantoolDBConnection)
|
||||||
def get_txids_filtered(
|
def get_txids_filtered(
|
||||||
connection, asset_ids: list[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
|
): # TODO here is used 'OR' operator
|
||||||
actions = {
|
actions = {
|
||||||
"CREATE": {"sets": ["CREATE", asset_ids], "index": "transaction_search"},
|
"CREATE": {"sets": ["CREATE", asset_ids], "index": "transaction_search"},
|
||||||
@ -330,7 +335,9 @@ def get_txids_filtered(
|
|||||||
_transactions.extend(_tmp_transactions)
|
_transactions.extend(_tmp_transactions)
|
||||||
else:
|
else:
|
||||||
_tx_ids = connection.run(connection.space(TARANT_TABLE_TRANSACTION).select(asset_ids, index=TARANT_ID_SEARCH))
|
_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"))
|
_assets_ids = connection.run(
|
||||||
|
connection.space(TARANT_TABLE_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]))
|
return tuple(set([sublist[1] for sublist in _assets_ids] + [sublist[0] for sublist in _tx_ids]))
|
||||||
|
|
||||||
if last_tx:
|
if last_tx:
|
||||||
@ -409,20 +416,27 @@ def delete_transactions(connection, txn_ids: list):
|
|||||||
for _id in txn_ids:
|
for _id in txn_ids:
|
||||||
connection.run(connection.space(TARANT_TABLE_TRANSACTION).delete(_id), only_data=False)
|
connection.run(connection.space(TARANT_TABLE_TRANSACTION).delete(_id), only_data=False)
|
||||||
for _id in txn_ids:
|
for _id in txn_ids:
|
||||||
_inputs = connection.run(connection.space(TARANT_TABLE_INPUT).select(_id, index=TARANT_ID_SEARCH),
|
_inputs = connection.run(
|
||||||
only_data=False)
|
connection.space(TARANT_TABLE_INPUT).select(_id, index=TARANT_ID_SEARCH), only_data=False
|
||||||
_outputs = connection.run(connection.space(TARANT_TABLE_OUTPUT).select(_id, index=TARANT_ID_SEARCH),
|
)
|
||||||
only_data=False)
|
_outputs = connection.run(
|
||||||
_keys = connection.run(connection.space(TARANT_TABLE_KEYS).select(_id, index=TARANT_TX_ID_SEARCH),
|
connection.space(TARANT_TABLE_OUTPUT).select(_id, index=TARANT_ID_SEARCH), only_data=False
|
||||||
only_data=False)
|
)
|
||||||
|
_keys = connection.run(
|
||||||
|
connection.space(TARANT_TABLE_KEYS).select(_id, index=TARANT_TX_ID_SEARCH), only_data=False
|
||||||
|
)
|
||||||
for _kID in _keys:
|
for _kID in _keys:
|
||||||
connection.run(connection.space(TARANT_TABLE_KEYS).delete(_kID[0], index=TARANT_ID_SEARCH), only_data=False)
|
connection.run(
|
||||||
|
connection.space(TARANT_TABLE_KEYS).delete(_kID[0], index=TARANT_ID_SEARCH), only_data=False
|
||||||
|
)
|
||||||
for _inpID in _inputs:
|
for _inpID in _inputs:
|
||||||
connection.run(connection.space(TARANT_TABLE_INPUT).delete(_inpID[5], index="delete_search"),
|
connection.run(
|
||||||
only_data=False)
|
connection.space(TARANT_TABLE_INPUT).delete(_inpID[5], index="delete_search"), only_data=False
|
||||||
|
)
|
||||||
for _outpID in _outputs:
|
for _outpID in _outputs:
|
||||||
connection.run(connection.space(TARANT_TABLE_OUTPUT).delete(_outpID[5], index="unique_search"),
|
connection.run(
|
||||||
only_data=False)
|
connection.space(TARANT_TABLE_OUTPUT).delete(_outpID[5], index="unique_search"), only_data=False
|
||||||
|
)
|
||||||
|
|
||||||
for _id in txn_ids:
|
for _id in txn_ids:
|
||||||
connection.run(connection.space(TARANT_TABLE_META_DATA).delete(_id, index=TARANT_ID_SEARCH), only_data=False)
|
connection.run(connection.space(TARANT_TABLE_META_DATA).delete(_id, index=TARANT_ID_SEARCH), only_data=False)
|
||||||
@ -558,7 +572,7 @@ def get_election(connection, election_id: str):
|
|||||||
|
|
||||||
@register_query(TarantoolDBConnection)
|
@register_query(TarantoolDBConnection)
|
||||||
def get_asset_tokens_for_public_key(
|
def get_asset_tokens_for_public_key(
|
||||||
connection, asset_id: str, public_key: str
|
connection, asset_id: str, public_key: str
|
||||||
): # FIXME Something can be wrong with this function ! (public_key) is not used # noqa: E501
|
): # FIXME Something can be wrong with this function ! (public_key) is not used # noqa: E501
|
||||||
# space = connection.space("keys")
|
# space = connection.space("keys")
|
||||||
# _keys = space.select([public_key], index="keys_search")
|
# _keys = space.select([public_key], index="keys_search")
|
||||||
|
|||||||
@ -1,7 +1,14 @@
|
|||||||
from transactions.common.memoize import HDict
|
from transactions.common.memoize import HDict
|
||||||
|
|
||||||
from planetmint.backend.tarantool.const import TARANT_TABLE_META_DATA, TARANT_TABLE_ASSETS, TARANT_TABLE_KEYS, \
|
from planetmint.backend.tarantool.const import (
|
||||||
TARANT_TABLE_TRANSACTION, TARANT_TABLE_INPUT, TARANT_TABLE_OUTPUT, TARANT_TABLE_SCRIPT
|
TARANT_TABLE_META_DATA,
|
||||||
|
TARANT_TABLE_ASSETS,
|
||||||
|
TARANT_TABLE_KEYS,
|
||||||
|
TARANT_TABLE_TRANSACTION,
|
||||||
|
TARANT_TABLE_INPUT,
|
||||||
|
TARANT_TABLE_OUTPUT,
|
||||||
|
TARANT_TABLE_SCRIPT,
|
||||||
|
)
|
||||||
|
|
||||||
|
|
||||||
def get_items(_list):
|
def get_items(_list):
|
||||||
|
|||||||
@ -49,7 +49,7 @@ def test_write_assets(db_conn):
|
|||||||
Asset("2", "2", "2"),
|
Asset("2", "2", "2"),
|
||||||
Asset("3", "3", "3"),
|
Asset("3", "3", "3"),
|
||||||
# Duplicated id. Should not be written to the database
|
# Duplicated id. Should not be written to the database
|
||||||
Asset("1", "1", "1")
|
Asset("1", "1", "1"),
|
||||||
]
|
]
|
||||||
|
|
||||||
# write the assets
|
# write the assets
|
||||||
@ -186,7 +186,7 @@ def test_get_metadata(db_conn):
|
|||||||
|
|
||||||
metadata = [
|
metadata = [
|
||||||
MetaData("dd86682db39e4b424df0eec1413cfad65488fd48712097c5d865ca8e8e059b64", None),
|
MetaData("dd86682db39e4b424df0eec1413cfad65488fd48712097c5d865ca8e8e059b64", None),
|
||||||
MetaData("55a2303e3bcd653e4b5bd7118d39c0e2d48ee2f18e22fbcf64e906439bdeb45d", {"key": "value"})
|
MetaData("55a2303e3bcd653e4b5bd7118d39c0e2d48ee2f18e22fbcf64e906439bdeb45d", {"key": "value"}),
|
||||||
]
|
]
|
||||||
|
|
||||||
# conn.db.metadata.insert_many(deepcopy(metadata), ordered=False)
|
# conn.db.metadata.insert_many(deepcopy(metadata), ordered=False)
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user