Skip to content
Projects
Groups
Snippets
Help
This project
Loading...
Sign in / Register
Toggle navigation
O
openzeppelin-contracts-upgradeable
Overview
Overview
Details
Activity
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
俞永鹏
openzeppelin-contracts-upgradeable
Commits
b709206f
Commit
b709206f
authored
Nov 24, 2017
by
zava
Committed by
Alejandro Santander
Jan 18, 2018
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
fixes
parent
2a560ad8
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
41 additions
and
16 deletions
+41
-16
Inheritable.sol
contracts/ownership/Inheritable.sol
+15
-9
Inheritable.js
test/Inheritable.js
+26
-7
No files found.
contracts/ownership/Inheritable.sol
View file @
b709206f
...
...
@@ -13,14 +13,16 @@ import './Ownable.sol';
contract Inheritable is Ownable {
address public heir;
// Time window the owner has to notify
she is
alive.
// Time window the owner has to notify
they are
alive.
uint public heartbeatTimeout;
// Timestamp of the owner's death, as pronounced by the heir.
uint public timeOfDeath;
event OwnerPronouncedDead(address indexed owner, address indexed heir, uint indexed timeOfDeath);
event HeirChanged(address indexed owner, address indexed newHeir);
event OwnerHeartbeated(address indexed owner);
event OwnerPronouncedDead(address indexed owner, address indexed heir, uint timeOfDeath);
/**
...
...
@@ -34,7 +36,7 @@ contract Inheritable is Ownable {
/**
* @notice Create a new Inheritable Contract with heir address 0x0.
* @param _heartbeatTimeout time available for the owner to notify
she's
alive,
* @param _heartbeatTimeout time available for the owner to notify
they are
alive,
* before the heir can take ownership.
*/
function Inheritable(uint _heartbeatTimeout) public {
...
...
@@ -42,6 +44,8 @@ contract Inheritable is Ownable {
}
function setHeir(address newHeir) public onlyOwner {
heartbeat();
HeirChanged(owner, newHeir);
heir = newHeir;
}
...
...
@@ -49,7 +53,8 @@ contract Inheritable is Ownable {
* @dev set heir = 0x0
*/
function removeHeir() public onlyOwner {
delete(heir);
heartbeat();
heir = 0;
}
function setHeartbeatTimeout(uint newHeartbeatTimeout) public onlyOwner {
...
...
@@ -58,20 +63,21 @@ contract Inheritable is Ownable {
}
/**
* @dev Heir can pronounce the owners death. To inherit the ownership,
he
will
* @dev Heir can pronounce the owners death. To inherit the ownership,
they
will
* have to wait for `heartbeatTimeout` seconds.
*/
function pronounceDeath() public onlyHeir {
require(ownerLives());
timeOfDeath = now;
OwnerPronouncedDead(owner, heir, timeOfDeath);
timeOfDeath = now;
}
/**
* @dev Owner can send a heartbeat if
she was
mistakenly pronounced dead.
* @dev Owner can send a heartbeat if
they were
mistakenly pronounced dead.
*/
function heartbeat() public onlyOwner {
delete(timeOfDeath);
OwnerHeartbeated(owner);
timeOfDeath = 0;
}
/**
...
...
@@ -82,7 +88,7 @@ contract Inheritable is Ownable {
require(now >= timeOfDeath + heartbeatTimeout);
OwnershipTransferred(owner, heir);
owner = heir;
delete(timeOfDeath)
;
timeOfDeath = 0
;
}
function ownerLives() internal returns (bool) {
...
...
test/Inheritable.js
View file @
b709206f
...
...
@@ -58,7 +58,7 @@ contract('Inheritable', function(accounts) {
assert
.
isTrue
(
heir
===
NULL_ADDRESS
)
})
it
(
'owner can set heartbeatTimeout only if
she
\'
s
alive'
,
async
function
()
{
it
(
'owner can set heartbeatTimeout only if
they are
alive'
,
async
function
()
{
const
newTimeout
=
41414141
await
inheritable
.
setHeartbeatTimeout
(
newTimeout
,
{
from
:
owner
})
...
...
@@ -127,13 +127,31 @@ contract('Inheritable', function(accounts) {
}
})
it
(
'should log
owner dead and ownership transfer
'
,
async
function
()
{
it
(
'should log
events appropriately
'
,
async
function
()
{
const
heir
=
accounts
[
1
]
await
inheritable
.
setHeir
(
heir
,
{
from
:
owner
})
const
{
logs
}
=
await
inheritable
.
pronounceDeath
({
from
:
heir
})
const
event
=
logs
.
find
(
e
=>
e
.
event
===
'OwnerPronouncedDead'
)
assert
.
isTrue
(
event
.
args
.
owner
===
owner
)
assert
.
isTrue
(
event
.
args
.
heir
===
heir
)
const
setHeirLogs
=
(
await
inheritable
.
setHeir
(
heir
,
{
from
:
owner
})).
logs
const
setHeirEvent
=
setHeirLogs
.
find
(
e
=>
e
.
event
===
'HeirChanged'
)
assert
.
isTrue
(
setHeirEvent
.
args
.
owner
===
owner
)
assert
.
isTrue
(
setHeirEvent
.
args
.
newHeir
===
heir
)
const
heartbeatLogs
=
(
await
inheritable
.
heartbeat
({
from
:
owner
})).
logs
const
heartbeatEvent
=
heartbeatLogs
.
find
(
e
=>
e
.
event
===
'OwnerHeartbeated'
)
assert
.
isTrue
(
heartbeatEvent
.
args
.
owner
===
owner
)
const
pronounceDeathLogs
=
(
await
inheritable
.
pronounceDeath
({
from
:
heir
})).
logs
const
ownerDeadEvent
=
pronounceDeathLogs
.
find
(
e
=>
e
.
event
===
'OwnerPronouncedDead'
)
assert
.
isTrue
(
ownerDeadEvent
.
args
.
owner
===
owner
)
assert
.
isTrue
(
ownerDeadEvent
.
args
.
heir
===
heir
)
const
inheritLogs
=
(
await
inheritable
.
inherit
({
from
:
heir
})).
logs
const
ownershipTransferredEvent
=
inheritLogs
.
find
(
e
=>
e
.
event
===
'OwnershipTransferred'
)
assert
.
isTrue
(
ownershipTransferredEvent
.
args
.
previousOwner
===
owner
)
assert
.
isTrue
(
ownershipTransferredEvent
.
args
.
newOwner
===
heir
)
})
})
\ No newline at end of file
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment