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
52b6181d
Commit
52b6181d
authored
Nov 30, 2017
by
zava
Committed by
Alejandro Santander
Jan 18, 2018
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
renamed Inheritable --> Heritable
parent
fe712c67
Show whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
45 additions
and
44 deletions
+45
-44
SimpleSavingsWallet.sol
contracts/examples/SimpleSavingsWallet.sol
+6
-5
Heritable.sol
contracts/ownership/Heritable.sol
+7
-7
Heritable.js
test/Heritable.js
+32
-32
No files found.
contracts/examples/SimpleSavingsWallet.sol
View file @
52b6181d
pragma solidity ^0.4.11;
import "../ownership/
Inh
eritable.sol";
import "../ownership/
H
eritable.sol";
/**
* @title SimpleSavingsWallet
* @dev Simplest form of savings wallet that can be inherited if owner dies.
* @dev Simplest form of savings wallet whose ownership can be claimed by a heir
* if owner dies.
* In this example, we take a very simple savings wallet providing two operations
* (to send and receive funds) and extend its capabilities by making it
Inh
eritable.
* (to send and receive funds) and extend its capabilities by making it
H
eritable.
* The account that creates the contract is set as owner, who has the authority to
* choose an heir account. Heir account can reclaim the contract ownership in the
* case that the owner dies.
*/
contract SimpleSavingsWallet is
Inh
eritable {
contract SimpleSavingsWallet is
H
eritable {
event Sent(address payee, uint amount, uint balance);
event Received(address payer, uint amount, uint balance);
function SimpleSavingsWallet(uint _heartbeatTimeout)
Inh
eritable(_heartbeatTimeout) public {}
function SimpleSavingsWallet(uint _heartbeatTimeout)
H
eritable(_heartbeatTimeout) public {}
/**
* @dev wallet can receive funds.
...
...
contracts/ownership/
Inh
eritable.sol
→
contracts/ownership/
H
eritable.sol
View file @
52b6181d
...
...
@@ -5,12 +5,12 @@ import './Ownable.sol';
/**
* @title
Inh
eritable
* @dev The
Inh
eritable contract provides ownership transfer capabilities, in the
* @title
H
eritable
* @dev The
H
eritable contract provides ownership transfer capabilities, in the
* case that the current owner stops "heartbeating". Only the heir can pronounce the
* owner's death.
*/
contract
Inh
eritable is Ownable {
contract
H
eritable is Ownable {
address public heir;
// Time window the owner has to notify they are alive.
...
...
@@ -35,11 +35,11 @@ contract Inheritable is Ownable {
/**
* @notice Create a new
Inh
eritable Contract with heir address 0x0.
* @notice Create a new
H
eritable Contract with heir address 0x0.
* @param _heartbeatTimeout time available for the owner to notify they are alive,
* before the heir can take ownership.
*/
function
Inh
eritable(uint _heartbeatTimeout) public {
function
H
eritable(uint _heartbeatTimeout) public {
setHeartbeatTimeout(_heartbeatTimeout);
}
...
...
@@ -59,7 +59,7 @@ contract Inheritable is Ownable {
}
/**
* @dev Heir can pronounce the owners death. To
inherit
the ownership, they will
* @dev Heir can pronounce the owners death. To
claim
the ownership, they will
* have to wait for `heartbeatTimeout` seconds.
*/
function proclaimDeath() public onlyHeir {
...
...
@@ -79,7 +79,7 @@ contract Inheritable is Ownable {
/**
* @dev Allows heir to transfer ownership only if heartbeat has timed out.
*/
function
inherit
() public onlyHeir {
function
claimHeirOwnership
() public onlyHeir {
require(!ownerLives());
require(now >= timeOfDeath + heartbeatTimeout);
OwnershipTransferred(owner, heir);
...
...
test/
Inh
eritable.js
→
test/
H
eritable.js
View file @
52b6181d
...
...
@@ -4,19 +4,19 @@ import expectThrow from './helpers/expectThrow';
const
NULL_ADDRESS
=
'0x0000000000000000000000000000000000000000'
const
Inheritable
=
artifacts
.
require
(
'../contracts/ownership/Inh
eritable.sol'
)
const
Heritable
=
artifacts
.
require
(
'../contracts/ownership/H
eritable.sol'
)
contract
(
'
Inh
eritable'
,
function
(
accounts
)
{
let
in
heritable
contract
(
'
H
eritable'
,
function
(
accounts
)
{
let
heritable
let
owner
beforeEach
(
async
function
()
{
inheritable
=
await
Inh
eritable
.
new
(
4141
)
owner
=
await
in
heritable
.
owner
()
heritable
=
await
H
eritable
.
new
(
4141
)
owner
=
await
heritable
.
owner
()
})
it
(
'should start off with an owner, but without heir'
,
async
function
()
{
const
heir
=
await
in
heritable
.
heir
()
const
heir
=
await
heritable
.
heir
()
assert
.
equal
(
typeof
(
owner
),
'string'
)
assert
.
equal
(
typeof
(
heir
),
'string'
)
...
...
@@ -35,72 +35,72 @@ contract('Inheritable', function(accounts) {
const
someRandomAddress
=
accounts
[
2
]
assert
.
isTrue
(
owner
!==
someRandomAddress
)
await
in
heritable
.
setHeir
(
newHeir
,
{
from
:
owner
})
await
expectThrow
(
in
heritable
.
setHeir
(
newHeir
,
{
from
:
someRandomAddress
}))
await
heritable
.
setHeir
(
newHeir
,
{
from
:
owner
})
await
expectThrow
(
heritable
.
setHeir
(
newHeir
,
{
from
:
someRandomAddress
}))
})
it
(
'owner can remove heir'
,
async
function
()
{
const
newHeir
=
accounts
[
1
]
await
in
heritable
.
setHeir
(
newHeir
,
{
from
:
owner
})
let
heir
=
await
in
heritable
.
heir
()
await
heritable
.
setHeir
(
newHeir
,
{
from
:
owner
})
let
heir
=
await
heritable
.
heir
()
assert
.
notStrictEqual
(
heir
,
NULL_ADDRESS
)
await
in
heritable
.
removeHeir
()
heir
=
await
in
heritable
.
heir
()
await
heritable
.
removeHeir
()
heir
=
await
heritable
.
heir
()
assert
.
isTrue
(
heir
===
NULL_ADDRESS
)
})
it
(
'heir can
inherit
only if owner is dead and timeout was reached'
,
async
function
()
{
it
(
'heir can
claim ownership
only if owner is dead and timeout was reached'
,
async
function
()
{
const
heir
=
accounts
[
1
]
await
in
heritable
.
setHeir
(
heir
,
{
from
:
owner
})
await
expectThrow
(
inheritable
.
inherit
({
from
:
heir
}))
await
heritable
.
setHeir
(
heir
,
{
from
:
owner
})
await
expectThrow
(
heritable
.
claimHeirOwnership
({
from
:
heir
}))
await
in
heritable
.
proclaimDeath
({
from
:
heir
})
await
heritable
.
proclaimDeath
({
from
:
heir
})
await
increaseTime
(
1
)
await
expectThrow
(
inheritable
.
inherit
({
from
:
heir
}))
await
expectThrow
(
heritable
.
claimHeirOwnership
({
from
:
heir
}))
await
increaseTime
(
4141
)
await
inheritable
.
inherit
({
from
:
heir
})
assert
.
isTrue
(
await
in
heritable
.
heir
()
===
heir
)
await
heritable
.
claimHeirOwnership
({
from
:
heir
})
assert
.
isTrue
(
await
heritable
.
heir
()
===
heir
)
})
it
(
'heir can
\'
t
inherit
if owner heartbeats'
,
async
function
()
{
it
(
'heir can
\'
t
claim ownership
if owner heartbeats'
,
async
function
()
{
const
heir
=
accounts
[
1
]
await
in
heritable
.
setHeir
(
heir
,
{
from
:
owner
})
await
heritable
.
setHeir
(
heir
,
{
from
:
owner
})
await
in
heritable
.
proclaimDeath
({
from
:
heir
})
await
in
heritable
.
heartbeat
({
from
:
owner
})
await
expectThrow
(
inheritable
.
inherit
({
from
:
heir
}))
await
heritable
.
proclaimDeath
({
from
:
heir
})
await
heritable
.
heartbeat
({
from
:
owner
})
await
expectThrow
(
heritable
.
claimHeirOwnership
({
from
:
heir
}))
await
in
heritable
.
proclaimDeath
({
from
:
heir
})
await
heritable
.
proclaimDeath
({
from
:
heir
})
await
increaseTime
(
4141
)
await
in
heritable
.
heartbeat
({
from
:
owner
})
await
expectThrow
(
inheritable
.
inherit
({
from
:
heir
}))
await
heritable
.
heartbeat
({
from
:
owner
})
await
expectThrow
(
heritable
.
claimHeirOwnership
({
from
:
heir
}))
})
it
(
'should log events appropriately'
,
async
function
()
{
const
heir
=
accounts
[
1
]
const
setHeirLogs
=
(
await
in
heritable
.
setHeir
(
heir
,
{
from
:
owner
})).
logs
const
setHeirLogs
=
(
await
heritable
.
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
in
heritable
.
heartbeat
({
from
:
owner
})).
logs
const
heartbeatLogs
=
(
await
heritable
.
heartbeat
({
from
:
owner
})).
logs
const
heartbeatEvent
=
heartbeatLogs
.
find
(
e
=>
e
.
event
===
'OwnerHeartbeated'
)
assert
.
isTrue
(
heartbeatEvent
.
args
.
owner
===
owner
)
const
proclaimDeathLogs
=
(
await
in
heritable
.
proclaimDeath
({
from
:
heir
})).
logs
const
proclaimDeathLogs
=
(
await
heritable
.
proclaimDeath
({
from
:
heir
})).
logs
const
ownerDeadEvent
=
proclaimDeathLogs
.
find
(
e
=>
e
.
event
===
'OwnerProclaimedDead'
)
assert
.
isTrue
(
ownerDeadEvent
.
args
.
owner
===
owner
)
assert
.
isTrue
(
ownerDeadEvent
.
args
.
heir
===
heir
)
await
increaseTime
(
4141
)
const
inheritLogs
=
(
await
inheritable
.
inherit
({
from
:
heir
})).
logs
const
ownershipTransferredEvent
=
inherit
Logs
.
find
(
e
=>
e
.
event
===
'OwnershipTransferred'
)
const
claimHeirOwnershipLogs
=
(
await
heritable
.
claimHeirOwnership
({
from
:
heir
})).
logs
const
ownershipTransferredEvent
=
claimHeirOwnership
Logs
.
find
(
e
=>
e
.
event
===
'OwnershipTransferred'
)
assert
.
isTrue
(
ownershipTransferredEvent
.
args
.
previousOwner
===
owner
)
assert
.
isTrue
(
ownershipTransferredEvent
.
args
.
newOwner
===
heir
)
...
...
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