当前位置: 首页>>代码示例>>Python>>正文


Python Contract._find_matching_fn_abi方法代码示例

本文整理汇总了Python中web3.contract.Contract._find_matching_fn_abi方法的典型用法代码示例。如果您正苦于以下问题:Python Contract._find_matching_fn_abi方法的具体用法?Python Contract._find_matching_fn_abi怎么用?Python Contract._find_matching_fn_abi使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在web3.contract.Contract的用法示例。


在下文中一共展示了Contract._find_matching_fn_abi方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。

示例1: execute

# 需要导入模块: from web3.contract import Contract [as 别名]
# 或者: from web3.contract.Contract import _find_matching_fn_abi [as 别名]
    def execute(
        self, to_contract: Contract, func: str, args=None, amount_in_eth: Optional[Decimal] = None, max_gas=100000
    ):
        """Calls a smart contract from the hosted wallet.

        Creates a transaction that is proxyed through hosted wallet execute method. We need to have ABI as Populus Contract instance.

        :param wallet_address: Wallet address
        :param contract: Contract to called as address bound Populus Contract class
        :param func: Method name to be called
        :param args: Arguments passed to the method
        :param value: Additional value carried in the call in ETH
        :param gas: The max amount of gas the coinbase account is allowed to pay for this transaction.
        :return: txid of the execution as hex string
        """

        assert isinstance(to_contract, Contract)

        if amount_in_eth:
            assert isinstance(amount_in_eth, Decimal)  # Don't let floats slip through
            value = to_wei(amount_in_eth)
        else:
            value = 0

        # Encode function arguments
        function_abi = to_contract._find_matching_fn_abi(func, args)
        # 4 byte function hash
        function_selector = function_abi_to_4byte_selector(function_abi)

        # data payload passed to the function
        arg_data = to_contract.encodeABI(func, args=args)

        call_data = function_selector + arg_data[2:]

        # test_event_execute() call data should look like
        # function selector + random int as 256-bit
        # 0x5093dc7d000000000000000000000000000000000000000000000000000000002a3f58fe

        # web3 takes bytes argument as actual bytes, not hex
        call_data = binascii.unhexlify(call_data[2:])

        tx_info = {
            # The Ethereum account that pays the gas for this operation
            "from": self.contract.web3.eth.coinbase,
            "gas": max_gas,
        }

        txid = self.contract.transact(tx_info).execute(to_contract.address, value, max_gas, call_data)
        return txid
开发者ID:websauna,项目名称:websauna.wallet,代码行数:51,代码来源:wallet.py


注:本文中的web3.contract.Contract._find_matching_fn_abi方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。