mirror of
https://github.com/planetmint/planetmint.git
synced 2025-11-24 14:35:45 +00:00
Fix subcondition serialization
Signed-off-by: cybnon <stefan.weber93@googlemail.com>
This commit is contained in:
parent
10567fcc8d
commit
f0c9b259cc
@ -16,10 +16,20 @@ class SubCondition:
|
|||||||
def to_tuple(self) -> tuple:
|
def to_tuple(self) -> tuple:
|
||||||
return self.type, self.public_key
|
return self.type, self.public_key
|
||||||
|
|
||||||
|
def to_dict(self) -> dict:
|
||||||
|
return {
|
||||||
|
"type": self.type,
|
||||||
|
"public_key": self.public_key
|
||||||
|
}
|
||||||
|
|
||||||
@staticmethod
|
@staticmethod
|
||||||
def from_dict(subcondition_dict: dict) -> SubCondition:
|
def from_dict(subcondition_dict: dict) -> SubCondition:
|
||||||
return SubCondition(subcondition_dict["type"], subcondition_dict["public_key"])
|
return SubCondition(subcondition_dict["type"], subcondition_dict["public_key"])
|
||||||
|
|
||||||
|
@staticmethod
|
||||||
|
def list_to_dict(subconditions: List[SubCondition]) -> List[dict]:
|
||||||
|
return [subcondition.to_dict() for subcondition in subconditions]
|
||||||
|
|
||||||
@dataclass
|
@dataclass
|
||||||
class ConditionDetails:
|
class ConditionDetails:
|
||||||
type: str = ""
|
type: str = ""
|
||||||
@ -27,11 +37,24 @@ class ConditionDetails:
|
|||||||
threshold: int = None
|
threshold: int = None
|
||||||
sub_conditions: list[SubCondition] = None
|
sub_conditions: list[SubCondition] = None
|
||||||
|
|
||||||
|
def to_dict(self) -> dict:
|
||||||
|
if self.sub_conditions is None:
|
||||||
|
return {
|
||||||
|
"type": self.type,
|
||||||
|
"public_key": self.public_key,
|
||||||
|
}
|
||||||
|
else:
|
||||||
|
return {
|
||||||
|
"type": self.type,
|
||||||
|
"threshold": self.threshold,
|
||||||
|
"subconditions": [subcondition.to_dict() for subcondition in self.sub_conditions],
|
||||||
|
}
|
||||||
|
|
||||||
@staticmethod
|
@staticmethod
|
||||||
def from_dict(data: dict) -> ConditionDetails:
|
def from_dict(data: dict) -> ConditionDetails:
|
||||||
sub_conditions = None
|
sub_conditions = None
|
||||||
if data["sub_conditions"] is not None:
|
if data["subconditions"] is not None:
|
||||||
sub_conditions = [SubCondition.from_dict(sub_condition) for sub_condition in data["sub_conditions"]]
|
sub_conditions = [SubCondition.from_dict(sub_condition) for sub_condition in data["subconditions"]]
|
||||||
return ConditionDetails(
|
return ConditionDetails(
|
||||||
type=data.get("type"),
|
type=data.get("type"),
|
||||||
public_key=data.get("public_key"),
|
public_key=data.get("public_key"),
|
||||||
@ -55,7 +78,7 @@ class Condition:
|
|||||||
def to_dict(self) -> dict:
|
def to_dict(self) -> dict:
|
||||||
return {
|
return {
|
||||||
"uri": self.uri,
|
"uri": self.uri,
|
||||||
"details": self.details.__dict__,
|
"details": self.details.to_dict(),
|
||||||
}
|
}
|
||||||
|
|
||||||
@staticmethod
|
@staticmethod
|
||||||
@ -105,7 +128,7 @@ class Output:
|
|||||||
"type": self.condition.details.type,
|
"type": self.condition.details.type,
|
||||||
"public_key": self.condition.details.public_key,
|
"public_key": self.condition.details.public_key,
|
||||||
"threshold": self.condition.details.threshold,
|
"threshold": self.condition.details.threshold,
|
||||||
"subconditions": self.condition.details.sub_conditions,
|
"subconditions": SubCondition.list_to_dict(self.condition.details.sub_conditions),
|
||||||
},
|
},
|
||||||
"uri": self.condition.uri,
|
"uri": self.condition.uri,
|
||||||
},
|
},
|
||||||
|
|||||||
@ -281,7 +281,7 @@ 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:
|
||||||
tx_id = transactions[0]["transactions"].id
|
tx_id = transactions[0].id
|
||||||
tx = backend.query.get_transaction_single(self.connection, tx_id)
|
tx = backend.query.get_transaction_single(self.connection, tx_id)
|
||||||
tx.assets = backend.query.get_assets_by_tx_id(self.connection, tx_id)
|
tx.assets = backend.query.get_assets_by_tx_id(self.connection, tx_id)
|
||||||
transaction = tx.to_dict()
|
transaction = tx.to_dict()
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user