Web3j v3.3.1 : Error while generating compiled solidity smart contracts which returns array of struct

北城以北 提交于 2019-12-11 21:32:52

问题


I am returning an array of struct from solidity function as below.

pragma solidity ^0.4.21;

pragma experimental ABIEncoderV2;

function getPurchaseOrderForVendor(string vendorNameInput) constant returns (PurchaseOrderStruct[])

It is compiled to abi and bin files. The issue is with creating wrapper files for the contract using web3j(v3.3.1). Im getting the below errors.

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)

回答1:


Solidity does not support returning structs in external calls. It is only allowed in internal function calls. You need to decompose the struct and return the elements via a tuple.

Source: Solidity documentation



来源:https://stackoverflow.com/questions/49428518/web3j-v3-3-1-error-while-generating-compiled-solidity-smart-contracts-which-re

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!