The following code works - after changing uint to unit16 - and I find now after running it, that getStorageAt does not show the actual values. Are the values stored outside that access to that method or in memory?
pragma solidity ^0.4.18;
contract CA3 {
struct Student {
uint16 age;
uint16 income;
uint16 score;
uint16 attendance;
}
Student[] public students;
function setStudent (uint16 _age, uint16 _income, uint16 _score, uint16 _attendan
ce) public {
Student memory tempStudent = Student({age: _age, income: _income, score: _scor
e, attendance: _attendance});
students.push(tempStudent);
//students.push(Student({age: _age, income: _income, score: _score, attendance: _
attendance}));
}
}
> con.setStudent(8,1,1,1)
"0x9886c2de6ace867efedc4c06d2fa79d7148807287a827d2f31a6f01956d6b4ca"
> con.students(0)
[8, 1, 1, 1]
> eth.getStorageAt(con.address,0)
"0x0000000000000000000000000000000000000000000000000000000000000001"
The 1 appears to be somekind of index.
When I run -
> eth.getStorageAt(con.address,0)
"0x0000000000000000000000000000000000000000000000000000000000000001"
> con.setStudent(8,10,10,15)
"0x2e9ad070deaa4cd044ae3d1b4673a676efde828faf5043bc1b62fdb746efb583"
> eth.pendingTransactions.length
0
> con.students(1)
[8, 10, 10, 15]
> eth.getStorageAt(con.address,1)
"0x0000000000000000000000000000000000000000000000000000000000000000"
> eth.getStorageAt(con.address,2)
"0x0000000000000000000000000000000000000000000000000000000000000000"
> eth.getStorageAt(con.address,0)
"0x0000000000000000000000000000000000000000000000000000000000000002"
After the second run, storage shows 2. But where is the students array stored?
I just exited the geth and entered again to find the same results. So students are not held in memory. The values are in storage. But where? Also why does getStorageAt not show them? Is there an equivalent method to show them?