示例#1
0
 def getBlockTransactionCount(self, block_identifier, chain_address=None):
     """
     `hls_getBlockTransactionCountByHash`
     `hls_getBlockTransactionCountByNumber`
     """
     method = select_method_for_block_identifier(
         block_identifier,
         if_predefined='hls_getBlockTransactionCountByNumber',
         if_hash='hls_getBlockTransactionCountByHash',
         if_number='hls_getBlockTransactionCountByNumber',
     )
     if method == 'hls_getBlockTransactionCountByNumber':
         if chain_address is None:
             raise TypeError(
                 "To get the block transaction count by block number, you must provide a chain address"
             )
         return self.web3.manager.request_blocking(
             method,
             [block_identifier, chain_address],
         )
     else:
         return self.web3.manager.request_blocking(
             method,
             [block_identifier],
         )
示例#2
0
 def getTransactionFromBlock(self,
                             block_identifier,
                             transaction_index,
                             chain_address=None):
     """
     `hls_getTransactionByBlockHashAndIndex`
     `hls_getTransactionByBlockNumberAndIndex`
     """
     method = select_method_for_block_identifier(
         block_identifier,
         if_predefined='hls_getTransactionByBlockNumberAndIndex',
         if_hash='hls_getTransactionByBlockHashAndIndex',
         if_number='hls_getTransactionByBlockNumberAndIndex',
     )
     if method == 'hls_getTransactionByBlockNumberAndIndex':
         if chain_address is None:
             raise TypeError(
                 "To get the block transaction count by block number, you must provide a chain address"
             )
         return self.web3.manager.request_blocking(
             method,
             [block_identifier, transaction_index, chain_address],
         )
     else:
         return self.web3.manager.request_blocking(
             method,
             [block_identifier, transaction_index],
         )
示例#3
0
文件: eth.py 项目: miohtama/web3.py
 def getTransactionByBlock(self, block_identifier, transaction_index):
     """
     `eth_getTransactionByBlockHashAndIndex`
     `eth_getTransactionByBlockNumberAndIndex`
     """
     method = select_method_for_block_identifier(
         block_identifier,
         if_predefined='eth_getTransactionByBlockNumberAndIndex',
         if_hash='eth_getTransactionByBlockHashAndIndex',
         if_number='eth_getTransactionByBlockNumberAndIndex',
     )
     return self.web3.manager.request_blocking(
         method,
         [block_identifier, transaction_index],
     )
示例#4
0
文件: eth.py 项目: miohtama/web3.py
 def getUncleCount(self, block_identifier):
     """
     `eth_getUncleCountByBlockHash`
     `eth_getUncleCountByBlockNumber`
     """
     method = select_method_for_block_identifier(
         block_identifier,
         if_predefined='eth_getUncleCountByBlockNumber',
         if_hash='eth_getUncleCountByBlockHash',
         if_number='eth_getUncleCountByBlockNumber',
     )
     return self.web3.manager.request_blocking(
         method,
         [block_identifier],
     )
示例#5
0
文件: eth.py 项目: whoerau/web3.py
 def getUncleCount(self, block_identifier):
     """
     `eth_getUncleCountByBlockHash`
     `eth_getUncleCountByBlockNumber`
     """
     method = select_method_for_block_identifier(
         block_identifier,
         if_predefined='eth_getUncleCountByBlockNumber',
         if_hash='eth_getUncleCountByBlockHash',
         if_number='eth_getUncleCountByBlockNumber',
     )
     return self.web3.manager.request_blocking(
         method,
         [block_identifier],
     )
示例#6
0
文件: eth.py 项目: whoerau/web3.py
 def getTransactionByBlock(self, block_identifier, transaction_index):
     """
     `eth_getTransactionByBlockHashAndIndex`
     `eth_getTransactionByBlockNumberAndIndex`
     """
     method = select_method_for_block_identifier(
         block_identifier,
         if_predefined='eth_getTransactionByBlockNumberAndIndex',
         if_hash='eth_getTransactionByBlockHashAndIndex',
         if_number='eth_getTransactionByBlockNumberAndIndex',
     )
     return self.web3.manager.request_blocking(
         method,
         [block_identifier, transaction_index],
     )
示例#7
0
文件: eth.py 项目: whoerau/web3.py
    def getBlock(self, block_identifier, full_transactions=False):
        """
        `eth_getBlockByHash`
        `eth_getBlockByNumber`
        """
        method = select_method_for_block_identifier(
            block_identifier,
            if_predefined='eth_getBlockByNumber',
            if_hash='eth_getBlockByHash',
            if_number='eth_getBlockByNumber',
        )

        return self.web3.manager.request_blocking(
            method,
            [block_identifier, full_transactions],
        )
示例#8
0
文件: eth.py 项目: miohtama/web3.py
    def getBlock(self, block_identifier, full_transactions=False):
        """
        `eth_getBlockByHash`
        `eth_getBlockByNumber`
        """
        method = select_method_for_block_identifier(
            block_identifier,
            if_predefined='eth_getBlockByNumber',
            if_hash='eth_getBlockByHash',
            if_number='eth_getBlockByNumber',
        )

        return self.web3.manager.request_blocking(
            method,
            [block_identifier, full_transactions],
        )
示例#9
0
文件: eth.py 项目: sheldrake/web3.py
 def getBlockTransactionCount(self, block_identifier):
     """
     `eth_getBlockTransactionCountByHash`
     `eth_getBlockTransactionCountByNumber`
     """
     method = select_method_for_block_identifier(
         block_identifier,
         if_predefined='eth_getBlockTransactionCountByNumber',
         if_hash='eth_getBlockTransactionCountByHash',
         if_number='eth_getBlockTransactionCountByNumber',
     )
     result = self.web3.manager.request_blocking(
         method,
         [block_identifier],
     )
     if result is None:
         raise BlockNotFound(f"Block with id: {block_identifier} not found.")
     return result
示例#10
0
 def getUncleCount(self, block_identifier: BlockIdentifier) -> int:
     """
     `eth_getUncleCountByBlockHash`
     `eth_getUncleCountByBlockNumber`
     """
     method = select_method_for_block_identifier(
         block_identifier,
         if_predefined=RPC.eth_getUncleCountByBlockNumber,
         if_hash=RPC.eth_getUncleCountByBlockHash,
         if_number=RPC.eth_getUncleCountByBlockNumber,
     )
     result = self.web3.manager.request_blocking(
         method,
         [block_identifier],
     )
     if result is None:
         raise BlockNotFound(f"Block with id: {block_identifier} not found.")
     return result
示例#11
0
 def getTransactionByBlock(self, block_identifier, transaction_index):
     """
     `eth_getTransactionByBlockHashAndIndex`
     `eth_getTransactionByBlockNumberAndIndex`
     """
     method = select_method_for_block_identifier(
         block_identifier,
         if_predefined='eth_getTransactionByBlockNumberAndIndex',
         if_hash='eth_getTransactionByBlockHashAndIndex',
         if_number='eth_getTransactionByBlockNumberAndIndex',
     )
     result = self.web3.manager.request_blocking(
         method,
         [block_identifier, transaction_index],
     )
     if result is None:
         raise TransactionNotFound(
             f"Transaction index: {transaction_index} "
             f"on block id: {block_identifier} not found.")
     return result
示例#12
0
    def getBlock(self, block_identifier, full_transactions=False):
        """
        `hpb_getBlockByHash`
        `hpb_getBlockByNumber`
        """
        method = select_method_for_block_identifier(
            block_identifier,
            if_predefined='hpb_getBlockByNumber',
            if_hash='hpb_getBlockByHash',
            if_number='hpb_getBlockByNumber',
        )

        result = self.web3.manager.request_blocking(
            method,
            [block_identifier, full_transactions],
        )
        if result is None:
            raise BlockNotFound(
                f"Block with id: {block_identifier} not found.")
        return result
示例#13
0
 def getUncleByBlock(self, block_identifier: BlockIdentifier, uncle_index: int) -> Uncle:
     """
     `eth_getUncleByBlockHashAndIndex`
     `eth_getUncleByBlockNumberAndIndex`
     """
     method = select_method_for_block_identifier(
         block_identifier,
         if_predefined=RPC.eth_getUncleByBlockNumberAndIndex,
         if_hash=RPC.eth_getUncleByBlockHashAndIndex,
         if_number=RPC.eth_getUncleByBlockNumberAndIndex,
     )
     result = self.web3.manager.request_blocking(
         method,
         [block_identifier, uncle_index],
     )
     if result is None:
         raise BlockNotFound(
             f"Uncle at index: {uncle_index} of block with id: {block_identifier} not found."
         )
     return result
示例#14
0
    def getBlock(
        self, block_identifier: BlockIdentifier, full_transactions: bool=False
    ) -> BlockData:
        """
        `eth_getBlockByHash`
        `eth_getBlockByNumber`
        """
        method = select_method_for_block_identifier(
            block_identifier,
            if_predefined=RPC.eth_getBlockByNumber,
            if_hash=RPC.eth_getBlockByHash,
            if_number=RPC.eth_getBlockByNumber,
        )

        result = self.web3.manager.request_blocking(
            method,
            [block_identifier, full_transactions],
        )
        if result is None:
            raise BlockNotFound(f"Block with id: {block_identifier} not found.")
        return result
示例#15
0
文件: eth.py 项目: fubuloubu/web3.py
class Eth(BaseEth):
    account = Account()
    iban = Iban
    defaultContractFactory: Type[Union[Contract, ConciseContract,
                                       ContractCaller]] = Contract

    def namereg(self) -> NoReturn:
        raise NotImplementedError()

    def icapNamereg(self) -> NoReturn:
        raise NotImplementedError()

    @property
    def syncing(self) -> Union[SyncStatus, bool]:
        return self._is_syncing()

    @property
    def coinbase(self) -> ChecksumAddress:
        return self.get_coinbase()

    @property
    def mining(self) -> bool:
        return self._is_mining()

    @property
    def hashrate(self) -> int:
        return self._get_hashrate()

    @property
    def gas_price(self) -> Wei:
        return self._gas_price()

    @property
    def accounts(self) -> Tuple[ChecksumAddress]:
        return self._get_accounts()

    @property
    def block_number(self) -> BlockNumber:
        return self.get_block_number()

    @property
    def chain_id(self) -> int:
        return self._chain_id()

    get_balance: Method[Callable[..., Wei]] = Method(
        RPC.eth_getBalance,
        mungers=[BaseEth.block_id_munger],
    )

    @property
    def max_priority_fee(self) -> Wei:
        """
        Try to use eth_maxPriorityFeePerGas but, since this is not part of the spec and is only
        supported by some clients, fall back to an eth_feeHistory calculation with min and max caps.
        """
        try:
            return self._max_priority_fee()
        except ValueError:
            warnings.warn(
                "There was an issue with the method eth_maxPriorityFeePerGas. Calculating using "
                "eth_feeHistory.")
            return fee_history_priority_fee(self)

    get_storage_at: Method[Callable[..., HexBytes]] = Method(
        RPC.eth_getStorageAt,
        mungers=[BaseEth.get_storage_at_munger],
    )

    def get_proof_munger(
        self,
        account: Union[Address, ChecksumAddress, ENS],
        positions: Sequence[int],
        block_identifier: Optional[BlockIdentifier] = None
    ) -> Tuple[Union[Address, ChecksumAddress, ENS], Sequence[int],
               Optional[BlockIdentifier]]:
        if block_identifier is None:
            block_identifier = self.default_block
        return (account, positions, block_identifier)

    get_proof: Method[Callable[[
        Tuple[Union[Address, ChecksumAddress, ENS], Sequence[int],
              Optional[BlockIdentifier]]
    ], MerkleProof]] = Method(
        RPC.eth_getProof,
        mungers=[get_proof_munger],
    )

    def get_block(self,
                  block_identifier: BlockIdentifier,
                  full_transactions: bool = False) -> BlockData:
        return self._get_block(block_identifier, full_transactions)

    get_code: Method[Callable[..., HexBytes]] = Method(
        RPC.eth_getCode, mungers=[BaseEth.block_id_munger])
    """
    `eth_getBlockTransactionCountByHash`
    `eth_getBlockTransactionCountByNumber`
    """
    get_block_transaction_count: Method[Callable[
        [BlockIdentifier], int]] = Method(
            method_choice_depends_on_args=select_method_for_block_identifier(
                if_predefined=RPC.eth_getBlockTransactionCountByNumber,
                if_hash=RPC.eth_getBlockTransactionCountByHash,
                if_number=RPC.eth_getBlockTransactionCountByNumber,
            ),
            mungers=[default_root_munger])
    """
    `eth_getUncleCountByBlockHash`
    `eth_getUncleCountByBlockNumber`
    """
    get_uncle_count: Method[Callable[[BlockIdentifier], int]] = Method(
        method_choice_depends_on_args=select_method_for_block_identifier(
            if_predefined=RPC.eth_getUncleCountByBlockNumber,
            if_hash=RPC.eth_getUncleCountByBlockHash,
            if_number=RPC.eth_getUncleCountByBlockNumber,
        ),
        mungers=[default_root_munger])
    """
    `eth_getUncleByBlockHashAndIndex`
    `eth_getUncleByBlockNumberAndIndex`
    """
    get_uncle_by_block: Method[Callable[
        [BlockIdentifier, int], Uncle]] = Method(
            method_choice_depends_on_args=select_method_for_block_identifier(
                if_predefined=RPC.eth_getUncleByBlockNumberAndIndex,
                if_hash=RPC.eth_getUncleByBlockHashAndIndex,
                if_number=RPC.eth_getUncleByBlockNumberAndIndex,
            ),
            mungers=[default_root_munger])

    def get_transaction(self, transaction_hash: _Hash32) -> TxData:
        return self._get_transaction(transaction_hash)

    def get_raw_transaction(self, transaction_hash: _Hash32) -> _Hash32:
        return self._get_raw_transaction(transaction_hash)

    def get_raw_transaction_by_block(self, block_identifier: BlockIdentifier,
                                     index: int) -> HexBytes:
        return self._get_raw_transaction_by_block(block_identifier, index)

    get_transaction_by_block: Method[Callable[
        [BlockIdentifier, int], TxData]] = Method(
            method_choice_depends_on_args=select_method_for_block_identifier(
                if_predefined=RPC.eth_getTransactionByBlockNumberAndIndex,
                if_hash=RPC.eth_getTransactionByBlockHashAndIndex,
                if_number=RPC.eth_getTransactionByBlockNumberAndIndex,
            ),
            mungers=[default_root_munger])

    def wait_for_transaction_receipt(self,
                                     transaction_hash: _Hash32,
                                     timeout: float = 120,
                                     poll_latency: float = 0.1) -> TxReceipt:
        try:
            with Timeout(timeout) as _timeout:
                while True:
                    try:
                        tx_receipt = self._get_transaction_receipt(
                            transaction_hash)
                    except TransactionNotFound:
                        tx_receipt = None
                    if tx_receipt is not None:
                        break
                    _timeout.sleep(poll_latency)
            return tx_receipt

        except Timeout:
            raise TimeExhausted(
                f"Transaction {HexBytes(transaction_hash) !r} is not in the chain "
                f"after {timeout} seconds")

    def get_transaction_receipt(self, transaction_hash: _Hash32) -> TxReceipt:
        return self._get_transaction_receipt(transaction_hash)

    get_transaction_count: Method[Callable[..., Nonce]] = Method(
        RPC.eth_getTransactionCount,
        mungers=[BaseEth.block_id_munger],
    )

    def replace_transaction(self, transaction_hash: _Hash32,
                            new_transaction: TxParams) -> HexBytes:
        current_transaction = get_required_transaction(self.w3,
                                                       transaction_hash)
        return replace_transaction(self.w3, current_transaction,
                                   new_transaction)

    # todo: Update Any to stricter kwarg checking with TxParams
    # https://github.com/python/mypy/issues/4441
    def modify_transaction(self, transaction_hash: _Hash32,
                           **transaction_params: Any) -> HexBytes:
        assert_valid_transaction_params(cast(TxParams, transaction_params))
        current_transaction = get_required_transaction(self.w3,
                                                       transaction_hash)
        current_transaction_params = extract_valid_transaction_params(
            current_transaction)
        new_transaction = merge(current_transaction_params, transaction_params)
        return replace_transaction(self.w3, current_transaction,
                                   new_transaction)

    def send_transaction(self, transaction: TxParams) -> HexBytes:
        return self._send_transaction(transaction)

    def send_raw_transaction(self, transaction: Union[HexStr,
                                                      bytes]) -> HexBytes:
        return self._send_raw_transaction(transaction)

    def sign_munger(
        self,
        account: Union[Address, ChecksumAddress, ENS],
        data: Union[int, bytes] = None,
        hexstr: HexStr = None,
        text: str = None
    ) -> Tuple[Union[Address, ChecksumAddress, ENS], HexStr]:
        message_hex = to_hex(data, hexstr=hexstr, text=text)
        return (account, message_hex)

    sign: Method[Callable[..., HexStr]] = Method(
        RPC.eth_sign,
        mungers=[sign_munger],
    )

    sign_transaction: Method[Callable[[TxParams], SignedTx]] = Method(
        RPC.eth_signTransaction,
        mungers=[default_root_munger],
    )

    sign_typed_data: Method[Callable[..., HexStr]] = Method(
        RPC.eth_signTypedData,
        mungers=[default_root_munger],
    )

    _call: Method[Callable[..., Union[bytes, bytearray]]] = Method(
        RPC.eth_call, mungers=[BaseEth.call_munger])

    def call(
        self,
        transaction: TxParams,
        block_identifier: Optional[BlockIdentifier] = None,
        state_override: Optional[CallOverride] = None,
        ccip_read_enabled: bool = True,
    ) -> Union[bytes, bytearray]:
        if ccip_read_enabled:
            # if ccip read is enabled, handle OffchainLookup reverts via durin call
            self._durin_call(transaction, block_identifier, state_override)

        return self._call(transaction, block_identifier, state_override)

    def _durin_call(
        self,
        transaction: TxParams,
        block_identifier: Optional[BlockIdentifier] = None,
        state_override: Optional[CallOverride] = None,
    ) -> Union[bytes, bytearray]:
        max_redirects = self.w3.provider.ccip_read_max_redirects

        if not max_redirects or max_redirects < 4:
            raise ValueError(
                "ccip_read_max_redirects property on provider must be at least 4."
            )

        for _ in range(max_redirects):
            try:
                return self._call(transaction, block_identifier,
                                  state_override)
            except OffchainLookup as offchain_lookup:
                durin_calldata = handle_offchain_lookup(
                    offchain_lookup.payload, transaction)
                transaction['data'] = durin_calldata

        raise TooManyRequests("Too many CCIP read redirects")

    def estimate_gas(
            self,
            transaction: TxParams,
            block_identifier: Optional[BlockIdentifier] = None) -> int:
        return self._estimate_gas(transaction, block_identifier)

    def fee_history(
            self,
            block_count: int,
            newest_block: Union[BlockParams, BlockNumber],
            reward_percentiles: Optional[List[float]] = None) -> FeeHistory:
        return self._fee_history(block_count, newest_block, reward_percentiles)

    def filter_munger(
        self,
        filter_params: Optional[Union[str, FilterParams]] = None,
        filter_id: Optional[HexStr] = None
    ) -> Union[List[FilterParams], List[HexStr], List[str]]:
        if filter_id and filter_params:
            raise TypeError(
                "Ambiguous invocation: provide either a `filter_params` or a `filter_id` argument. "
                "Both were supplied.")
        if isinstance(filter_params, dict):
            return [filter_params]
        elif is_string(filter_params):
            if filter_params in ['latest', 'pending']:
                return [filter_params]
            else:
                raise ValueError(
                    "The filter API only accepts the values of `pending` or "
                    "`latest` for string based filters")
        elif filter_id and not filter_params:
            return [filter_id]
        else:
            raise TypeError(
                "Must provide either filter_params as a string or "
                "a valid filter object, or a filter_id as a string "
                "or hex.")

    filter: Method[Callable[..., Any]] = Method(
        method_choice_depends_on_args=select_filter_method(
            if_new_block_filter=RPC.eth_newBlockFilter,
            if_new_pending_transaction_filter=RPC.
            eth_newPendingTransactionFilter,
            if_new_filter=RPC.eth_newFilter,
        ),
        mungers=[filter_munger],
    )

    get_filter_changes: Method[Callable[[HexStr], List[LogReceipt]]] = Method(
        RPC.eth_getFilterChanges, mungers=[default_root_munger])

    get_filter_logs: Method[Callable[[HexStr], List[LogReceipt]]] = Method(
        RPC.eth_getFilterLogs, mungers=[default_root_munger])

    get_logs: Method[Callable[[FilterParams], List[LogReceipt]]] = Method(
        RPC.eth_getLogs, mungers=[default_root_munger])

    submit_hashrate: Method[Callable[[int, _Hash32], bool]] = Method(
        RPC.eth_submitHashrate,
        mungers=[default_root_munger],
    )

    submit_work: Method[Callable[[int, _Hash32, _Hash32], bool]] = Method(
        RPC.eth_submitWork,
        mungers=[default_root_munger],
    )

    uninstall_filter: Method[Callable[[HexStr], bool]] = Method(
        RPC.eth_uninstallFilter,
        mungers=[default_root_munger],
    )

    get_work: Method[Callable[[], List[HexBytes]]] = Method(
        RPC.eth_getWork,
        is_property=True,
    )

    def generate_gas_price(
            self,
            transaction_params: Optional[TxParams] = None) -> Optional[Wei]:
        return self._generate_gas_price(transaction_params)
示例#16
0
class Eth(ModuleV2, Module):
    account = Account()
    defaultAccount = empty
    defaultBlock: Literal["latest"] = "latest"  # noqa: E704
    defaultContractFactory: Type[
        Union[Contract, ConciseContract,
              ContractCaller]] = Contract  # noqa: E704,E501
    iban = Iban
    gasPriceStrategy = None

    def namereg(self) -> NoReturn:
        raise NotImplementedError()

    def icapNamereg(self) -> NoReturn:
        raise NotImplementedError()

    protocol_version: Method[Callable[[], str]] = Method(
        RPC.eth_protocolVersion,
        mungers=None,
    )

    @property
    def protocolVersion(self) -> str:
        return self.protocol_version()

    is_syncing: Method[Callable[[], Union[SyncStatus, bool]]] = Method(
        RPC.eth_syncing,
        mungers=None,
    )

    @property
    def syncing(self) -> Union[SyncStatus, bool]:
        return self.is_syncing()

    get_coinbase: Method[Callable[[], ChecksumAddress]] = Method(
        RPC.eth_coinbase,
        mungers=None,
    )

    @property
    def coinbase(self) -> ChecksumAddress:
        return self.get_coinbase()

    is_mining: Method[Callable[[], bool]] = Method(
        RPC.eth_mining,
        mungers=None,
    )

    @property
    def mining(self) -> bool:
        return self.is_mining()

    get_hashrate: Method[Callable[[], int]] = Method(
        RPC.eth_hashrate,
        mungers=None,
    )

    @property
    def hashrate(self) -> int:
        return self.get_hashrate()

    gas_price: Method[Callable[[], Wei]] = Method(
        RPC.eth_gasPrice,
        mungers=None,
    )

    @property
    def gasPrice(self) -> Wei:
        return self.gas_price()

    get_accounts: Method[Callable[[], Tuple[ChecksumAddress]]] = Method(
        RPC.eth_accounts,
        mungers=None,
    )

    @property
    def accounts(self) -> Tuple[ChecksumAddress]:
        return self.get_accounts()

    block_number: Method[Callable[[], BlockNumber]] = Method(
        RPC.eth_blockNumber,
        mungers=None,
    )

    @property
    def blockNumber(self) -> BlockNumber:
        return self.block_number()

    chain_id: Method[Callable[[], int]] = Method(
        RPC.eth_chainId,
        mungers=None,
    )

    @property
    def chainId(self) -> int:
        return self.web3.manager.request_blocking(RPC.eth_chainId, [])

    def block_id_munger(
        self,
        account: Union[Address, ChecksumAddress, ENS],
        block_identifier: Optional[BlockIdentifier] = None
    ) -> Tuple[Union[Address, ChecksumAddress, ENS], BlockIdentifier]:
        if block_identifier is None:
            block_identifier = self.defaultBlock
        return (account, block_identifier)

    getBalance: Method[Callable[..., Wei]] = Method(
        RPC.eth_getBalance,
        mungers=[block_id_munger],
    )

    def get_storage_at_munger(
        self,
        account: Union[Address, ChecksumAddress, ENS],
        position: int,
        block_identifier: Optional[BlockIdentifier] = None
    ) -> Tuple[Union[Address, ChecksumAddress, ENS], int, BlockIdentifier]:
        if block_identifier is None:
            block_identifier = self.defaultBlock
        return (account, position, block_identifier)

    getStorageAt: Method[Callable[..., HexBytes]] = Method(
        RPC.eth_getStorageAt,
        mungers=[get_storage_at_munger],
    )

    def get_proof_munger(
        self,
        account: Union[Address, ChecksumAddress, ENS],
        positions: Sequence[int],
        block_identifier: Optional[BlockIdentifier] = None
    ) -> Tuple[Union[Address, ChecksumAddress, ENS], Sequence[int],
               Optional[BlockIdentifier]]:
        if block_identifier is None:
            block_identifier = self.defaultBlock
        return (account, positions, block_identifier)

    getProof: Method[Callable[[
        Tuple[Union[Address, ChecksumAddress, ENS], Sequence[int],
              Optional[BlockIdentifier]]
    ], MerkleProof]] = Method(
        RPC.eth_getProof,
        mungers=[get_proof_munger],
    )

    getCode: Method[Callable[...,
                             HexBytes]] = Method(RPC.eth_getCode,
                                                 mungers=[block_id_munger])

    def get_block_munger(
            self,
            block_identifier: BlockIdentifier,
            full_transactions: bool = False) -> Tuple[BlockIdentifier, bool]:
        return (block_identifier, full_transactions)

    """
    `eth_getBlockByHash`
    `eth_getBlockByNumber`
    """
    getBlock: Method[Callable[..., BlockData]] = Method(
        method_choice_depends_on_args=select_method_for_block_identifier(
            if_predefined=RPC.eth_getBlockByNumber,
            if_hash=RPC.eth_getBlockByHash,
            if_number=RPC.eth_getBlockByNumber,
        ),
        mungers=[get_block_munger],
    )
    """
    `eth_getBlockTransactionCountByHash`
    `eth_getBlockTransactionCountByNumber`
    """
    getBlockTransactionCount: Method[Callable[
        [BlockIdentifier], int]] = Method(
            method_choice_depends_on_args=select_method_for_block_identifier(
                if_predefined=RPC.eth_getBlockTransactionCountByNumber,
                if_hash=RPC.eth_getBlockTransactionCountByHash,
                if_number=RPC.eth_getBlockTransactionCountByNumber,
            ),
            mungers=[default_root_munger])
    """
    `eth_getUncleCountByBlockHash`
    `eth_getUncleCountByBlockNumber`
    """
    getUncleCount: Method[Callable[[BlockIdentifier], int]] = Method(
        method_choice_depends_on_args=select_method_for_block_identifier(
            if_predefined=RPC.eth_getUncleCountByBlockNumber,
            if_hash=RPC.eth_getUncleCountByBlockHash,
            if_number=RPC.eth_getUncleCountByBlockNumber,
        ),
        mungers=[default_root_munger])
    """
    `eth_getUncleByBlockHashAndIndex`
    `eth_getUncleByBlockNumberAndIndex`
    """
    getUncleByBlock: Method[Callable[[BlockIdentifier, int], Uncle]] = Method(
        method_choice_depends_on_args=select_method_for_block_identifier(
            if_predefined=RPC.eth_getUncleByBlockNumberAndIndex,
            if_hash=RPC.eth_getUncleByBlockHashAndIndex,
            if_number=RPC.eth_getUncleByBlockNumberAndIndex,
        ),
        mungers=[default_root_munger])

    getTransaction: Method[Callable[[_Hash32], TxData]] = Method(
        RPC.eth_getTransactionByHash, mungers=[default_root_munger])

    def getTransactionFromBlock(self, block_identifier: BlockIdentifier,
                                transaction_index: int) -> NoReturn:
        """
        Alias for the method getTransactionByBlock
        Deprecated to maintain naming consistency with the json-rpc API
        """
        raise DeprecationWarning(
            "This method has been deprecated as of EIP 1474.")

    getTransactionByBlock: Method[Callable[
        [BlockIdentifier, int], TxData]] = Method(
            method_choice_depends_on_args=select_method_for_block_identifier(
                if_predefined=RPC.eth_getTransactionByBlockNumberAndIndex,
                if_hash=RPC.eth_getTransactionByBlockHashAndIndex,
                if_number=RPC.eth_getTransactionByBlockNumberAndIndex,
            ),
            mungers=[default_root_munger])

    def waitForTransactionReceipt(self,
                                  transaction_hash: _Hash32,
                                  timeout: int = 120,
                                  poll_latency: float = 0.1) -> TxReceipt:
        try:
            return wait_for_transaction_receipt(self.web3, transaction_hash,
                                                timeout, poll_latency)
        except Timeout:
            raise TimeExhausted(
                "Transaction {} is not in the chain, after {} seconds".format(
                    to_hex(transaction_hash),
                    timeout,
                ))

    getTransactionReceipt: Method[Callable[[_Hash32], TxReceipt]] = Method(
        RPC.eth_getTransactionReceipt, mungers=[default_root_munger])

    getTransactionCount: Method[Callable[..., Nonce]] = Method(
        RPC.eth_getTransactionCount,
        mungers=[block_id_munger],
    )

    def replaceTransaction(self, transaction_hash: _Hash32,
                           new_transaction: TxParams) -> HexBytes:
        current_transaction = get_required_transaction(self.web3,
                                                       transaction_hash)
        return replace_transaction(self.web3, current_transaction,
                                   new_transaction)

    # todo: Update Any to stricter kwarg checking with TxParams
    # https://github.com/python/mypy/issues/4441
    def modifyTransaction(self, transaction_hash: _Hash32,
                          **transaction_params: Any) -> HexBytes:
        assert_valid_transaction_params(cast(TxParams, transaction_params))
        current_transaction = get_required_transaction(self.web3,
                                                       transaction_hash)
        current_transaction_params = extract_valid_transaction_params(
            current_transaction)
        new_transaction = merge(current_transaction_params, transaction_params)
        return replace_transaction(self.web3, current_transaction,
                                   new_transaction)

    def send_transaction_munger(self,
                                transaction: TxParams) -> Tuple[TxParams]:
        # TODO: move to middleware
        if 'from' not in transaction and is_checksum_address(
                self.defaultAccount):
            transaction = assoc(transaction, 'from', self.defaultAccount)

        # TODO: move gas estimation in middleware
        if 'gas' not in transaction:
            transaction = assoc(
                transaction,
                'gas',
                get_buffered_gas_estimate(self.web3, transaction),
            )
        return (transaction, )

    sendTransaction: Method[Callable[[TxParams], HexBytes]] = Method(
        RPC.eth_sendTransaction, mungers=[send_transaction_munger])

    sendRawTransaction: Method[Callable[[Union[HexStr, bytes]],
                                        HexBytes]] = Method(
                                            RPC.eth_sendRawTransaction,
                                            mungers=[default_root_munger],
                                        )

    def sign_munger(
        self,
        account: Union[Address, ChecksumAddress, ENS],
        data: Union[int, bytes] = None,
        hexstr: HexStr = None,
        text: str = None
    ) -> Tuple[Union[Address, ChecksumAddress, ENS], HexStr]:
        message_hex = to_hex(data, hexstr=hexstr, text=text)
        return (account, message_hex)

    sign: Method[Callable[..., HexStr]] = Method(
        RPC.eth_sign,
        mungers=[sign_munger],
    )

    signTransaction: Method[Callable[[TxParams], SignedTx]] = Method(
        RPC.eth_signTransaction,
        mungers=[default_root_munger],
    )

    signTypedData: Method[Callable[..., HexStr]] = Method(
        RPC.eth_signTypedData,
        mungers=[default_root_munger],
    )

    def call_munger(
        self,
        transaction: TxParams,
        block_identifier: Optional[BlockIdentifier] = None
    ) -> Tuple[TxParams, BlockIdentifier]:
        # TODO: move to middleware
        if 'from' not in transaction and is_checksum_address(
                self.defaultAccount):
            transaction = assoc(transaction, 'from', self.defaultAccount)

        # TODO: move to middleware
        if block_identifier is None:
            block_identifier = self.defaultBlock

        return (transaction, block_identifier)

    call: Method[Callable[...,
                          Union[bytes,
                                bytearray]]] = Method(RPC.eth_call,
                                                      mungers=[call_munger])

    def estimate_gas_munger(
        self,
        transaction: TxParams,
        block_identifier: Optional[BlockIdentifier] = None
    ) -> Sequence[Union[TxParams, BlockIdentifier]]:
        if 'from' not in transaction and is_checksum_address(
                self.defaultAccount):
            transaction = assoc(transaction, 'from', self.defaultAccount)

        if block_identifier is None:
            params: Sequence[Union[TxParams, BlockIdentifier]] = [transaction]
        else:
            params = [transaction, block_identifier]

        return params

    estimateGas: Method[Callable[...,
                                 Wei]] = Method(RPC.eth_estimateGas,
                                                mungers=[estimate_gas_munger])

    def filter(self,
               filter_params: Optional[Union[str, FilterParams]] = None,
               filter_id: Optional[HexStr] = None) -> Filter:
        if filter_id and filter_params:
            raise TypeError(
                "Ambiguous invocation: provide either a `filter_params` or a `filter_id` argument. "
                "Both were supplied.")
        if is_string(filter_params):
            if filter_params == "latest":
                filter_id = self.web3.manager.request_blocking(
                    RPC.eth_newBlockFilter,
                    [],
                )
                return BlockFilter(self.web3, filter_id)
            elif filter_params == "pending":
                filter_id = self.web3.manager.request_blocking(
                    RPC.eth_newPendingTransactionFilter,
                    [],
                )
                return TransactionFilter(self.web3, filter_id)
            else:
                raise ValueError(
                    "The filter API only accepts the values of `pending` or "
                    "`latest` for string based filters")
        elif isinstance(filter_params, dict):
            _filter_id = self.web3.manager.request_blocking(
                RPC.eth_newFilter,
                [filter_params],
            )
            return LogFilter(self.web3, _filter_id)
        elif filter_id and not filter_params:
            return LogFilter(self.web3, filter_id)
        else:
            raise TypeError(
                "Must provide either filter_params as a string or "
                "a valid filter object, or a filter_id as a string "
                "or hex.")

    def getFilterChanges(self, filter_id: HexStr) -> List[LogReceipt]:
        return self.web3.manager.request_blocking(
            RPC.eth_getFilterChanges,
            [filter_id],
        )

    def getFilterLogs(self, filter_id: HexStr) -> List[LogReceipt]:
        return self.web3.manager.request_blocking(
            RPC.eth_getFilterLogs,
            [filter_id],
        )

    def getLogs(self, filter_params: FilterParams) -> List[LogReceipt]:
        return self.web3.manager.request_blocking(
            RPC.eth_getLogs,
            [filter_params],
        )

    submitHashrate: Method[Callable[[int, _Hash32], bool]] = Method(
        RPC.eth_submitHashrate,
        mungers=[default_root_munger],
    )

    submitWork: Method[Callable[[int, _Hash32, _Hash32], bool]] = Method(
        RPC.eth_submitWork,
        mungers=[default_root_munger],
    )

    uninstallFilter: Method[Callable[[HexStr], bool]] = Method(
        RPC.eth_uninstallFilter,
        mungers=[default_root_munger],
    )

    @overload
    def contract(self, address: None = None, **kwargs: Any) -> Type[Contract]:
        ...  # noqa: E704,E501

    @overload  # noqa: F811
    def contract(self, address: Union[Address, ChecksumAddress, ENS],
                 **kwargs: Any) -> Contract:
        ...  # noqa: E704,E501

    def contract(  # noqa: F811
            self,
            address: Optional[Union[Address, ChecksumAddress, ENS]] = None,
            **kwargs: Any) -> Union[Type[Contract], Contract]:
        ContractFactoryClass = kwargs.pop('ContractFactoryClass',
                                          self.defaultContractFactory)

        ContractFactory = ContractFactoryClass.factory(self.web3, **kwargs)

        if address:
            return ContractFactory(address)
        else:
            return ContractFactory

    def setContractFactory(
        self, contractFactory: Type[Union[Contract, ConciseContract,
                                          ContractCaller]]
    ) -> None:
        self.defaultContractFactory = contractFactory

    def getCompilers(self) -> NoReturn:
        raise DeprecationWarning(
            "This method has been deprecated as of EIP 1474.")

    getWork: Method[Callable[[], List[HexBytes]]] = Method(
        RPC.eth_getWork,
        mungers=None,
    )

    def generateGasPrice(
            self,
            transaction_params: Optional[TxParams] = None) -> Optional[Wei]:
        if self.gasPriceStrategy:
            return self.gasPriceStrategy(self.web3, transaction_params)
        return None

    def setGasPriceStrategy(self,
                            gas_price_strategy: GasPriceStrategy) -> None:
        self.gasPriceStrategy = gas_price_strategy
示例#17
0
文件: eth.py 项目: kclowes/web3.py
class BaseEth(Module):
    _default_account: Union[ChecksumAddress, Empty] = empty
    _default_block: BlockIdentifier = "latest"
    gasPriceStrategy = None

    _gas_price: Method[Callable[[], Wei]] = Method(
        RPC.eth_gasPrice,
        mungers=None,
    )

    @property
    def default_block(self) -> BlockIdentifier:
        return self._default_block

    @default_block.setter
    def default_block(self, value: BlockIdentifier) -> None:
        self._default_block = value

    @property
    def defaultBlock(self) -> BlockIdentifier:
        warnings.warn(
            'defaultBlock is deprecated in favor of default_block',
            category=DeprecationWarning,
        )
        return self._default_block

    @defaultBlock.setter
    def defaultBlock(self, value: BlockIdentifier) -> None:
        warnings.warn(
            'defaultBlock is deprecated in favor of default_block',
            category=DeprecationWarning,
        )
        self._default_block = value

    @property
    def default_account(self) -> Union[ChecksumAddress, Empty]:
        return self._default_account

    @default_account.setter
    def default_account(self, account: Union[ChecksumAddress, Empty]) -> None:
        self._default_account = account

    @property
    def defaultAccount(self) -> Union[ChecksumAddress, Empty]:
        warnings.warn(
            'defaultAccount is deprecated in favor of default_account',
            category=DeprecationWarning,
        )
        return self._default_account

    @defaultAccount.setter
    def defaultAccount(self, account: Union[ChecksumAddress, Empty]) -> None:
        warnings.warn(
            'defaultAccount is deprecated in favor of default_account',
            category=DeprecationWarning,
        )
        self._default_account = account

    def send_transaction_munger(self,
                                transaction: TxParams) -> Tuple[TxParams]:
        if 'from' not in transaction and is_checksum_address(
                self.default_account):
            transaction = assoc(transaction, 'from', self.default_account)

        return (transaction, )

    _send_transaction: Method[Callable[[TxParams], HexBytes]] = Method(
        RPC.eth_sendTransaction, mungers=[send_transaction_munger])

    _send_raw_transaction: Method[Callable[[Union[HexStr, bytes]],
                                           HexBytes]] = Method(
                                               RPC.eth_sendRawTransaction,
                                               mungers=[default_root_munger],
                                           )

    _get_transaction: Method[Callable[[_Hash32], TxData]] = Method(
        RPC.eth_getTransactionByHash, mungers=[default_root_munger])

    _get_raw_transaction: Method[Callable[[_Hash32], HexBytes]] = Method(
        RPC.eth_getRawTransactionByHash, mungers=[default_root_munger])
    """
    `eth_getRawTransactionByBlockHashAndIndex`
    `eth_getRawTransactionByBlockNumberAndIndex`
    """
    _get_raw_transaction_by_block: Method[Callable[
        [BlockIdentifier, int], HexBytes]] = Method(
            method_choice_depends_on_args=select_method_for_block_identifier(
                if_predefined=RPC.eth_getRawTransactionByBlockNumberAndIndex,
                if_hash=RPC.eth_getRawTransactionByBlockHashAndIndex,
                if_number=RPC.eth_getRawTransactionByBlockNumberAndIndex,
            ),
            mungers=[default_root_munger])

    def _generate_gas_price(
            self,
            transaction_params: Optional[TxParams] = None) -> Optional[Wei]:
        if self.gasPriceStrategy:
            return self.gasPriceStrategy(self.web3, transaction_params)
        return None

    def set_gas_price_strategy(self,
                               gas_price_strategy: GasPriceStrategy) -> None:
        self.gasPriceStrategy = gas_price_strategy

    def estimate_gas_munger(
        self,
        transaction: TxParams,
        block_identifier: Optional[BlockIdentifier] = None
    ) -> Sequence[Union[TxParams, BlockIdentifier]]:
        if 'from' not in transaction and is_checksum_address(
                self.default_account):
            transaction = assoc(transaction, 'from', self.default_account)

        if block_identifier is None:
            params: Sequence[Union[TxParams, BlockIdentifier]] = [transaction]
        else:
            params = [transaction, block_identifier]

        return params

    _estimate_gas: Method[Callable[..., int]] = Method(
        RPC.eth_estimateGas, mungers=[estimate_gas_munger])

    _fee_history: Method[Callable[..., FeeHistory]] = Method(
        RPC.eth_feeHistory, mungers=[default_root_munger])

    _max_priority_fee: Method[Callable[..., Wei]] = Method(
        RPC.eth_maxPriorityFeePerGas,
        mungers=None,
    )

    def get_block_munger(
            self,
            block_identifier: BlockIdentifier,
            full_transactions: bool = False) -> Tuple[BlockIdentifier, bool]:
        return (block_identifier, full_transactions)

    """
    `eth_getBlockByHash`
    `eth_getBlockByNumber`
    """
    _get_block: Method[Callable[..., BlockData]] = Method(
        method_choice_depends_on_args=select_method_for_block_identifier(
            if_predefined=RPC.eth_getBlockByNumber,
            if_hash=RPC.eth_getBlockByHash,
            if_number=RPC.eth_getBlockByNumber,
        ),
        mungers=[get_block_munger],
    )

    get_block_number: Method[Callable[[], BlockNumber]] = Method(
        RPC.eth_blockNumber,
        mungers=None,
    )

    get_coinbase: Method[Callable[[], ChecksumAddress]] = Method(
        RPC.eth_coinbase,
        mungers=None,
    )

    def block_id_munger(
        self,
        account: Union[Address, ChecksumAddress, ENS],
        block_identifier: Optional[BlockIdentifier] = None
    ) -> Tuple[Union[Address, ChecksumAddress, ENS], BlockIdentifier]:
        if block_identifier is None:
            block_identifier = self.default_block
        return (account, block_identifier)

    def get_storage_at_munger(
        self,
        account: Union[Address, ChecksumAddress, ENS],
        position: int,
        block_identifier: Optional[BlockIdentifier] = None
    ) -> Tuple[Union[Address, ChecksumAddress, ENS], int, BlockIdentifier]:
        if block_identifier is None:
            block_identifier = self.default_block
        return (account, position, block_identifier)

    def call_munger(
        self,
        transaction: TxParams,
        block_identifier: Optional[BlockIdentifier] = None,
        state_override: Optional[CallOverrideParams] = None,
    ) -> Union[Tuple[TxParams, BlockIdentifier], Tuple[
            TxParams, BlockIdentifier, CallOverrideParams]]:  # noqa-E501
        # TODO: move to middleware
        if 'from' not in transaction and is_checksum_address(
                self.default_account):
            transaction = assoc(transaction, 'from', self.default_account)

        # TODO: move to middleware
        if block_identifier is None:
            block_identifier = self.default_block

        if state_override is None:
            return (transaction, block_identifier)
        else:
            return (transaction, block_identifier, state_override)

    _get_accounts: Method[Callable[[], Tuple[ChecksumAddress]]] = Method(
        RPC.eth_accounts,
        mungers=None,
    )

    _get_hashrate: Method[Callable[[], int]] = Method(
        RPC.eth_hashrate,
        mungers=None,
    )

    _chain_id: Method[Callable[[], int]] = Method(
        RPC.eth_chainId,
        mungers=None,
    )

    _is_mining: Method[Callable[[], bool]] = Method(
        RPC.eth_mining,
        mungers=None,
    )

    _is_syncing: Method[Callable[[], Union[SyncStatus, bool]]] = Method(
        RPC.eth_syncing,
        mungers=None,
    )

    _get_transaction_receipt: Method[Callable[[_Hash32], TxReceipt]] = Method(
        RPC.eth_getTransactionReceipt, mungers=[default_root_munger])
示例#18
0
class BaseEth(Module):
    _default_account: Union[ChecksumAddress, Empty] = empty
    gasPriceStrategy = None

    _gas_price: Method[Callable[[], Wei]] = Method(
        RPC.eth_gasPrice,
        mungers=None,
    )

    @property
    def default_account(self) -> Union[ChecksumAddress, Empty]:
        return self._default_account

    def send_transaction_munger(self,
                                transaction: TxParams) -> Tuple[TxParams]:
        if 'from' not in transaction and is_checksum_address(
                self.default_account):
            transaction = assoc(transaction, 'from', self.default_account)

        return (transaction, )

    _send_transaction: Method[Callable[[TxParams], HexBytes]] = Method(
        RPC.eth_sendTransaction, mungers=[send_transaction_munger])

    _get_transaction: Method[Callable[[_Hash32], TxData]] = Method(
        RPC.eth_getTransactionByHash, mungers=[default_root_munger])

    def _generate_gas_price(
            self,
            transaction_params: Optional[TxParams] = None) -> Optional[Wei]:
        if self.gasPriceStrategy:
            return self.gasPriceStrategy(self.web3, transaction_params)
        return None

    def set_gas_price_strategy(self,
                               gas_price_strategy: GasPriceStrategy) -> None:
        self.gasPriceStrategy = gas_price_strategy

    def estimate_gas_munger(
        self,
        transaction: TxParams,
        block_identifier: Optional[BlockIdentifier] = None
    ) -> Sequence[Union[TxParams, BlockIdentifier]]:
        if 'from' not in transaction and is_checksum_address(
                self.default_account):
            transaction = assoc(transaction, 'from', self.default_account)

        if block_identifier is None:
            params: Sequence[Union[TxParams, BlockIdentifier]] = [transaction]
        else:
            params = [transaction, block_identifier]

        return params

    _estimate_gas: Method[Callable[..., Wei]] = Method(
        RPC.eth_estimateGas, mungers=[estimate_gas_munger])

    def get_block_munger(
            self,
            block_identifier: BlockIdentifier,
            full_transactions: bool = False) -> Tuple[BlockIdentifier, bool]:
        return (block_identifier, full_transactions)

    """
    `eth_getBlockByHash`
    `eth_getBlockByNumber`
    """
    _get_block: Method[Callable[..., BlockData]] = Method(
        method_choice_depends_on_args=select_method_for_block_identifier(
            if_predefined=RPC.eth_getBlockByNumber,
            if_hash=RPC.eth_getBlockByHash,
            if_number=RPC.eth_getBlockByNumber,
        ),
        mungers=[get_block_munger],
    )

    get_block_number: Method[Callable[[], BlockNumber]] = Method(
        RPC.eth_blockNumber,
        mungers=None,
    )

    get_coinbase: Method[Callable[[], ChecksumAddress]] = Method(
        RPC.eth_coinbase,
        mungers=None,
    )
示例#19
0
class Eth(BaseEth, Module):
    account = Account()
    _default_block: BlockIdentifier = "latest"
    defaultContractFactory: Type[
        Union[Contract, ConciseContract,
              ContractCaller]] = Contract  # noqa: E704,E501
    iban = Iban

    def namereg(self) -> NoReturn:
        raise NotImplementedError()

    def icapNamereg(self) -> NoReturn:
        raise NotImplementedError()

    _protocol_version: Method[Callable[[], str]] = Method(
        RPC.eth_protocolVersion,
        mungers=None,
    )

    @property
    def protocol_version(self) -> str:
        warnings.warn(
            "This method has been deprecated in some clients.",
            category=DeprecationWarning,
        )
        return self._protocol_version()

    @property
    def protocolVersion(self) -> str:
        warnings.warn(
            'protocolVersion is deprecated in favor of protocol_version',
            category=DeprecationWarning,
        )
        return self.protocol_version

    is_syncing: Method[Callable[[], Union[SyncStatus, bool]]] = Method(
        RPC.eth_syncing,
        mungers=None,
    )

    @property
    def syncing(self) -> Union[SyncStatus, bool]:
        return self.is_syncing()

    @property
    def coinbase(self) -> ChecksumAddress:
        return self.get_coinbase()

    is_mining: Method[Callable[[], bool]] = Method(
        RPC.eth_mining,
        mungers=None,
    )

    @property
    def mining(self) -> bool:
        return self.is_mining()

    get_hashrate: Method[Callable[[], int]] = Method(
        RPC.eth_hashrate,
        mungers=None,
    )

    @property
    def hashrate(self) -> int:
        return self.get_hashrate()

    @property
    def gas_price(self) -> Wei:
        return self._gas_price()

    @property
    def gasPrice(self) -> Wei:
        warnings.warn(
            'gasPrice is deprecated in favor of gas_price',
            category=DeprecationWarning,
        )
        return self.gas_price

    get_accounts: Method[Callable[[], Tuple[ChecksumAddress]]] = Method(
        RPC.eth_accounts,
        mungers=None,
    )

    @property
    def accounts(self) -> Tuple[ChecksumAddress]:
        return self.get_accounts()

    @property
    def block_number(self) -> BlockNumber:
        return self.get_block_number()

    @property
    def blockNumber(self) -> BlockNumber:
        warnings.warn(
            'blockNumber is deprecated in favor of block_number',
            category=DeprecationWarning,
        )
        return self.block_number

    _chain_id: Method[Callable[[], int]] = Method(
        RPC.eth_chainId,
        mungers=None,
    )

    @property
    def chain_id(self) -> int:
        return self._chain_id()

    @property
    def chainId(self) -> int:
        warnings.warn(
            'chainId is deprecated in favor of chain_id',
            category=DeprecationWarning,
        )
        return self.chain_id

    """ property default_account """

    @property
    def default_account(self) -> Union[ChecksumAddress, Empty]:
        return self._default_account

    @default_account.setter
    def default_account(self, account: Union[ChecksumAddress, Empty]) -> None:
        self._default_account = account

    @property
    def defaultAccount(self) -> Union[ChecksumAddress, Empty]:
        warnings.warn(
            'defaultAccount is deprecated in favor of default_account',
            category=DeprecationWarning,
        )
        return self._default_account

    @defaultAccount.setter
    def defaultAccount(self, account: Union[ChecksumAddress, Empty]) -> None:
        warnings.warn(
            'defaultAccount is deprecated in favor of default_account',
            category=DeprecationWarning,
        )
        self._default_account = account

    """ property default_block """

    @property
    def default_block(self) -> BlockIdentifier:
        return self._default_block

    @default_block.setter
    def default_block(self, value: BlockIdentifier) -> None:
        self._default_block = value

    @property
    def defaultBlock(self) -> BlockIdentifier:
        warnings.warn(
            'defaultBlock is deprecated in favor of default_block',
            category=DeprecationWarning,
        )
        return self._default_block

    @defaultBlock.setter
    def defaultBlock(self, value: BlockIdentifier) -> None:
        warnings.warn(
            'defaultBlock is deprecated in favor of default_block',
            category=DeprecationWarning,
        )
        self._default_block = value

    def block_id_munger(
        self,
        account: Union[Address, ChecksumAddress, ENS],
        block_identifier: Optional[BlockIdentifier] = None
    ) -> Tuple[Union[Address, ChecksumAddress, ENS], BlockIdentifier]:
        if block_identifier is None:
            block_identifier = self.default_block
        return (account, block_identifier)

    get_balance: Method[Callable[..., Wei]] = Method(
        RPC.eth_getBalance,
        mungers=[block_id_munger],
    )

    def get_storage_at_munger(
        self,
        account: Union[Address, ChecksumAddress, ENS],
        position: int,
        block_identifier: Optional[BlockIdentifier] = None
    ) -> Tuple[Union[Address, ChecksumAddress, ENS], int, BlockIdentifier]:
        if block_identifier is None:
            block_identifier = self.default_block
        return (account, position, block_identifier)

    get_storage_at: Method[Callable[..., HexBytes]] = Method(
        RPC.eth_getStorageAt,
        mungers=[get_storage_at_munger],
    )

    def get_proof_munger(
        self,
        account: Union[Address, ChecksumAddress, ENS],
        positions: Sequence[int],
        block_identifier: Optional[BlockIdentifier] = None
    ) -> Tuple[Union[Address, ChecksumAddress, ENS], Sequence[int],
               Optional[BlockIdentifier]]:
        if block_identifier is None:
            block_identifier = self.default_block
        return (account, positions, block_identifier)

    get_proof: Method[Callable[[
        Tuple[Union[Address, ChecksumAddress, ENS], Sequence[int],
              Optional[BlockIdentifier]]
    ], MerkleProof]] = Method(
        RPC.eth_getProof,
        mungers=[get_proof_munger],
    )

    get_code: Method[Callable[...,
                              HexBytes]] = Method(RPC.eth_getCode,
                                                  mungers=[block_id_munger])

    def get_block(self,
                  block_identifier: BlockIdentifier,
                  full_transactions: bool = False) -> BlockData:
        return self._get_block(block_identifier, full_transactions)

    """
    `eth_getBlockTransactionCountByHash`
    `eth_getBlockTransactionCountByNumber`
    """
    get_block_transaction_count: Method[Callable[
        [BlockIdentifier], int]] = Method(
            method_choice_depends_on_args=select_method_for_block_identifier(
                if_predefined=RPC.eth_getBlockTransactionCountByNumber,
                if_hash=RPC.eth_getBlockTransactionCountByHash,
                if_number=RPC.eth_getBlockTransactionCountByNumber,
            ),
            mungers=[default_root_munger])
    """
    `eth_getUncleCountByBlockHash`
    `eth_getUncleCountByBlockNumber`
    """
    get_uncle_count: Method[Callable[[BlockIdentifier], int]] = Method(
        method_choice_depends_on_args=select_method_for_block_identifier(
            if_predefined=RPC.eth_getUncleCountByBlockNumber,
            if_hash=RPC.eth_getUncleCountByBlockHash,
            if_number=RPC.eth_getUncleCountByBlockNumber,
        ),
        mungers=[default_root_munger])
    """
    `eth_getUncleByBlockHashAndIndex`
    `eth_getUncleByBlockNumberAndIndex`
    """
    get_uncle_by_block: Method[Callable[
        [BlockIdentifier, int], Uncle]] = Method(
            method_choice_depends_on_args=select_method_for_block_identifier(
                if_predefined=RPC.eth_getUncleByBlockNumberAndIndex,
                if_hash=RPC.eth_getUncleByBlockHashAndIndex,
                if_number=RPC.eth_getUncleByBlockNumberAndIndex,
            ),
            mungers=[default_root_munger])

    def get_transaction(self, transaction_hash: _Hash32) -> TxData:
        return self._get_transaction(transaction_hash)

    def getTransactionFromBlock(self, block_identifier: BlockIdentifier,
                                transaction_index: int) -> NoReturn:
        """
        Alias for the method getTransactionByBlock
        Deprecated to maintain naming consistency with the json-rpc API
        """
        raise DeprecationWarning(
            "This method has been deprecated as of EIP 1474.")

    get_transaction_by_block: Method[Callable[
        [BlockIdentifier, int], TxData]] = Method(
            method_choice_depends_on_args=select_method_for_block_identifier(
                if_predefined=RPC.eth_getTransactionByBlockNumberAndIndex,
                if_hash=RPC.eth_getTransactionByBlockHashAndIndex,
                if_number=RPC.eth_getTransactionByBlockNumberAndIndex,
            ),
            mungers=[default_root_munger])

    @deprecated_for("wait_for_transaction_receipt")
    def waitForTransactionReceipt(self,
                                  transaction_hash: _Hash32,
                                  timeout: int = 120,
                                  poll_latency: float = 0.1) -> TxReceipt:
        return self.wait_for_transaction_receipt(transaction_hash, timeout,
                                                 poll_latency)

    def wait_for_transaction_receipt(self,
                                     transaction_hash: _Hash32,
                                     timeout: int = 120,
                                     poll_latency: float = 0.1) -> TxReceipt:
        try:
            return wait_for_transaction_receipt(self.web3, transaction_hash,
                                                timeout, poll_latency)
        except Timeout:
            raise TimeExhausted(
                "Transaction {} is not in the chain, after {} seconds".format(
                    to_hex(transaction_hash),
                    timeout,
                ))

    get_transaction_receipt: Method[Callable[[_Hash32], TxReceipt]] = Method(
        RPC.eth_getTransactionReceipt, mungers=[default_root_munger])

    get_transaction_count: Method[Callable[..., Nonce]] = Method(
        RPC.eth_getTransactionCount,
        mungers=[block_id_munger],
    )

    @deprecated_for("replace_transaction")
    def replaceTransaction(self, transaction_hash: _Hash32,
                           new_transaction: TxParams) -> HexBytes:
        return self.replace_transaction(transaction_hash, new_transaction)

    def replace_transaction(self, transaction_hash: _Hash32,
                            new_transaction: TxParams) -> HexBytes:
        current_transaction = get_required_transaction(self.web3,
                                                       transaction_hash)
        return replace_transaction(self.web3, current_transaction,
                                   new_transaction)

    # todo: Update Any to stricter kwarg checking with TxParams
    # https://github.com/python/mypy/issues/4441
    @deprecated_for("modify_transaction")
    def modifyTransaction(self, transaction_hash: _Hash32,
                          **transaction_params: Any) -> HexBytes:
        return self.modify_transaction(transaction_hash, **transaction_params)

    def modify_transaction(self, transaction_hash: _Hash32,
                           **transaction_params: Any) -> HexBytes:
        assert_valid_transaction_params(cast(TxParams, transaction_params))
        current_transaction = get_required_transaction(self.web3,
                                                       transaction_hash)
        current_transaction_params = extract_valid_transaction_params(
            current_transaction)
        new_transaction = merge(current_transaction_params, transaction_params)
        return replace_transaction(self.web3, current_transaction,
                                   new_transaction)

    def send_transaction(self, transaction: TxParams) -> HexBytes:
        return self._send_transaction(transaction)

    send_raw_transaction: Method[Callable[[Union[HexStr, bytes]],
                                          HexBytes]] = Method(
                                              RPC.eth_sendRawTransaction,
                                              mungers=[default_root_munger],
                                          )

    def sign_munger(
        self,
        account: Union[Address, ChecksumAddress, ENS],
        data: Union[int, bytes] = None,
        hexstr: HexStr = None,
        text: str = None
    ) -> Tuple[Union[Address, ChecksumAddress, ENS], HexStr]:
        message_hex = to_hex(data, hexstr=hexstr, text=text)
        return (account, message_hex)

    sign: Method[Callable[..., HexStr]] = Method(
        RPC.eth_sign,
        mungers=[sign_munger],
    )

    sign_transaction: Method[Callable[[TxParams], SignedTx]] = Method(
        RPC.eth_signTransaction,
        mungers=[default_root_munger],
    )

    sign_typed_data: Method[Callable[..., HexStr]] = Method(
        RPC.eth_signTypedData,
        mungers=[default_root_munger],
    )

    def call_munger(
        self,
        transaction: TxParams,
        block_identifier: Optional[BlockIdentifier] = None,
        state_override: Optional[CallOverrideParams] = None,
    ) -> Union[Tuple[TxParams, BlockIdentifier], Tuple[
            TxParams, BlockIdentifier, CallOverrideParams]]:  # noqa-E501
        # TODO: move to middleware
        if 'from' not in transaction and is_checksum_address(
                self.default_account):
            transaction = assoc(transaction, 'from', self.default_account)

        # TODO: move to middleware
        if block_identifier is None:
            block_identifier = self.default_block

        if state_override is None:
            return (transaction, block_identifier)
        else:
            return (transaction, block_identifier, state_override)

    call: Method[Callable[...,
                          Union[bytes,
                                bytearray]]] = Method(RPC.eth_call,
                                                      mungers=[call_munger])

    def estimate_gas(
            self,
            transaction: TxParams,
            block_identifier: Optional[BlockIdentifier] = None) -> Wei:
        return self._estimate_gas(transaction, block_identifier)

    def filter_munger(
        self,
        filter_params: Optional[Union[str, FilterParams]] = None,
        filter_id: Optional[HexStr] = None
    ) -> Union[List[FilterParams], List[HexStr], List[str]]:
        if filter_id and filter_params:
            raise TypeError(
                "Ambiguous invocation: provide either a `filter_params` or a `filter_id` argument. "
                "Both were supplied.")
        if isinstance(filter_params, dict):
            return [filter_params]
        elif is_string(filter_params):
            if filter_params in ['latest', 'pending']:
                return [filter_params]
            else:
                raise ValueError(
                    "The filter API only accepts the values of `pending` or "
                    "`latest` for string based filters")
        elif filter_id and not filter_params:
            return [filter_id]
        else:
            raise TypeError(
                "Must provide either filter_params as a string or "
                "a valid filter object, or a filter_id as a string "
                "or hex.")

    filter: Method[Callable[..., Any]] = Method(
        method_choice_depends_on_args=select_filter_method(
            if_new_block_filter=RPC.eth_newBlockFilter,
            if_new_pending_transaction_filter=RPC.
            eth_newPendingTransactionFilter,
            if_new_filter=RPC.eth_newFilter,
        ),
        mungers=[filter_munger],
    )

    get_filter_changes: Method[Callable[[HexStr], List[LogReceipt]]] = Method(
        RPC.eth_getFilterChanges, mungers=[default_root_munger])

    get_filter_logs: Method[Callable[[HexStr], List[LogReceipt]]] = Method(
        RPC.eth_getFilterLogs, mungers=[default_root_munger])

    get_logs: Method[Callable[[FilterParams], List[LogReceipt]]] = Method(
        RPC.eth_getLogs, mungers=[default_root_munger])

    submit_hashrate: Method[Callable[[int, _Hash32], bool]] = Method(
        RPC.eth_submitHashrate,
        mungers=[default_root_munger],
    )

    submit_work: Method[Callable[[int, _Hash32, _Hash32], bool]] = Method(
        RPC.eth_submitWork,
        mungers=[default_root_munger],
    )

    uninstall_filter: Method[Callable[[HexStr], bool]] = Method(
        RPC.eth_uninstallFilter,
        mungers=[default_root_munger],
    )

    @overload
    def contract(self, address: None = None, **kwargs: Any) -> Type[Contract]:
        ...  # noqa: E704,E501

    @overload  # noqa: F811
    def contract(self, address: Union[Address, ChecksumAddress, ENS],
                 **kwargs: Any) -> Contract:
        ...  # noqa: E704,E501

    def contract(  # noqa: F811
            self,
            address: Optional[Union[Address, ChecksumAddress, ENS]] = None,
            **kwargs: Any) -> Union[Type[Contract], Contract]:
        ContractFactoryClass = kwargs.pop('ContractFactoryClass',
                                          self.defaultContractFactory)

        ContractFactory = ContractFactoryClass.factory(self.web3, **kwargs)

        if address:
            return ContractFactory(address)
        else:
            return ContractFactory

    @deprecated_for("set_contract_factory")
    def setContractFactory(
        self, contractFactory: Type[Union[Contract, ConciseContract,
                                          ContractCaller]]
    ) -> None:
        return self.set_contract_factory(contractFactory)

    def set_contract_factory(
        self, contractFactory: Type[Union[Contract, ConciseContract,
                                          ContractCaller]]
    ) -> None:
        self.defaultContractFactory = contractFactory

    def getCompilers(self) -> NoReturn:
        raise DeprecationWarning(
            "This method has been deprecated as of EIP 1474.")

    get_work: Method[Callable[[], List[HexBytes]]] = Method(
        RPC.eth_getWork,
        mungers=None,
    )

    @deprecated_for("generate_gas_price")
    def generateGasPrice(
            self,
            transaction_params: Optional[TxParams] = None) -> Optional[Wei]:
        return self._generate_gas_price(transaction_params)

    def generate_gas_price(
            self,
            transaction_params: Optional[TxParams] = None) -> Optional[Wei]:
        return self._generate_gas_price(transaction_params)

    @deprecated_for("set_gas_price_strategy")
    def setGasPriceStrategy(self,
                            gas_price_strategy: GasPriceStrategy) -> None:
        return self.set_gas_price_strategy(gas_price_strategy)

    # Deprecated Methods
    getBalance = DeprecatedMethod(get_balance, 'getBalance', 'get_balance')
    getStorageAt = DeprecatedMethod(get_storage_at, 'getStorageAt',
                                    'get_storage_at')
    getBlock = DeprecatedMethod(get_block, 'getBlock',
                                'get_block')  # type: ignore
    getBlockTransactionCount = DeprecatedMethod(get_block_transaction_count,
                                                'getBlockTransactionCount',
                                                'get_block_transaction_count')
    getCode = DeprecatedMethod(get_code, 'getCode', 'get_code')
    getProof = DeprecatedMethod(get_proof, 'getProof', 'get_proof')
    getTransaction = DeprecatedMethod(
        get_transaction,  # type: ignore
        'getTransaction',
        'get_transaction')
    getTransactionByBlock = DeprecatedMethod(get_transaction_by_block,
                                             'getTransactionByBlock',
                                             'get_transaction_by_block')
    getTransactionCount = DeprecatedMethod(get_transaction_count,
                                           'getTransactionCount',
                                           'get_transaction_count')
    getUncleByBlock = DeprecatedMethod(get_uncle_by_block, 'getUncleByBlock',
                                       'get_uncle_by_block')
    getUncleCount = DeprecatedMethod(get_uncle_count, 'getUncleCount',
                                     'get_uncle_count')
    sendTransaction = DeprecatedMethod(
        send_transaction,  # type: ignore
        'sendTransaction',
        'send_transaction')
    signTransaction = DeprecatedMethod(sign_transaction, 'signTransaction',
                                       'sign_transaction')
    signTypedData = DeprecatedMethod(sign_typed_data, 'signTypedData',
                                     'sign_typed_data')
    submitHashrate = DeprecatedMethod(submit_hashrate, 'submitHashrate',
                                      'submit_hashrate')
    submitWork = DeprecatedMethod(submit_work, 'submitWork', 'submit_work')
    getLogs = DeprecatedMethod(get_logs, 'getLogs', 'get_logs')
    estimateGas = DeprecatedMethod(estimate_gas, 'estimateGas',
                                   'estimate_gas')  # type: ignore
    sendRawTransaction = DeprecatedMethod(send_raw_transaction,
                                          'sendRawTransaction',
                                          'send_raw_transaction')
    getTransactionReceipt = DeprecatedMethod(get_transaction_receipt,
                                             'getTransactionReceipt',
                                             'get_transaction_receipt')
    uninstallFilter = DeprecatedMethod(uninstall_filter, 'uninstallFilter',
                                       'uninstall_filter')
    getFilterLogs = DeprecatedMethod(get_filter_logs, 'getFilterLogs',
                                     'get_filter_logs')
    getFilterChanges = DeprecatedMethod(get_filter_changes, 'getFilterChanges',
                                        'get_filter_changes')
    getWork = DeprecatedMethod(get_work, 'getWork', 'get_work')