hyperledger-web3j / web3j-maven-plugin

web3j Maven plugin
Apache License 2.0
117 stars 83 forks source link

Generated code do not compile #13

Closed flefevre closed 6 years ago

flefevre commented 6 years ago

Dear web3j-maven-plugin,

thanks for the work done and i wish an happy new year.

I have extracted here a small smartcontract that do not compile anymore with your java generator

[ERROR] Failed to execute goal org.apache.maven.plugins:maven-compiler-plugin:3.1:compile (default-compile) on project blockchainergy-smartcontracts: Compilation failure
[ERROR] /volatile/home/fl218080/gitBlockChain/blockchainergy-poc/blockchainergy-smartcontracts/target/main/java/com/cea/licia/blockchainenergy/Predictor.java:[43,78] <identifier> expected
[ERROR] -> [Help 1]
[ERROR] 
pragma solidity ^0.4.18;

/**
 * 
 * version 0.3 
 */
contract Predictor {

    /* this runs when the contract is executed */
    function Predictor() public {
        // initialize the variables
    }

    // returns an int array by adding to all its elements a scalar value "a"
    function subtractScalar(int[] self, int a) public pure returns (int[] s) {
        s = new int[](self.length);
        for (uint i = 0; i < self.length; i++)
            s[i] = self[i] - a;
    }

} // contract Predictor

the generated code snipped is:

    public RemoteCall<List<BigInteger>> subtractScalar(List<BigInteger> self, BigInteger a) {
        Function function = new Function("subtractScalar", 
                Arrays.<Type>asList(new org.web3j.abi.datatypes.DynamicArray<org.web3j.abi.datatypes.generated.Int256>(
                        org.web3j.abi.Utils.typeMap(self, org.web3j.abi.datatypes.generated.Int256.class)), 
                new org.web3j.abi.datatypes.generated.Int256(a)), 
                Arrays.<TypeReference<?>>asList(new TypeReference<DynamicArray<Int256>>() {}));
        return executeRemoteCallSingleValueReturn(function, List<BigInteger>.class);
    }

Do you have any idea why it is not working anymore?

I would appreciate your help. Thanks Francois from France

h2mch commented 6 years ago

which version of solidity have you installed? On my Windows Machine with

C:\>solc --version
solc, the solidity compiler commandline interface
Version: 0.4.18+commit.9cf6e910.Windows.msvc  

and the maven plugin

<!-- https://mvnrepository.com/artifact/org.web3j/web3j-maven-plugin -->
<dependency>
    <groupId>org.web3j</groupId>
    <artifactId>web3j-maven-plugin</artifactId>
    <version>0.1.4</version>
</dependency>

I get code like this:

    public RemoteCall<DynamicArray<Int256>> subtractScalar(DynamicArray<Int256> self, Int256 a) {
        Function function = new Function("subtractScalar", 
                Arrays.<Type>asList(self, a), 
                Arrays.<TypeReference<?>>asList(new TypeReference<DynamicArray<Int256>>() {}));
        return executeRemoteCallSingleValueReturn(function);
    }

which compiles fine

flefevre commented 6 years ago

Hello, the problem comes in fact from web3j. Have a look to https://github.com/web3j/web3j/issues/303 which link to https://github.com/web3j/web3j/issues/238. personnaly i have the version 0.1.5-snapshot, web3j-maven-plugin with a modify version to match last version solcj. perhaps we could close this issue as it is taken into account by the other one?

flefevre commented 6 years ago

we can close this item, seems to be solved