コード例 #1
0
ファイル: net.py プロジェクト: liguopeng80/asyncio-web3.py
class Net(Module):
    _listening: Method[Callable[[], bool]] = Method(
        RPC.net_listening,
        mungers=[default_root_munger],
    )

    _peer_count: Method[Callable[[], int]] = Method(
        RPC.net_peerCount,
        mungers=[default_root_munger],
    )

    _version: Method[Callable[[], str]] = Method(
        RPC.net_version,
        mungers=[default_root_munger],
    )

    @property
    def chainId(self) -> NoReturn:
        raise DeprecationWarning(
            "This method has been deprecated in EIP 1474.")

    @property
    def listening(self) -> bool:
        return self._listening()

    @property
    def peer_count(self) -> int:
        return self._peer_count()

    @property
    def version(self) -> str:
        return self._version()

    #
    # Deprecated Methods
    #
    peerCount = DeprecatedMethod(peer_count, 'peerCount',
                                 'peer_count')  # type: ignore
コード例 #2
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')
コード例 #3
0
ファイル: admin.py プロジェクト: liguopeng80/asyncio-web3.py
start_rpc: Method[ServerConnection] = Method(
    RPC.admin_startRPC,
    mungers=[admin_start_params_munger],
)

start_ws: Method[ServerConnection] = Method(
    RPC.admin_startWS,
    mungers=[admin_start_params_munger],
)

stop_rpc: Method[Callable[[], bool]] = Method(
    RPC.admin_stopRPC,
    mungers=None,
)

stop_ws: Method[Callable[[], bool]] = Method(
    RPC.admin_stopWS,
    mungers=None,
)

#
# Deprecated Methods
#
addPeer = DeprecatedMethod(add_peer, 'addPeer', 'add_peer')
nodeInfo = DeprecatedMethod(node_info, 'nodeInfo', 'node_info')
startRPC = DeprecatedMethod(start_rpc, 'startRPC', 'start_rpc')
stopRPC = DeprecatedMethod(stop_rpc, 'stopRPC', 'stop_rpc')
startWS = DeprecatedMethod(start_ws, 'startWS', 'start_ws')
stopWS = DeprecatedMethod(stop_ws, 'stopWS', 'stop_ws')
コード例 #4
0
class Parity(Module):
    """
    https://paritytech.github.io/wiki/JSONRPC-parity-module
    """
    _default_block: BlockIdentifier = "latest"
    personal: ParityPersonal

    enode: Method[Callable[[], str]] = Method(
        RPC.parity_enode,
        mungers=None,
    )
    """ 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 list_storage_keys_munger(
        self,
        address: Union[Address, ChecksumAddress, ENS, Hash32],
        quantity: int,
        hash_: Hash32,
        block_identifier: Optional[BlockIdentifier] = None,
    ) -> Tuple[Union[Address, ChecksumAddress, ENS, Hash32], int, Hash32,
               BlockIdentifier]:
        if block_identifier is None:
            block_identifier = self.default_block
        return (address, quantity, hash_, block_identifier)

    list_storage_keys: Method[Callable[..., List[Hash32]]] = Method(
        RPC.parity_listStorageKeys,
        mungers=[list_storage_keys_munger],
    )

    net_peers: Method[Callable[[],
                               ParityNetPeers]] = Method(RPC.parity_netPeers,
                                                         mungers=None)

    add_reserved_peer: Method[Callable[[EnodeURI], bool]] = Method(
        RPC.parity_addReservedPeer,
        mungers=[default_root_munger],
    )

    def trace_replay_transaction_munger(
        self,
        block_identifier: Union[_Hash32, BlockIdentifier],
        mode: ParityTraceMode = ['trace']
    ) -> Tuple[Union[BlockIdentifier, _Hash32], ParityTraceMode]:
        return (block_identifier, mode)

    trace_replay_transaction: Method[Callable[..., ParityBlockTrace]] = Method(
        RPC.trace_replayTransaction,
        mungers=[trace_replay_transaction_munger],
    )

    trace_replay_block_transactions: Method[Callable[
        ..., List[ParityBlockTrace]]] = Method(
            RPC.trace_replayBlockTransactions,
            mungers=[trace_replay_transaction_munger])

    trace_block: Method[Callable[[BlockIdentifier],
                                 List[ParityBlockTrace]]] = Method(
                                     RPC.trace_block,
                                     mungers=[default_root_munger],
                                 )

    trace_filter: Method[Callable[[ParityFilterParams],
                                  List[ParityFilterTrace]]] = Method(
                                      RPC.trace_filter,
                                      mungers=[default_root_munger],
                                  )

    trace_transaction: Method[Callable[[_Hash32],
                                       List[ParityFilterTrace]]] = Method(
                                           RPC.trace_transaction,
                                           mungers=[default_root_munger],
                                       )

    def trace_call_munger(
        self,
        transaction: TxParams,
        mode: ParityTraceMode = ['trace'],
        block_identifier: Optional[BlockIdentifier] = None
    ) -> Tuple[TxParams, ParityTraceMode, BlockIdentifier]:
        # TODO: move to middleware
        if 'from' not in transaction and is_checksum_address(
                self.web3.eth.default_account):
            transaction = assoc(transaction, 'from',
                                self.web3.eth.default_account)

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

        return (transaction, mode, block_identifier)

    trace_call: Method[Callable[..., ParityBlockTrace]] = Method(
        RPC.trace_call,
        mungers=[trace_call_munger],
    )

    def trace_transactions_munger(self,
                                  raw_transaction: HexStr,
                                  mode: ParityTraceMode = ['trace']
                                  ) -> Tuple[HexStr, ParityTraceMode]:
        return (raw_transaction, mode)

    trace_raw_transaction: Method[Callable[..., ParityBlockTrace]] = Method(
        RPC.trace_rawTransaction,
        mungers=[trace_transactions_munger],
    )

    set_mode: Method[Callable[[ParityMode], bool]] = Method(
        RPC.parity_setMode,
        mungers=[default_root_munger],
    )

    mode: Method[Callable[[], ParityMode]] = Method(RPC.parity_mode,
                                                    mungers=None)

    # Deprecated Methods
    addReservedPeer = DeprecatedMethod(add_reserved_peer, 'addReservedPeer',
                                       'add_reserved_peer')
    listStorageKeys = DeprecatedMethod(list_storage_keys, 'listStorageKeys',
                                       'list_storage_keys')
    netPeers = DeprecatedMethod(net_peers, 'netPeers', 'net_peers')
    setMode = DeprecatedMethod(set_mode, 'setMode', 'set_mode')
    traceBlock = DeprecatedMethod(trace_block, 'traceBlock', 'trace_block')
    traceCall = DeprecatedMethod(trace_call, 'traceCall', 'trace_call')
    traceFilter = DeprecatedMethod(trace_filter, 'traceFilter', 'trace_filter')
    traceRawTransaction = DeprecatedMethod(trace_raw_transaction,
                                           'traceRawTransaction',
                                           'trace_raw_transaction')
    traceReplayTransaction = DeprecatedMethod(trace_replay_transaction,
                                              'traceReplayTransaction',
                                              'trace_replay_transaction')
    traceReplayBlockTransactions = DeprecatedMethod(
        trace_replay_block_transactions, 'traceReplayBlockTransactions',
        'trace_replay_block_transactions')
    traceTransaction = DeprecatedMethod(trace_transaction, 'traceTransaction',
                                        'trace_transaction')
コード例 #5
0

subscribe: Method[Callable[[ShhMessageFilter], ShhSubscriptionID]] = Method(
    RPC.shh_subscribe,
    mungers=[default_root_munger],
)


unsubscribe: Method[Callable[[ShhSubscriptionID], bool]] = Method(
    RPC.shh_unsubscribe,
    mungers=[default_root_munger],
)

# DeprecatedMethods
setMaxMessageSize = DeprecatedMethod(
    set_max_message_size,
    'setMaxMessageSize',
    'set_max_message_size')
setMinPoW = DeprecatedMethod(set_min_pow, 'setMinPoW', 'set_min_pow')
markTrustedPeer = DeprecatedMethod(mark_trusted_peer, 'markTrustedPeer', 'mark_trusted_peer')
newKeyPair = DeprecatedMethod(new_key_pair, 'newKeyPair', 'new_key_pair')
addPrivateKey = DeprecatedMethod(add_private_key, 'addPrivateKey', 'add_private_key')
deleteKeyPair = DeprecatedMethod(delete_key_pair, 'deleteKeyPair', 'delete_key_pair')
deleteKey = DeprecatedMethod(delete_key, 'deleteKey', 'delete_key')
hasKeyPair = DeprecatedMethod(has_key_pair, 'hasKeyPair', 'has_key_pair')
getPublicKey = DeprecatedMethod(get_public_key, 'getPublicKey', 'get_public_key')
getPrivateKey = DeprecatedMethod(get_private_key, 'getPrivateKey', 'get_private_key')
newSymKey = DeprecatedMethod(new_sym_key, 'newSymKey', 'new_sym_key')
addSymKey = DeprecatedMethod(add_sym_key, 'addSymKey', 'add_sym_key')
generateSymKeyFromPassword = DeprecatedMethod(
    generate_sym_key_from_password,
    'generateSymKeyFromPassword',
コード例 #6
0
ファイル: net.py プロジェクト: nseidm1/1inchpython
from typing import (
    Callable, )

from web3._utils.rpc_abi import (
    RPC, )
from web3.method import (
    DeprecatedMethod,
    Method,
    default_root_munger,
)

listening: Method[Callable[[], bool]] = Method(
    RPC.net_listening,
    mungers=[default_root_munger],
)

peer_count: Method[Callable[[], int]] = Method(
    RPC.net_peerCount,
    mungers=[default_root_munger],
)

version: Method[Callable[[], str]] = Method(
    RPC.net_version,
    mungers=[default_root_munger],
)

#
# Deprecated Methods
#
peerCount = DeprecatedMethod(peer_count, 'peerCount', 'peer_count')
コード例 #7
0

sign: Method[Callable[[str, ChecksumAddress, Optional[str]], HexStr]] = Method(
    RPC.personal_sign,
    mungers=[default_root_munger],
)


sign_typed_data: Method[Callable[[Dict[str, Any], ChecksumAddress, str], HexStr]] = Method(
    RPC.personal_signTypedData,
    mungers=[default_root_munger],
)


ec_recover: Method[Callable[[str, HexStr], ChecksumAddress]] = Method(
    RPC.personal_ecRecover,
    mungers=[default_root_munger],
)

#
# Deprecated Methods
#
importRawKey = DeprecatedMethod(import_raw_key, 'importRawKey', 'import_raw_key')
newAccount = DeprecatedMethod(new_account, 'newAccount', 'new_account')
listAccounts = DeprecatedMethod(list_accounts, 'listAccounts', 'list_accounts')
sendTransaction = DeprecatedMethod(send_transaction, 'sendTransaction', 'send_transaction')
lockAccount = DeprecatedMethod(lock_account, 'lockAccount', 'lock_account')
unlockAccount = DeprecatedMethod(unlock_account, 'unlockAccount', 'unlock_account')
signTypedData = DeprecatedMethod(sign_typed_data, 'signTypedData', 'sign_typed_data')
ecRecover = DeprecatedMethod(ec_recover, 'ecRecover', 'ec_recover')
コード例 #8
0
start: Method[Callable[[int], bool]] = Method(
    RPC.miner_start,
    mungers=[default_root_munger],
)

stop: Method[Callable[[], bool]] = Method(
    RPC.miner_stop,
    mungers=None,
)

start_auto_dag: Method[Callable[[], bool]] = Method(
    RPC.miner_startAutoDag,
    mungers=None,
)

stop_auto_dag: Method[Callable[[], bool]] = Method(
    RPC.miner_stopAutoDag,
    mungers=None,
)

#
# Deprecated Methods
#
makeDag = DeprecatedMethod(make_dag, 'makeDag', 'make_dag')
setExtra = DeprecatedMethod(set_extra, 'setExtra', 'set_extra')
setEtherbase = DeprecatedMethod(set_etherbase, 'setEtherbase', 'set_etherbase')
setGasPrice = DeprecatedMethod(set_gas_price, 'setGasPrice', 'set_gas_price')
startAutoDag = DeprecatedMethod(start_auto_dag, 'startAutoDag',
                                'start_auto_dag')
stopAutoDag = DeprecatedMethod(stop_auto_dag, 'stopAutoDag', 'stop_auto_dag')