Skip to content

Commit

Permalink
fix: leaky brownie patch
Browse files Browse the repository at this point in the history
  • Loading branch information
BobTheBuidler committed May 10, 2023
1 parent 50fd4a2 commit ccc4905
Showing 1 changed file with 28 additions and 29 deletions.
57 changes: 28 additions & 29 deletions dank_mids/brownie_patch/call.py
Original file line number Diff line number Diff line change
Expand Up @@ -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)

0 comments on commit ccc4905

Please sign in to comment.