-
Notifications
You must be signed in to change notification settings - Fork 12k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
refactor HasNoTokens.sol to extract reclaimToken #348
Conversation
Love this, but I'm not 100% convinced with the name |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Great idea!
I agree the name is not ideal, but we can keep it if we have nothing better.
* @param tokenAddr address The address of the token contract | ||
*/ | ||
function reclaimToken(address tokenAddr) external onlyOwner { | ||
ERC20Basic tokenInst = ERC20Basic(tokenAddr); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
You can avoid this cast by defining the function to take an ERC20Basic
instance: reclaimToken(ERC20Basic token)
. (I also think token
is a better variable name than tokenInst
.)
test/CanReclaimToken.js
Outdated
let token = null; | ||
let canReclaimToken = null; | ||
|
||
beforeEach(async () => { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Please use a function
expression instead of an arrow function here. (See https://mochajs.org/#arrow-functions)
The cast was already there. Didn't touch the code.
This is not used in the test.
Le mer. 9 août 2017 18:40, Francisco Giordano <[email protected]> a
écrit :
… ***@***.**** requested changes on this pull request.
Great idea!
I agree the name is not ideal, but we can keep it if we have nothing
better.
------------------------------
In contracts/ownership/CanReclaimToken.sol
<#348 (comment)>
:
> +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);
You can avoid this cast by defining the function to take an ERC20Basic
instance: reclaimToken(ERC20Basic token). (I also think token is a better
variable name than tokenInst.)
------------------------------
In test/CanReclaimToken.js
<#348 (comment)>
:
> @@ -0,0 +1,35 @@
+'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 () => {
Please use a function expression instead of an arrow function here. (See
https://mochajs.org/#arrow-functions)
—
You are receiving this because you authored the thread.
Reply to this email directly, view it on GitHub
<#348 (review)>,
or mute the thread
<https://github.com/notifications/unsubscribe-auth/ABsFfNHCepZiUg_kk1RX0ESgCFGmcocCks5sWeD9gaJpZM4OsULr>
.
|
ea7839f
to
51906ba
Compare
Merging this but it may be superceded by the more general |
refactor HasNoTokens.sol to extract reclaimToken
By splitting reclaimToken of HasNoTokens.sol, it can be used on a contract that can receive a specific type of token, or receive them only a certain way (through transferFrom for example) but want to be able to reclaim all others. inheriting from a HasNoTokens on that type of contract seems counter-intuitive?