I was wondering if anyone could help. I'm trying to check to see if an address has been stored in a struct, but the results I'm getting are not what I'm expecting.
So basically I have two functions....one is to store a value, and the other is to check if an address has already used the first function and stored a value.
so if I call storeValue()
and then I input a value, the value gets stored correctly, but if I then call checkForAddress()
and input my address, it still shows "false". I'm expecting it to show true because it was the same address I called storeValue()
with to begin with.
I need to be able to confirm if addresses have already stored values....ultimately it will mean that if they have stored a vlue, then they won't be able to call storeValue()
any more....they only get one chance to store a value from a single address.
Can anyone help, as I'm not really sure what I've done wrong :-(
thanks
pragma solidity 0.4.24;
import "github.com/OpenZeppelin/openzeppelin-solidity/contracts/math/SafeMath.sol";
// MAIN CONTRACT
contract DoesAddressExist {
using SafeMath for uint256;
constructor() public {
}
function () private payable {}
struct ValueRecorded {
uint valueEntered;
uint8 flag;
}
ValueRecorded[] public valueRecorded;
mapping(address => ValueRecorded) user;
function storeValue(uint _value) public {
ValueRecorded memory newValueRecorded = ValueRecorded ({
valueEntered: _value,
flag: 1
});
valueRecorded.push(newValueRecorded);
}
function checkForAddress(address _address) public view returns (bool) {
if(user[_address].flag == 1) {
return true; }
else return false;
}
}