|
1 | 1 | from typing import (
|
2 | 2 | Any,
|
3 | 3 | Awaitable,
|
| 4 | + Dict, |
| 5 | + List, |
| 6 | + Optional, |
| 7 | +) |
| 8 | + |
| 9 | +from eth_typing.encoding import ( |
| 10 | + HexStr, |
| 11 | +) |
| 12 | +from eth_typing.evm import ( |
| 13 | + ChecksumAddress, |
| 14 | +) |
| 15 | +from hexbytes.main import ( |
| 16 | + HexBytes, |
4 | 17 | )
|
5 | 18 |
|
6 | 19 | from web3._utils.admin import (
|
|
64 | 77 | Module,
|
65 | 78 | )
|
66 | 79 | from web3.types import (
|
| 80 | + GethWallet, |
| 81 | + TxParams, |
67 | 82 | TxPoolContent,
|
68 | 83 | TxPoolInspect,
|
69 | 84 | TxPoolStatus,
|
70 | 85 | )
|
71 | 86 |
|
72 | 87 |
|
73 |
| -class GethPersonal(Module): |
| 88 | +class BaseGethPersonal(Module): |
74 | 89 | """
|
75 | 90 | https://github.com/ethereum/go-ethereum/wiki/management-apis#personal
|
76 | 91 | """
|
77 |
| - ec_recover = ec_recover |
78 |
| - import_raw_key = import_raw_key |
79 |
| - list_accounts = list_accounts |
80 |
| - list_wallets = list_wallets |
81 |
| - lock_account = lock_account |
82 |
| - new_account = new_account |
83 |
| - send_transaction = send_transaction |
84 |
| - sign = sign |
85 |
| - sign_typed_data = sign_typed_data |
86 |
| - unlock_account = unlock_account |
| 92 | + _ec_recover = ec_recover |
| 93 | + _import_raw_key = import_raw_key |
| 94 | + _list_accounts = list_accounts |
| 95 | + _list_wallets = list_wallets |
| 96 | + _lock_account = lock_account |
| 97 | + _new_account = new_account |
| 98 | + _send_transaction = send_transaction |
| 99 | + _sign = sign |
| 100 | + _sign_typed_data = sign_typed_data |
| 101 | + _unlock_account = unlock_account |
87 | 102 | # deprecated
|
88 |
| - ecRecover = ecRecover |
89 |
| - importRawKey = importRawKey |
90 |
| - listAccounts = listAccounts |
91 |
| - lockAccount = lockAccount |
92 |
| - newAccount = newAccount |
93 |
| - sendTransaction = sendTransaction |
94 |
| - signTypedData = signTypedData |
95 |
| - unlockAccount = unlockAccount |
| 103 | + _ecRecover = ecRecover |
| 104 | + _importRawKey = importRawKey |
| 105 | + _listAccounts = listAccounts |
| 106 | + _lockAccount = lockAccount |
| 107 | + _newAccount = newAccount |
| 108 | + _sendTransaction = sendTransaction |
| 109 | + _signTypedData = signTypedData |
| 110 | + _unlockAccount = unlockAccount |
| 111 | + |
| 112 | + |
| 113 | +class GethPersonal(BaseGethPersonal): |
| 114 | + is_async = False |
| 115 | + |
| 116 | + def ec_recover(self, message: str, signature: HexStr) -> ChecksumAddress: |
| 117 | + return self._ec_recover(message, signature) |
| 118 | + |
| 119 | + def import_raw_key(self, private_key: str, passphrase: str) -> ChecksumAddress: |
| 120 | + return self._import_raw_key(private_key, passphrase) |
| 121 | + |
| 122 | + def list_accounts(self) -> List[ChecksumAddress]: |
| 123 | + return self._list_accounts() |
| 124 | + |
| 125 | + def list_wallets(self) -> List[GethWallet]: |
| 126 | + return self._list_wallets() |
| 127 | + |
| 128 | + def lock_account(self, account: ChecksumAddress) -> bool: |
| 129 | + return self._lock_account(account) |
| 130 | + |
| 131 | + def new_account(self, passphrase: str) -> ChecksumAddress: |
| 132 | + return self._new_account(passphrase) |
| 133 | + |
| 134 | + def send_transaction(self, transaction: TxParams, passphrase: str) -> HexBytes: |
| 135 | + return self._send_transaction(transaction, passphrase) |
| 136 | + |
| 137 | + def sign(self, message: str, account: ChecksumAddress, password: Optional[str]) -> HexStr: |
| 138 | + return self._sign(message, account, password) |
| 139 | + |
| 140 | + def sign_typed_data(self, |
| 141 | + message: Dict[str, Any], |
| 142 | + account: ChecksumAddress, |
| 143 | + password: Optional[str]) -> HexStr: |
| 144 | + return self._sign_typed_data(message, account, password) |
| 145 | + |
| 146 | + def unlock_account(self, |
| 147 | + account: ChecksumAddress, |
| 148 | + passphrase: str, |
| 149 | + duration: Optional[int] = None) -> bool: |
| 150 | + return self._unlock_account(account, passphrase, duration) |
| 151 | + |
| 152 | + def ecRecover(self, message: str, signature: HexStr) -> ChecksumAddress: |
| 153 | + return self._ecRecover(message, signature) |
| 154 | + |
| 155 | + def importRawKey(self, private_key: str, passphrase: str) -> ChecksumAddress: |
| 156 | + return self._importRawKey(private_key, passphrase) |
| 157 | + |
| 158 | + def listAccounts(self) -> List[ChecksumAddress]: |
| 159 | + return self._listAccounts() |
| 160 | + |
| 161 | + def lockAccount(self, account: ChecksumAddress) -> bool: |
| 162 | + return self._lockAccount(account) |
| 163 | + |
| 164 | + def newAccount(self, passphrase: str) -> ChecksumAddress: |
| 165 | + return self._newAccount(passphrase) |
| 166 | + |
| 167 | + def sendTransaction(self, transaction: TxParams, passphrase: str) -> HexBytes: |
| 168 | + return self._sendTransaction(transaction, passphrase) |
| 169 | + |
| 170 | + def signTypedData(self, |
| 171 | + message: Dict[str, Any], |
| 172 | + account: ChecksumAddress, |
| 173 | + password: Optional[str] = None) -> HexStr: |
| 174 | + return self._signTypedData(message, account, password) |
| 175 | + |
| 176 | + def unlockAccount(self, |
| 177 | + account: ChecksumAddress, |
| 178 | + passphrase: str, |
| 179 | + duration: Optional[int] = None) -> bool: |
| 180 | + return self._unlockAccount(account, passphrase, duration) |
| 181 | + |
| 182 | + |
| 183 | +class AsyncGethPersonal(BaseGethPersonal): |
| 184 | + is_async = True |
| 185 | + |
| 186 | + async def ec_recover(self, message: str, signature: HexStr) -> Awaitable[ChecksumAddress]: |
| 187 | + return await self._ec_recover(message, signature) # type: ignore |
| 188 | + |
| 189 | + async def import_raw_key(self, private_key: str, passphrase: str) -> Awaitable[ChecksumAddress]: |
| 190 | + return await self._import_raw_key(private_key, passphrase) # type: ignore |
| 191 | + |
| 192 | + async def list_accounts(self) -> Awaitable[List[ChecksumAddress]]: |
| 193 | + return await self._list_accounts() # type: ignore |
| 194 | + |
| 195 | + async def list_wallets(self) -> Awaitable[List[GethWallet]]: |
| 196 | + return await self._list_wallets() # type: ignore |
| 197 | + |
| 198 | + async def lock_account(self, account: ChecksumAddress) -> Awaitable[bool]: |
| 199 | + return await self._lock_account(account) # type: ignore |
| 200 | + |
| 201 | + async def new_account(self, passphrase: str) -> Awaitable[ChecksumAddress]: |
| 202 | + return await self._new_account(passphrase) # type: ignore |
| 203 | + |
| 204 | + async def send_transaction(self, transaction: TxParams, passphrase: str) -> Awaitable[HexBytes]: |
| 205 | + return await self._send_transaction(transaction, passphrase) # type: ignore |
| 206 | + |
| 207 | + async def sign(self, |
| 208 | + message: str, |
| 209 | + account: ChecksumAddress, |
| 210 | + password: Optional[str]) -> Awaitable[HexStr]: |
| 211 | + return await self._sign(message, account, password) # type: ignore |
| 212 | + |
| 213 | + async def sign_typed_data(self, |
| 214 | + message: Dict[str, Any], |
| 215 | + account: ChecksumAddress, |
| 216 | + password: Optional[str]) -> Awaitable[HexStr]: |
| 217 | + return await self._sign_typed_data(message, account, password) # type: ignore |
| 218 | + |
| 219 | + async def unlock_account(self, |
| 220 | + account: ChecksumAddress, |
| 221 | + passphrase: str, |
| 222 | + duration: Optional[int] = None) -> Awaitable[bool]: |
| 223 | + return await self._unlock_account(account, passphrase, duration) # type: ignore |
96 | 224 |
|
97 | 225 |
|
98 | 226 | class BaseTxPool(Module):
|
|
0 commit comments