Skip to content

Commit 865729b

Browse files
committed
fix: return checksummed addresses
1 parent e1ec612 commit 865729b

File tree

1 file changed

+19
-4
lines changed

1 file changed

+19
-4
lines changed

src/ape_ethereum/ecosystem.py

Lines changed: 19 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
from typing import Any, Dict, Optional
1+
from typing import Any, Dict, List, Optional, Tuple
22

33
from eth_abi import decode_abi as abi_decode
44
from eth_abi import encode_abi as abi_encode
@@ -9,7 +9,7 @@
99
serializable_unsigned_transaction_from_dict,
1010
)
1111
from eth_typing import HexStr
12-
from eth_utils import add_0x_prefix, keccak, to_bytes, to_int
12+
from eth_utils import add_0x_prefix, keccak, to_bytes, to_checksum_address, to_int
1313
from hexbytes import HexBytes
1414

1515
from ape.api import (
@@ -236,10 +236,25 @@ def encode_calldata(self, abi: ABI, *args) -> bytes:
236236
else:
237237
return HexBytes(b"")
238238

239-
def decode_calldata(self, abi: ABI, raw_data: bytes) -> Any:
239+
def decode_calldata(self, abi: ABI, raw_data: bytes) -> Tuple[Any, ...]:
240240
output_types = [o.canonical_type for o in abi.outputs]
241241
try:
242-
return abi_decode(output_types, raw_data)
242+
vm_return_values = abi_decode(output_types, raw_data)
243+
if not vm_return_values:
244+
return vm_return_values
245+
246+
if not isinstance(vm_return_values, (tuple, list)):
247+
vm_return_values = (vm_return_values,)
248+
249+
output_values: List[Any] = []
250+
for index in range(len(vm_return_values)):
251+
value = vm_return_values[index]
252+
if index < len(output_types) and output_types[index] == "address":
253+
value = to_checksum_address(value)
254+
255+
output_values.append(value)
256+
257+
return tuple(output_values)
243258

244259
except InsufficientDataBytes as err:
245260
raise DecodingError() from err

0 commit comments

Comments
 (0)