diff --git a/terra_sdk/core/authz/data.py b/terra_sdk/core/authz/data.py index b0cd55d8..d8ad2d84 100644 --- a/terra_sdk/core/authz/data.py +++ b/terra_sdk/core/authz/data.py @@ -201,7 +201,7 @@ def from_amino(cls, amino: dict) -> AuthorizationGrant: value = amino["value"] return cls( authorization=Authorization.from_amino(value["authorization"]), - expiration=value["expiration"] + expiration=parser.parse(value["expiration"]) ) diff --git a/terra_sdk/core/authz/msgs.py b/terra_sdk/core/authz/msgs.py index b2249cb6..f5ae8166 100644 --- a/terra_sdk/core/authz/msgs.py +++ b/terra_sdk/core/authz/msgs.py @@ -126,10 +126,7 @@ def from_data(cls, data: dict) -> MsgGrantAuthorization: return cls( granter=data["granter"], grantee=data["grantee"], - grant=AuthorizationGrant( - authorization=Authorization.from_data(data["grant"]["authorization"]), - expiration=str(data["grant"]["expiration"]), - ), + grant=AuthorizationGrant.from_data(data["grant"]) ) def to_proto(self) -> MsgGrant_pb: diff --git a/terra_sdk/core/compact_bit_array.py b/terra_sdk/core/compact_bit_array.py index 3f8345a1..49286b8c 100644 --- a/terra_sdk/core/compact_bit_array.py +++ b/terra_sdk/core/compact_bit_array.py @@ -21,9 +21,19 @@ class CompactBitArray(JSONSerializable): @classmethod def from_data(cls, data: dict) -> CompactBitArray: - return cls( - data["extra_bits_stored"], bytearray(base64.b64decode(data["elems"])) - ) + return cls(data["extra_bits_stored"], bytearray(base64.b64decode(data["elems"]))) + + def to_data(self) -> dict: + return { + "extra_bits_stored": self.extra_bits_stored, + "elems": base64.b64encode(self.elems) + } + + def to_data(self) -> dict: + return { + "extra_bits_stored": self.extra_bits_stored, + "elems": base64.b64encode(self.elems).decode() + } @classmethod def from_proto(cls, proto: CompactBitArray_pb) -> CompactBitArray: diff --git a/terra_sdk/core/gov/data.py b/terra_sdk/core/gov/data.py index ae08eaae..26d220e2 100644 --- a/terra_sdk/core/gov/data.py +++ b/terra_sdk/core/gov/data.py @@ -112,11 +112,11 @@ def from_data(cls, data: dict) -> Proposal: content=parse_content(data["content"]), status=data["status"], final_tally_result=data["final_tally_result"], - submit_time=data["submit_time"], - deposit_end_time=data["deposit_end_time"], + submit_time=parser.parse(data["submit_time"]), + deposit_end_time=parser.parse(data["deposit_end_time"]), total_deposit=Coins.from_data(data["total_deposit"]), - voting_start_time=data["voting_start_time"], - voting_end_time=data["voting_end_time"], + voting_start_time=parser.parse(data["voting_start_time"]), + voting_end_time=parser.parse(data["voting_end_time"]), ) def to_proto(self) -> Proposal_pb: diff --git a/terra_sdk/core/staking/data/delegation.py b/terra_sdk/core/staking/data/delegation.py index 34838ef2..bc27ce82 100644 --- a/terra_sdk/core/staking/data/delegation.py +++ b/terra_sdk/core/staking/data/delegation.py @@ -115,7 +115,7 @@ def from_data(cls, data: dict) -> UnbondingDelegationEntry: initial_balance=data["initial_balance"], balance=data["balance"], creation_height=data["creation_height"], - completion_time=data["completion_time"], + completion_time=parser.parse(data["completion_time"]), ) def to_proto(self) -> UnbondingDelegationEntry_pb: @@ -141,12 +141,12 @@ class UnbondingDelegation(JSONSerializable): def to_amino(self) -> dict: return { "delegator_address": self.delegator_address, - "validator_addresS": self.validator_address, + "validator_address": self.validator_address, "entries": [entry.to_amino() for entry in self.entries], } @classmethod - def from_data(cls, data) -> UnbondingDelegation: + def from_data(cls, data: dict) -> UnbondingDelegation: entries = [ UnbondingDelegationEntry.from_data(entry) for entry in data["entries"] ] @@ -179,6 +179,23 @@ def to_amino(self) -> dict: return { "initial_balance": str(self.initial_balance), "shares_dst": str(self.shares_dst), + "creation_height": str(self.creation_height), + "completion_time": to_isoformat(self.completion_time), + } + + @classmethod + def from_data(cls, data: dict) -> RedelegationEntryInfo: + return cls( + initial_balance=data["initial_balance"], + shares_dst=Dec.from_data(data("shares_dst")), + creation_height=data["creation_height"], + completion_time=parser.parse(data["completion_time"]) + ) + + def to_data(self) -> dict: + return { + "initial_balance": self.initial_balance, + "shares_dst": self.shares_dst.to_data(), "creation_height": self.creation_height, "completion_time": to_isoformat(self.completion_time), } diff --git a/terra_sdk/core/staking/data/validator.py b/terra_sdk/core/staking/data/validator.py index f4afa7cb..57b1bfb4 100644 --- a/terra_sdk/core/staking/data/validator.py +++ b/terra_sdk/core/staking/data/validator.py @@ -95,7 +95,7 @@ def to_amino(self) -> dict: def from_data(cls, data: dict) -> Commission: return cls( commission_rates=CommissionRates.from_data(data["commission_rates"]), - update_time=data["update_time"], + update_time=parser.parse(data["update_time"]), ) def to_proto(self) -> Commission_pb: diff --git a/terra_sdk/util/json.py b/terra_sdk/util/json.py index edf19c77..94d5ebe0 100644 --- a/terra_sdk/util/json.py +++ b/terra_sdk/util/json.py @@ -12,6 +12,8 @@ def to_data(x: Any) -> Any: return x.to_data() if isinstance(x, int): return str(x) + if isinstance(x, datetime): + return to_isoformat(x) if isinstance(x, list): return [to_data(g) for g in x] if isinstance(x, dict): @@ -26,6 +28,8 @@ def to_amino(x: Any) -> Any: return x.to_amino() if isinstance(x, list): return [to_data(g) for g in x] + if isinstance(x, datetime): + return to_isoformat(x) if isinstance(x, dict): return dict_to_amino(x) if isinstance(x, int):