* Add IntelliJ IDE config to .gitignore * Fix variable name in ERC20 function comments * Fix typos in Arrays function comment * Fix typos in ownership test names * Fix typo in Pausable test name * Fix grammar in Ownable function comment * Fix grammar in Crowdsale contract comment * Fix typo in Counters contract comment * Fix typo in ERC721Enumerable comment * Fix typo in ERC721PausedToken test name * Fix typo in Crowdsale function comment * Fix typo in IncreasingPriceCrowdsale function comment * Fix grammar in IncreasingPriceCrowdsale test name * Fix typo in AllowanceCrowdsale test name * Fix typo in RefundEscrow function comment * Fix typo in ERC20Migrator contract comment * Fix typos in SignatureBouncer comments * Fix typo in SignedSafeMath test name * Fix typo in TokenVesting contract comment * Move Ownable comment from @notice section to @dev The Ownable contract has a comment explaining that renouncing ownership will prevent execution of functions with the onlyOwner modifier. This commit moves that comment to the @dev section and replaces it with a description suitable for a generic user. * Clarify purpose of ERC20 transfer function * Clarify registration of ERC721Enumerable interface * Clarify purpose of AllowanceCrowdsale test * Increase specificity of inheritance comments FinalizableCrowdsale and RefundableCrowsale both have comments indicating that they are extensions of the Crowdsale contract. This commit refines those comments to the most immediate ancestor ( TimedCrowdsale and RefundableCrowdsale respectively ) * Remove unused parameter in PaymentSplitter test * Rename parameter in SignatureBouncer functions The SignatureBouncer contract has modifiers to validate the message sender is authorised to perform an action. They pass msg.sender to internal functions as the variable `account`, but the function comments refer to the variable as `sender` This commit changes the variable name to `sender` * Clarify comments in SignatureBouncer functions The SignatureBouncer has comments that use the description `sender` to refer to the variable `account`. This commit updates the comments for consistency. Maintainer Note: this reverts changes in the previous commit, which renamed the variable `account` instead.
93 lines
2.7 KiB
Solidity
93 lines
2.7 KiB
Solidity
pragma solidity ^0.5.2;
|
||
|
||
import "./ConditionalEscrow.sol";
|
||
|
||
/**
|
||
* @title RefundEscrow
|
||
* @dev Escrow that holds funds for a beneficiary, deposited from multiple
|
||
* parties.
|
||
* @dev Intended usage: See Escrow.sol. Same usage guidelines apply here.
|
||
* @dev The primary account (that is, the contract that instantiates this
|
||
* contract) may deposit, close the deposit period, and allow for either
|
||
* withdrawal by the beneficiary, or refunds to the depositors. All interactions
|
||
* with RefundEscrow will be made through the primary contract. See the
|
||
* RefundableCrowdsale contract for an example of RefundEscrow’s use.
|
||
*/
|
||
contract RefundEscrow is ConditionalEscrow {
|
||
enum State { Active, Refunding, Closed }
|
||
|
||
event RefundsClosed();
|
||
event RefundsEnabled();
|
||
|
||
State private _state;
|
||
address payable private _beneficiary;
|
||
|
||
/**
|
||
* @dev Constructor.
|
||
* @param beneficiary The beneficiary of the deposits.
|
||
*/
|
||
constructor (address payable beneficiary) public {
|
||
require(beneficiary != address(0));
|
||
_beneficiary = beneficiary;
|
||
_state = State.Active;
|
||
}
|
||
|
||
/**
|
||
* @return the current state of the escrow.
|
||
*/
|
||
function state() public view returns (State) {
|
||
return _state;
|
||
}
|
||
|
||
/**
|
||
* @return the beneficiary of the escrow.
|
||
*/
|
||
function beneficiary() public view returns (address) {
|
||
return _beneficiary;
|
||
}
|
||
|
||
/**
|
||
* @dev Stores funds that may later be refunded.
|
||
* @param refundee The address funds will be sent to if a refund occurs.
|
||
*/
|
||
function deposit(address refundee) public payable {
|
||
require(_state == State.Active);
|
||
super.deposit(refundee);
|
||
}
|
||
|
||
/**
|
||
* @dev Allows for the beneficiary to withdraw their funds, rejecting
|
||
* further deposits.
|
||
*/
|
||
function close() public onlyPrimary {
|
||
require(_state == State.Active);
|
||
_state = State.Closed;
|
||
emit RefundsClosed();
|
||
}
|
||
|
||
/**
|
||
* @dev Allows for refunds to take place, rejecting further deposits.
|
||
*/
|
||
function enableRefunds() public onlyPrimary {
|
||
require(_state == State.Active);
|
||
_state = State.Refunding;
|
||
emit RefundsEnabled();
|
||
}
|
||
|
||
/**
|
||
* @dev Withdraws the beneficiary's funds.
|
||
*/
|
||
function beneficiaryWithdraw() public {
|
||
require(_state == State.Closed);
|
||
_beneficiary.transfer(address(this).balance);
|
||
}
|
||
|
||
/**
|
||
* @dev Returns whether refundees can withdraw their deposits (be refunded). The overridden function receives a
|
||
* 'payee' argument, but we ignore it here since the condition is global, not per-payee.
|
||
*/
|
||
function withdrawalAllowed(address) public view returns (bool) {
|
||
return _state == State.Refunding;
|
||
}
|
||
}
|