mirror of
https://github.com/planetmint/planetmint.git
synced 2025-11-24 14:35:45 +00:00
Get rid of decompose
Signed-off-by: cybnon <stefan.weber93@googlemail.com>
This commit is contained in:
parent
7796d5c615
commit
2e9d05e1b0
@ -15,11 +15,10 @@ class Keys:
|
||||
|
||||
@staticmethod
|
||||
def from_dict(output: dict, tx_id: str = "") -> Keys:
|
||||
if output["condition"]["details"].get("subconditions") is None:
|
||||
return Keys(
|
||||
tx_id=tx_id,
|
||||
public_keys=output["public_keys"],
|
||||
)
|
||||
return Keys(
|
||||
tx_id=tx_id,
|
||||
public_keys=output["public_keys"],
|
||||
)
|
||||
|
||||
|
||||
@staticmethod
|
||||
|
||||
@ -13,7 +13,7 @@ from planetmint.backend.models.keys import Keys
|
||||
@dataclass
|
||||
class SubCondition:
|
||||
type: str
|
||||
body: str
|
||||
public_key: str
|
||||
|
||||
|
||||
@dataclass
|
||||
@ -23,6 +23,11 @@ class ConditionDetails:
|
||||
threshold: int = 0
|
||||
sub_conditions: list[SubCondition] = None
|
||||
|
||||
def sub_conditions_to_list_dict(self):
|
||||
if self.sub_conditions is None:
|
||||
return None
|
||||
return [sub_condition.__dict__ for sub_condition in self.sub_conditions]
|
||||
|
||||
|
||||
@dataclass
|
||||
class Condition:
|
||||
@ -106,7 +111,7 @@ def output_with_sub_conditions(output, tx_id) -> Output:
|
||||
sub_conditions=[
|
||||
SubCondition(
|
||||
type=sub_condition["type"],
|
||||
body=sub_condition["body"],
|
||||
public_key=sub_condition["public_key"],
|
||||
)
|
||||
for sub_condition in output["condition"]["details"][
|
||||
"subconditions"
|
||||
|
||||
@ -500,3 +500,14 @@ def _group_transaction_by_ids(txids: list, connection):
|
||||
def get_script_by_tx_id(connection, tx_id: str) -> Script:
|
||||
"""Retrieve script for a transaction by its id"""
|
||||
raise NotImplementedError
|
||||
|
||||
|
||||
@singledispatch
|
||||
def get_outputs_by_tx_id(connection, tx_id: str) -> list[Output]:
|
||||
"""Retrieve outputs for a transaction by its id"""
|
||||
raise NotImplementedError
|
||||
|
||||
@singledispatch
|
||||
def get_keys_by_tx_id(connection, tx_id: str) -> list[Keys]:
|
||||
"""Retrieve keys for a transaction by its id"""
|
||||
raise NotImplementedError
|
||||
@ -31,9 +31,8 @@ def _group_transaction_by_ids(connection, txids: list):
|
||||
continue
|
||||
_txobject = _txobject[0]
|
||||
_txinputs = get_inputs_by_tx_id(connection, txid)
|
||||
_txoutputs = connection.run(connection.space(TARANT_TABLE_OUTPUT).select(txid, index=TARANT_ID_SEARCH))
|
||||
_txkeys = connection.run(connection.space(TARANT_TABLE_KEYS).select(txid, index=TARANT_TX_ID_SEARCH))
|
||||
_txassets = connection.run(connection.space(TARANT_TABLE_ASSETS).select(txid, index=TARANT_TX_ID_SEARCH))
|
||||
_txoutputs = get_outputs_by_tx_id(connection, txid)
|
||||
_txkeys = get_keys_by_tx_id(connection, txid)
|
||||
_txassets = get_assets(connection, [txid])
|
||||
_txmeta = get_metadata_by_tx_id(connection, txid)
|
||||
_txscript = get_script_by_tx_id(connection, txid)
|
||||
@ -62,6 +61,20 @@ def get_inputs_by_tx_id(connection, tx_id: str) -> list[Input]:
|
||||
return [Input.from_tuple(input) for input in _sorted_inputs]
|
||||
|
||||
|
||||
@register_query(TarantoolDBConnection)
|
||||
def get_outputs_by_tx_id(connection, tx_id: str) -> list[Output]:
|
||||
_outputs = connection.run(connection.space(TARANT_TABLE_OUTPUT).select(tx_id, index=TARANT_ID_SEARCH))
|
||||
_sorted_inputs = sorted(_outputs, key=itemgetter(6))
|
||||
return [Output.from_tuple(output) for output in _sorted_inputs]
|
||||
|
||||
|
||||
@register_query(TarantoolDBConnection)
|
||||
def get_keys_by_tx_id(connection, tx_id: str) -> list[Keys]:
|
||||
_keys = connection.run(connection.space(TARANT_TABLE_KEYS).select(tx_id, index=TARANT_ID_SEARCH))
|
||||
_sorted_keys = sorted(_keys, key=itemgetter(6))
|
||||
return [Keys.from_tuple(key) for key in _sorted_keys]
|
||||
|
||||
|
||||
@register_query(TarantoolDBConnection)
|
||||
def store_transaction_inputs(connection, input: Input, index: int):
|
||||
connection.run(connection.space(TARANT_TABLE_INPUT).insert((
|
||||
@ -105,7 +118,7 @@ def store_transaction_outputs(connection, output: Output, index: int) -> str:
|
||||
None,
|
||||
output_id,
|
||||
output.condition.details.threshold if output.condition.details else "",
|
||||
json.dumps(output.condition.details.sub_conditions, default=) if output.condition.details.sub_conditions else "",
|
||||
output.condition.details.sub_conditions_to_list_dict() if output.condition.details.sub_conditions else "",
|
||||
index,
|
||||
)
|
||||
|
||||
@ -130,11 +143,6 @@ def store_transaction_keys(connection, keys: Keys, output_id: str, index: int):
|
||||
@register_query(TarantoolDBConnection)
|
||||
def store_transactions(connection, signed_transactions: list):
|
||||
for transaction in signed_transactions:
|
||||
txprepare = TransactionDecompose(transaction)
|
||||
txtuples = txprepare.convert_to_tuple()
|
||||
|
||||
connection.run(connection.space(TARANT_TABLE_TRANSACTION).insert(txtuples[TARANT_TABLE_TRANSACTION]),
|
||||
only_data=False)
|
||||
|
||||
[store_transaction_inputs(connection, Input.from_dict(input, transaction["id"]), index) for
|
||||
index, input in enumerate(transaction[TARANT_TABLE_INPUT])]
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user