如何在solidity智能契约中返回结构数组形式的函数

时间:2018-03-22 10:44:34

标签: ethereum solidity smartcontracts

我想从函数 getPurchaseOrderForVendor 返回一个struct数组。编译即时收到错误,比如 invoiceSettlement.sol:44:80:ParserError:预期的类型名称         function getPurchaseOrderForVendor(string vendorNameInput)constant ret urns(struct [])       ^

pragma solidity ^0.4.21;
pragma experimental ABIEncoderV2;

contract InvoiceSettlement {

struct PurchaseOrderStruct {

    uint8 requisitionNumber;
    uint8 poNumber;

}

PurchaseOrderStruct[10] public PurchaseOrderStructArray;


function InvoiceSettlement()
{
        for (uint i = 0; i < purchaseOrderLength; i++) {

                PurchaseOrderStructArray[i].requisitionNumber = 1;
                PurchaseOrderStructArray[i].poNumber = 1;

        }
}


function  getPurchaseOrderForVendor(string vendorNameInput) constant returns (struct[])
{


    struct[] memory y = new struct[](16);

    for (uint i = 0; i < purchaseOrderLength; i++)
    {
        y[i] = PurchaseOrderStructArray[i];
    }
    return (y);

}


}

1 个答案:

答案 0 :(得分:0)

这份合同中有一个以上的错误,但不知道你想要实现什么,我只会回答这个问题

应该是这样的

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