diff --git a/dank_mids/brownie_patch/call.py b/dank_mids/brownie_patch/call.py index 6abc90fc..7a8125d6 100644 --- a/dank_mids/brownie_patch/call.py +++ b/dank_mids/brownie_patch/call.py @@ -45,39 +45,38 @@ def __decode_output(hexstr: str, abi: Dict[str, Any]) -> Any: result = result[0] return result -def _patch_call(call: ContractCall, w3: Web3) -> None: - async def _encode_input(self: ContractCall, *args: Tuple[Any,...]) -> str: - return await run_in_subprocess( - __encode_input, - self.abi, - self.signature, - *(arg if not hasattr(arg, 'address') else arg.address for arg in args) # type: ignore - ) +async def _encode_input(self: ContractCall, *args: Tuple[Any,...]) -> str: + return await run_in_subprocess( + __encode_input, + self.abi, + self.signature, + *(arg if not hasattr(arg, 'address') else arg.address for arg in args) # type: ignore + ) - async def _decode_output(self: ContractCall, data: str) -> Any: - return await run_in_subprocess(__decode_output, data, self.abi) +async def _decode_output(self: ContractCall, data: str) -> Any: + return await run_in_subprocess(__decode_output, data, self.abi) - @functools.wraps(call) - async def coroutine( - self: ContractCall, - *args: Tuple[Any,...], - block_identifier: Optional[Union[int, str, bytes]] = None, - override: Optional[Dict[str, str]] = None - ) -> Any: - if override: - raise ValueError("Cannot use state override with `coroutine`.") +async def coroutine( + self: ContractCall, + *args: Tuple[Any,...], + block_identifier: Optional[Union[int, str, bytes]] = None, + override: Optional[Dict[str, str]] = None +) -> Any: + if override: + raise ValueError("Cannot use state override with `coroutine`.") - async with brownie_call_semaphore: + async with brownie_call_semaphore: + try: + return await self._decode_output( + await w3.eth.call({"to": self._address, "data": await self._encode_input(*args)}, block_identifier) # type: ignore + ) + except ValueError as e: try: - return await self._decode_output( - await w3.eth.call({"to": self._address, "data": await self._encode_input(*args)}, block_identifier) # type: ignore - ) - except ValueError as e: - try: - raise VirtualMachineError(e) from None - except: - raise e - + raise VirtualMachineError(e) from None + except: + raise e + +def _patch_call(call: ContractCall, w3: Web3) -> None: call.coroutine = MethodType(coroutine, call) call._encode_input = MethodType(_encode_input, call) call._decode_output = MethodType(_decode_output, call)