Add cic package
This commit is contained in:
0
cic/__init__.py
Normal file
0
cic/__init__.py
Normal file
41
cic/runnable/abilist.py
Normal file
41
cic/runnable/abilist.py
Normal file
@@ -0,0 +1,41 @@
|
||||
# standard imports
|
||||
import json
|
||||
import sys
|
||||
|
||||
# external imports
|
||||
import sha3
|
||||
|
||||
|
||||
def main():
|
||||
f = open(sys.argv[1], 'r')
|
||||
o = json.load(f)
|
||||
f.close()
|
||||
|
||||
ks = []
|
||||
r = {}
|
||||
for v in o:
|
||||
if v['type'] != "function":
|
||||
continue
|
||||
name = ''
|
||||
try:
|
||||
name = v['name']
|
||||
except KeyError:
|
||||
continue
|
||||
args = []
|
||||
for vv in v['inputs']:
|
||||
args.append(vv['type'])
|
||||
sig = '{}({})'.format(name, ','.join(args))
|
||||
h = sha3.keccak_256()
|
||||
h.update(sig.encode('utf-8'))
|
||||
z = h.digest()
|
||||
k = z[:4].hex()
|
||||
#ks.append(k)
|
||||
r[k] = sig
|
||||
|
||||
ks = list(r.keys())
|
||||
ks.sort()
|
||||
for k in ks:
|
||||
print("{}\t{}".format(k, r[k]))
|
||||
|
||||
if __name__ == '__main__':
|
||||
main()
|
||||
34
cic/runnable/calculate_eip165.py
Normal file
34
cic/runnable/calculate_eip165.py
Normal file
@@ -0,0 +1,34 @@
|
||||
# standard imports
|
||||
import logging
|
||||
import sys
|
||||
|
||||
# external imports
|
||||
import sha3
|
||||
|
||||
logging.basicConfig(level=logging.WARNING)
|
||||
#logging.basicConfig(level=logging.DEBUG)
|
||||
logg = logging.getLogger()
|
||||
|
||||
def main():
|
||||
if __name__ == '__main__':
|
||||
f = open(sys.argv[1], 'r')
|
||||
z = b''
|
||||
for i in range(32):
|
||||
z += b'\x00'
|
||||
while True:
|
||||
l = f.readline().rstrip()
|
||||
if l == '':
|
||||
break
|
||||
logg.debug('line {}'.format(l))
|
||||
h = sha3.keccak_256()
|
||||
h.update(l.encode('utf-8'))
|
||||
r = h.digest()
|
||||
z = bytes([a ^ b for a, b in zip(r, z)])
|
||||
logg.debug('{} -> {}'.format(r.hex(), z.hex()))
|
||||
f.close()
|
||||
|
||||
print(z[:4].hex())
|
||||
|
||||
|
||||
if __name__ == '__main__':
|
||||
main()
|
||||
16
cic/runnable/mergeabis.py
Normal file
16
cic/runnable/mergeabis.py
Normal file
@@ -0,0 +1,16 @@
|
||||
# standard imports
|
||||
import sys
|
||||
import json
|
||||
|
||||
def main():
|
||||
merged = []
|
||||
for a in sys.argv[1:]:
|
||||
f = open(a, 'r')
|
||||
j = json.load(f)
|
||||
f.close()
|
||||
merged += j
|
||||
|
||||
print(json.dumps(merged))
|
||||
|
||||
if __name__ == '__main__':
|
||||
main()
|
||||
136
cic/runnable/reduce_to_methods.py
Normal file
136
cic/runnable/reduce_to_methods.py
Normal file
@@ -0,0 +1,136 @@
|
||||
import sys
|
||||
import logging
|
||||
|
||||
import ply.lex as lex
|
||||
|
||||
logging.basicConfig(level=logging.WARNING)
|
||||
logg = logging.getLogger()
|
||||
|
||||
|
||||
tokens = (
|
||||
'NUMBER',
|
||||
# 'PLUS',
|
||||
# 'MINUS',
|
||||
# 'TIMES',
|
||||
# 'DIVIDE',
|
||||
'LPAREN',
|
||||
'RPAREN',
|
||||
)
|
||||
|
||||
methods = {}
|
||||
contract = False
|
||||
method = None
|
||||
typ = None
|
||||
function = False
|
||||
signature = False
|
||||
|
||||
|
||||
# Define a rule so we can track line numbers
|
||||
def t_newline(t):
|
||||
r'\n+'
|
||||
t.lexer.lineno += len(t.value)
|
||||
|
||||
def t_comment(t):
|
||||
r'//.+'
|
||||
pass
|
||||
|
||||
|
||||
def t_item(t):
|
||||
r';'
|
||||
global function, signature, method, typ
|
||||
|
||||
signature = False
|
||||
function = False
|
||||
method = None
|
||||
typ = None
|
||||
|
||||
|
||||
def t_contract(t):
|
||||
r'(interface|contract).+\{'
|
||||
global contract
|
||||
if contract:
|
||||
raise SyntaxError('this meagre parser will only handle one interface/contract definition per file')
|
||||
contract = True
|
||||
|
||||
|
||||
def t_pragma(t):
|
||||
r'pragma.+'
|
||||
pass
|
||||
|
||||
|
||||
def t_function(t):
|
||||
r'function'
|
||||
global function, contract
|
||||
|
||||
if not contract:
|
||||
raise SyntaxError('functions must be within inteface/contract definitions')
|
||||
function = True
|
||||
|
||||
|
||||
def t_LPAREN(t):
|
||||
r'\('
|
||||
global function, signature
|
||||
|
||||
if not function:
|
||||
return
|
||||
signature = True
|
||||
|
||||
|
||||
def t_RPAREN(t):
|
||||
r'\)'
|
||||
global signature
|
||||
|
||||
signature = None
|
||||
|
||||
|
||||
def t_WORD(t):
|
||||
r'([\w\d]+)'
|
||||
global method, typ, signature
|
||||
|
||||
if typ and not signature:
|
||||
return
|
||||
|
||||
if function and method == None:
|
||||
method = t.value
|
||||
methods[method] = []
|
||||
elif typ == None and signature:
|
||||
typ = t.value
|
||||
methods[method].append(typ)
|
||||
|
||||
|
||||
def t_COMMA(t):
|
||||
r','
|
||||
global typ
|
||||
|
||||
typ = None
|
||||
|
||||
|
||||
# Error handling rule
|
||||
def t_error(t):
|
||||
print("Illegal character '%s'" % t.value[0])
|
||||
t.lexer.skip(1)
|
||||
|
||||
# A string containing ignored characters (spaces and tabs)
|
||||
t_ignore = ' \t}'
|
||||
|
||||
def main():
|
||||
# Build the lexer
|
||||
lexer = lex.lex()
|
||||
|
||||
# Tokenize
|
||||
f = open(sys.argv[1], 'r')
|
||||
while True:
|
||||
l = f.readline()
|
||||
if not l:
|
||||
break
|
||||
lexer.input(l)
|
||||
tok = lexer.token()
|
||||
logg.debug('token {}'.format(tok))
|
||||
|
||||
|
||||
for k in methods.keys():
|
||||
print('{}({})'.format(k, ','.join(methods[k])))
|
||||
|
||||
|
||||
if __name__ == '__main__':
|
||||
main()
|
||||
Reference in New Issue
Block a user