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


Python eth_abi.encode_abi方法代码示例

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


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

示例1: encode_input

# 需要导入模块: import eth_abi [as 别名]
# 或者: from eth_abi import encode_abi [as 别名]
def encode_input(self, *args: Tuple) -> str:
        """
        Generate encoded ABI data to call the method with the given arguments.

        Arguments
        ---------
        *args
            Contract method inputs

        Returns
        -------
        str
            Hexstring of encoded ABI data
        """
        data = format_input(self.abi, args)
        types_list = get_type_strings(self.abi["inputs"])
        return self.signature + eth_abi.encode_abi(types_list, data).hex() 
开发者ID:eth-brownie,项目名称:brownie,代码行数:19,代码来源:contract.py

示例2: web3_request_side_effect

# 需要导入模块: import eth_abi [as 别名]
# 或者: from eth_abi import encode_abi [as 别名]
def web3_request_side_effect(method, params):
    if method == 'eth_gasPrice':
        return 20000000000
    elif method == 'eth_estimateGas':
        return 125000
    elif method == 'eth_getTransactionCount':
        return 1
    elif method == 'net_version':
        return 42
    elif method == 'eth_blockNumber':
        return 8400000
    elif method == 'eth_call':
        encoded_abi = encode_abi(abi_swaps_types, non_zero_balance_abi_contract)
        return encoded_abi.hex()
    elif method == 'eth_getFilterLogs':
        return [
            {
                'data': '0xbc2424e1dcdd2e425c555bcea35a54fd27cf540e60f18366e153e3fb7cf4490c',
                'transactionHash': HexBytes('0x65320e57b9d18ec08388896b029ad1495beb7a57c547440253a1dde01b4485f1'),
            }
        ]
    return None 
开发者ID:Lamden,项目名称:clove,代码行数:24,代码来源:conftest.py

示例3: _make_call_throws_transaction

# 需要导入模块: import eth_abi [as 别名]
# 或者: from eth_abi import encode_abi [as 别名]
def _make_call_throws_transaction(eth_tester, contract_address, contract_name,
                                  fn_name, fn_args=None):
    from eth_abi import encode_abi

    if fn_args is None:
        fn_args = tuple()

    fn_abi = THROWS_ABI[contract_name][fn_name]
    arg_types = [
        arg_abi['type']
        for arg_abi
        in fn_abi['inputs']
    ]
    fn_selector = function_abi_to_4byte_selector(fn_abi)
    transaction = {
        "from": eth_tester.get_accounts()[0],
        "to": contract_address,
        "gas": 500000,
        "data": encode_hex(fn_selector + encode_abi(arg_types, fn_args)),
    }
    return transaction 
开发者ID:ethereum,项目名称:eth-tester,代码行数:23,代码来源:throws_contract.py

示例4: _call_emitter

# 需要导入模块: import eth_abi [as 别名]
# 或者: from eth_abi import encode_abi [as 别名]
def _call_emitter(eth_tester, contract_address, fn_name, fn_args):
    from eth_abi import encode_abi

    fn_abi = EMITTER_ABI[fn_name]
    arg_types = [
        arg_abi['type']
        for arg_abi
        in fn_abi['inputs']
    ]
    fn_selector = function_abi_to_4byte_selector(fn_abi)
    emit_a_hash = eth_tester.send_transaction({
        "from": eth_tester.get_accounts()[0],
        "to": contract_address,
        "gas": 500000,
        "data": encode_hex(fn_selector + encode_abi(arg_types, fn_args)),
    })
    return emit_a_hash 
开发者ID:ethereum,项目名称:eth-tester,代码行数:19,代码来源:emitter_contract.py

示例5: _make_call_math_transaction

# 需要导入模块: import eth_abi [as 别名]
# 或者: from eth_abi import encode_abi [as 别名]
def _make_call_math_transaction(eth_tester, contract_address, fn_name, fn_args=None):
    from eth_abi import encode_abi

    if fn_args is None:
        fn_args = tuple()

    fn_abi = MATH_ABI[fn_name]
    arg_types = [
        arg_abi['type']
        for arg_abi
        in fn_abi['inputs']
    ]
    fn_selector = function_abi_to_4byte_selector(fn_abi)
    transaction = {
        "from": eth_tester.get_accounts()[0],
        "to": contract_address,
        "gas": 500000,
        "data": encode_hex(fn_selector + encode_abi(arg_types, fn_args)),
    }
    return transaction 
开发者ID:ethereum,项目名称:eth-tester,代码行数:22,代码来源:math_contract.py

示例6: _verify_token_networks

# 需要导入模块: import eth_abi [as 别名]
# 或者: from eth_abi import encode_abi [as 别名]
def _verify_token_networks(chain_id: ChainID, apikey: str) -> None:
    deployment_file_path = contracts_deployed_path(chain_id=chain_id)
    with deployment_file_path.open() as f:
        deployed_contracts_info = json.load(f)
    token_networks = deployed_contracts_info.get("token_networks", [])

    with open(contracts_precompiled_path()) as f:
        contract_dict = json.load(f)["contracts"][CONTRACT_TOKEN_NETWORK]
    metadata = json.loads(contract_dict["metadata"])
    constructor = [func for func in contract_dict["abi"] if func["type"] == "constructor"][0]
    arg_types = [arg["type"] for arg in constructor["inputs"]]
    arg_names = [arg["name"] for arg in constructor["inputs"]]

    for tn in token_networks:
        args = [tn["constructor_arguments"][arg_name] for arg_name in arg_names]
        etherscan_verify_contract(
            chain_id=chain_id,
            apikey=apikey,
            address=tn["token_network_address"],
            contract_name=CONTRACT_TOKEN_NETWORK,
            metadata=metadata,
            constructor_args=encode_abi(arg_types, args).hex(),
        ) 
开发者ID:raiden-network,项目名称:raiden-contracts,代码行数:25,代码来源:etherscan_verify.py

示例7: get_packed_transfers

# 需要导入模块: import eth_abi [as 别名]
# 或者: from eth_abi import encode_abi [as 别名]
def get_packed_transfers(pending_transfers: Collection, types: List) -> bytes:
    packed_transfers: List[bytes] = [encode_abi(types, x[:-1]) for x in pending_transfers]
    return reduce((lambda x, y: x + y), packed_transfers) 
开发者ID:raiden-network,项目名称:raiden-contracts,代码行数:5,代码来源:pending_transfers.py

示例8: get_constructor_args

# 需要导入模块: import eth_abi [as 别名]
# 或者: from eth_abi import encode_abi [as 别名]
def get_constructor_args(
    deployment_info: DeployedContracts, contract_name: str, contract_manager: ContractManager
) -> str:
    constructor_arguments = deployment_info["contracts"][contract_name]["constructor_arguments"]
    if constructor_arguments != []:
        constructor_types = contract_manager.get_constructor_argument_types(contract_name)
        constructor_args = encode_abi(types=constructor_types, args=constructor_arguments).hex()
    else:
        constructor_types = []
        constructor_args = ""
    print("constructor_args", constructor_arguments, constructor_types, constructor_args)
    return constructor_args 
开发者ID:raiden-network,项目名称:raiden-contracts,代码行数:14,代码来源:etherscan_verify.py

示例9: _encode_data

# 需要导入模块: import eth_abi [as 别名]
# 或者: from eth_abi import encode_abi [as 别名]
def _encode_data(primaryType: str, data: any, types) -> str:
    encodedTypes = ['bytes32']
    encodedValues = [_type_hash(primaryType, types)]

    for field in types[primaryType]:
        value = data[field['name']]

        if field['type'] == 'string':
            hashValue = keccak(text=value)
            encodedTypes.append('bytes32')
            encodedValues.append(hashValue)

        elif field['type'] == 'bytes':
            hashValue = keccak(hexstr=value)
            encodedTypes.append('bytes32')
            encodedValues.append(hashValue)

        elif field['type'] in types:
            encodedTypes.append('bytes32')
            hashValue = keccak(_encode_data(field['type'], value, types).encode())
            encodedValues.append(hashValue)

        elif field['type'] == 'uint256':
            encodedTypes.append('uint256')
            encodedValues.append(int(value))

        else:
            encodedTypes.append(field['type'])
            normalizedValue = _normalize_value(field['type'], value)
            encodedValues.append(normalizedValue)

    return encode_abi(encodedTypes, encodedValues) 
开发者ID:CoinAlpha,项目名称:hummingbot,代码行数:34,代码来源:zero_ex_transaction_encoder_v3.py


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