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


Java FunctionEncoder类代码示例

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


FunctionEncoder类属于org.web3j.abi包,在下文中一共展示了FunctionEncoder类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的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: sendCreateContractTransaction

import org.web3j.abi.FunctionEncoder; //导入依赖的package包/类
private String sendCreateContractTransaction() throws Exception {
    BigInteger nonce = getNonce(ALICE.getAddress());

    String encodedConstructor =
            FunctionEncoder.encodeConstructor(Collections.singletonList(new Utf8String(VALUE)));

    Transaction transaction = Transaction.createContractTransaction(
            ALICE.getAddress(),
            nonce,
            GAS_PRICE,
            GAS_LIMIT,
            BigInteger.ZERO,
            getGreeterSolidityBinary() + encodedConstructor);

    org.web3j.protocol.core.methods.response.EthSendTransaction
            transactionResponse = web3j.ethSendTransaction(transaction)
            .sendAsync().get();

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

示例6: buildDeployWithParams

import org.web3j.abi.FunctionEncoder; //导入依赖的package包/类
private static MethodSpec buildDeployWithParams(
        MethodSpec.Builder methodBuilder, String className, String inputParams,
        String authName, boolean isPayable) {

    methodBuilder.addStatement("$T encodedConstructor = $T.encodeConstructor("
                    + "$T.<$T>asList($L)"
                    + ")",
            String.class, FunctionEncoder.class, Arrays.class, Type.class, inputParams);
    if (isPayable) {
        methodBuilder.addStatement(
                "return deployRemoteCall("
                        + "$L.class, $L, $L, $L, $L, $L, encodedConstructor, $L)",
                className, WEB3J, authName, GAS_PRICE, GAS_LIMIT, BINARY, INITIAL_VALUE);
    } else {
        methodBuilder.addStatement(
                "return deployRemoteCall($L.class, $L, $L, $L, $L, $L, encodedConstructor)",
                className, WEB3J, authName, GAS_PRICE, GAS_LIMIT, BINARY);
    }

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

示例7: deployContract

import org.web3j.abi.FunctionEncoder; //导入依赖的package包/类
public Address deployContract(TransactionManager transactionManager, String binary, Map<String, Address> libraries, Type... constructorArgs) throws IOException, InterruptedException, TransactionException {
    ContractLinker linker = new ContractLinker(binary);
    if (libraries != null && !libraries.isEmpty()) {
        libraries.forEach(linker::link);
    }
    linker.assertLinked();
    String encodedConstructor = FunctionEncoder.encodeConstructor(Arrays.<Type>asList(constructorArgs));
    String data = linker.getBinary() + encodedConstructor;

    EthSendTransaction transactionResponse = transactionManager.sendTransaction(
        properties.getGasPrice(), properties.getGasLimit(), null, data, BigInteger.ZERO);

    if (transactionResponse.hasError()) {
        throw new RuntimeException("Error processing transaction request: "
            + transactionResponse.getError().getMessage());
    }

    String transactionHash = transactionResponse.getTransactionHash();

    Optional<TransactionReceipt> receiptOptional =
        sendTransactionReceiptRequest(transactionHash, web3j);

    long millis = properties.getSleep().toMillis();
    int attempts = properties.getAttempts();
    for (int i = 0; i < attempts; i++) {
        if (!receiptOptional.isPresent()) {
            Thread.sleep(millis);
            receiptOptional = sendTransactionReceiptRequest(transactionHash, web3j);
        } else {
            String contractAddress = receiptOptional.get().getContractAddress();
            return new Address(contractAddress);
        }
    }
    throw new TransactionException("Transaction receipt was not generated after " + (millis * attempts / 1000)
        + " seconds for transaction: " + transactionHash);
}
 
开发者ID:papyrusglobal,项目名称:state-channels,代码行数:37,代码来源:DeployService.java

示例8: 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

示例9: deploy

import org.web3j.abi.FunctionEncoder; //导入依赖的package包/类
public static RemoteCall<HumanStandardToken> deploy(Web3j web3j, Credentials credentials, BigInteger gasPrice, BigInteger gasLimit, BigInteger _initialAmount, String _tokenName, BigInteger _decimalUnits, String _tokenSymbol) {
    String encodedConstructor = FunctionEncoder.encodeConstructor(Arrays.<Type>asList(new org.web3j.abi.datatypes.generated.Uint256(_initialAmount),
            new org.web3j.abi.datatypes.Utf8String(_tokenName),
            new org.web3j.abi.datatypes.generated.Uint8(_decimalUnits),
            new org.web3j.abi.datatypes.Utf8String(_tokenSymbol)));
    return deployRemoteCall(HumanStandardToken.class, web3j, credentials, gasPrice, gasLimit, BINARY, encodedConstructor);
}
 
开发者ID:web3j,项目名称:quorum,代码行数:8,代码来源:HumanStandardToken.java

示例10: sendCreateContractTransaction

import org.web3j.abi.FunctionEncoder; //导入依赖的package包/类
private String sendCreateContractTransaction(
        Credentials credentials, BigInteger initialSupply) throws Exception {
    BigInteger nonce = getNonce(credentials.getAddress());

    String encodedConstructor =
            FunctionEncoder.encodeConstructor(
                    Arrays.asList(
                            new Uint256(initialSupply),
                            new Utf8String("web3j tokens"),
                            new Uint8(BigInteger.TEN),
                            new Utf8String("w3j$")));

    RawTransaction rawTransaction = RawTransaction.createContractTransaction(
            nonce,
            GAS_PRICE,
            GAS_LIMIT,
            BigInteger.ZERO,
            getHumanStandardTokenBinary() + encodedConstructor);

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

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

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

示例11: 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

示例12: deploy

import org.web3j.abi.FunctionEncoder; //导入依赖的package包/类
public static RemoteCall<HumanStandardToken> deploy(Web3j web3j, Credentials credentials, BigInteger gasPrice, BigInteger gasLimit, BigInteger _initialAmount, String _tokenName, BigInteger _decimalUnits, String _tokenSymbol) {
    String encodedConstructor = FunctionEncoder.encodeConstructor(Arrays.<Type>asList(new org.web3j.abi.datatypes.generated.Uint256(_initialAmount), 
            new org.web3j.abi.datatypes.Utf8String(_tokenName), 
            new org.web3j.abi.datatypes.generated.Uint8(_decimalUnits), 
            new org.web3j.abi.datatypes.Utf8String(_tokenSymbol)));
    return deployRemoteCall(HumanStandardToken.class, web3j, credentials, gasPrice, gasLimit, BINARY, encodedConstructor);
}
 
开发者ID:web3j,项目名称:web3j,代码行数:8,代码来源:HumanStandardToken.java

示例13: 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

示例14: deployContract

import org.web3j.abi.FunctionEncoder; //导入依赖的package包/类
private Contract deployContract(TransactionReceipt transactionReceipt)
        throws Exception {

    prepareTransaction(transactionReceipt);

    String encodedConstructor = FunctionEncoder.encodeConstructor(
            Arrays.<Type>asList(new Uint256(BigInteger.TEN)));

    return TestContract.deployRemoteCall(
            TestContract.class, web3j, SampleKeys.CREDENTIALS,
            ManagedTransaction.GAS_PRICE, Contract.GAS_LIMIT,
            "0xcafed00d", encodedConstructor, BigInteger.ZERO).send();
}
 
开发者ID:web3j,项目名称:web3j,代码行数:14,代码来源:ContractTest.java

示例15: 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


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