diff --git a/multicall/call.py b/multicall/call.py index 4840e0b..5dbc293 100644 --- a/multicall/call.py +++ b/multicall/call.py @@ -1,11 +1,10 @@ -from dataclasses import dataclass from eth_utils import to_checksum_address from web3.auto import w3 -from multicall.signature import Signature +from multicall import Signature class Call: - def __init__(self, target, function, returns): + def __init__(self, target, function, returns=None): self.target = to_checksum_address(target) if isinstance(function, list): self.function, *self.args = function @@ -15,13 +14,23 @@ class Call: self.signature = Signature(self.function) self.returns = returns + @property + def data(self): + return self.signature.encode_data(self.args) + + def decode_output(self, output): + decoded = self.signature.decode_data(output) + if self.returns: + return { + name: handler(value) if handler else value + for (name, handler), value + in zip(self.returns, decoded) + } + else: + return decoded + def __call__(self, args=None): args = args or self.args calldata = self.signature.encode_data(args) output = w3.eth.call({'to': self.target, 'data': calldata}) - decoded = self.signature.decode_data(output) - return { - name: handler(value) if handler else value - for (name, handler), value - in zip(self.returns, decoded) - } + return self.decode_output(output) diff --git a/tests/test_call.py b/tests/test_call.py index 1f61902..3fb5936 100644 --- a/tests/test_call.py +++ b/tests/test_call.py @@ -1,4 +1,4 @@ -from multicall.call import Call +from multicall import Call CHAI = '0x06AF07097C9Eeb7fD685c692751D5C66dB49c215'