Java Web3j v3.3.1:生成返回结构数组的已编译solidity智能合约时出错

Java Web3j v3.3.1:生成返回结构数组的已编译solidity智能合约时出错,java,blockchain,ethereum,solidity,smartcontracts,Java,Blockchain,Ethereum,Solidity,Smartcontracts,我从solidity函数返回一个struct数组,如下所示 布拉格坚实度^0.4.21 布拉格实验区2 函数getPurchaseOrderForVendor(字符串vendorNameInput)常量返回(PurchaseOrderStruct[]) 它被编译成abi和bin文件。问题在于使用web3j(v3.3.1)为合同创建包装文件。我得到下面的错误 Generating com.contract.InvoiceSettlement_sol_InvoiceSettlement ... E

我从solidity函数返回一个struct数组,如下所示

布拉格坚实度^0.4.21

布拉格实验区2

函数getPurchaseOrderForVendor(字符串vendorNameInput)常量返回(PurchaseOrderStruct[])

它被编译成abi和bin文件。问题在于使用web3j(v3.3.1)为合同创建包装文件。我得到下面的错误

Generating com.contract.InvoiceSettlement_sol_InvoiceSettlement ... 
Exception in thread "main" java.lang.UnsupportedOperationException: 
Unsupported type
encountered: tuple
    at org.web3j.abi.datatypes.generated.AbiTypes.getType(AbiTypes.java:221)

    at org.web3j.codegen.SolidityFunctionWrapper.buildTypeName(SolidityFunct
ionWrapper.java:851)
    at org.web3j.codegen.SolidityFunctionWrapper.buildTypeNames(SolidityFunc
tionWrapper.java:508)
    at org.web3j.codegen.SolidityFunctionWrapper.buildFunction(SolidityFunct
ionWrapper.java:523)
    at org.web3j.codegen.SolidityFunctionWrapper.buildFunctionDefinitions(So
lidityFunctionWrapper.java:216)
    at org.web3j.codegen.SolidityFunctionWrapper.generateJavaFiles(SolidityF
unctionWrapper.java:112)
    at org.web3j.codegen.SolidityFunctionWrapper.generateJavaFiles(SolidityF
unctionWrapper.java:94)
    at org.web3j.codegen.SolidityFunctionWrapperGenerator.generate(SolidityF
unctionWrapperGenerator.java:123)
    at org.web3j.codegen.SolidityFunctionWrapperGenerator.main(SolidityFunct
ionWrapperGenerator.java:87)
    at org.web3j.codegen.SolidityFunctionWrapperGenerator.run(SolidityFuncti
onWrapperGenerator.java:48)
    at org.web3j.console.Runner.main(Runner.java:38)

Solidity不支持在外部调用中返回结构。仅在
内部
函数调用中允许。您需要分解结构并通过元组返回元素


来源:

我尝试了分解的方法。但是我无法返回字符串数组(我的结构包含一个类型为string的元素)。您需要以
bytes32
的形式返回字符串,或者(我的首选方法)使用一个函数返回所需数组的大小,并让检索函数接受索引参数,一次返回一个分解的struct元素。这种方法更简洁,避免了在数组较大的情况下可能出现的气体不足异常。同样,如果您有一个带有struct的公共变量,您也会遇到此错误。i、 映射(uint256=>SomeStruct)公共somemapping。