mirror of
https://github.com/ethereum/solidity
synced 2023-10-03 13:03:40 +00:00
57 lines
1.5 KiB
Solidity
57 lines
1.5 KiB
Solidity
pragma solidity ^0.4.11;
|
|
|
|
import '../math/SafeMath.sol';
|
|
import '../ownership/Ownable.sol';
|
|
|
|
/**
|
|
* @title RefundVault
|
|
* @dev This contract is used for storing funds while a crowdsale
|
|
* is in progress. Supports refunding the money if crowdsale fails,
|
|
* and forwarding it if crowdsale is successful.
|
|
*/
|
|
contract RefundVault is Ownable {
|
|
using SafeMath for uint256;
|
|
|
|
enum State { Active, Refunding, Closed }
|
|
|
|
mapping (address => uint256) public deposited;
|
|
address public wallet;
|
|
State public state;
|
|
|
|
event Closed();
|
|
event RefundsEnabled();
|
|
event Refunded(address indexed beneficiary, uint256 weiAmount);
|
|
|
|
constructor(address _wallet) public {
|
|
require(_wallet != address(0x0));
|
|
wallet = _wallet;
|
|
state = State.Active;
|
|
}
|
|
|
|
function deposit(address investor) public onlyOwner payable {
|
|
require(state == State.Active);
|
|
deposited[investor] = deposited[investor].add(msg.value);
|
|
}
|
|
|
|
function close() public onlyOwner {
|
|
require(state == State.Active);
|
|
state = State.Closed;
|
|
emit Closed();
|
|
wallet.transfer(address(this).balance);
|
|
}
|
|
|
|
function enableRefunds() public onlyOwner {
|
|
require(state == State.Active);
|
|
state = State.Refunding;
|
|
emit RefundsEnabled();
|
|
}
|
|
|
|
function refund(address investor) public {
|
|
require(state == State.Refunding);
|
|
uint256 depositedValue = deposited[investor];
|
|
deposited[investor] = 0;
|
|
investor.transfer(depositedValue);
|
|
emit Refunded(investor, depositedValue);
|
|
}
|
|
}
|