Skip to content

Commit

Permalink
feat: added support for ether types in account calls
Browse files Browse the repository at this point in the history
  • Loading branch information
fubuloubu committed Jul 16, 2021
1 parent c1f7b33 commit a7313bd
Showing 1 changed file with 16 additions and 4 deletions.
20 changes: 16 additions & 4 deletions src/ape/api/accounts.py
Original file line number Diff line number Diff line change
@@ -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
Expand Down Expand Up @@ -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
Expand Down

0 comments on commit a7313bd

Please sign in to comment.