From a7313bd5dd03cf42d57222737d8f6ed0c8ddcc25 Mon Sep 17 00:00:00 2001 From: Ser Doggo <3859395+fubuloubu@users.noreply.github.com> Date: Thu, 15 Jul 2021 21:18:44 -0400 Subject: [PATCH] feat: added support for ether types in account calls --- src/ape/api/accounts.py | 20 ++++++++++++++++---- 1 file changed, 16 insertions(+), 4 deletions(-) diff --git a/src/ape/api/accounts.py b/src/ape/api/accounts.py index 9454963680..37feb83abd 100644 --- a/src/ape/api/accounts.py +++ b/src/ape/api/accounts.py @@ -1,10 +1,11 @@ from pathlib import Path -from typing import Iterator, List, Optional, Type, Union +from typing import Callable, Iterator, List, Optional, Type, Union from eth_account.datastructures import SignedMessage # type: ignore from eth_account.messages import SignableMessage # type: ignore from ape.types import ContractType +from ape.utils import cached_property from .address import AddressAPI from .base import abstractdataclass, abstractmethod @@ -57,20 +58,31 @@ def call(self, txn: TransactionAPI) -> ReceiptAPI: return self.provider.send_transaction(signed_txn) + @cached_property + def _convert(self) -> Callable: + # NOTE: Need to differ loading this property + from ape import convert + + return convert + def transfer( self, account: Union[str, "AddressAPI"], - value: int = None, + value: Union[str, int, None] = None, + data: Union[bytes, str, None] = None, **kwargs, ) -> ReceiptAPI: txn = self._transaction_class( # type: ignore sender=self.address, - receiver=account.address if isinstance(account, AddressAPI) else account, + receiver=self._convert("address", account), **kwargs, ) + if data: + txn.data = self._convert(data, bytes) + if value: - txn.value = value + txn.value = self._convert(value, int) else: # NOTE: If `value` is `None`, send everything