Skip to content

Commit 1da7df6

Browse files
Merge pull request #1746 from eth-brownie/fix-multicall
`multicall` - reset call code even if call reverts
2 parents 405a3e4 + 8b77a6a commit 1da7df6

File tree

1 file changed

+12
-8
lines changed

1 file changed

+12
-8
lines changed

brownie/network/multicall.py

+12-8
Original file line numberDiff line numberDiff line change
@@ -97,12 +97,14 @@ def _flush(self, future_result: Result = None) -> Any:
9797
print(color.highlight(f"{message}\n"))
9898

9999
ContractCall.__call__.__code__ = getattr(ContractCall, "__original_call_code")
100-
results = self._contract.tryAggregate( # type: ignore
101-
False,
102-
[_call.calldata for _call in pending_calls],
103-
block_identifier=self._block_number[get_ident()],
104-
)
105-
ContractCall.__call__.__code__ = getattr(ContractCall, "__proxy_call_code")
100+
try:
101+
results = self._contract.tryAggregate( # type: ignore
102+
False,
103+
[_call.calldata for _call in pending_calls],
104+
block_identifier=self._block_number[get_ident()],
105+
)
106+
finally:
107+
ContractCall.__call__.__code__ = getattr(ContractCall, "__proxy_call_code")
106108

107109
for _call, result in zip(pending_calls, results):
108110
_call.__wrapped__ = _call.decoder(result[1]) if result[0] else None # type: ignore
@@ -133,8 +135,10 @@ def _proxy_call(*args: Tuple, **kwargs: Dict[str, Any]) -> Any:
133135

134136
# standard call we let pass through
135137
ContractCall.__call__.__code__ = getattr(ContractCall, "__original_call_code")
136-
result = ContractCall.__call__(*args, **kwargs) # type: ignore
137-
ContractCall.__call__.__code__ = getattr(ContractCall, "__proxy_call_code")
138+
try:
139+
result = ContractCall.__call__(*args, **kwargs) # type: ignore
140+
finally:
141+
ContractCall.__call__.__code__ = getattr(ContractCall, "__proxy_call_code")
138142
return result
139143

140144
def __enter__(self) -> "Multicall":

0 commit comments

Comments
 (0)