Skip to content

Commit

Permalink
Merge pull request #125 from terra-money/chore-updates
Browse files Browse the repository at this point in the history
fix CompactBitArray conversion error
  • Loading branch information
Geoff Lee authored Apr 20, 2022
2 parents bd17672 + 344d23c commit 3ea115a
Show file tree
Hide file tree
Showing 7 changed files with 44 additions and 16 deletions.
2 changes: 1 addition & 1 deletion terra_sdk/core/authz/data.py
Original file line number Diff line number Diff line change
Expand Up @@ -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"])
)


Expand Down
5 changes: 1 addition & 4 deletions terra_sdk/core/authz/msgs.py
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand Down
16 changes: 13 additions & 3 deletions terra_sdk/core/compact_bit_array.py
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand Down
8 changes: 4 additions & 4 deletions terra_sdk/core/gov/data.py
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand Down
23 changes: 20 additions & 3 deletions terra_sdk/core/staking/data/delegation.py
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand All @@ -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"]
]
Expand Down Expand Up @@ -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),
}
Expand Down
2 changes: 1 addition & 1 deletion terra_sdk/core/staking/data/validator.py
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand Down
4 changes: 4 additions & 0 deletions terra_sdk/util/json.py
Original file line number Diff line number Diff line change
Expand Up @@ -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):
Expand All @@ -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):
Expand Down

0 comments on commit 3ea115a

Please sign in to comment.