Update collateral totals and balance at the same time
This commit is contained in:
parent
c86fdfbec1
commit
9e0d05965d
|
@ -16,18 +16,26 @@ contract Collateral {
|
||||||
return balances[account];
|
return balances[account];
|
||||||
}
|
}
|
||||||
|
|
||||||
function deposit(uint256 amount) public invariant {
|
function add(address account, uint256 amount) private {
|
||||||
token.transferFrom(msg.sender, address(this), amount);
|
balances[account] += amount;
|
||||||
totals.deposited += amount;
|
|
||||||
balances[msg.sender] += amount;
|
|
||||||
totals.balance += amount;
|
totals.balance += amount;
|
||||||
}
|
}
|
||||||
|
|
||||||
function withdraw() public invariant {
|
function subtract(address account, uint256 amount) private {
|
||||||
uint256 amount = balances[msg.sender];
|
balances[account] -= amount;
|
||||||
balances[msg.sender] = 0;
|
|
||||||
totals.balance -= amount;
|
totals.balance -= amount;
|
||||||
|
}
|
||||||
|
|
||||||
|
function deposit(uint256 amount) public invariant {
|
||||||
|
token.transferFrom(msg.sender, address(this), amount);
|
||||||
|
totals.deposited += amount;
|
||||||
|
add(msg.sender, amount);
|
||||||
|
}
|
||||||
|
|
||||||
|
function withdraw() public invariant {
|
||||||
|
uint256 amount = balanceOf(msg.sender);
|
||||||
totals.withdrawn += amount;
|
totals.withdrawn += amount;
|
||||||
|
subtract(msg.sender, amount);
|
||||||
assert(token.transfer(msg.sender, amount));
|
assert(token.transfer(msg.sender, amount));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue