|
1 | | -from abc import ABCMeta, abstractmethod |
2 | 1 | from pathlib import Path |
3 | 2 | from typing import TYPE_CHECKING, Iterator, Optional, Type |
4 | 3 |
|
5 | | -from dataclassy import dataclass |
6 | 4 | from eth_account.datastructures import SignedMessage # type: ignore |
7 | 5 | from eth_account.datastructures import SignedTransaction |
8 | 6 | from eth_account.messages import SignableMessage # type: ignore |
9 | 7 |
|
| 8 | +from .base import abstractdataclass, abstractmethod |
| 9 | + |
10 | 10 | if TYPE_CHECKING: |
11 | 11 | from ape.managers.networks import NetworkManager |
12 | 12 |
|
13 | 13 |
|
14 | | -@dataclass |
15 | | -class AddressAPI(metaclass=ABCMeta): |
| 14 | +@abstractdataclass |
| 15 | +class AddressAPI: |
16 | 16 | network_manager: Optional["NetworkManager"] = None |
17 | 17 |
|
18 | 18 | @property |
@@ -78,8 +78,8 @@ def sign_transaction(self, txn: dict) -> Optional[SignedTransaction]: |
78 | 78 | ... |
79 | 79 |
|
80 | 80 |
|
81 | | -@dataclass |
82 | | -class AccountContainerAPI(metaclass=ABCMeta): |
| 81 | +@abstractdataclass |
| 82 | +class AccountContainerAPI: |
83 | 83 | data_folder: Path |
84 | 84 | account_type: Type[AccountAPI] |
85 | 85 |
|
@@ -107,17 +107,31 @@ def append(self, account: AccountAPI): |
107 | 107 | if not isinstance(account, self.account_type): |
108 | 108 | raise # Not the right type for this container |
109 | 109 |
|
110 | | - if account in self: |
| 110 | + if account.address in self: |
111 | 111 | raise # Account already in container |
112 | 112 |
|
113 | 113 | if account.alias and account.alias in self.aliases: |
114 | 114 | raise # Alias already in use |
115 | 115 |
|
116 | 116 | self.__setitem__(account.address, account) |
117 | 117 |
|
118 | | - @abstractmethod |
119 | 118 | def __setitem__(self, address: str, account: AccountAPI): |
120 | | - raise NotImplementedError("Must define this method to use `container.append(...)`") |
| 119 | + raise NotImplementedError("Must define this method to use `container.append(acct)`") |
| 120 | + |
| 121 | + def remove(self, account: AccountAPI): |
| 122 | + if not isinstance(account, self.account_type): |
| 123 | + raise # Not the right type for this container |
| 124 | + |
| 125 | + if account.address not in self: |
| 126 | + raise # Account not in container |
| 127 | + |
| 128 | + if account.alias and account.alias in self.aliases: |
| 129 | + raise # Alias already in use |
| 130 | + |
| 131 | + self.__delitem__(account.address) |
| 132 | + |
| 133 | + def __delitem__(self, address: str): |
| 134 | + raise NotImplementedError("Must define this method to use `container.remove(acct)`") |
121 | 135 |
|
122 | 136 | def __contains__(self, address: str) -> bool: |
123 | 137 | try: |
|
0 commit comments