I am trying to implement the simple storage.
When calling set
function, the contract will append a new Log
object to logs
array, and also return the related index
to the caller for reference data.
The problem is I cannot get returned index
, it is always empty.
How can I get the index
from calling set
function?
pragma solidity ^0.5.0;
contract Storage {
struct Log {
string fname;
string lname;
string dob;
}
mapping (uint => Log) logs;
uint index = 0;
function set(string memory fname, string memory lname, string memory dob) public returns (uint) {
index++;
logs[index] = Log(fname, lname, dob);
return (index);
}
function get(uint idx) public view returns (string memory, string memory, string memory) {
return (logs[idx].fname, logs[idx].lname, logs[idx].dob);
}
}