This crowdfunding contract is far from complete, I'm still in the process of writing the code and testing each individual function. The approach that I have taken with the getRefund() function seems to work perfectly, however, I'm a little concerned about there being potential collisions as I have mapped all the investor's addresses to the amount of ETH sent to the contract. Is it possible for address A and address B to map to the same index within the mapping? If so, wouldn't this mean that if address A were to claim a refund, wouldn't address A also obtain the funds that were sent from address B?
pragma solidity ^0.4.0;
contract Crowdfunding {
address private owner;
mapping (address => uint) investors;
//Constructor
function Crowdfunding() {
owner = msg.sender;
}
//Modifiers
modifier investorsOnly {
if(investors[msg.sender] == 0) throw;
_;
}
//Events
event PaymentReceived(uint Amount, address From, address To);
event WithdrawalClaimed(uint Amount, address From);
//Functions
function() payable {
investors[msg.sender] += msg.value;
PaymentReceived(msg.value, msg.sender, this);
}
function withdrawFunds() {
suicide(owner);
}
function getRefund() investorsOnly {
uint amount = investors[msg.sender];
investors[msg.sender] = 0;
msg.sender.transfer(amount);
WithdrawalClaimed(amount, msg.sender);
}
}