forked from ONT-Avocados/python-template
-
Notifications
You must be signed in to change notification settings - Fork 0
/
compile_contract.py
60 lines (41 loc) · 1.77 KB
/
compile_contract.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
import binascii
from boa.compiler import Compiler
def hexlify_avm(blob):
return binascii.hexlify(blob).decode('ascii')
def read_avm(filename):
with open(filename, 'rb') as f:
return hexlify_avm(f.read())
def save_avm(filename, a):
with open(filename,'w') as f:
f.write(a)
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"))
if __name__ == '__main__':
""" set up the compiled file path and file name"""
# template_file_path = "./OEP4Sample_raise_Exception/"
# template_file_name = "OEP4Sample_raiseException"
# template_file_path = "./MigrateDestruct/"
# template_file_name = "migrate_destroyWithinContract"
# template_file_path = "./MySimpleToken/"
# template_file_name = "MySimpleToken"
# template_file_path = "./Static_Call_Oep4/"
# template_file_name = "static_call_Oep4"
template_file_path = "./Storage_Example/"
template_file_name = "storage_example"
# template_file_path = "./Struct_Example/"
# template_file_name = "struct_example"
# template_file_path = "./NativeAssetInvoke/"
# template_file_name = "native_asset_invoke"
# Compile the designated file.py
run(template_file_path, template_file_name)