From 86586067af1f09bd47927b9d860a82d32e41c97f Mon Sep 17 00:00:00 2001 From: BobTheBuidler <70677534+BobTheBuidler@users.noreply.github.com> Date: Wed, 10 Apr 2024 11:32:02 -0400 Subject: [PATCH] fix: conflict with eth-abi>=4.0.0 (#140) --- dank_mids/brownie_patch/call.py | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) diff --git a/dank_mids/brownie_patch/call.py b/dank_mids/brownie_patch/call.py index aa91fb38..7920ae49 100644 --- a/dank_mids/brownie_patch/call.py +++ b/dank_mids/brownie_patch/call.py @@ -121,11 +121,15 @@ async def decode_output(call: ContractCall, data: bytes) -> Any: async def __request_data_no_args(call: ContractCall) -> str: return call.signature +# These methods were renamed in eth-abi 4.0.0 +__eth_abi_encode = eth_abi.encode if hasattr(eth_abi, 'encode') else eth_abi.encode_abi +__eth_abi_decode = eth_abi.decode if hasattr(eth_abi, 'decode') else eth_abi.decode_abi + def __encode_input(abi: Dict[str, Any], signature: str, *args: Tuple[Any,...]) -> str: try: data = format_input(abi, args) types_list = get_type_strings(abi["inputs"]) - return signature + eth_abi.encode_abi(types_list, data).hex() + return signature + __eth_abi_encode(types_list, data).hex() except Exception as e: return e @@ -136,7 +140,7 @@ def __encode_input(abi: Dict[str, Any], signature: str, *args: Tuple[Any,...]) - def __decode_output(hexstr: str, abi: Dict[str, Any]) -> Any: try: types_list = get_type_strings(abi["outputs"]) - result = eth_abi.decode_abi(types_list, HexBytes(hexstr)) + result = __eth_abi_decode(types_list, HexBytes(hexstr)) result = format_output(abi, result) if len(result) == 1: result = result[0]