I want to return a list of user-defined struct
function sortByEtherValues (string category) public view returns (JobStruct[]) {
...
}
I am getting the following error:
Failed to decode output: Error: Unsupported or invalid type: tuple
I want to return a list of user-defined struct
function sortByEtherValues (string category) public view returns (JobStruct[]) {
...
}
I am getting the following error:
Failed to decode output: Error: Unsupported or invalid type: tuple
Solidity supports returning multiple values:
struct JobStruct {
uint a;
uint b;
uint c;
}
function sortByEtherValues (string category) public view returns (uint, uint, uint) {
JobStruct memory js = JobStruct(1, 2, 3);
return (js.a, js.b, js.c);
}
It'll be a little dirty to return an array of structs by decomposing your struct
elements. If you can, you should try to return just a single JobStruct
by getting the number of elements by category
in a separate function, then adding the index to sortByEtherValues
.