• 设为首页
  • 点击收藏
  • 手机版
    手机扫一扫访问
    迪恩网络手机版
  • 关注官方公众号
    微信扫一扫关注
    公众号

Java FunctionEncoder类代码示例

原作者: [db:作者] 来自: [db:来源] 收藏 邀请

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



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


示例16: deploy

import org.web3j.abi.FunctionEncoder; //导入依赖的package包/类
public static Future<Greeter> deploy(Web3j web3j, Credentials credentials, BigInteger gasPrice, BigInteger gasLimit, BigInteger initialValue, Utf8String _greeting) {
    String encodedConstructor = FunctionEncoder.encodeConstructor(Arrays.<Type>asList(_greeting));
    return deployAsync(Greeter.class, web3j, credentials, gasPrice, gasLimit, BINARY, encodedConstructor, initialValue);
}
 
开发者ID:matthiaszimmermann,项目名称:web3j_demo,代码行数:5,代码来源:Greeter.java


示例17: initGame

import org.web3j.abi.FunctionEncoder; //导入依赖的package包/类
@OnClick(R.id.init_game)
    void initGame() {
//        machine
//                .initGameForPlayer(new Uint256(Convert.toWei(0.001, Convert.Unit.ETHER)), new Uint256(20))
//                .map(receipt -> machine.getGameInitializedEvents(receipt))
//                .subscribe(gameInitializedEventResponses -> {
//                    if (gameInitializedEventResponses.isEmpty()) {
//                        Log.i(TAG, "response is empty");
//                        return;
//                    }
//                    SlotMachine.GameInitializedEventResponse response = gameInitializedEventResponses.get(0);
//
//                    Log.i(TAG, "player address : " + response.player.toString());
//                    Log.i(TAG, "bet : " + response.bet.getValue());
//                    Log.i(TAG, "lines : " + response.lines.getValue());
//                });

        Completable
                .create(e -> {
                    CredentialManager.setDefault(1, "asdf");

                    Function function = new Function(
                            "initGameForPlayer",
                            Arrays.asList(
                                    new Uint256(Convert.toWei(0.001, Convert.Unit.ETHER)),
                                    new Uint256(20),
                                    new Uint256(playerSeed.getIndex())),
                            Collections.emptyList());
                    Transaction tx = new Transaction(
                            playerNonce++, // nonce
                            new org.ethereum.geth.Address(machine.getContractAddress()), // receiver address
                            new BigInt(0),
                            Convert.toBigInt(GethConstants.DEFAULT_GAS_LIMIT), // gas limit
                            Convert.toBigInt(GethConstants.DEFAULT_GAS_PRICE), // gas price
                            Utils.hexToByte(FunctionEncoder.encode(function))
                    );
                    Transaction signed = CredentialManager.getDefault().sign(tx);
                    GethManager.getClient().sendTransaction(GethManager.getMainContext(), signed);

                    e.onComplete();
                })
                .subscribeOn(Schedulers.io())
                .subscribe(() -> {
                }, Throwable::printStackTrace);
    }
 
开发者ID:SlotNSlot,项目名称:SlotNSlot_Android,代码行数:46,代码来源:PlayExampleActivity.java


示例18: setBankerSeed

import org.web3j.abi.FunctionEncoder; //导入依赖的package包/类
@OnClick(R.id.set_banker_seed)
    void setBankerSeed() {
//        machine
//                .setBankerSeed(new Bytes32(Utils.generateRandom(bankerSeed, banker--)))
//                .map(receipt -> machine.getBankerSeedSetEvents(receipt))
//                .subscribe(bankerSeedSetEventResponses -> {
//                    if (bankerSeedSetEventResponses.isEmpty()) {
//                        Log.i(TAG, "response is empty");
//                        return;
//                    }
//
//                    SlotMachine.BankerSeedSetEventResponse response = bankerSeedSetEventResponses.get(0);
//
//                    Log.i(TAG, "banker seed : " + Utils.byteToHex(response.bankerSeed.getValue()));
//                });

        Completable
                .create(e -> {
                    CredentialManager.setDefault(0, "asdf");

                    Function function = new Function(
                            "setBankerSeed",
                            Arrays.asList(
                                    bankerSeed.getSeed(playerSeed.getIndex()),
                                    new Uint256(playerSeed.getIndex())),
                            Collections.emptyList());
                    Transaction tx = new Transaction(
                            bankerNonce++, // nonce
                            new org.ethereum.geth.Address(machine.getContractAddress()), // receiver address
                            new BigInt(0),
                            Convert.toBigInt(GethConstants.DEFAULT_GAS_LIMIT), // gas limit
                            Convert.toBigInt(GethConstants.DEFAULT_GAS_PRICE), // gas price
                            Utils.hexToByte(FunctionEncoder.encode(function))
                    );
                    Transaction signed = CredentialManager.getDefault().sign(tx);
                    GethManager.getClient().sendTransaction(GethManager.getMainContext(), signed);

                    e.onComplete();
                })
                .subscribeOn(Schedulers.io())
                .subscribe(() -> {
                }, Throwable::printStackTrace);
    }
 
开发者ID:SlotNSlot,项目名称:SlotNSlot_Android,代码行数:44,代码来源:PlayExampleActivity.java


示例19: setPlayerSeed

import org.web3j.abi.FunctionEncoder; //导入依赖的package包/类
@OnClick(R.id.set_player_seed)
    void setPlayerSeed() {
//        machine
//                .setPlayerSeed(new Bytes32(Utils.generateRandom(playerSeed, player--)))
//                .map(receipt -> machine.getGameConfirmedEvents(receipt))
//                .subscribe(gameConfirmedEventResponses -> {
//                    if (gameConfirmedEventResponses.isEmpty()) {
//                        Log.i(TAG, "response is empty");
//                        return;
//                    }
//
//                    SlotMachine.GameConfirmedEventResponse response = gameConfirmedEventResponses.get(0);
//
//                    Log.i(TAG, "reward : " + response.reward.getValue());
//                });

        Completable
                .create(e -> {
                    CredentialManager.setDefault(1, "asdf");

                    Function function = new Function(
                            "setPlayerSeed",
                            Arrays.asList(
                                    playerSeed.getSeed(),
                                    new Uint256(playerSeed.getIndex())),
                            Collections.emptyList());
                    Transaction tx = new Transaction(
                            playerNonce++, // nonce
                            new org.ethereum.geth.Address(machine.getContractAddress()), // receiver address
                            new BigInt(0),
                            Convert.toBigInt(GethConstants.DEFAULT_GAS_LIMIT), // gas limit
                            Convert.toBigInt(GethConstants.DEFAULT_GAS_PRICE), // gas price
                            Utils.hexToByte(FunctionEncoder.encode(function))
                    );
                    Transaction signed = CredentialManager.getDefault().sign(tx);
                    GethManager.getClient().sendTransaction(GethManager.getMainContext(), signed);

                    bankerSeed.confirm(playerSeed.getIndex());
                    playerSeed.confirm(playerSeed.getIndex());
                    e.onComplete();
                })
                .subscribeOn(Schedulers.io())
                .subscribe(() -> {
                }, Throwable::printStackTrace);
    }
 
开发者ID:SlotNSlot,项目名称:SlotNSlot_Android,代码行数:46,代码来源:PlayExampleActivity.java


示例20: executeTransaction

import org.web3j.abi.FunctionEncoder; //导入依赖的package包/类
protected Observable<Receipt> executeTransaction(Function function) {
    return send(contractAddress, FunctionEncoder.encode(function), BigInteger.ZERO, gasPrice, gasLimit);
}
 
开发者ID:SlotNSlot,项目名称:SlotNSlot_Android,代码行数:4,代码来源:Contract.java



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


鲜花

握手

雷人

路过

鸡蛋
该文章已有0人参与评论

请发表评论

全部评论

专题导读
上一篇:
Java Config类代码示例发布时间:2022-05-23
下一篇:
Java DocumentSection类代码示例发布时间:2022-05-23
热门推荐
阅读排行榜

扫描微信二维码

查看手机版网站

随时了解更新最新资讯

139-2527-9053

在线客服(服务时间 9:00~18:00)

在线QQ客服
地址:深圳市南山区西丽大学城创智工业园
电邮:jeky_zhao#qq.com
移动电话:139-2527-9053

Powered by 互联科技 X3.4© 2001-2213 极客世界.|Sitemap