def contract_decode_data(contract_file, encoded_data, sophia_type, compiler_url, json_): try: set_global_options(json_, False, False) c = CompilerClient(compiler_url) result = c.decode_data(sophia_type, encoded_data) _print_object(result, title="contract") except Exception as e: _print_error(e, exit_code=1)
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) _print_object(result, title="contract") except Exception as e: _print_error(e, exit_code=1)
def contract_encode_calldata(contract_file, function_name, arguments, compiler_url, json_): try: set_global_options(json_, False, False) with open(contract_file) as fp: code = fp.read() c = CompilerClient(compiler_url) arguments = [] if arguments is None else arguments.split(",") result = c.encode_calldata(code, function_name, arguments=arguments) _print_object(result, title="contract") # except Exception as e: # _print_error(e, exit_code=1) finally: pass
def contract_compile(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) result = c.compile(code) if click.confirm(f'Save contract bytecode to file ({contract_file}.bin) ?', default=True, show_default=True): with open(f"{contract_file}.bin", "w") as fp: fp.write(result.bytecode) _print_object(result, title="contract") except Exception as e: _print_error(e, exit_code=1)
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(namedtupled.reduce(result), indent=2)) _print_object(result, title="contract") except Exception as e: _print_error(e, exit_code=1)
def inspect(obj, height, force, wait, json_): try: set_global_options(json_, force, wait) if obj.endswith(".test") or obj.endswith(".aet"): data = _node_cli().get_name_entry_by_name(name=obj) _print_object(data, title="name") elif obj.startswith("kh_") or obj.startswith("mh_"): v = _node_cli().get_block_by_hash(obj) _print_object(v, title="block") elif obj.startswith("th_"): # v = _node_cli().get_transaction_by_hash(hash=obj) v = _node_cli().get_transaction(obj) _print_object(v, title="transaction") elif obj.startswith("ak_"): if height is not None and height > 0: account = _node_cli().get_account_by_pubkey_and_height( pubkey=obj, height=height) _print_object(account, title=f"account at {height}") return account = _node_cli().get_account_by_pubkey(pubkey=obj) _print_object(account, title="account") elif obj.startswith("ct_"): v = _node_cli().get_contract(pubkey=obj) _print_object(v, title="contract") elif obj.startswith("ok_"): cli = _node_cli() data = dict(oracle=cli.get_oracle_by_pubkey(pubkey=obj), queries=cli.get_oracle_queries_by_pubkey(pubkey=obj)) _print_object(data, title="oracle context") elif obj.startswith("tx_"): v = _node_cli().verify(obj) _print_object(v, title="tx") elif obj.startswith("cb_"): v = CompilerClient.decode_bytecode(obj) _print_object(v, title="contract") elif obj.isdigit() and int(obj) >= 0: v = _node_cli().get_key_block_by_height(height=int(obj)) _print_object(v, title="block") else: raise ValueError(f"input not recognized: {obj}") except Exception as e: _print_error(e)
def compiler_fixture(scope="module"): # Instantiate the node client for the tests compiler = CompilerClient(COMPILER_URL) return namedtupled.map({"COMPILER": compiler}, _nt_name="TestData")
def compiler_fixture(scope="module"): compiler = CompilerClient(COMPILER_URL) return namedtupled.map({"COMPILER": compiler}, _nt_name="TestData")