RefundVault.sol 1.4 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556
  1. pragma solidity ^0.4.11;
  2. import '../SafeMath.sol';
  3. import '../ownership/Ownable.sol';
  4. /**
  5. * @title RefundVault
  6. * @dev This contract is used for storing funds while a crowdsale
  7. * is in progress. Supports refunding the money if crowdsale fails,
  8. * and forwarding it if crowdsale is successful.
  9. */
  10. contract RefundVault is Ownable {
  11. using SafeMath for uint256;
  12. enum State { Active, Refunding, Closed }
  13. mapping (address => uint256) public deposited;
  14. address public wallet;
  15. State public state;
  16. event Closed();
  17. event RefundsEnabled();
  18. event Refunded(address indexed beneficiary, uint256 weiAmount);
  19. function RefundVault(address _wallet) {
  20. require(_wallet != 0x0);
  21. wallet = _wallet;
  22. state = State.Active;
  23. }
  24. function deposit(address investor) onlyOwner payable {
  25. require(state == State.Active);
  26. deposited[investor] = deposited[investor].add(msg.value);
  27. }
  28. function close() onlyOwner {
  29. require(state == State.Active);
  30. state = State.Closed;
  31. Closed();
  32. wallet.transfer(this.balance);
  33. }
  34. function enableRefunds() onlyOwner {
  35. require(state == State.Active);
  36. state = State.Refunding;
  37. RefundsEnabled();
  38. }
  39. function refund(address investor) {
  40. require(state == State.Refunding);
  41. uint256 depositedValue = deposited[investor];
  42. deposited[investor] = 0;
  43. investor.transfer(depositedValue);
  44. Refunded(investor, depositedValue);
  45. }
  46. }