如何return结构数组在solidity智能合约中形成一个函数
How to return array of struct form a function in solidity smart contract
我想 return 来自函数 getPurchaseOrderForVendor 的结构数组。编译时出现错误 invoiceSettlement.sol:44:80: ParserError: Expected type name
函数 getPurchaseOrderForVendor(string vendorNameInput) 常量 ret
骨灰盒(结构[])
^
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);
}
}
这份合同中有不止一个错误,但不知道你想达到什么目的,我就回答这个问题
应该是这样的
function getPurchaseOrderForVendor(string vendorNameInput) constant returns (PurchaseOrderStruct[])
我想 return 来自函数 getPurchaseOrderForVendor 的结构数组。编译时出现错误 invoiceSettlement.sol:44:80: ParserError: Expected type name 函数 getPurchaseOrderForVendor(string vendorNameInput) 常量 ret 骨灰盒(结构[]) ^
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);
}
}
这份合同中有不止一个错误,但不知道你想达到什么目的,我就回答这个问题
应该是这样的
function getPurchaseOrderForVendor(string vendorNameInput) constant returns (PurchaseOrderStruct[])