Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

sol2java.sh 生成java代码编译报错 #622

Open
ywy2090 opened this issue May 27, 2022 · 1 comment
Open

sol2java.sh 生成java代码编译报错 #622

ywy2090 opened this issue May 27, 2022 · 1 comment

Comments

@ywy2090
Copy link
Collaborator

ywy2090 commented May 27, 2022

原始合约:

pragma solidity ^0.4.25;

contract OneToOne  {
    function updateInfo(uint256 assetId, string memory info) public{
    }
}

使用sol2java.sh工具:

bash sol2java.sh

最终生成的代码:

package com;

import java.math.BigInteger;
import java.util.Arrays;
import java.util.Collections;
import java.util.List;
import org.fisco.bcos.sdk.abi.FunctionReturnDecoder;
import org.fisco.bcos.sdk.abi.TypeReference;
import org.fisco.bcos.sdk.abi.datatypes.Function;
import org.fisco.bcos.sdk.abi.datatypes.Type;
import org.fisco.bcos.sdk.abi.datatypes.Utf8String;
import org.fisco.bcos.sdk.abi.datatypes.generated.Uint256;
import org.fisco.bcos.sdk.abi.datatypes.generated.tuples.generated.Tuple2;
import org.fisco.bcos.sdk.client.Client;
import org.fisco.bcos.sdk.contract.Contract;
import org.fisco.bcos.sdk.crypto.CryptoSuite;
import org.fisco.bcos.sdk.crypto.keypair.CryptoKeyPair;
import org.fisco.bcos.sdk.model.CryptoType;
import org.fisco.bcos.sdk.model.TransactionReceipt;
import org.fisco.bcos.sdk.model.callback.TransactionCallback;
import org.fisco.bcos.sdk.transaction.model.exception.ContractException;

@SuppressWarnings("unchecked")
public class OneToOne extends Contract {
    public static final String[] BINARY_ARRAY = {"608060405234801561001057600080fd5b5060e48061001f6000396000f300608060405260043610603f576000357c0100000000000000000000000000000000000000000000000000000000900463ffffffff16806350c00197146044575b600080fd5b348015604f57600080fd5b5060b260048036038101908080359060200190929190803590602001908201803590602001908080601f016020809104026020016040519081016040528093929190818152602001838380828437820191505050505050919291929050505060b4565b005b50505600a165627a7a72305820e8891134ccea817cb561032019a44ab13ec3f8e69e001ab6d8859c4771d455fa0029"};

    public static final String BINARY = org.fisco.bcos.sdk.utils.StringUtils.joinAll("", BINARY_ARRAY);

    public static final String[] SM_BINARY_ARRAY = {"608060405234801561001057600080fd5b5060e48061001f6000396000f300608060405260043610603f576000357c0100000000000000000000000000000000000000000000000000000000900463ffffffff1680635549e5a6146044575b600080fd5b348015604f57600080fd5b5060b260048036038101908080359060200190929190803590602001908201803590602001908080601f016020809104026020016040519081016040528093929190818152602001838380828437820191505050505050919291929050505060b4565b005b50505600a165627a7a72305820d16533d3155da9786804cc043dffad773fce02adf9ca96e6ff720f91e7d41efb0029"};

    public static final String SM_BINARY = org.fisco.bcos.sdk.utils.StringUtils.joinAll("", SM_BINARY_ARRAY);

    public static final String[] ABI_ARRAY = {"[{\"constant\":false,\"inputs\":[{\"name\":\"assetId\",\"type\":\"uint256\"},{\"name\":\"info\",\"type\":\"string\"}],\"name\":\"updateInfo\",\"outputs\":[],\"payable\":false,\"stateMutability\":\"nonpayable\",\"type\":\"function\"}]"};

    public static final String ABI = org.fisco.bcos.sdk.utils.StringUtils.joinAll("", ABI_ARRAY);

    public static final String FUNC_UPDATEINFO = "updateInfo";

    protected OneToOne(String contractAddress, Client client, CryptoKeyPair credential) {
        super(getBinary(client.getCryptoSuite()), contractAddress, client, credential);
    }

    public static String getBinary(CryptoSuite cryptoSuite) {
        return (cryptoSuite.getCryptoTypeConfig() == CryptoType.ECDSA_TYPE ? BINARY : SM_BINARY);
    }

    public TransactionReceipt updateInfo(BigInteger assetId, BigInteger info) {
        final Function function = new Function(
                FUNC_UPDATEINFO, 
                Arrays.<Type>asList(new org.fisco.bcos.sdk.abi.datatypes.generated.Uint256(assetId), 
                new org.fisco.bcos.sdk.abi.datatypes.Utf8String(info)), 
                Collections.<TypeReference<?>>emptyList());
        return executeTransaction(function);
    }

    public byte[] updateInfo(BigInteger assetId, BigInteger info, TransactionCallback callback) {
        final Function function = new Function(
                FUNC_UPDATEINFO, 
                Arrays.<Type>asList(new org.fisco.bcos.sdk.abi.datatypes.generated.Uint256(assetId), 
                new org.fisco.bcos.sdk.abi.datatypes.Utf8String(info)), 
                Collections.<TypeReference<?>>emptyList());
        return asyncExecuteTransaction(function, callback);
    }

    public String getSignedTransactionForUpdateInfo(BigInteger assetId, BigInteger info) {
        final Function function = new Function(
                FUNC_UPDATEINFO, 
                Arrays.<Type>asList(new org.fisco.bcos.sdk.abi.datatypes.generated.Uint256(assetId), 
                new org.fisco.bcos.sdk.abi.datatypes.Utf8String(info)), 
                Collections.<TypeReference<?>>emptyList());
        return createSignedTransaction(function);
    }

    public Tuple2<BigInteger, String> getUpdateInfoInput(TransactionReceipt transactionReceipt) {
        String data = transactionReceipt.getInput().substring(10);
        final Function function = new Function(FUNC_UPDATEINFO, 
                Arrays.<Type>asList(), 
                Arrays.<TypeReference<?>>asList(new TypeReference<Uint256>() {}, new TypeReference<Utf8String>() {}));
        List<Type> results = FunctionReturnDecoder.decode(data, function.getOutputParameters());
        return new Tuple2<BigInteger, String>(

                (BigInteger) results.get(0).getValue(), 
                (String) results.get(1).getValue()
                );
    }

    public static OneToOne load(String contractAddress, Client client, CryptoKeyPair credential) {
        return new OneToOne(contractAddress, client, credential);
    }

    public static OneToOne deploy(Client client, CryptoKeyPair credential) throws ContractException {
        return deploy(OneToOne.class, client, credential, getBinary(client.getCryptoSuite()), "");
    }
}

image

生成的updateInfo接口数据类型不一致,经测试2.8.0 console没有这个问题,是2.9.0 console新引入的问题。

@ywy2090
Copy link
Collaborator Author

ywy2090 commented Jun 16, 2022

最新进展,可以下载console 2.9.1版本,正式版本已经修复该问题。

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

1 participant