Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
def _print_object(data, title):
ctx = click.get_current_context()
if ctx.obj.get(CTX_OUTPUT_JSON, False):
if isinstance(data, tuple):
print(json.dumps(Munch.toDict(data), indent=2))
return
if isinstance(data, TxObject):
print(json.dumps(data.asdict(), indent=2))
return
if isinstance(data, str):
print(data)
return
print(json.dumps(data, indent=2))
return
_po(title, data)
def contract_aci(contract_file, compiler_url, json_):
try:
set_global_options(json_, False, False)
with open(contract_file) as fp:
code = fp.read()
c = CompilerClient(compiler_url=compiler_url)
result = c.aci(code)
if click.confirm(f'Save contract ACI to file ({contract_file}.aci.json) ?', default=True, show_default=True):
with open(f"{contract_file}.aci.json", "w") as fp:
fp.write(json.dumps(Munch.toDict(result), indent=2))
_print_object(result, title="contract")
except OpenAPIClientException as e:
_print_object(e.data, title="compiler error")
except Exception as e:
_print_error(e, exit_code=1)