Commit 7a0bfdfb by trejas Committed by Francisco Giordano

Enhancement/heritable encapsulation #692 (#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
parent f4228f1b
...@@ -11,13 +11,13 @@ import "./Ownable.sol"; ...@@ -11,13 +11,13 @@ import "./Ownable.sol";
* owner's death. * owner's death.
*/ */
contract Heritable is Ownable { contract Heritable is Ownable {
address public heir; address private heir_;
// Time window the owner has to notify they are alive. // Time window the owner has to notify they are alive.
uint256 public heartbeatTimeout; uint256 private heartbeatTimeout_;
// Timestamp of the owner's death, as pronounced by the heir. // Timestamp of the owner's death, as pronounced by the heir.
uint256 public timeOfDeath; uint256 private timeOfDeath_;
event HeirChanged(address indexed owner, address indexed newHeir); event HeirChanged(address indexed owner, address indexed newHeir);
event OwnerHeartbeated(address indexed owner); event OwnerHeartbeated(address indexed owner);
...@@ -29,7 +29,7 @@ contract Heritable is Ownable { ...@@ -29,7 +29,7 @@ contract Heritable is Ownable {
* @dev Throw an exception if called by any account other than the heir's. * @dev Throw an exception if called by any account other than the heir's.
*/ */
modifier onlyHeir() { modifier onlyHeir() {
require(msg.sender == heir); require(msg.sender == heir_);
_; _;
} }
...@@ -47,7 +47,23 @@ contract Heritable is Ownable { ...@@ -47,7 +47,23 @@ contract Heritable is Ownable {
require(newHeir != owner); require(newHeir != owner);
heartbeat(); heartbeat();
HeirChanged(owner, newHeir); HeirChanged(owner, newHeir);
heir = newHeir; heir_ = newHeir;
}
/**
* @dev Use these getter functions to access the internal variables in
* an inherited contract.
*/
function heir() public view returns(address) {
return heir_;
}
function heartbeatTimeout() public view returns(uint256) {
return heartbeatTimeout_;
}
function timeOfDeath() public view returns(uint256) {
return timeOfDeath_;
} }
/** /**
...@@ -55,7 +71,7 @@ contract Heritable is Ownable { ...@@ -55,7 +71,7 @@ contract Heritable is Ownable {
*/ */
function removeHeir() public onlyOwner { function removeHeir() public onlyOwner {
heartbeat(); heartbeat();
heir = 0; heir_ = 0;
} }
/** /**
...@@ -64,8 +80,8 @@ contract Heritable is Ownable { ...@@ -64,8 +80,8 @@ contract Heritable is Ownable {
*/ */
function proclaimDeath() public onlyHeir { function proclaimDeath() public onlyHeir {
require(ownerLives()); require(ownerLives());
OwnerProclaimedDead(owner, heir, timeOfDeath); OwnerProclaimedDead(owner, heir_, timeOfDeath_);
timeOfDeath = now; timeOfDeath_ = block.timestamp;
} }
/** /**
...@@ -73,7 +89,7 @@ contract Heritable is Ownable { ...@@ -73,7 +89,7 @@ contract Heritable is Ownable {
*/ */
function heartbeat() public onlyOwner { function heartbeat() public onlyOwner {
OwnerHeartbeated(owner); OwnerHeartbeated(owner);
timeOfDeath = 0; timeOfDeath_ = 0;
} }
/** /**
...@@ -81,19 +97,19 @@ contract Heritable is Ownable { ...@@ -81,19 +97,19 @@ contract Heritable is Ownable {
*/ */
function claimHeirOwnership() public onlyHeir { function claimHeirOwnership() public onlyHeir {
require(!ownerLives()); require(!ownerLives());
require(now >= timeOfDeath + heartbeatTimeout); require(block.timestamp >= timeOfDeath_ + heartbeatTimeout_);
OwnershipTransferred(owner, heir); OwnershipTransferred(owner, heir_);
HeirOwnershipClaimed(owner, heir); HeirOwnershipClaimed(owner, heir_);
owner = heir; owner = heir_;
timeOfDeath = 0; timeOfDeath_ = 0;
} }
function setHeartbeatTimeout(uint256 newHeartbeatTimeout) internal onlyOwner { function setHeartbeatTimeout(uint256 newHeartbeatTimeout) internal onlyOwner {
require(ownerLives()); require(ownerLives());
heartbeatTimeout = newHeartbeatTimeout; heartbeatTimeout_ = newHeartbeatTimeout;
} }
function ownerLives() internal view returns (bool) { function ownerLives() internal view returns (bool) {
return timeOfDeath == 0; return timeOfDeath_ == 0;
} }
} }
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment