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


Java FunctionEncoder.encode方法代码示例

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


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

示例1: callHash

import org.web3j.abi.FunctionEncoder; //导入方法依赖的package包/类
private byte[] callHash(String name, Type...parameters) throws InterruptedException, ExecutionException {

        Function function = new Function(name,
            Arrays.asList(parameters),
            Arrays.asList(new TypeReference<Bytes32>() {})
        );
        String encodedFunction = FunctionEncoder.encode(function);

        TransactionManager transactionManager = cfg.getTransactionManager(cfg.getMainAddress());
        String channelLibraryAddress = contractsProperties.getAddress().get("ChannelLibrary").toString();
        org.web3j.protocol.core.methods.response.EthCall ethCall = web3j.ethCall(
            Transaction.createEthCallTransaction(
                transactionManager.getFromAddress(), channelLibraryAddress, encodedFunction),
            DefaultBlockParameterName.LATEST)
            .sendAsync().get();

        String value = ethCall.getValue();
        List<Type> list = FunctionReturnDecoder.decode(value, function.getOutputParameters());
        return ((Bytes32) list.get(0)).getValue();
    }
 
开发者ID:papyrusglobal,项目名称:state-channels,代码行数:21,代码来源:HashTest.java

示例2: execute

import org.web3j.abi.FunctionEncoder; //导入方法依赖的package包/类
private String execute(
        Credentials credentials, Function function, String contractAddress) throws Exception {
    BigInteger nonce = getNonce(credentials.getAddress());

    String encodedFunction = FunctionEncoder.encode(function);

    RawTransaction rawTransaction = RawTransaction.createTransaction(
            nonce,
            GAS_PRICE,
            GAS_LIMIT,
            contractAddress,
            encodedFunction);

    byte[] signedMessage = TransactionEncoder.signMessage(rawTransaction, credentials);
    String hexValue = Numeric.toHexString(signedMessage);

    EthSendTransaction transactionResponse = web3j.ethSendRawTransaction(hexValue)
            .sendAsync().get();

    return transactionResponse.getTransactionHash();
}
 
开发者ID:web3j,项目名称:web3j,代码行数:22,代码来源:HumanStandardTokenIT.java

示例3: createTokenTransferData

import org.web3j.abi.FunctionEncoder; //导入方法依赖的package包/类
public static byte[] createTokenTransferData(String to, BigInteger tokenAmount) {
    List<Type> params = Arrays.asList(new Address(to), new Uint256(tokenAmount));

    List<TypeReference<?>> returnTypes = Arrays.<TypeReference<?>>asList(new TypeReference<Bool>() {
    });

    Function function = new Function("transfer", params, returnTypes);
    String encodedFunction = FunctionEncoder.encode(function);
    return Numeric.hexStringToByteArray(Numeric.cleanHexPrefix(encodedFunction));
}
 
开发者ID:TrustWallet,项目名称:trust-wallet-android,代码行数:11,代码来源:TokenRepository.java

示例4: callSmartContractFunction

import org.web3j.abi.FunctionEncoder; //导入方法依赖的package包/类
private String callSmartContractFunction(
        Function function, String contractAddress) throws Exception {
    String encodedFunction = FunctionEncoder.encode(function);

    org.web3j.protocol.core.methods.response.EthCall response = web3j.ethCall(
            Transaction.createEthCallTransaction(
                    ALICE.getAddress(), contractAddress, encodedFunction),
            DefaultBlockParameterName.LATEST)
            .sendAsync().get();

    return response.getValue();
}
 
开发者ID:web3j,项目名称:web3j,代码行数:13,代码来源:HumanStandardTokenIT.java

示例5: callSmartContractFunction

import org.web3j.abi.FunctionEncoder; //导入方法依赖的package包/类
private String callSmartContractFunction(
        org.web3j.abi.datatypes.Function function, String contractAddress, Wallet wallet) throws Exception {
    String encodedFunction = FunctionEncoder.encode(function);

    org.web3j.protocol.core.methods.response.EthCall response = web3j.ethCall(
            Transaction.createEthCallTransaction(wallet.address, contractAddress, encodedFunction),
            DefaultBlockParameterName.LATEST)
            .sendAsync().get();

    return response.getValue();
}
 
开发者ID:TrustWallet,项目名称:trust-wallet-android,代码行数:12,代码来源:TokenRepository.java

示例6: callSmartContractFunction

import org.web3j.abi.FunctionEncoder; //导入方法依赖的package包/类
private String callSmartContractFunction(
        Function function, String contractAddress) throws Exception {

    String encodedFunction = FunctionEncoder.encode(function);

    org.web3j.protocol.core.methods.response.EthCall response = web3j.ethCall(
            Transaction.createEthCallTransaction(
                    ALICE.getAddress(), contractAddress, encodedFunction),
            DefaultBlockParameterName.LATEST)
            .sendAsync().get();

    return response.getValue();
}
 
开发者ID:web3j,项目名称:web3j,代码行数:14,代码来源:DeployContractIT.java

示例7: executeCall

import org.web3j.abi.FunctionEncoder; //导入方法依赖的package包/类
/**
 * Execute constant function call - i.e. a call that does not change state of the contract
 *
 * @param function to call
 * @return {@link List} of values returned by function call
 */
private List<Type> executeCall(
        Function function) throws IOException {
    String encodedFunction = FunctionEncoder.encode(function);
    org.web3j.protocol.core.methods.response.EthCall ethCall = web3j.ethCall(
            Transaction.createEthCallTransaction(
                    transactionManager.getFromAddress(), contractAddress, encodedFunction),
            DefaultBlockParameterName.LATEST)
            .send();

    String value = ethCall.getValue();
    return FunctionReturnDecoder.decode(value, function.getOutputParameters());
}
 
开发者ID:web3j,项目名称:web3j,代码行数:19,代码来源:Contract.java

示例8: FunctionCall

import org.web3j.abi.FunctionEncoder; //导入方法依赖的package包/类
public FunctionCall(String contractAddress, Function function) {
    this.contractAddress = contractAddress;
    this.function = function;
    this.data = FunctionEncoder.encode(function);
}
 
开发者ID:papyrusglobal,项目名称:state-channels,代码行数:6,代码来源:FunctionCall.java

示例9: testEventFilter

import org.web3j.abi.FunctionEncoder; //导入方法依赖的package包/类
@Test
public void testEventFilter() throws Exception {
    unlockAccount();

    Function function = createFibonacciFunction();
    String encodedFunction = FunctionEncoder.encode(function);

    BigInteger gas = estimateGas(encodedFunction);
    String transactionHash = sendTransaction(ALICE, CONTRACT_ADDRESS, gas, encodedFunction);

    TransactionReceipt transactionReceipt =
            waitForTransactionReceipt(transactionHash);

    assertFalse("Transaction execution ran out of gas",
            gas.equals(transactionReceipt.getGasUsed()));

    List<Log> logs = transactionReceipt.getLogs();
    assertFalse(logs.isEmpty());

    Log log = logs.get(0);

    List<String> topics = log.getTopics();
    assertThat(topics.size(), is(1));

    Event event = new Event("Notify",
            Collections.emptyList(),
            Arrays.asList(new TypeReference<Uint256>() {}, new TypeReference<Uint256>() {}));

    // check function signature - we only have a single topic our event signature,
    // there are no indexed parameters in this example
    String encodedEventSignature = EventEncoder.encode(event);
    assertThat(topics.get(0),
            is(encodedEventSignature));

    // verify our two event parameters
    List<Type> results = FunctionReturnDecoder.decode(
            log.getData(), event.getNonIndexedParameters());
    assertThat(results, equalTo(Arrays.asList(
            new Uint256(BigInteger.valueOf(7)), new Uint256(BigInteger.valueOf(13)))));

    // finally check it shows up in the event filter
    List<EthLog.LogResult> filterLogs = createFilterForEvent(
            encodedEventSignature, CONTRACT_ADDRESS);
    assertFalse(filterLogs.isEmpty());
}
 
开发者ID:web3j,项目名称:web3j,代码行数:46,代码来源:EventFilterIT.java


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