Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

make parse_msg() won't panic with a non-json string #179

Open
wants to merge 3 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 3 additions & 1 deletion .github/workflows/main.yml
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,9 @@ jobs:
python-version: 3.9

- name: Setup Poetry
uses: Gr1N/setup-poetry@v4
uses: Gr1N/setup-poetry@v7
with:
poetry-version: 1.2.0

- name: Cache Dependencies
uses: actions/cache@v2
Expand Down
11 changes: 11 additions & 0 deletions integration_tests/decode.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
from terra_sdk.client.lcd import LCDClient


def main():
terra = LCDClient(
url="https://phoenix-lcd.terra.dev",
chain_id="phoenix-1",
)
print(terra.tx.tx_infos_by_height(1763383))

main()
7 changes: 1 addition & 6 deletions terra_sdk/core/wasm/data.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,17 +14,12 @@

from terra_sdk.core.bech32 import AccAddress
from terra_sdk.core.msg import Msg
from terra_sdk.core.wasm.util import parse_msg
from terra_sdk.util.json import JSONSerializable

__all__ = ["AccessType", "AccessConfig", "AccessConfigUpdate", "AccessTypeParam"]


def parse_msg(msg: Union[dict, str, bytes]) -> dict:
if type(msg) is dict:
return msg
return json.loads(msg)


def convert_access_type_from_json(access_type: str) -> AccessType:
if access_type == "Everybody":
return AccessType.ACCESS_TYPE_EVERYBODY
Expand Down
7 changes: 1 addition & 6 deletions terra_sdk/core/wasm/msgs.py
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@
from terra_sdk.core.msg import Msg
from terra_sdk.core.wasm.data import AccessConfig, AccessTypeParam
from terra_sdk.util.remove_none import remove_none
from terra_sdk.core.wasm.util import parse_msg

__all__ = [
"MsgStoreCode",
Expand All @@ -33,12 +34,6 @@
]


def parse_msg(msg: Union[dict, str, bytes]) -> dict:
if type(msg) is dict:
return msg
return json.loads(msg)


@attr.s
class MsgStoreCode(Msg):
"""Upload a new smart contract WASM binary to the blockchain.
Expand Down
7 changes: 1 addition & 6 deletions terra_sdk/core/wasm/proposals.py
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@
from terra_sdk.core.bech32 import AccAddress
from terra_sdk.core.coins import Coins
from terra_sdk.core.wasm.data import AccessConfig, AccessConfigUpdate
from terra_sdk.core.wasm.util import parse_msg
from terra_sdk.util.json import JSONSerializable
from terra_sdk.util.remove_none import remove_none

Expand All @@ -49,12 +50,6 @@
]


def parse_msg(msg: Union[dict, str, bytes]) -> dict:
if type(msg) is dict:
return msg
return json.loads(msg)


@attr.s
class ClearAdminProposal(JSONSerializable):
"""
Expand Down
8 changes: 8 additions & 0 deletions terra_sdk/core/wasm/util.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
import json
from typing import Union

def parse_msg(msg: Union[dict, str, bytes]) -> dict:
try:
return json.loads(msg)
except:
return msg