I wish to map the time to the address key. But currently it is working on the index key only. I just want to map time as well. Means the current time. So that I can able to get the record with time as well.
pragma solidity ^0.4.17;
contract Experment2 {
uint public creationTime = now;
struct Record {
// address owner;
//uint id;
string name;
string senderaddress;
string reciveraddress;
string scheduletime;
string scheduledate;
// uint Index;
uint time;
}
mapping (uint => Record[]) records;
function setRec (uint id, string name, string senderaddress, string reciveraddress, string scheduletime, string scheduledate, uint time) public {
records[id].push(Record(name, senderaddress, reciveraddress, scheduletime, scheduledate, time =now));
}
function getrec(uint id , uint index) constant returns(string, string, string, string, string, uint){ {
var a = records[id][index].name;
var b = records[id][index].senderaddress;
var c = records[id][index].reciveraddress;
var d = records[id][index].scheduletime;
var e = records[id][index].scheduledate;
var f = records[id][index].time;
}
return(a,b,c,d,e,f);
}
function get_last_ten(uint id) constant returns (uint[10]){
//uint[10] memory lastItem1;
uint[10] memory lastItem2;
for(uint i=0;i<10;i++){
if(records[id].length>i){
// lastItem1[i] = records[id][records[id].length-i-1].index;
lastItem2[i] = records[id][records[id].length-i-1].time;
}
}
return (lastItem2);
}
}
Like in the above code the mapping is only through with index value. I can onl manage to return the current time. But I want to map the data on time as well.
So that I can run
function getrec(uint id , uint time) constant returns(string, string, string, string, string, uint){ {
var a = records[id][time].name;
var b = records[id][time].senderaddress;
var c = records[id][time].reciveraddress;
var d = records[id][time].scheduletime;
var e = records[id][time].scheduledate;
var f = records[id][time].time;
}
return(a,b,c,d,e,f);
}