diff --git a/Makefile b/Makefile index dedd011..e0a5ec9 100644 --- a/Makefile +++ b/Makefile @@ -3,17 +3,22 @@ # File-version: 5 INPUTS = $(wildcard *.sol) -OUTPUTS = $(patsubst %.sol, %.json, $(INPUTS)) +OUTPUTS_JSON = $(patsubst %.sol, %.json, $(INPUTS)) +OUTPUTS_INTERFACE = $(patsubst %.sol, %.interface, $(INPUTS)) +OUTPUTS = ${OUTPUTS_JSON} ${OUTPUTS_INTERFACE} PREFIX = /usr/local/share/cic/solidity/abi #%.abi.json: $(wildcard *.sol) # install -vDm0644 $@ $(PREFIX)/$@ -.SUFFIXES: .sol .json +.SUFFIXES: .sol .json .interface .sol.json: solc $(basename $@).sol --abi | awk 'NR>3' > $@ +.sol.interface: + bash $(basename $@).sol > $@ + all: $(OUTPUTS) install: $(OUTPUTS) diff --git a/calculate_eip165.py b/calculate_eip165.py new file mode 100644 index 0000000..97e8d52 --- /dev/null +++ b/calculate_eip165.py @@ -0,0 +1,29 @@ +# standard imports +import logging +import sys + +# external imports +import sha3 + +#logging.basicConfig(level=logging.WARNING) +logging.basicConfig(level=logging.DEBUG) +logg = logging.getLogger() + +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()) diff --git a/calculate_erc165.py b/calculate_erc165.py deleted file mode 100644 index dcf1cfa..0000000 --- a/calculate_erc165.py +++ /dev/null @@ -1,16 +0,0 @@ -import sys -import web3 - -f = open(sys.argv[1], 'r') -z = b'' -for i in range(32): - z += b'\x00' -while True: - l = f.readline() - if l == '': - break - print('line {}'.format(l)) - h = web3.Web3.keccak(text=l) - z = bytes([a ^ b for a, b in zip(h, z)]) - print(h.hex(), z.hex()) -f.close() diff --git a/parse.py b/reduce_to_methods.py similarity index 100% rename from parse.py rename to reduce_to_methods.py diff --git a/to_interface.sh b/to_interface.sh new file mode 100644 index 0000000..825e468 --- /dev/null +++ b/to_interface.sh @@ -0,0 +1,9 @@ +#!/bin/bash + +d=`mktemp -d` +b=`basename $1` +s=${b%%.*} +echo $s +python3 reduce_to_methods.py $1 > $d/$b +python3 calculate_eip165.py $d/$b > ${s}.interface +>&2 echo $d/$b