mirror of
https://github.com/FlipsideCrypto/multicall.py.git
synced 2026-02-06 10:47:05 +00:00
Add block identifier for multicall
This commit is contained in:
parent
2f64a8f248
commit
454ff536dd
@ -4,7 +4,7 @@ from multicall import Signature
|
||||
|
||||
|
||||
class Call:
|
||||
def __init__(self, target, function, returns=None, _w3=None):
|
||||
def __init__(self, target, function, returns=None, _w3=None, block_id=None):
|
||||
self.target = to_checksum_address(target)
|
||||
|
||||
if isinstance(function, list):
|
||||
@ -20,6 +20,7 @@ class Call:
|
||||
|
||||
self.signature = Signature(self.function)
|
||||
self.returns = returns
|
||||
self.block_id = block_id
|
||||
|
||||
@property
|
||||
def data(self):
|
||||
@ -39,5 +40,5 @@ class Call:
|
||||
def __call__(self, args=None):
|
||||
args = args or self.args
|
||||
calldata = self.signature.encode_data(args)
|
||||
output = self.w3.eth.call({'to': self.target, 'data': calldata})
|
||||
output = self.w3.eth.call({'to': self.target, 'data': calldata}, block_identifier=self.block_id)
|
||||
return self.decode_output(output)
|
||||
|
||||
@ -7,9 +7,9 @@ from multicall.constants import MULTICALL_ADDRESSES
|
||||
|
||||
|
||||
class Multicall:
|
||||
def __init__(self, calls: List[Call], _w3=None):
|
||||
def __init__(self, calls: List[Call], _w3=None, block_id=None):
|
||||
self.calls = calls
|
||||
|
||||
self.block_id = block_id
|
||||
if _w3 is None:
|
||||
self.w3 = w3
|
||||
else:
|
||||
@ -19,8 +19,9 @@ class Multicall:
|
||||
aggregate = Call(
|
||||
MULTICALL_ADDRESSES[self.w3.eth.chainId],
|
||||
'aggregate((address,bytes)[])(uint256,bytes[])',
|
||||
None,
|
||||
self.w3
|
||||
returns=None,
|
||||
_w3=self.w3,
|
||||
block_id=self.block_id
|
||||
)
|
||||
args = [[[call.target, call.data] for call in self.calls]]
|
||||
block, outputs = aggregate(args)
|
||||
|
||||
Loading…
Reference in New Issue
Block a user