-
Notifications
You must be signed in to change notification settings - Fork 11.8k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. Weβll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Improve encapsulation on lifecycle, ownership and payments #1269
Changes from 6 commits
97be1da
3a2c242
6416991
82f23f0
2842284
fe431bf
bb5a1a9
63ee53f
1e69a33
bd25984
647b4b2
b3b4195
fc473b4
5d04b0a
61a7f21
68ebdb0
436ceeb
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -7,7 +7,7 @@ pragma solidity ^0.4.24; | |
* functions, this simplifies the implementation of "user permissions". | ||
*/ | ||
contract Ownable { | ||
address public owner; | ||
address private owner_; | ||
|
||
|
||
event OwnershipRenounced(address indexed previousOwner); | ||
|
@@ -22,14 +22,21 @@ contract Ownable { | |
* account. | ||
*/ | ||
constructor() public { | ||
owner = msg.sender; | ||
owner_ = msg.sender; | ||
} | ||
|
||
/** | ||
* @return the address of the owner. | ||
*/ | ||
function getOwner() public view returns(address) { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I'm not fond of starting this convention of getters prefixed with There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This is what we discussed about having verbs on function names. I won't like it, but I can remove the There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Yes, I'd prefer to remove the |
||
return owner_; | ||
} | ||
|
||
/** | ||
* @dev Throws if called by any account other than the owner. | ||
*/ | ||
modifier onlyOwner() { | ||
require(msg.sender == owner); | ||
require(msg.sender == owner_); | ||
_; | ||
} | ||
|
||
|
@@ -40,8 +47,8 @@ contract Ownable { | |
* modifier anymore. | ||
*/ | ||
function renounceOwnership() public onlyOwner { | ||
emit OwnershipRenounced(owner); | ||
owner = address(0); | ||
emit OwnershipRenounced(owner_); | ||
owner_ = address(0); | ||
} | ||
|
||
/** | ||
|
@@ -58,7 +65,7 @@ contract Ownable { | |
*/ | ||
function _transferOwnership(address _newOwner) internal { | ||
require(_newOwner != address(0)); | ||
emit OwnershipTransferred(owner, _newOwner); | ||
owner = _newOwner; | ||
emit OwnershipTransferred(owner_, _newOwner); | ||
owner_ = _newOwner; | ||
} | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -16,25 +16,39 @@ contract RefundEscrow is Ownable, ConditionalEscrow { | |
event Closed(); | ||
event RefundsEnabled(); | ||
|
||
State public state; | ||
address public beneficiary; | ||
State private state_; | ||
address private beneficiary_; | ||
|
||
/** | ||
* @dev Constructor. | ||
* @param _beneficiary The beneficiary of the deposits. | ||
*/ | ||
constructor(address _beneficiary) public { | ||
require(_beneficiary != address(0)); | ||
beneficiary = _beneficiary; | ||
state = State.Active; | ||
beneficiary_ = _beneficiary; | ||
state_ = State.Active; | ||
} | ||
|
||
/** | ||
* @return the current state of the escrow. | ||
*/ | ||
function getState() public view returns(State) { | ||
return state_; | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. any idea how to test this? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I think the error just means that they're not the same thing. Try using There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. that helped, thanks! |
||
} | ||
|
||
/** | ||
* @return the beneficiary of the escrow. | ||
*/ | ||
function getBeneficiary() 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); | ||
require(state_ == State.Active); | ||
super.deposit(_refundee); | ||
} | ||
|
||
|
@@ -43,32 +57,32 @@ contract RefundEscrow is Ownable, ConditionalEscrow { | |
* further deposits. | ||
*/ | ||
function close() public onlyOwner { | ||
require(state == State.Active); | ||
state = State.Closed; | ||
require(state_ == State.Active); | ||
state_ = State.Closed; | ||
emit Closed(); | ||
} | ||
|
||
/** | ||
* @dev Allows for refunds to take place, rejecting further deposits. | ||
*/ | ||
function enableRefunds() public onlyOwner { | ||
require(state == State.Active); | ||
state = State.Refunding; | ||
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); | ||
require(state_ == State.Closed); | ||
beneficiary_.transfer(address(this).balance); | ||
} | ||
|
||
/** | ||
* @dev Returns whether refundees can withdraw their deposits (be refunded). | ||
*/ | ||
function withdrawalAllowed(address _payee) public view returns (bool) { | ||
return state == State.Refunding; | ||
return state_ == State.Refunding; | ||
} | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This line should stay because it's not part of
_transferOwnership
. But we've removedClaimable
in #1274.There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Ah, #1274 is not merged yet.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
indeed, and no test failed π