我从solidity函数返回一个struct数组,如下所示。
pragma solidity ^ 0.4.21;
pragma experimental ABIEncoderV2;
function getPurchaseOrderForVendor(string vendorNameInput)constant return(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)
答案 0 :(得分:1)
Solidity不支持在外部调用中返回结构。它仅允许在internal
函数调用中使用。您需要分解结构并通过元组返回元素。