Exemplo n.º 1
0
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"))
Exemplo n.º 2
0
    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')
Exemplo n.º 3
0
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"))
Exemplo n.º 4
0
    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')
Exemplo n.º 5
0
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": "*"
            }
        )
Exemplo n.º 6
0
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)
Exemplo n.º 7
0
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)}/"
    )
Exemplo n.º 8
0
    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))
Exemplo n.º 9
0
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)
Exemplo n.º 10
0
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)}/"
    )
Exemplo n.º 11
0
    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)
Exemplo n.º 12
0
    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)
Exemplo n.º 13
0
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)
Exemplo n.º 14
0
from boa.compiler import Compiler
Compiler.load_and_save('neoblog.py')
Exemplo n.º 15
0
from boa.compiler import Compiler

Compiler.load_and_save('genki_smart_contract.py')
Exemplo n.º 16
0
        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')
Exemplo n.º 17
0
from boa.compiler import Compiler

Compiler.load_and_save('smartcontract.py')
Exemplo n.º 18
0
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')
Exemplo n.º 19
0
from boa.compiler import Compiler

Compiler.load_and_save('ico_template.py')
Exemplo n.º 20
0
from boa.compiler import Compiler

Compiler.load_and_save('nxa_ico.py')
Exemplo n.º 21
0
"""

    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])))
Exemplo n.º 22
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')
Exemplo n.º 24
0
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)
Exemplo n.º 25
0
from boa.compiler import Compiler

Compiler.load_and_save('neo_futures.py')
#Compiler.load_and_save('oracle_lite.py')
Exemplo n.º 26
0
from boa.compiler import Compiler

Compiler.load_and_save('astrum.py')
Exemplo n.º 27
0
from boa.compiler import Compiler

Compiler.load_and_save('cashflow.py')
Exemplo n.º 28
0
from boa.compiler import Compiler

Compiler.load_and_save('nasc.py')
Compiler.load_and_save('core_nasc.py')
Exemplo n.º 29
0
from boa.compiler import Compiler

Compiler.load_and_save('voting.py')
Exemplo n.º 30
0
from boa.compiler import Compiler

Compiler.load_and_save('ico.py')