Apparently my question was misunderstood, but I solved the problem with the help of Mikko Ohtamaa in the comments.
For some reason I didn't realized I could return multiple variables (and of different types!) Once you know you can do this, there's no problem really. Javascript handles it very well.
My solution looks somewhat like this:
contract myContract {
struct Ownable {
string name;
address creator;
address currentOwner;
bool isDestructible;
uint price;
}
mapping (uint => Ownable) public Ownables;
function getOwnableInfo(uint OwnableId) public view returns (string, address, address, bool, uint){
Ownable o = Ownables[OwnableId];
return (o.name, o.creator, o.currentOwner, o.isDestructible, o.price);
}
/.../
}
And in the corresponding truffle, the call
will return an array with the variables of the return in order:
myContractInstance.getOwnableInfo.call(ownableId).then((resultArray => {
name = resultArray[0];
creator = resultArray[1];
currentOwner = resultArray[2];
/.../
});
Notes:
- Don't look too much into the
Ownable o = Ownables[OwnableId];
, I did that to increase readability, I don't think it's useful or a good thing at all.
- If one of the data is a big number (typically a wei price), I convert it using bignumber's
resultArray[4].toNumber()
so that JavaScript can handle it.
return ( struct.member1,struct.member2)
– Kaki Master Of Time Mar 6 '18 at 10:48