def run(file_path, file_name): template_file = template_file_path + template_file_name template_file_name_py = template_file + ".py" Compiler.load_and_save(template_file_name_py) readable_out_avm_file = template_file_path + "Out_readable_Avm.avm" save_avm(readable_out_avm_file, read_avm(template_file + ".avm"))
def test_abi_script_hash_fail(self): path = '%s/boa_test/example/AbiMethods1.py' % TestContract.dirname abi_path = path.replace('.py', '.abi.json') Compiler.load_and_save(path) self.assertTrue(os.path.exists(abi_path)) with open(abi_path, 'r') as abi_file: json_file = json.loads(abi_file.read()) self.assertIn('hash', json_file) script_hash = json_file['hash'] self.assertNotEqual(script_hash, 'a623cc41d62bf5783acde35fd105cdc4')
def run(file_path, file_name): """ Read the source py file and compile it, save it into readable avm file :param file_path: the folder of file :param file_name: the source file name without ".py"-suffix :return: """ template_file = template_file_path + template_file_name template_file_name_py = template_file + ".py" Compiler.load_and_save(template_file_name_py) # Out_readable_Avm.avm is the output file that we are going to use when deploying our contract readable_out_avm_file= template_file_path + "Out_readable_Avm.avm" save_avm(readable_out_avm_file, read_avm(template_file + ".avm"))
def test_abi_script_hash_success(self): path = '%s/boa_test/example/AbiMethods1.py' % TestContract.dirname abi_path = path.replace('.py', '.abi.json') Compiler.load_and_save(path) self.assertTrue(os.path.exists(abi_path)) with open(abi_path, 'r') as abi_file: json_file = json.loads(abi_file.read()) self.assertIn('hash', json_file) script_hash = json_file['hash'] self.assertEqual(script_hash, '0xd0fce96885b76b14beed1c401af22d438ace50d4')
async def compile(request): if request.json.get("type") != "Python": return sanic.response.text("Not A Available Code Type. ") else: pycode = request.json.get("code") tmpfile = tempfile.NamedTemporaryFile(mode="w", delete=False) tmp_name = tmpfile.name + ".py" fp = open(tmp_name, mode="wb+") fp.write(pycode.encode()) fp.flush() Compiler.load_and_save(tmp_name) compiler = Compiler.load(tmp_name) bak = os.sys.stdout default_module = compiler.default default_module.write() os.sys.stdout = tmpfile.file default_module.to_s() os.sys.stdout.flush() os.sys.stdout = bak data = { "abi": "", "avm": "", "debug": "", "errorcode": 0, "funcmap": "", "opcode": "" } read_value(data, tmpfile.name + ".abi.json", "abi") read_value(data, tmpfile.name + ".avm.str", "avm") read_value(data, tmpfile.name + ".FuncMap.json", "funcmap") read_value(data, tmpfile.name + ".debug.json", "debug") read_value(data, tmpfile.name, "opcode") _deletedebugfile = functools.partial(deletedebugfile, tmp_name) list(map(_deletedebugfile, tmp_exts)) tmpfile.close() fp.close() deletedebugfile(tmp_name, ".py") # return sanic.response.text( # "{}".format(data), # headers={ # "Access-Control-Allow-Origin": "*" # }, # content_type="text/html; charset=UTF-8" # ) return sanic.response.json( data, headers={ "Access-Control-Allow-Origin": "*" } )
def hello_compiler(): avm_path = os.path.join(os.getcwd(), 'hello_compiler.avm') with open(avm_path, 'w'): pass Compiler.load_and_save(avm_path) json_path = os.path.join(os.getcwd(), 'hello_compiler.debug.json') with open(avm_path, 'r') as f: avm = f.read() print("avm: " + avm) with open(json_path, 'r') as f: debug_json = json.load(f) print("debug_json: " + str(debug_json)) os.remove(avm_path) os.remove(json_path)
def main(): parser = argparse.ArgumentParser() parser.add_argument("--version", action="version", version=f"neo-boa v{__version__}") parser.add_argument("input", help=".py smart contract to compile") args = parser.parse_args() if not args.input.endswith(".py") or not os.path.isfile(args.input): print("Input file is not .py") sys.exit(1) Compiler.load_and_save(args.input) print( f"Wrote {args.input.replace('.py', '.avm')} to {os.path.abspath(os.curdir)}/" )
def test_compile_1(self): sc = Compiler.load_and_save('%s/boa_test/example/AddTest1.py' % TestContract.dirname) expected_output = '%s/%s' % (TestContract.dirname, self.TEST_SC_OUTPUT) self.assertTrue(os.path.exists(expected_output))
def main(argv): inputfile = '' try: opts, args = getopt.getopt(argv,"hi:") except getopt.GetoptError: print ('compileSmartContract.py -i <inputfile>') sys.exit(2) for opt, arg in opts: if opt == '-h': print ('compileSmartContract.py -i <inputfile>') sys.exit() elif opt in ("-i"): inputfile = arg if inputfile == '': print ('ERROR: Please provide an input file. See -h for help.') sys.exit(2); Compiler.load_and_save(inputfile)
def main(): parser = argparse.ArgumentParser() parser.add_argument("--version", action="version", version=f"neo-boa v{__version__}") parser.add_argument("-o", "--output", help="output directory") parser.add_argument("-n8", "--no-nep8", action='store_true', help="enable/disable nep8") parser.add_argument("input", help=".py smart contract to compile") args = parser.parse_args() if not args.input.endswith(".py") or not os.path.isfile(args.input): print("Input file is not .py") sys.exit(1) Compiler.load_and_save(args.input, args.output, args.no_nep8) print( f"Wrote {args.input.replace('.py', '.avm')} to {os.path.abspath(os.curdir)}/" )
def _testitem(self, item): result = Compiler.load_and_save(item) self.assertIsNotNone(result) self.assertIsInstance(result, bytes) # this is the output path output = item.replace('.py', '.avm') # check to make sure it was saved correctly self.assertTrue(os.path.isfile(output)) os.remove(output)
def test_a_single_compile(self): # just test a single compilation to see how things are going first_item = self.items_to_test[0] result = Compiler.load_and_save(first_item) self.assertIsNotNone(result) self.assertIsInstance(result, bytes) # this is the output path output = first_item.replace('.py', '.avm') # check to make sure it was saved correctly self.assertTrue(os.path.isfile(output)) os.remove(output)
import os from boa.compiler import Compiler input_file_dir = '/python-contracts' output_file_dir = '/compiled-contracts' for file in os.listdir(input_file_dir): if file.endswith('.py'): file_name = file.replace('.py','') input_file_path = os.path.join(input_file_dir, file) output_file = file_name + '.avm' output_file_path = os.path.join(output_file_dir, output_file) Compiler.load_and_save(path=input_file_path, output_path=output_file_path) print('Compiled ' + file)
from boa.compiler import Compiler Compiler.load_and_save('neoblog.py')
from boa.compiler import Compiler Compiler.load_and_save('genki_smart_contract.py')
subprocess.call(["rm", d_file]) if __name__ == '__main__': opts, args = getopt.getopt(sys.argv[1:], "n:m:d") for op, value in opts: if op == "-n": filename = value if op == "-m": runmode = int(value) if op == "-d": deletedebug = True if filename == None: print("Filename do not set!!!") exit() if runmode == 1: print("Runmode 1. Compile file", filename) Compiler.load_and_save(filename) elif runmode == 0: print("Runmode 0. Dump avm code message of file", filename) module = Compiler.load(filename).default module.write() module.to_s() if deletedebug: deletedebugfile(filename, '.abi.json') deletedebugfile(filename, '.debug.json') deletedebugfile(filename, '.FuncMap.json')
from boa.compiler import Compiler Compiler.load_and_save('smartcontract.py')
from boa.compiler import Compiler Compiler.load_and_save('examples/hello.py') Compiler.load_and_save('examples/key_store.py') Compiler.load_and_save('examples/early_oracle_judge.py') Compiler.load_and_save('examples/timestamp.py') Compiler.load_and_save('examples/voting.py') Compiler.load_and_save('online_voting.py') Compiler.load_and_save('oracle_judge.py')
from boa.compiler import Compiler Compiler.load_and_save('ico_template.py')
from boa.compiler import Compiler Compiler.load_and_save('nxa_ico.py')
""" Compiler helper =============== This modules simply imports the neo-boa `Compiler` abstraction and triggers the compilation of the contract whose filename is passed as first argument. """ import os import sys from boa.compiler import Compiler path = sys.argv[1] filename = os.path.basename(path) Compiler.load_and_save( path, output_path=os.path.join(os.getcwd(), 'build', '{}.avm'.format(os.path.splitext(filename)[0])))
from boa.compiler import Compiler Compiler.load_and_save('ico_smart_contract.py')
#!/usr/bin/env python3 from boa.compiler import Compiler Compiler.load_and_save('event-print-smart-contract.py')
import argparse import os import sys from boa.compiler import Compiler parser = argparse.ArgumentParser("simple_example") parser.add_argument("input", help="Input python file.", type=str) parser.add_argument("output", help="Output avm file.", type=str) args = parser.parse_args() path = os.path.dirname(os.path.abspath(args.input)) sys.path = [path] + sys.path print('Compiling {0} to {1}'.format(args.input, args.output)) Compiler.load_and_save(path=args.input, output_path=args.output)
from boa.compiler import Compiler Compiler.load_and_save('neo_futures.py') #Compiler.load_and_save('oracle_lite.py')
from boa.compiler import Compiler Compiler.load_and_save('astrum.py')
from boa.compiler import Compiler Compiler.load_and_save('cashflow.py')
from boa.compiler import Compiler Compiler.load_and_save('nasc.py') Compiler.load_and_save('core_nasc.py')
from boa.compiler import Compiler Compiler.load_and_save('voting.py')
from boa.compiler import Compiler Compiler.load_and_save('ico.py')