I'm not sure what changed, but with the original contract, I could not change the values of the variables. Originally, I had tested storing values using the setSample() function a second time... then retrieving them resulted in the second storage being ignored (the variables were the same as the first time I stored them). Now, when I store different variables under the same index (stackID) and retrieve them, it seems that I can overwrite them. Maybe I'm missing some basic fundamental like [for example], maybe immutability doesn't apply to uints, but only addresses. My goal here is to make sure that the values can't be overwritten, per the index (stackID) when stored via the EVM.
Below is the contract. Also appreciate any suggestions if there's anything else I'm doing wrong, not related to this issue.
pragma solidity ^0.4.24;
contract StackSample {
struct Sample {
uint48 tm;
uint56 tdn;
uint56 ash;
uint56 ndf;
uint56 adf;
uint56 cp;
uint48 nitr;
uint64 rfv;
uint64 rfq;
uint48 nel;
uint40 grower;
}
mapping(uint56 => Sample) public samples;
address public owner;
constructor() public {
owner = msg.sender;
}
modifier onlyOwner {
require(msg.sender == owner);
_;
}
function setSample(uint56 _stackID, uint48 _tm, uint56 _tdn, uint56 _ash, uint56 _ndf, uint56 _adf, uint56 _cp, uint48 _nitr, uint64 _rfv, uint64 _rfq, uint48 _nel, uint40 _grower) onlyOwner public {
Sample storage sample = samples[_stackID];
sample.tm = _tm;
sample.tdn = _tdn;
sample.ash = _ash;
sample.ndf = _ndf;
sample.adf = _adf;
sample.cp = _cp;
sample.nitr = _nitr;
sample.rfv = _rfv;
sample.rfq = _rfq;
sample.nel = _nel;
sample.grower = _grower;
}
function getSample(uint56 _stackID) view public returns (uint48, uint56, uint56, uint56, uint56, uint56, uint48, uint64, uint64, uint48, uint40) {
Sample storage sample = samples[_stackID];
return (sample.tm, sample.tdn, sample.ash, sample.ndf, sample.adf, sample.cp, sample.nitr, sample.rfv, sample.rfq, sample.nel, sample.grower);
}
}