diff --git a/ethereum/abi.py b/ethereum/abi.py index 50d407567..d02b88831 100644 --- a/ethereum/abi.py +++ b/ethereum/abi.py @@ -20,6 +20,7 @@ def __init__(self, full_signature): full_signature = json_decode(full_signature) for sig_item in full_signature: encode_types = [f['type'] for f in sig_item['inputs']] + signature = [(f['type'], f['name']) for f in sig_item['inputs']] name = sig_item['name'] if '(' in name: name = name[:name.find('(')] @@ -41,7 +42,8 @@ def __init__(self, full_signature): "prefix": prefix, "encode_types": encode_types, "decode_types": decode_types, - "is_unknown_type": is_unknown_type + "is_unknown_type": is_unknown_type, + "signature": signature } elif sig_item['type'] == 'event': prefix = big_endian_to_int(utils.sha3(sig)) diff --git a/ethereum/tester.py b/ethereum/tester.py index a57626a28..1cf06439e 100644 --- a/ethereum/tester.py +++ b/ethereum/tester.py @@ -9,8 +9,9 @@ from ethereum.slogging import LogRecorder, configure_logging, set_level from ethereum.utils import to_string from ethereum._solidity import get_solidity +from ethereum import slogging import rlp -from rlp.utils import decode_hex, encode_hex, ascii_chr +from rlp.utils import ascii_chr serpent = None @@ -141,8 +142,24 @@ def kall(*args, **kwargs): return outdata return kall - for f in self._translator.function_data: - vars(self)[f] = kall_factory(f) + for fname in self._translator.function_data: + func = kall_factory(fname) + # create wrapper with signature + # in IPython: mycontract.yeah? + # Definition: mycontract.yeah(number, peers, really, **kargs) + # Docstring: yeah(uint32 number, uint256 peers, bool really) + signature = self._translator.function_data[fname]['signature'] + fsig = ', '.join(name for typ, name in signature) + if fsig: + fsig += ', ' + wfunc = 'def %s(%s**kargs): return func(%s**kargs)' % (fname, fsig, fsig) + wfunc_code = compile(wfunc, 'na', 'exec') + fakeglobals = {} + eval(wfunc_code, {'func': func}, fakeglobals) # evil, use in tester only! + func = fakeglobals[fname] + func.__doc__ = '%s(%s)' % (fname, ', '.join(('%s %s' % x) for x in signature)) + + setattr(self, fname, func) return _abi_contract(me, code, sender, endowment, language)