Yep, my fault for playing around with contracts on the live net so I'm only to blame but wondered if anyone with more knowledge can help or just confirm that my 1 ETH is now forever stuck or there is a way I can get it.
I know what what the problem is, it's that I've used the safeWithdrawal once already so the var 'amountRaised' has not been reset and if I send more it doesn't match.
What happened was I sent 0.5 ETH, then used safeWithdrawl and got it back fine. Later I sent 1 ETH and tried to safeWithdrawl that. Because amountRaised didn't clear it tries to withdraw 1.5 ETH when there is only 1ETH and would do the same if more was sent to it. Any help or am I stuck?
pragma solidity ^0.4.2;
contract token { function transfer(address receiver, uint amount); }
contract Crowdsale {
address public beneficiary;
uint public fundingGoal; uint public amountRaised; uint public
deadline; uint public price;
token public tokenReward;
mapping(address => uint256) public balanceOf;
bool fundingGoalReached = false;
event GoalReached(address beneficiary, uint amountRaised);
event FundTransfer(address backer, uint amount, bool
isContribution);
bool crowdsaleClosed = false;
/* data structure to hold information about campaign contributors */
/* at initialization, setup the owner */
function Crowdsale(
address ifSuccessfulSendTo,
uint fundingGoalInEthers,
uint durationInMinutes,
token addressOfTokenUsedAsReward
) {
beneficiary = ifSuccessfulSendTo;
fundingGoal = fundingGoalInEthers * 1 ether;
deadline = now + durationInMinutes * 1 minutes;
price = 25;
tokenReward = token(addressOfTokenUsedAsReward);
}
/* The function without name is the default function that is called whenever anyone sends funds to a contract */
function () payable {
if (crowdsaleClosed) throw;
uint amount = msg.value;
balanceOf[msg.sender] = amount;
amountRaised += amount;
tokenReward.transfer(msg.sender, amount * price);
FundTransfer(msg.sender, amount, true);
}
modifier afterDeadline() { if (now >= deadline) _; }
/* checks if the goal or time limit has been reached and ends the campaign */
function checkGoalReached() afterDeadline {
fundingGoalReached = true;
GoalReached(beneficiary, amountRaised);
}
function closeCrowdSale() {
if (beneficiary == msg.sender) {
crowdsaleClosed = true;
}
}
function safeWithdrawal() {
if (beneficiary == msg.sender) {
if (beneficiary.send(amountRaised)) {
FundTransfer(beneficiary, amountRaised, false);
}
}
}
}