web3j icon indicating copy to clipboard operation
web3j copied to clipboard

Smart Contract Wrapper Generation in error with functions with parameters without name

Open fraspadafora opened this issue 10 years ago • 4 comments

Hi, I was using web3j (0.5.1) to create the Smart Contract wrapper. But I have this error:

Exception in thread "main" java.lang.IllegalArgumentException: not a valid name: at com.squareup.javapoet.Util.checkArgument(Util.java:64) at com.squareup.javapoet.ParameterSpec.builder(ParameterSpec.java:83) at com.squareup.javapoet.MethodSpec$Builder.addParameter(MethodSpec.java:379) at org.web3j.codegen.SolidityFunctionWrapperGenerator.createFunctionDefinitions(SolidityFunctionWrapperGenerator.java:191) at org.web3j.codegen.SolidityFunctionWrapperGenerator.generateSolidityWrappers(SolidityFunctionWrapperGenerator.java:159) at org.web3j.codegen.SolidityFunctionWrapperGenerator.generate(SolidityFunctionWrapperGenerator.java:124) at org.web3j.codegen.SolidityFunctionWrapperGenerator.main(SolidityFunctionWrapperGenerator.java:66) at com.nttdata.ethereum.marketplace.Test.main(Test.java:26)

I debugged the code, and I noticed that in the ABI there was a function like this:

{"constant":true,"inputs":[{"name":"","type":"address"}],"name":"insuranceWithdraw","outputs":[{"name":"","type":"uint256"}],"payable":false,"type":"function"}

This function is created by Solidity because of I'm using a public map

mapping (address => unit) public insuranceWithdraw;

I think the best thing is to give a default name, with an increasing number.

fraspadafora avatar Nov 15 '16 13:11 fraspadafora

I'm presuming you updated to the latest release?

conor10 avatar Nov 15 '16 23:11 conor10

Yes, I was using an old version.

fraspadafora avatar Nov 19 '16 11:11 fraspadafora

3.2 is the latest release ri8 ?

RakeshSainiRk avatar Feb 12 '18 14:02 RakeshSainiRk

The same problem occurs with unnamed event parameters. I’m guessing it’s the same underlying bug. @conor10 Example:

// HelloWorld.sol
pragma solidity ^0.4.24;


contract HelloWorld {
    event Foo(uint);
}
$ solc HelloWorld.sol --bin --abi -o ./
$ web3j solidity generate HelloWorld.bin HelloWorld.abi -o . -p org.web3j.sample

              _      _____ _     _
             | |    |____ (_)   (_)
__      _____| |__      / /_     _   ___
\ \ /\ / / _ \ '_ \     \ \ |   | | / _ \
 \ V  V /  __/ |_) |.___/ / | _ | || (_) |
  \_/\_/ \___|_.__/ \____/| |(_)|_| \___/
                         _/ |
                        |__/

Generating org.web3j.sample.HelloWorld ... Exception in thread "main" java.lang.IllegalArgumentException: not a valid name:
	at com.squareup.javapoet.Util.checkArgument(Util.java:64)
	at com.squareup.javapoet.FieldSpec.builder(FieldSpec.java:92)
	at com.squareup.javapoet.TypeSpec$Builder.addField(TypeSpec.java:499)
	at org.web3j.codegen.SolidityFunctionWrapper.buildEventResponseObject(SolidityFunctionWrapper.java:753)
	at org.web3j.codegen.SolidityFunctionWrapper.buildEventFunctions(SolidityFunctionWrapper.java:896)
	at org.web3j.codegen.SolidityFunctionWrapper.buildFunctionDefinitions(SolidityFunctionWrapper.java:255)
	at org.web3j.codegen.SolidityFunctionWrapper.generateJavaFiles(SolidityFunctionWrapper.java:130)
	at org.web3j.codegen.SolidityFunctionWrapper.generateJavaFiles(SolidityFunctionWrapper.java:111)
	at org.web3j.codegen.SolidityFunctionWrapperGenerator.generate(SolidityFunctionWrapperGenerator.java:123)
	at org.web3j.codegen.SolidityFunctionWrapperGenerator.main(SolidityFunctionWrapperGenerator.java:87)
	at org.web3j.codegen.SolidityFunctionWrapperGenerator.run(SolidityFunctionWrapperGenerator.java:48)
	at org.web3j.console.Runner.main(Runner.java:38)

Once a name is added, it works fine.

tjanson avatar Sep 30 '18 23:09 tjanson