简体   繁体   中英

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

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)

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

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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