I'm deploying via Remix and Metamask.
I'm using this SafeMath function, which seems to be preventing my contract from initializing all its state variables (contract deploys, but all vars are zero):
function add(uint256 a, uint256 b) internal constant returns (uint256) {
uint256 c = a + b;
assert(c >= a);
return c;
}
The library function seems to be causing the problem in the following function. To be clear, the deposit
function below isn't even being called during deployment. But when I deploy the contract with the FIRST line in the if-block enabled (which uses the .add
SafeMath formula), the contract deploys but none of the state variables are set.
Everything works fine when I use the second line.
Am I using the SafeMath library incorrectly?
function deposit(address addr) payable {
uint256 amt = msg.value;
uint alreadyDeposited = deposits[addr]; // deposits is an address => uint mapping
if (alreadyDeposited > 0) {
// deposits[addr] = alreadyDeposited.add(amt); // When this line is enabled, my contract doesn't initialize (for example, "ownerWallet", which should be msg.sender, is not set when the contract deploys).
deposits[addr] = alreadyDeposited + amt; // this line lets contract vars initialize appropriately.
}
sendFunds();
}
PS can someone explain how add
knows how to use itself as the first parameter?