function getUserRecord(address addr, uint index) returns (uint a, address b, address c, uint d, uint e, uint f) { uint recordID = recordByUser[addr][index]; if (recordID==0) return; Record r = records[recordID]; a = r.id; b = r.from; c = r.to; d = r.amount; e = r.timestamp; f = r.blockNumber; }
Answers
{ "a" : 1000, "b" : 100, "c" : .... }
Currently we have a getter() defined for each field in struct
Also, I would love to see it supported for externals.
Since all variables are pre-initialised in Solidity, so are return values of struct type (with their members being initialised recursively). This means if you use
function f() internal returns (Record r) { ... }
you could also just assign the members of r individually.The struct itself resides in memory and the function returns a reference to this point in memory. This means that in the case of "return records[recordID]", the storage-struct is first copied to memory and then the function returns a reference to this place in memory. If you would like to return the storage reference itself, you have to use "function ... returns (Record storage) { ... }".