mirror of
https://github.com/FlipsideCrypto/multicall.py.git
synced 2026-02-06 10:47:05 +00:00
update call
This commit is contained in:
parent
328c6392e1
commit
bdcc6691eb
@ -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)
|
||||
|
||||
@ -1,4 +1,4 @@
|
||||
from multicall.call import Call
|
||||
from multicall import Call
|
||||
|
||||
CHAI = '0x06AF07097C9Eeb7fD685c692751D5C66dB49c215'
|
||||
|
||||
|
||||
Loading…
Reference in New Issue
Block a user