Skip to content

Commit 889d090

Browse files
trejasfrangio
authored andcommitted
Enhancement/heritable encapsulation OpenZeppelin#692 (OpenZeppelin#702)
* Modified Gitignore for Sublime * Added getter functions for public variables * Added encapsulation to Heritable public variables. * Added encapsulation to Heritable public variables. * Added encapsulation to Heritable public variables. * Updated tests to use getter methods instead of, now, private variables. * Conformed variable names to current conventions. * Requested changes * revert package-lock.json changes
1 parent b2fbac4 commit 889d090

File tree

1 file changed

+32
-16
lines changed

1 file changed

+32
-16
lines changed

contracts/ownership/Heritable.sol

Lines changed: 32 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -11,13 +11,13 @@ import "./Ownable.sol";
1111
* owner's death.
1212
*/
1313
contract Heritable is Ownable {
14-
address public heir;
14+
address private heir_;
1515

1616
// Time window the owner has to notify they are alive.
17-
uint256 public heartbeatTimeout;
17+
uint256 private heartbeatTimeout_;
1818

1919
// Timestamp of the owner's death, as pronounced by the heir.
20-
uint256 public timeOfDeath;
20+
uint256 private timeOfDeath_;
2121

2222
event HeirChanged(address indexed owner, address indexed newHeir);
2323
event OwnerHeartbeated(address indexed owner);
@@ -29,7 +29,7 @@ contract Heritable is Ownable {
2929
* @dev Throw an exception if called by any account other than the heir's.
3030
*/
3131
modifier onlyHeir() {
32-
require(msg.sender == heir);
32+
require(msg.sender == heir_);
3333
_;
3434
}
3535

@@ -47,15 +47,31 @@ contract Heritable is Ownable {
4747
require(newHeir != owner);
4848
heartbeat();
4949
HeirChanged(owner, newHeir);
50-
heir = newHeir;
50+
heir_ = newHeir;
51+
}
52+
53+
/**
54+
* @dev Use these getter functions to access the internal variables in
55+
* an inherited contract.
56+
*/
57+
function heir() public view returns(address) {
58+
return heir_;
59+
}
60+
61+
function heartbeatTimeout() public view returns(uint256) {
62+
return heartbeatTimeout_;
63+
}
64+
65+
function timeOfDeath() public view returns(uint256) {
66+
return timeOfDeath_;
5167
}
5268

5369
/**
5470
* @dev set heir = 0x0
5571
*/
5672
function removeHeir() public onlyOwner {
5773
heartbeat();
58-
heir = 0;
74+
heir_ = 0;
5975
}
6076

6177
/**
@@ -64,36 +80,36 @@ contract Heritable is Ownable {
6480
*/
6581
function proclaimDeath() public onlyHeir {
6682
require(ownerLives());
67-
OwnerProclaimedDead(owner, heir, timeOfDeath);
68-
timeOfDeath = now;
83+
OwnerProclaimedDead(owner, heir_, timeOfDeath_);
84+
timeOfDeath_ = block.timestamp;
6985
}
7086

7187
/**
7288
* @dev Owner can send a heartbeat if they were mistakenly pronounced dead.
7389
*/
7490
function heartbeat() public onlyOwner {
7591
OwnerHeartbeated(owner);
76-
timeOfDeath = 0;
92+
timeOfDeath_ = 0;
7793
}
7894

7995
/**
8096
* @dev Allows heir to transfer ownership only if heartbeat has timed out.
8197
*/
8298
function claimHeirOwnership() public onlyHeir {
8399
require(!ownerLives());
84-
require(now >= timeOfDeath + heartbeatTimeout);
85-
OwnershipTransferred(owner, heir);
86-
HeirOwnershipClaimed(owner, heir);
87-
owner = heir;
88-
timeOfDeath = 0;
100+
require(block.timestamp >= timeOfDeath_ + heartbeatTimeout_);
101+
OwnershipTransferred(owner, heir_);
102+
HeirOwnershipClaimed(owner, heir_);
103+
owner = heir_;
104+
timeOfDeath_ = 0;
89105
}
90106

91107
function setHeartbeatTimeout(uint256 newHeartbeatTimeout) internal onlyOwner {
92108
require(ownerLives());
93-
heartbeatTimeout = newHeartbeatTimeout;
109+
heartbeatTimeout_ = newHeartbeatTimeout;
94110
}
95111

96112
function ownerLives() internal view returns (bool) {
97-
return timeOfDeath == 0;
113+
return timeOfDeath_ == 0;
98114
}
99115
}

0 commit comments

Comments
 (0)