-
Notifications
You must be signed in to change notification settings - Fork 33
/
Copy pathassemble-iele-test
executable file
·53 lines (45 loc) · 1.29 KB
/
assemble-iele-test
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
#!/usr/bin/env python2
import subprocess
import sys
import json
import tempfile
import os
dir_path = os.path.dirname(__file__)
def assembleIele(code):
if len(code) == 0:
return ""
if code[0:2] == "0x":
return code
if os.path.isabs(code):
path = code
else:
path = source_dir + "/" + code
binary = subprocess.check_output(["kiele", "assemble", path])
return binary
def convertToBinaryIele(json):
if isinstance(json, dict):
res = {}
isCreateTx = False
if "to" in json.keys():
if json["to"] == "":
isCreateTx = True
for key, value in json.iteritems():
if key == "code" or (key == "contractCode" and isCreateTx):
res[key] = assembleIele(value)
else:
res[key] = convertToBinaryIele(value)
return res
elif isinstance(json, list):
res = []
for value in json:
res.append(convertToBinaryIele(value))
return res
elif isinstance(json, unicode) or isinstance(json, bool) \
or isinstance(json, long) or isinstance(json, int):
return json
source_file = sys.argv[1]
source_dir = os.path.dirname(os.path.realpath(source_file))
with open(source_file, "r") as source:
original_test = json.load(source)
new_test = convertToBinaryIele(original_test)
json.dump(new_test, sys.stdout, indent=4)