Skip to content

Commit

Permalink
feat: ret checksummed addresses
Browse files Browse the repository at this point in the history
  • Loading branch information
antazoey committed Dec 8, 2021
1 parent e1ec612 commit 93a45a3
Showing 1 changed file with 18 additions and 4 deletions.
22 changes: 18 additions & 4 deletions src/ape_ethereum/ecosystem.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
from typing import Any, Dict, Optional
from typing import Any, Dict, List, Optional, Tuple

from eth_abi import decode_abi as abi_decode
from eth_abi import encode_abi as abi_encode
Expand All @@ -9,7 +9,7 @@
serializable_unsigned_transaction_from_dict,
)
from eth_typing import HexStr
from eth_utils import add_0x_prefix, keccak, to_bytes, to_int
from eth_utils import add_0x_prefix, keccak, to_bytes, to_checksum_address, to_int
from hexbytes import HexBytes

from ape.api import (
Expand Down Expand Up @@ -236,10 +236,24 @@ def encode_calldata(self, abi: ABI, *args) -> bytes:
else:
return HexBytes(b"")

def decode_calldata(self, abi: ABI, raw_data: bytes) -> Any:
def decode_calldata(self, abi: ABI, raw_data: bytes) -> Tuple[Any, ...]:
output_types = [o.canonical_type for o in abi.outputs]
try:
return abi_decode(output_types, raw_data)
vm_return_values = abi_decode(output_types, raw_data)
if not vm_return_values:
return vm_return_values

if not isinstance(vm_return_values, (tuple, list)):
vm_return_values = (vm_return_values,)

output_values: List[Any] = []
for index in range(len(vm_return_values)):
if index < len(output_types) and output_types[index] == "address":
output_values.append(to_checksum_address(vm_return_values[index]))
else:
output_values.append(vm_return_values[index])

return tuple(output_values)

except InsufficientDataBytes as err:
raise DecodingError() from err
Expand Down

0 comments on commit 93a45a3

Please sign in to comment.