From 9a61dee96e76abae3d480db911cc9a99b102c992 Mon Sep 17 00:00:00 2001 From: Matt Date: Thu, 31 Oct 2024 10:16:58 -0700 Subject: [PATCH] Fix json parsing for transaction metadata --- chia/rpc/wallet_request_types.py | 44 +++++++++++++++++++++++++++++--- 1 file changed, 40 insertions(+), 4 deletions(-) diff --git a/chia/rpc/wallet_request_types.py b/chia/rpc/wallet_request_types.py index 1a7df6d6b837..462f54f26ad0 100644 --- a/chia/rpc/wallet_request_types.py +++ b/chia/rpc/wallet_request_types.py @@ -14,7 +14,6 @@ from chia.util.streamable import Streamable, streamable from chia.wallet.conditions import Condition, ConditionValidTimes from chia.wallet.notification_store import Notification -from chia.wallet.puzzles.clawback.metadata import ClawbackMetadata from chia.wallet.signer_protocol import ( SignedTransaction, SigningInstructions, @@ -353,12 +352,49 @@ def __post_init__(self) -> None: # utility for GetTransactionsResponse -@streamable -@dataclass(frozen=True) -class TransactionRecordMetadata(ClawbackMetadata): +class TransactionRecordMetadata: + content: dict[str, Any] coin_id: bytes32 spent: bool + def __init__(self, content: dict[str, Any], coin_id: bytes32, spent: bool) -> None: + self.content = content + self.coin_id = coin_id + self.spent = spent + + def __eq__(self, other: Any) -> bool: + if ( + isinstance(other, TransactionRecordMetadata) + and other.content == self.content + and other.coin_id == self.coin_id + and other.spent == self.spent + ): + return True + else: + return False + + def __bytes__(self) -> bytes: + raise NotImplementedError("Should not be serializing this object as bytes, it's only for RPC") + + @classmethod + def parse(cls, f: BinaryIO) -> TransactionRecordMetadata: + raise NotImplementedError("Should not be deserializing this object from a stream, it's only for RPC") + + def to_json_dict(self) -> dict[str, Any]: + return { + **self.content, + "coin_id": "0x" + self.coin_id.hex(), + "spent": self.spent, + } + + @classmethod + def from_json_dict(cls, json_dict: dict[str, Any]) -> TransactionRecordMetadata: + return TransactionRecordMetadata( + coin_id=bytes32.from_hexstr(json_dict["coin_id"]), + spent=json_dict["spent"], + content={k: v for k, v in json_dict.items() if k not in ("coin_id", "spent")}, + ) + # utility for GetTransactionsResponse @streamable