简体   繁体   English

在 Web3j 中生成 Java Wrapper 时出错

[英]Error in generating Java Wrapper in Web3j

I am trying to generate java Wrapper for a smart contract, but it failed because of this error:我正在尝试为智能合约生成 java Wrapper,但由于此错误而失败:

Exception in thread "main" java.lang.IllegalArgumentException: not a valid name: Main.sol:main
at com.squareup.javapoet.Util.checkArgument(Util.java:64)
at com.squareup.javapoet.TypeSpec$Builder.<init>(TypeSpec.java:383)
at com.squareup.javapoet.TypeSpec$Builder.<init>(TypeSpec.java:362)
at com.squareup.javapoet.TypeSpec.classBuilder(TypeSpec.java:90)
at org.web3j.codegen.SolidityFunctionWrapper.createClassBuilder(SolidityFunctionWrapper.java:172)
at org.web3j.codegen.SolidityFunctionWrapper.generateJavaFiles(SolidityFunctionWrapper.java:103)
at org.web3j.codegen.SolidityFunctionWrapper.generateJavaFiles(SolidityFunctionWrapper.java:91)
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)

I followed what this guy said to remove this error我按照这个人所说的来消除这个错误

https://github.com/web3j/web3j/issues/16] https://github.com/web3j/web3j/issues/16]

and give a default name (letters alphabetically) for each empty property as the following:并为每个空属性指定一个默认名称(按字母顺序排列),如下所示:

[{"constant":true,"inputs":
[{"name”:”a”,”type":"bytes32"}],"name":"ApprovedTAs","outputs":
[{"name":"Trade_id","type":"bytes32"},{"name":"Trade_producer","type":"address"},{"name":"Trade_consumer","type":"address"},{"name":"Trade_rate","type":"uint256"},{"name":"Trade_from","type":"uint256"},{"name":"Trade_to","type":"uint256"},{"name":"Trade_broker","type":"address"},{"name":"Trade_topic","type":"uint256"},{"name":"approvedByA","type":"bool"},{"name":"approvedByB","type":"bool"}],"payable":false,"type":"function"},{"constant":true,"inputs":[{"name”:”b”,”type":"address"},{"name”:”c”,”type":"uint256"}],"name":"offersByProducer","outputs":[{"name":"offer_id","type":"uint256"},{"name":"offer_producer","type":"address"},{"name":"offer_topic","type":"uint256"},{"name":"offer_rate","type":"uint256"},{"name":"offer_from","type":"uint256"},{"name":"offer_to","type":"uint256"},{"name":"offer_broker","type":"address"}],"payable":false,"type":"function"},{"constant":true,"inputs":[],"name":"getAll","outputs":[{"name”:”d”,”type":"address[]"},{"name”:”e”,”type":"address[]"},{"name”:”f”,”type":"address[]"}],"payable":false,"type":"function"},{"constant":false,"inputs":[{"name":"mk_producer","type":"address"},{"name":"mk_topic","type":"uint256"},{"name":"mk_rate","type":"uint256"},{"name":"mk_from","type":"uint256"},{"name":"mk_to","type":"uint256"},{"name":"mk_broker","type":"address"}],"name":"mkOrder","outputs":[],"payable":false,"type":"function"},{"constant":true,"inputs":[{"name”:”g”,”type":"uint256"}],"name":"offers","outputs":[{"name":"offer_id","type":"uint256"},{"name":"offer_producer","type":"address"},{"name":"offer_topic","type":"uint256"},{"name":"offer_rate","type":"uint256"},{"name":"offer_from","type":"uint256"},{"name":"offer_to","type":"uint256"},{"name":"offer_broker","type":"address"}],"payable":false,"type":"function"},{"constant":false,"inputs":[{"name":"ofr_topic","type":"uint256"},{"name":"ofr_rate","type":"uint256"},{"name":"ofr_from","type":"uint256"},{"name":"ofr_to","type":"uint256"},{"name":"ofr_broker","type":"address"}],"name":"offer","outputs":[],"payable":false,"type":"function"},{"constant":true,"inputs":[{"name”:”h”,”type":"uint256"},{"name”:”ii”,”type":"uint256"}],"name":"allAdd","outputs":[{"name”:”j”,”type":"address"}],"payable":false,"type":"function"},{"constant":false,"inputs":[{"name":"sndC_id","type":"bytes32"},{"name":"sndC_producer","type":"address"},{"name":"sndC_broker","type":"address"},{"name":"sndC_topic","type":"uint256"},{"name":"sndC_from","type":"uint256"},{"name":"sndC_to","type":"uint256"},{"name":"sndC_count","type":"uint256"}],"name":"sendCCube","outputs":[{"name”:”l”,”type":"bool"}],"payable":false,"type":"function"},{"constant":false,"inputs":[{"name":"id","type":"bytes32"}],"name":"agreeTA","outputs":[{"name”:”m”,”type":"bool"}],"payable":false,"type":"function"},{"constant":false,"inputs":[{"name":"sndP_id","type":"bytes32"},{"name":"sndP_broker","type":"address"},{"name":"sndP_topic","type":"uint256"},{"name":"sndP_from","type":"uint256"},{"name":"sndP_to","type":"uint256"},{"name":"sndP_count","type":"uint256"}],"name":"sendPCube","outputs":[{"name”:”n”,”type":"bool"}],"payable":false,"type":"function"},{"constant":true,"inputs":[{"name”:”o”,”type":"bytes32"}],"name":"CreatedTAs","outputs":[{"name":"Trade_id","type":"bytes32"},{"name":"Trade_producer","type":"address"},{"name":"Trade_consumer","type":"address"},{"name":"Trade_rate","type":"uint256"},{"name":"Trade_from","type":"uint256"},{"name":"Trade_to","type":"uint256"},{"name":"Trade_broker","type":"address"},{"name":"Trade_topic","type":"uint256"},{"name":"approvedByA","type":"bool"},{"name":"approvedByB","type":"bool"}],"payable":false,"type":"function"},{"constant":false,"inputs":[{"name":"nkname","type":"string"},{"name":"code","type":"uint256"}],"name":"register","outputs": [{"name”:”p”,”type":"bool"}],"payable":false,"type":"function"}]

But the error still the same.但是错误还是一样。 I also changed the name of the contract rather than "main" but nothing change.我还更改了合同的名称而不是“主要”,但没有任何变化。

I also changed every variable name has numbers, special characters or even starting with _ but still doesn't work.我还更改了每个变量名都有数字、特殊字符甚至以 _ 开头,但仍然不起作用。

Any idea what I should change to solve this error知道我应该改变什么来解决这个错误

Thanks谢谢

This error is triggered if you are declaring a function o event with only the argument type without a name.for example :如果您声明一个只有参数类型而没有名称的函数 o 事件,则会触发此错误。例如:

event myevent(string)

should be应该

event myevent(string message);

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM