Web3j v3.3.1:生成返回结构数组的已编译的实体智能合约时出错 [英] Web3j v3.3.1 : Error while generating compiled solidity smart contracts which returns array of struct

查看:1300
本文介绍了Web3j v3.3.1:生成返回结构数组的已编译的实体智能合约时出错的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我要从solidity函数返回一个结构数组,如下所示.

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

实用性实体^ 0.4.21;

实用的实验性ABIEncoderV2;

函数getPurchaseOrderForVendor(string vendorNameInput)常量返回(PurchaseOrderStruct [])

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

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不支持在外部调用中返回结构.仅在internal函数调用中允许使用.您需要分解结构并通过元组返回元素.

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.

来源: Solidity文档

这篇关于Web3j v3.3.1:生成返回结构数组的已编译的实体智能合约时出错的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆