forked from yanyanho/zk-client
-
Notifications
You must be signed in to change notification settings - Fork 0
/
compile.py
92 lines (76 loc) · 2.69 KB
/
compile.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
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
# Copyright (c) 2015-2020 Clearmatics Technologies Ltd
#
# SPDX-License-Identifier: LGPL-3.0+
import os
from os.path import join
from solcx import compile_files, set_solc_version
from zeth.constants import SOL_COMPILER_VERSION
from zeth.contracts import Interface
from zeth.utils import get_zeth_dir
def compile_mixer() -> Interface:
"""
Compile the testing ERC20 token contract
"""
zeth_dir = get_zeth_dir()
print("***********", zeth_dir)
allowed_path = join(
zeth_dir,
"zeth_contracts/node_modules/openzeppelin-solidity/contracts")
path_to_token = join(
zeth_dir,
"zeth_contracts/node_modules/openzeppelin-solidity/contracts",
"token/ERC20/ERC20Mintable.sol")
# Compilation
set_solc_version(SOL_COMPILER_VERSION)
compiled_sol = compile_files([path_to_token], allow_paths=allowed_path)
token_interface = compiled_sol[path_to_token + ":ERC20Mintable"]
return token_interface
def compile_mixer() -> Interface:
"""
Compile the testing mixer token contract
"""
# zeth_dir = "/Users/ruanyang/works/snark-project/zeth/zeth/client"
# print("***********", zeth_dir)
# allowed_path = join(
# zeth_dir,
# "zeth_contracts/contracts")
path_to_token = join(
os.path.abspath('.'),
"contract",
"mixer","Groth16Mixer.sol")
# Compilation
set_solc_version(SOL_COMPILER_VERSION)
compiled_sol = compile_files([path_to_token], allow_paths=os.path.abspath('.').join("contract"))
mixer_interface = compiled_sol[path_to_token + ":Groth16Mixer"]
fo = open("./contract/mixer/abi/Groth16Mixer.abi", "w")
fo1 = open("./contract/mixer/abi/Groth16Mixer.bin", "w")
s1 = str(mixer_interface["abi"])
s2 = s1.replace('True','true')
s3 = s2.replace('False','false')
s4 = s3.replace('\'','\"')
fo.write(s4)
fo.close()
fo1.write(str(mixer_interface["bin"]))
fo1.close()
def compile_token():
zeth_dir = "/Users/ruanyang/works/snark-project/zeth/zeth/client"
print("***********", zeth_dir)
allowed_path = join(
zeth_dir,
"contract")
path_to_token = join(
zeth_dir,
"contract",
"bac/BAC001.sol")
# Compilation
set_solc_version(SOL_COMPILER_VERSION)
compiled_sol = compile_files([path_to_token], allow_paths=allowed_path)
token_interface = compiled_sol[path_to_token + ":BAC001"]
fo = open("./contract/bac/abi/BAC001.abi", "w")
fo1 = open("./contract/bac/abi/BAC001.bin", "w")
fo.write(str(token_interface["abi"]))
fo.close()
fo1.write(str(token_interface["bin"]))
fo1.close()
if __name__ == "__main__":
compile_mixer() # pylint: disable=no-value-for-parameter