The following is a simplification of the problem I'm facing;
pragma solidity 0.4.18;
contract ValueSetter {
struct BasicValue {
uint256 value;
}
address my_address; // Just for the require later
BasicValue fixed_value;
mapping(address => BasicValue) fixed_values;
function ValueSetter(address init_address) public {
my_address = init_address;
fixed_values[init_address] = fixed_value;
}
function set_value(uint256 my_value) external {
// Just to prove that the bug isn't in my calling params
require(msg.sender == my_address && my_value != 0);
fixed_values[msg.sender].value = my_value;
assert(fixed_value.value != 0);
}
}
When I call set_value
with a non-zero value, I hit the assert. It looks like the problem is that in this line,
fixed_values[msg.sender].value = my_value;
my attempt to assign to the struct inside the mapping is not assigning to the struct stored in fixed_value
. I've also tried the following instead;
BasicValue storage basic_val = fixed_values[msg.sender];
basic_val.value = my_value;
But this doesn't change the result. I read in the solidity documentation that,
assignments between storage and memory and also to a state variable (even from other state variables) always create an independent copy
If that's the case, then how can I get a the struct "out of" the mapping, to use it locally?
(Notes; the contract above looks like it does ridiculously more complicated stuff than it needs to because the real contract has more requirements. For example, there's more than one attribute in the struct, there's more than one struct declared on initialization, there's more than one struct in the mapping, and I need to do logic involving more than one of them.)