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
406004a9
Commit
406004a9
authored
Aug 03, 2017
by
SylTi
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
refactor HasNoTokens.sol
parent
b50894aa
Show whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
62 additions
and
12 deletions
+62
-12
CanReclaimToken.sol
contracts/ownership/CanReclaimToken.sol
+25
-0
HasNoTokens.sol
contracts/ownership/HasNoTokens.sol
+2
-12
CanReclaimToken.js
test/CanReclaimToken.js
+35
-0
No files found.
contracts/ownership/CanReclaimToken.sol
0 → 100644
View file @
406004a9
pragma solidity ^0.4.11;
import "./Ownable.sol";
import "../token/ERC20Basic.sol";
/**
* @title Contracts that should be able to recover tokens
* @author SylTi
* @dev This allow a contract to recover any ERC20 token received in a contract by transfering the balance to the contract owner.
* This will prevent any accidental loss of tokens.
*/
contract CanReclaimToken is Ownable {
/**
* @dev Reclaim all ERC20Basic compatible tokens
* @param tokenAddr address The address of the token contract
*/
function reclaimToken(address tokenAddr) external onlyOwner {
ERC20Basic tokenInst = ERC20Basic(tokenAddr);
uint256 balance = tokenInst.balanceOf(this);
tokenInst.transfer(owner, balance);
}
}
\ No newline at end of file
contracts/ownership/HasNoTokens.sol
View file @
406004a9
pragma solidity ^0.4.11;
import "./Ownable.sol";
import "../token/ERC20Basic.sol";
import "./CanReclaimToken.sol";
/**
* @title Contracts that should not own Tokens
...
...
@@ -10,7 +9,7 @@ import "../token/ERC20Basic.sol";
* Should tokens (any ERC20Basic compatible) end up in the contract, it allows the
* owner to reclaim the tokens.
*/
contract HasNoTokens is
Ownable
{
contract HasNoTokens is
CanReclaimToken
{
/**
* @dev Reject all ERC23 compatible tokens
...
...
@@ -22,13 +21,4 @@ contract HasNoTokens is Ownable {
revert();
}
/**
* @dev Reclaim all ERC20Basic compatible tokens
* @param tokenAddr address The address of the token contract
*/
function reclaimToken(address tokenAddr) external onlyOwner {
ERC20Basic tokenInst = ERC20Basic(tokenAddr);
uint256 balance = tokenInst.balanceOf(this);
tokenInst.transfer(owner, balance);
}
}
test/CanReclaimToken.js
0 → 100644
View file @
406004a9
'use strict'
;
import
expectThrow
from
'./helpers/expectThrow'
;
import
toPromise
from
'./helpers/toPromise'
;
const
CanReclaimToken
=
artifacts
.
require
(
'../contracts/ownership/CanReclaimToken.sol'
);
const
BasicTokenMock
=
artifacts
.
require
(
"./helpers/BasicTokenMock.sol"
);
contract
(
'CanReclaimToken'
,
function
(
accounts
)
{
let
token
=
null
;
let
canReclaimToken
=
null
;
beforeEach
(
async
()
=>
{
// Create contract and token
token
=
await
BasicTokenMock
.
new
(
accounts
[
0
],
100
);
canReclaimToken
=
await
CanReclaimToken
.
new
();
// Force token into contract
await
token
.
transfer
(
canReclaimToken
.
address
,
10
);
const
startBalance
=
await
token
.
balanceOf
(
canReclaimToken
.
address
);
assert
.
equal
(
startBalance
,
10
);
});
it
(
'should allow owner to reclaim tokens'
,
async
function
()
{
const
ownerStartBalance
=
await
token
.
balanceOf
(
accounts
[
0
]);
await
canReclaimToken
.
reclaimToken
(
token
.
address
);
const
ownerFinalBalance
=
await
token
.
balanceOf
(
accounts
[
0
]);
const
finalBalance
=
await
token
.
balanceOf
(
canReclaimToken
.
address
);
assert
.
equal
(
finalBalance
,
0
);
assert
.
equal
(
ownerFinalBalance
-
ownerStartBalance
,
10
);
});
it
(
'should allow only owner to reclaim tokens'
,
async
function
()
{
await
expectThrow
(
canReclaimToken
.
reclaimToken
(
token
.
address
,
{
from
:
accounts
[
1
]}),
);
});
});
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