I am writing a contract which allows a user to deposit ether into it but when it is time to withdraw only the owner can process the withdrawals and gets to decide the amount of ether taken from your balance for your withdrawal. For some reason the withdraw function won't send any ether despite it being within the balance of the user and the contract. I am not sure why as I have been able to do this successfully in the past but not with this set up. My code is as follows:
contract sangalliCoin {
address sangalli;
mapping (address => uint) balances;
modifier sangalliOnly{ if(msg.sender != sangalli) throw; }
event _attemptWithdrawal(uint256 indexed amount, address indexed customer);
function deposit(){
if(msg.value > 0) balances[msg.sender] += msg.value;
else throw;
}
function attemptWithdrawal(uint256 amount) returns (string){
_attemptWithdrawal(amount, msg.sender);
return "you are probably gonna get ripped off... #sangalliCoin";
}
function setSangalli(){
sangalli = msg.sender;
}
function withdraw(uint withdrawAmount, address user, uint256 multiple) sangalliOnly public returns (uint remainingBal) {
if(balances[user] >= withdrawAmount * multiple) {
balances[user] -= withdrawAmount * multiple;
if (!user.send(withdrawAmount)) {
balances[user] += withdrawAmount * multiple;
}
}
return balances[msg.sender];
}
}