|
1 | | -from typing import Any, Dict, Optional |
| 1 | +from typing import Any, Dict, List, Optional, Tuple |
2 | 2 |
|
3 | 3 | from eth_abi import decode_abi as abi_decode |
4 | 4 | from eth_abi import encode_abi as abi_encode |
|
9 | 9 | serializable_unsigned_transaction_from_dict, |
10 | 10 | ) |
11 | 11 | 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 |
13 | 13 | from hexbytes import HexBytes |
14 | 14 |
|
15 | 15 | from ape.api import ( |
@@ -236,10 +236,25 @@ def encode_calldata(self, abi: ABI, *args) -> bytes: |
236 | 236 | else: |
237 | 237 | return HexBytes(b"") |
238 | 238 |
|
239 | | - def decode_calldata(self, abi: ABI, raw_data: bytes) -> Any: |
| 239 | + def decode_calldata(self, abi: ABI, raw_data: bytes) -> Tuple[Any, ...]: |
240 | 240 | output_types = [o.canonical_type for o in abi.outputs] |
241 | 241 | 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) |
243 | 258 |
|
244 | 259 | except InsufficientDataBytes as err: |
245 | 260 | raise DecodingError() from err |
|
0 commit comments