Skip to content

Commit

Permalink
Merge pull request #218 from multiversx/verify-logging-07
Browse files Browse the repository at this point in the history
Extra logging for contract verify
  • Loading branch information
andreibancioiu authored Feb 8, 2023
2 parents 2b355ea + 5b99ef2 commit 713c59f
Show file tree
Hide file tree
Showing 6 changed files with 47 additions and 25 deletions.
2 changes: 1 addition & 1 deletion multiversx_sdk_cli/_version.py
Original file line number Diff line number Diff line change
@@ -1 +1 @@
__version__ = "5.2.3"
__version__ = "5.3.0"
4 changes: 2 additions & 2 deletions multiversx_sdk_cli/cli.py
Original file line number Diff line number Diff line change
Expand Up @@ -45,9 +45,9 @@ def _do_main(cli_args: List[str]):
args = parser.parse_args(argv_with_config_args)

if args.verbose:
logging.basicConfig(level=logging.DEBUG)
logging.basicConfig(level=logging.DEBUG, force=True)
else:
logging.basicConfig(level=logging.WARN)
logging.basicConfig(level=logging.INFO, force=True)

if not hasattr(args, "func"):
parser.print_help()
Expand Down
52 changes: 40 additions & 12 deletions multiversx_sdk_cli/contract_verification.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,13 +3,14 @@
import logging
import time
from pathlib import Path
from typing import Any, Dict
from typing import Any, Dict, Tuple

import requests
from multiversx_sdk_core import MessageV1
from nacl.signing import SigningKey

from multiversx_sdk_cli.accounts import Account, Address
from multiversx_sdk_cli.errors import KnownError
from multiversx_sdk_cli.utils import dump_out_json, read_json_file

HTTP_REQUEST_TIMEOUT = 408
Expand Down Expand Up @@ -74,24 +75,25 @@ def trigger_contract_verification(
request_dictionary = contract_verification.to_dictionary()

url = f"{verifier_url}/verifier"
response = requests.post(url, json=request_dictionary)
status_code, message, data = _do_post(url, request_dictionary)

if response.status_code == HTTP_REQUEST_TIMEOUT:
task_id = response.json().get("taskId", "")
if status_code == HTTP_REQUEST_TIMEOUT:
task_id = data.get("taskId", "")

if task_id:
query_status_with_task_id(verifier_url, task_id)
else:
dump_out_json(response.json())
elif response.status_code != HTTP_SUCCESS:
dump_out_json(response.json())
elif response.status_code == HTTP_SUCCESS:
status = response.json().get("status", "")
dump_out_json(data)
elif status_code != HTTP_SUCCESS:
dump_out_json(data)
raise KnownError(f"Cannot verify contract: {message}")
else:
status = data.get("status", "")
if status:
logger.info(f"Task status: {status}")
dump_out_json(response.json())
dump_out_json(data)
else:
task_id = response.json().get("taskId", "")
task_id = data.get("taskId", "")
query_status_with_task_id(verifier_url, task_id)


Expand All @@ -116,7 +118,7 @@ def query_status_with_task_id(url: str, task_id: str, interval: int = 10):
old_status = ""

while True:
response = requests.get(f"{url}/tasks/{task_id}").json()
_, _, response = _do_get(f"{url}/tasks/{task_id}")
status = response.get("status", "")

if status == "finished":
Expand All @@ -129,3 +131,29 @@ def query_status_with_task_id(url: str, task_id: str, interval: int = 10):
old_status = status

time.sleep(interval)


def _do_post(url: str, payload: Any) -> Tuple[int, str, Dict[str, Any]]:
logger.debug(f"_do_post() to {url}")
response = requests.post(url, json=payload)

try:
data = response.json()
message = data.get("message", "")
return response.status_code, message, data
except Exception as error:
logger.error(f"Erroneous response from {url}: {response.text}")
raise KnownError(f"Cannot parse response from {url}", error)


def _do_get(url: str) -> Tuple[int, str, Dict[str, Any]]:
logger.debug(f"_do_get() from {url}")
response = requests.get(url)

try:
data = response.json()
message = data.get("message", "")
return response.status_code, message, data
except Exception as error:
logger.error(f"Erroneous response from {url}: {response.text}")
raise KnownError(f"Cannot parse response from {url}", error)
7 changes: 3 additions & 4 deletions multiversx_sdk_cli/docker.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,10 +4,9 @@
from pathlib import Path
from typing import List

from multiversx_sdk_cli import myprocess
from multiversx_sdk_cli.errors import ExternalProcessError, KnownError
from multiversx_sdk_cli.errors import KnownError

logger = logging.getLogger("build-with-docker")
logger = logging.getLogger("docker")


def is_docker_installed():
Expand Down Expand Up @@ -49,7 +48,7 @@ def run_docker(
docker_args += ["--user", f"{str(os.getuid())}:{str(os.getgid())}"]
docker_args += ["--rm", image]

if not(no_default_platform):
if not (no_default_platform):
docker_args += ["--platform", "linux/amd64"]

entrypoint_args: List[str] = []
Expand Down
5 changes: 0 additions & 5 deletions multiversx_sdk_cli/errors.py
Original file line number Diff line number Diff line change
Expand Up @@ -84,11 +84,6 @@ def __init__(self, argument: Any):
super().__init__(f"Cannot handle non-hex, non-number arguments yet: {argument}.")


class ProxyRequestError(KnownError):
def __init__(self, url: str, data: Any):
super().__init__(f"Proxy request error for url [{url}]: {data}")


class BadInputError(KnownError):
def __init__(self, input: str, message: str):
super().__init__(f"Bad input [{input}]: {message}")
Expand Down
2 changes: 1 addition & 1 deletion setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

import setuptools

VERSION = "5.2.3"
VERSION = "5.3.0"

try:
with open('./multiversx_sdk_cli/_version.py', 'wt') as versionfile:
Expand Down

0 comments on commit 713c59f

Please sign in to comment.