Skip to content

Commit

Permalink
fix: rest api contract deployment issue (fetchai#289)
Browse files Browse the repository at this point in the history
  • Loading branch information
solarw committed Oct 27, 2022
1 parent eeea6fb commit 7161772
Show file tree
Hide file tree
Showing 8 changed files with 138 additions and 41 deletions.
2 changes: 1 addition & 1 deletion Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -212,7 +212,7 @@ COSMOS_SDK_VERSION := v0.18.0
COSMOS_SDK_DIR := build/cosmos-sdk-proto-schema

WASMD_URL := https://github.com/CosmWasm/wasmd
WASMD_VERSION := v0.24.0
WASMD_VERSION := v0.27.0
WASMD_DIR := build/wasm-proto-shema

IBCGO_URL := https://github.com/cosmos/ibc-go
Expand Down
13 changes: 12 additions & 1 deletion cosmpy/common/rest_client.py
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,8 @@
# ------------------------------------------------------------------------------

"""Implementation of REST api client."""

import base64
import json
from typing import List, Optional
from urllib.parse import urlencode

Expand Down Expand Up @@ -109,6 +110,16 @@ def post(self, url_base_path: str, request: Message) -> bytes:
"""
json_request = MessageToDict(request)

# Workaround
if "tx" in json_request:
if "body" in json_request["tx"]:
if "messages" in json_request["tx"]["body"]:
for message in json_request["tx"]["body"]["messages"]:
if "msg" in message:
message["msg"] = json.loads(
base64.b64decode(message["msg"])
)

headers = {"Content-type": "application/json", "Accept": "application/json"}
response = self._session.post(
url=f"{self.rest_address}{url_base_path}",
Expand Down
20 changes: 20 additions & 0 deletions cosmpy/cosmwasm/rest_client.py
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,7 @@
QuerySmartContractStateRequest,
QuerySmartContractStateResponse,
)
from cosmpy.protos.cosmwasm.wasm.v1.types_pb2 import AccessType


class CosmWasmRestClient(CosmWasm):
Expand Down Expand Up @@ -191,8 +192,27 @@ def Codes(self, request: QueryCodesRequest) -> QueryCodesResponse:
:return: QueryCodesResponse
"""
response = self._rest_api.get(f"{self.API_URL}/code", request)
responses_json = json.loads(response)
for code_info in responses_json["code_infos"]:
if "instantiate_permission" not in code_info:
continue
code_info["instantiate_permission"]["permission"] = self._fix_permission(
code_info["instantiate_permission"]["permission"]
)
response = json.dumps(responses_json).encode("utf-8")
return Parse(response, QueryCodesResponse())

def _fix_permission(self, permission_name):
permission_map = {
"Nobody": AccessType.Value("ACCESS_TYPE_NOBODY"),
"OnlyAddress": AccessType.Value("ACCESS_TYPE_ONLY_ADDRESS"),
"Everybody": AccessType.Value("ACCESS_TYPE_EVERYBODY"),
"Unspecified": AccessType.Value("ACCESS_TYPE_UNSPECIFIED"),
}
return permission_map.get(
permission_name, AccessType.Value("ACCESS_TYPE_UNSPECIFIED")
)

@staticmethod
def _fix_state_response(response: bytes) -> JSONLike:
"""
Expand Down
32 changes: 31 additions & 1 deletion cosmpy/protos/cosmwasm/wasm/v1/proposal_pb2.py

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Loading

0 comments on commit 7161772

Please sign in to comment.