This repository has been archived by the owner on Oct 6, 2023. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 4
/
generate.py
executable file
·69 lines (55 loc) · 3.17 KB
/
generate.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
import os
import json
import shutil
from pathlib import Path
source_path = Path('../hubble-contracts/artifacts')
output_path = Path("../contracts")
def generate_bindings(path, type, pkg, filename):
with open(path, 'r') as f:
data = f.read()
obj = json.loads(data)
with open('tmp.abi', 'w') as out:
out.write(json.dumps(obj['abi']))
with open('tmp.bin', 'w') as out:
out.write(obj['bytecode'])
os.system(
f'abigen --abi tmp.abi --bin tmp.bin --pkg {pkg} --type {type} --out {filename}')
def generate(artifact, name):
path = source_path / artifact
lower = name.lower()
os.makedirs(output_path / lower, exist_ok=True)
filename = (output_path / lower / lower).with_suffix('.go')
generate_bindings(path, name, lower, filename)
def generate_subdir(subdir, artifact, name):
path = source_path / artifact
prefix_len = len(subdir)
pkg = name[prefix_len:].lower()
os.makedirs(output_path / subdir / pkg, exist_ok=True)
filename = (output_path / subdir / pkg / pkg).with_suffix('.go')
generate_bindings(path, name, pkg, filename)
os.system('rm -rf contracts')
generate('contracts/test/ProofOfAuthority.sol/ProofOfAuthority.json', 'ProofOfAuthority')
generate('contracts/proposers/Chooser.sol/Chooser.json', 'Chooser')
generate('contracts/TokenRegistry.sol/TokenRegistry.json', 'TokenRegistry')
generate('contracts/SpokeRegistry.sol/SpokeRegistry.json', 'SpokeRegistry')
generate('contracts/Vault.sol/Vault.json', 'Vault')
generate('contracts/WithdrawManager.sol/WithdrawManager.json', 'WithdrawManager')
generate('contracts/DepositManager.sol/DepositManager.json', 'DepositManager')
generate('contracts/BLSAccountRegistry.sol/BLSAccountRegistry.json', 'AccountRegistry')
generate('contracts/DefaultBLSAccountRegistry.sol/DefaultBLSAccountRegistry.json', 'DefaultAccountRegistry')
generate('contracts/Transfer.sol/Transfer.json', 'Transfer')
generate('contracts/MassMigrations.sol/MassMigration.json', 'MassMigration')
generate('contracts/Create2Transfer.sol/Create2Transfer.json', 'Create2Transfer')
generate('contracts/rollup/Rollup.sol/Rollup.json', 'Rollup')
generate_subdir('frontend', 'contracts/client/FrontendGeneric.sol/FrontendGeneric.json', 'FrontendGeneric')
generate_subdir('frontend', 'contracts/client/FrontendTransfer.sol/FrontendTransfer.json', 'FrontendTransfer')
generate_subdir('frontend', 'contracts/client/FrontendMassMigration.sol/FrontendMassMigration.json', 'FrontendMassMigration')
generate_subdir('frontend', 'contracts/client/FrontendCreate2Transfer.sol/FrontendCreate2Transfer.json', 'FrontendCreate2Transfer')
generate_subdir('test', 'contracts/test/TestTx.sol/TestTx.json', 'TestTx')
generate_subdir('test', 'contracts/test/TestTypes.sol/TestTypes.json', 'TestTypes')
generate_subdir('test', 'contracts/test/TestBLS.sol/TestBLS.json', 'TestBLS')
generate_subdir('test', 'contracts/test/CustomToken.sol/CustomToken.json', 'TestCustomToken')
generate_subdir('libs', 'contracts/libs/BNPairingPrecompileCostEstimator.sol/BNPairingPrecompileCostEstimator.json', 'CostEstimator')
generate('@openzeppelin/contracts/token/ERC20/IERC20.sol/IERC20.json', 'ERC20')
os.remove('tmp.abi')
os.remove('tmp.bin')