mirror of
https://github.com/planetmint/planetmint.git
synced 2025-11-24 06:25:45 +00:00
Adaptions due to schema change
Signed-off-by: cybnon <stefan.weber93@googlemail.com>
This commit is contained in:
parent
aeb2bba61b
commit
67d0d9b642
@ -9,6 +9,5 @@ from .input import Input
|
||||
from .metadata import MetaData
|
||||
from .script import Script
|
||||
from .output import Output
|
||||
from .keys import Keys
|
||||
from .dbtransaction import DbTransaction
|
||||
from .block import Block
|
||||
|
||||
@ -22,8 +22,8 @@ class Asset:
|
||||
}
|
||||
|
||||
@staticmethod
|
||||
def from_list_dict(asset_tuple_list: list[tuple]) -> list[Asset]:
|
||||
return [Asset.from_dict(asset_tuple) for asset_tuple in asset_tuple_list]
|
||||
def from_list_dict(asset_dict_list: list[dict]) -> list[Asset]:
|
||||
return [Asset.from_dict(asset_dict) for asset_dict in asset_dict_list]
|
||||
|
||||
@staticmethod
|
||||
def list_to_dict(asset_list: list[Asset]) -> list[dict]:
|
||||
|
||||
@ -6,8 +6,7 @@
|
||||
from __future__ import annotations
|
||||
from dataclasses import dataclass
|
||||
|
||||
from planetmint.backend.models import Asset, MetaData, Input, Output, Script
|
||||
from planetmint.backend.models.keys import Keys
|
||||
from planetmint.backend.models import Asset, MetaData, Input, Script
|
||||
|
||||
|
||||
@dataclass
|
||||
|
||||
@ -47,7 +47,7 @@ class Input:
|
||||
else None
|
||||
)
|
||||
|
||||
return {"fulfills": fulfills, "fulfillment": self.fulfillment, "owners_before": self.owners_before}
|
||||
return {"owners_before": self.owners_before, "fulfills": fulfills, "fulfillment": self.fulfillment}
|
||||
|
||||
@staticmethod
|
||||
def from_list_dict(input_tuple_list: list[dict]) -> list[Input]:
|
||||
|
||||
@ -1,37 +0,0 @@
|
||||
# Copyright © 2020 Interplanetary Database Association e.V.,
|
||||
# Planetmint and IPDB software contributors.
|
||||
# SPDX-License-Identifier: (Apache-2.0 AND CC-BY-4.0)
|
||||
# Code is Apache-2.0 and docs are CC-BY-4.0
|
||||
|
||||
from __future__ import annotations
|
||||
from dataclasses import dataclass, field
|
||||
from typing import Optional
|
||||
|
||||
|
||||
@dataclass
|
||||
class Keys:
|
||||
tx_id: str = ""
|
||||
output_id: str = ""
|
||||
public_keys: [str] = ""
|
||||
|
||||
@staticmethod
|
||||
def from_dict(output: dict, tx_id: str = "") -> Keys:
|
||||
return Keys(
|
||||
tx_id=tx_id,
|
||||
public_keys=output["public_keys"],
|
||||
)
|
||||
|
||||
@staticmethod
|
||||
def from_tuple(output: tuple) -> Keys:
|
||||
return Keys(
|
||||
tx_id=output[1],
|
||||
output_id=output[2],
|
||||
public_keys=output[3],
|
||||
)
|
||||
|
||||
def to_dict(self) -> dict:
|
||||
return {
|
||||
"tx_id": self.tx_id,
|
||||
"output_id": self.output_id,
|
||||
"public_keys": self.public_keys,
|
||||
}
|
||||
@ -14,9 +14,9 @@ class MetaData:
|
||||
metadata: Optional[str] = None
|
||||
|
||||
@staticmethod
|
||||
def from_dict(meta_data_tuple: dict) -> MetaData:
|
||||
def from_dict(meta_data_tuple: dict) -> MetaData | None:
|
||||
if meta_data_tuple is None:
|
||||
return MetaData()
|
||||
return None
|
||||
return MetaData(meta_data_tuple["meta_data"])
|
||||
|
||||
def to_dict(self) -> dict:
|
||||
|
||||
@ -7,8 +7,6 @@ from __future__ import annotations
|
||||
from dataclasses import dataclass, field
|
||||
from typing import List
|
||||
|
||||
from planetmint.backend.models.keys import Keys
|
||||
|
||||
|
||||
@dataclass
|
||||
class SubCondition:
|
||||
@ -26,7 +24,7 @@ class SubCondition:
|
||||
class ConditionDetails:
|
||||
type: str = ""
|
||||
public_key: str = ""
|
||||
threshold: int = 0
|
||||
threshold: int = None
|
||||
sub_conditions: list[SubCondition] = None
|
||||
|
||||
@staticmethod
|
||||
@ -100,18 +98,18 @@ class Output:
|
||||
|
||||
def to_dict(self) -> dict:
|
||||
return {
|
||||
"id": self.transaction_id,
|
||||
"amount": self.amount,
|
||||
"id": self.id,
|
||||
"public_keys": self.public_keys,
|
||||
"condition": {
|
||||
"uri": self.condition.uri,
|
||||
"details": {
|
||||
"type": self.condition.details.type,
|
||||
"public_key": self.condition.details.public_key,
|
||||
"threshold": self.condition.details.threshold,
|
||||
"subconditions": self.condition.details.sub_conditions,
|
||||
},
|
||||
"uri": self.condition.uri,
|
||||
},
|
||||
"amount": str(self.amount),
|
||||
}
|
||||
|
||||
|
||||
|
||||
@ -13,9 +13,9 @@ class Script:
|
||||
script: dict = None
|
||||
|
||||
@staticmethod
|
||||
def from_dict(script_dict: dict) -> Script:
|
||||
def from_dict(script_dict: dict) -> Script | None:
|
||||
if script_dict is None:
|
||||
return Script()
|
||||
return None
|
||||
return Script(script_dict["script"])
|
||||
|
||||
def to_dict(self) -> dict:
|
||||
|
||||
@ -10,7 +10,6 @@ from functools import singledispatch
|
||||
from planetmint.backend.models import Asset, MetaData, Output, Input, Script
|
||||
|
||||
from planetmint.backend.exceptions import OperationError
|
||||
from planetmint.backend.models.keys import Keys
|
||||
from planetmint.backend.interfaces import Block
|
||||
from planetmint.backend.models.dbtransaction import DbTransaction
|
||||
|
||||
@ -208,31 +207,6 @@ def get_block_with_transaction(connection, txid):
|
||||
raise NotImplementedError
|
||||
|
||||
|
||||
@singledispatch
|
||||
def get_metadata_by_tx_id(connection, transaction_id: str) -> MetaData:
|
||||
"""Get metadata from the metadata table containing `transaction_id`.
|
||||
|
||||
Args:
|
||||
transaction_id (str): id for the metadata to be retrieved from
|
||||
the database.
|
||||
|
||||
Returns:
|
||||
metadata (MetaData): the list of returned metadata.
|
||||
"""
|
||||
raise NotImplementedError
|
||||
|
||||
|
||||
@singledispatch
|
||||
def store_transaction_outputs_and_keys(connection, output: Output, index: int):
|
||||
"""Store the transaction outputs.
|
||||
|
||||
Args:
|
||||
output (Output): the output to store.
|
||||
index (int): the index of the output in the transaction.
|
||||
"""
|
||||
raise NotImplementedError
|
||||
|
||||
|
||||
@singledispatch
|
||||
def store_transaction_outputs(connection, output: Output, index: int):
|
||||
"""Store the transaction outputs.
|
||||
@ -244,31 +218,6 @@ def store_transaction_outputs(connection, output: Output, index: int):
|
||||
raise NotImplementedError
|
||||
|
||||
|
||||
@singledispatch
|
||||
def store_transaction_keys(connection, keys: [Keys], output_id: str, index: int):
|
||||
"""Store the transaction keys.
|
||||
|
||||
Args:
|
||||
input (Input): the input to store.
|
||||
index (int): the index of the input in the transaction.
|
||||
"""
|
||||
raise NotImplementedError
|
||||
|
||||
|
||||
@singledispatch
|
||||
def get_metadata(connection, transaction_ids) -> list[MetaData]:
|
||||
"""Get a list of metadata from the metadata table.
|
||||
|
||||
Args:
|
||||
transaction_ids (list): a list of ids for the metadata to be retrieved from
|
||||
the database.
|
||||
|
||||
Returns:
|
||||
metadata (list): the list of returned metadata.
|
||||
"""
|
||||
raise NotImplementedError
|
||||
|
||||
|
||||
@singledispatch
|
||||
def get_assets(connection, asset_ids) -> list[Asset]:
|
||||
"""Get a list of assets from the assets table.
|
||||
@ -547,6 +496,6 @@ def get_outputs_by_tx_id(connection, tx_id: str) -> list[Output]:
|
||||
|
||||
|
||||
@singledispatch
|
||||
def get_keys_by_tx_id(connection, tx_id: str) -> list[Keys]:
|
||||
"""Retrieve keys for a transaction by its id"""
|
||||
raise NotImplementedError
|
||||
def get_metadata(conn, transaction_ids):
|
||||
"""Retrieve metadata for a list of transactions by their ids"""
|
||||
raise NotImplementedError
|
||||
@ -70,7 +70,6 @@ def store_transaction_outputs(connection, output: Output, index: int) -> str:
|
||||
def store_transactions(connection, signed_transactions: list):
|
||||
for transaction in signed_transactions:
|
||||
store_transaction(connection, transaction)
|
||||
|
||||
[
|
||||
store_transaction_outputs(connection, Output.outputs_dict(output, transaction["id"]), index)
|
||||
for index, output in enumerate(transaction[TARANT_TABLE_OUTPUT])
|
||||
|
||||
@ -38,6 +38,7 @@ from transactions.common.transaction_mode_types import BROADCAST_TX_COMMIT, BROA
|
||||
from transactions.types.elections.election import Election
|
||||
from transactions.types.elections.validator_utils import election_id_to_public_key
|
||||
|
||||
from planetmint.backend.models import Output
|
||||
from planetmint.config import Config
|
||||
from planetmint import backend, config_utils, fastquery
|
||||
from planetmint.tendermint_utils import (
|
||||
@ -385,11 +386,11 @@ class Planetmint(object):
|
||||
if spent:
|
||||
raise DoubleSpend("input `{}` was already spent".format(input_txid))
|
||||
|
||||
|
||||
output = _output[input_.fulfills.output]
|
||||
input_conditions.append(output)
|
||||
tx_dict = input_tx.to_dict()
|
||||
tx_dict["outputs"] = output.to_dict()
|
||||
tx_dict["outputs"] = Output.list_to_dict(_output)
|
||||
tx_dict = remove_generated_fields(tx_dict)
|
||||
pm_transaction = Transaction.from_dict(tx_dict, False)
|
||||
input_txs.append(pm_transaction)
|
||||
|
||||
@ -927,3 +928,16 @@ class Planetmint(object):
|
||||
|
||||
|
||||
Block = namedtuple("Block", ("app_hash", "height", "transactions"))
|
||||
|
||||
|
||||
def remove_generated_fields(tx_dict: dict):
|
||||
tx_dict["outputs"] = [remove_generated_or_none_output_keys(output) for output in tx_dict["outputs"]]
|
||||
if tx_dict["script"] is None:
|
||||
tx_dict.pop("script")
|
||||
return tx_dict
|
||||
|
||||
|
||||
def remove_generated_or_none_output_keys(output):
|
||||
output["condition"]["details"] = {k: v for k, v in output["condition"]["details"].items() if v is not None}
|
||||
output.pop("id")
|
||||
return output
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user