Skip to content

Commit

Permalink
Rename variables
Browse files Browse the repository at this point in the history
  • Loading branch information
Jacques Dafflon committed Nov 4, 2018
1 parent 896d077 commit 3092995
Show file tree
Hide file tree
Showing 12 changed files with 51 additions and 44 deletions.
47 changes: 24 additions & 23 deletions contracts/ERC777BaseToken.sol
Original file line number Diff line number Diff line change
Expand Up @@ -20,11 +20,11 @@ contract ERC777BaseToken is ERC777Token, ERC820Implementer {


mapping(address => uint) internal mBalances;
mapping(address => mapping(address => bool)) internal mAuthorized;

address[] internal mDefaultOperators;
mapping(address => bool) internal mIsDefaultOperator;
mapping(address => mapping(address => bool)) internal mRevokedDefaultOperator;
mapping(address => mapping(address => bool)) internal mAuthorizedOperators;

/* -- Constructor -- */
//
Expand All @@ -40,7 +40,7 @@ contract ERC777BaseToken is ERC777Token, ERC820Implementer {
mGranularity = _granularity;

mDefaultOperators = _defaultOperators;
for (uint i = 0; i < mDefaultOperators.length; i++) { mIsDefaultOperator[mDefaultOperators[i]] = true; }
for (uint256 i = 0; i < mDefaultOperators.length; i++) { mIsDefaultOperator[mDefaultOperators[i]] = true; }

setInterfaceImplementation("ERC777Token", this);
}
Expand Down Expand Up @@ -68,11 +68,11 @@ contract ERC777BaseToken is ERC777Token, ERC820Implementer {
/// @return the list of all the default operators
function defaultOperators() public view returns (address[]) { return mDefaultOperators; }

/// @notice Send `_amount` of tokens to address `_to` passing `_userData` to the recipient
/// @notice Send `_amount` of tokens to address `_to` passing `_holderData` to the recipient
/// @param _to The address of the recipient
/// @param _amount The number of tokens to be sent
function send(address _to, uint256 _amount, bytes _userData) public {
doSend(msg.sender, msg.sender, _to, _amount, _userData, "", true);
function send(address _to, uint256 _amount, bytes _holderData) public {
doSend(msg.sender, msg.sender, _to, _amount, _holderData, "", true);
}

/// @notice Authorize a third party `_operator` to manage (send) `msg.sender`'s tokens.
Expand All @@ -82,7 +82,7 @@ contract ERC777BaseToken is ERC777Token, ERC820Implementer {
if (mIsDefaultOperator[_operator]) {
mRevokedDefaultOperator[_operator][msg.sender] = false;
} else {
mAuthorized[_operator][msg.sender] = true;
mAuthorizedOperators[_operator][msg.sender] = true;
}
AuthorizedOperator(_operator, msg.sender);
}
Expand All @@ -94,7 +94,7 @@ contract ERC777BaseToken is ERC777Token, ERC820Implementer {
if (mIsDefaultOperator[_operator]) {
mRevokedDefaultOperator[_operator][msg.sender] = true;
} else {
mAuthorized[_operator][msg.sender] = false;
mAuthorizedOperators[_operator][msg.sender] = false;
}
RevokedOperator(_operator, msg.sender);
}
Expand All @@ -105,19 +105,19 @@ contract ERC777BaseToken is ERC777Token, ERC820Implementer {
/// @return `true` if `_operator` is authorized for `_tokenHolder`
function isOperatorFor(address _operator, address _tokenHolder) public constant returns (bool) {
return (_operator == _tokenHolder
|| mAuthorized[_operator][_tokenHolder]
|| mAuthorizedOperators[_operator][_tokenHolder]
|| (mIsDefaultOperator[_operator] && !mRevokedDefaultOperator[_operator][_tokenHolder]));
}

/// @notice Send `_amount` of tokens on behalf of the address `from` to the address `to`.
/// @param _from The address holding the tokens being sent
/// @param _to The address of the recipient
/// @param _amount The number of tokens to be sent
/// @param _userData Data generated by the user to be sent to the recipient
/// @param _holderData Data generated by the user to be sent to the recipient
/// @param _operatorData Data generated by the operator to be sent to the recipient
function operatorSend(address _from, address _to, uint256 _amount, bytes _userData, bytes _operatorData) public {
function operatorSend(address _from, address _to, uint256 _amount, bytes _holderData, bytes _operatorData) public {
require(isOperatorFor(msg.sender, _from));
doSend(msg.sender, _from, _to, _amount, _userData, _operatorData, true);
doSend(msg.sender, _from, _to, _amount, _holderData, _operatorData, true);
}

function burn(uint256 _amount, bytes _holderData) public {
Expand Down Expand Up @@ -152,36 +152,36 @@ contract ERC777BaseToken is ERC777Token, ERC820Implementer {
/// @param _from The address holding the tokens being sent
/// @param _to The address of the recipient
/// @param _amount The number of tokens to be sent
/// @param _userData Data generated by the user to be passed to the recipient
/// @param _holderData Data generated by the user to be passed to the recipient
/// @param _operatorData Data generated by the operator to be passed to the recipient
/// @param _preventLocking `true` if you want this function to throw when tokens are sent to a contract not
/// implementing `erc777_tokenHolder`.
/// implementing `ERC777tokensRecipient`.
/// ERC777 native Send functions MUST set this parameter to `true`, and backwards compatible ERC20 transfer
/// functions SHOULD set this parameter to `false`.
function doSend(
address _operator,
address _from,
address _to,
uint256 _amount,
bytes _userData,
bytes _holderData,
bytes _operatorData,
bool _preventLocking
)
internal
{
requireMultiple(_amount);

callSender(_operator, _from, _to, _amount, _userData, _operatorData);
callSender(_operator, _from, _to, _amount, _holderData, _operatorData);

require(_to != address(0)); // forbid sending to 0x0 (=burning)
require(mBalances[_from] >= _amount); // ensure enough funds

mBalances[_from] = mBalances[_from].sub(_amount);
mBalances[_to] = mBalances[_to].add(_amount);

callRecipient(_operator, _from, _to, _amount, _userData, _operatorData, _preventLocking);
callRecipient(_operator, _from, _to, _amount, _holderData, _operatorData, _preventLocking);

Sent(_operator, _from, _to, _amount, _userData, _operatorData);
Sent(_operator, _from, _to, _amount, _holderData, _operatorData);
}

/// @notice Helper function actually performing the burning of tokens.
Expand Down Expand Up @@ -209,7 +209,7 @@ contract ERC777BaseToken is ERC777Token, ERC820Implementer {
/// @param _from The address holding the tokens being sent
/// @param _to The address of the recipient
/// @param _amount The number of tokens to be sent
/// @param _userData Data generated by the user to be passed to the recipient
/// @param _holderData Data generated by the user to be passed to the recipient
/// @param _operatorData Data generated by the operator to be passed to the recipient
/// @param _preventLocking `true` if you want this function to throw when tokens are sent to a contract not
/// implementing `ERC777TokensRecipient`.
Expand All @@ -220,7 +220,7 @@ contract ERC777BaseToken is ERC777Token, ERC820Implementer {
address _from,
address _to,
uint256 _amount,
bytes _userData,
bytes _holderData,
bytes _operatorData,
bool _preventLocking
)
Expand All @@ -229,7 +229,7 @@ contract ERC777BaseToken is ERC777Token, ERC820Implementer {
address recipientImplementation = interfaceAddr(_to, "ERC777TokensRecipient");
if (recipientImplementation != 0) {
ERC777TokensRecipient(recipientImplementation).tokensReceived(
_operator, _from, _to, _amount, _userData, _operatorData);
_operator, _from, _to, _amount, _holderData, _operatorData);
} else if (_preventLocking) {
require(isRegularAddress(_to));
}
Expand All @@ -240,7 +240,7 @@ contract ERC777BaseToken is ERC777Token, ERC820Implementer {
/// @param _from The address holding the tokens being sent
/// @param _to The address of the recipient
/// @param _amount The amount of tokens to be sent
/// @param _userData Data generated by the user to be passed to the recipient
/// @param _holderData Data generated by the user to be passed to the recipient
/// @param _operatorData Data generated by the operator to be passed to the recipient
/// implementing `ERC777TokensSender`.
/// ERC777 native Send functions MUST set this parameter to `true`, and backwards compatible ERC20 transfer
Expand All @@ -250,13 +250,14 @@ contract ERC777BaseToken is ERC777Token, ERC820Implementer {
address _from,
address _to,
uint256 _amount,
bytes _userData,
bytes _holderData,
bytes _operatorData
)
internal
{
address senderImplementation = interfaceAddr(_from, "ERC777TokensSender");
if (senderImplementation == 0) { return; }
ERC777TokensSender(senderImplementation).tokensToSend(_operator, _from, _to, _amount, _userData, _operatorData);
ERC777TokensSender(senderImplementation).tokensToSend(
_operator, _from, _to, _amount, _holderData, _operatorData);
}
}
5 changes: 2 additions & 3 deletions contracts/ERC777ERC20BaseToken.sol
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,6 @@ import { ERC777BaseToken } from "./ERC777BaseToken.sol";
contract ERC777ERC20BaseToken is ERC20Token, ERC777BaseToken {
bool internal mErc20compatible;

mapping(address => mapping(address => bool)) internal mAuthorized;
mapping(address => mapping(address => uint256)) internal mAllowed;

function ERC777ERC20BaseToken(
Expand Down Expand Up @@ -87,13 +86,13 @@ contract ERC777ERC20BaseToken is ERC20Token, ERC777BaseToken {
address _from,
address _to,
uint256 _amount,
bytes _userData,
bytes _holderData,
bytes _operatorData,
bool _preventLocking
)
internal
{
super.doSend(_operator, _from, _to, _amount, _userData, _operatorData, _preventLocking);
super.doSend(_operator, _from, _to, _amount, _holderData, _operatorData, _preventLocking);
if (mErc20compatible) { Transfer(_from, _to, _amount); }
}

Expand Down
2 changes: 1 addition & 1 deletion contracts/ERC777TokensRecipient.sol
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ interface ERC777TokensRecipient {
address from,
address to,
uint amount,
bytes userData,
bytes holderData,
bytes operatorData
) public;
}
2 changes: 1 addition & 1 deletion contracts/examples/ExampleTokensRecipient.sol
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ contract ExampleTokensRecipient is ERC820Implementer, ERC820ImplementerInterface
address from,
address to,
uint amount,
bytes userData,
bytes holderData,
bytes operatorData
) // solhint-enable no-unused-vars
public
Expand Down
2 changes: 1 addition & 1 deletion contracts/examples/ExampleTokensSender.sol
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ contract ExampleTokensSender is ERC820Implementer, ERC820ImplementerInterface, E
address from,
address to,
uint amount,
bytes userData,
bytes holderData,
bytes operatorData
) // solhint-enable no-unused-vars
public {
Expand Down
2 changes: 1 addition & 1 deletion contracts/examples/ReferenceToken.sol
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,7 @@ contract ReferenceToken is ERC777ERC20BaseToken, Ownable {
if (mErc20compatible) { Transfer(0x0, _tokenHolder, _amount); }
}

/// @notice Burns `_amount` tokens from `_tokenHolder`
/// @notice Burns `_amount` tokens from `msg.sender`
/// Silly example of overriding the `burn` function to only let the owner burn its tokens.
/// Do not forget to override the `burn` function in your token contract if you want to prevent users from
/// burning their tokens.
Expand Down
3 changes: 3 additions & 0 deletions test/ReferenceToken.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,9 @@ contract('ReferenceToken', function(accounts) {
const provider = new URL(this.web3.currentProvider.host);
provider.protocol = 'ws';
const web3 = new Web3(provider.toString());

accounts = accounts.map(web3.utils.toChecksumAddress); // normalize addresses

const ReferenceToken = new web3.eth.Contract(
OldReferenceToken.abi,
{ data: OldReferenceToken.bytecode }
Expand Down
3 changes: 2 additions & 1 deletion test/utils/erc20Compatibility.js
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,7 @@ exports.test = function(web3, accounts, token) {
});

it(`should approve ${utils.formatAccount(accounts[3])} ` +
`to send 3.5 ${token.symbol}` +
`to transfer 3.5 ${token.symbol}` +
` from ${utils.formatAccount(accounts[1])}`, async function() {
await utils.assertTotalSupply(web3, token, 10 * accounts.length);
await utils.assertBalance(web3, token, accounts[1], 10);
Expand All @@ -60,6 +60,7 @@ exports.test = function(web3, accounts, token) {
.send({ gas: 300000, from: accounts[1] });

await utils.getBlock(web3);

const allowance = await token.contract.methods
.allowance(accounts[1], accounts[3])
.call();
Expand Down
20 changes: 10 additions & 10 deletions test/utils/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,16 +5,16 @@ const chai = require('chai');
const assert = chai.assert;
const ERC820Registry = artifacts.require('ERC820Registry');
const testAccounts = [
'0x093d49d617a10f26915553255ec3fee532d2c12f',
'0x1dc728786e09f862e39be1f39dd218ee37feb68d',
'0x2eedf8a799b73bc02e4664183eb72422c377153b',
'0x3bf958fa0626e898f548a8f95cf9ab3a4db65169',
'0x4bd1280852cadb002734647305afc1db7ddd6acb',
'0x5ce162cfa6208d7c50a7cb3525ac126155e7bce4',
'0x6b09d6433a379752157fd1a9e537c5cae5fa3168',
'0x7dc0a40d64d72bb4590652b8f5c687bf7f26400c',
'0x8df64de79608f0ae9e72ecae3a400582aed8101c',
'0x9a5279029e9a2d6e787c5a09cb068ab3d45e209d',
'0x093d49D617a10F26915553255Ec3FEE532d2C12F',
'0x1dc728786E09F862E39Be1f39dD218EE37feB68D',
'0x2eeDf8a799B73BC02E4664183eB72422C377153B',
'0x3bF958Fa0626e898F548a8F95Cf9AB3A4Db65169',
'0x4bd1280852Cadb002734647305AFC1db7ddD6Acb',
'0x5cE162cFa6208d7c50A7cB3525AC126155e7bCe4',
'0x6b09D6433a379752157fD1a9E537c5CAe5fa3168',
'0x7dc0a40D64d72bb4590652B8f5C687bF7F26400c',
'0x8dF64de79608F0aE9e72ECAe3A400582AeD8101C',
'0x9a5279029e9A2D6E787c5A09CB068AB3D45e209d'
];
const blocks = [];
let blockIdx = 0;
Expand Down
3 changes: 2 additions & 1 deletion test/utils/mint.js
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,8 @@ exports.test = function(web3, accounts, token) {
);

it(`should mint 10 ${token.symbol} for ` +
`${utils.formatAccount(accounts[1])} (ERC20 disabled)`, async function() {
`${utils.formatAccount(accounts[1])} ` +
'(ERC20 Disabled)', async function() {
await utils.assertBalance(web3, token, accounts[1], 0);

await token.disableERC20();
Expand Down
2 changes: 1 addition & 1 deletion test/utils/operator.js
Original file line number Diff line number Diff line change
Expand Up @@ -162,7 +162,7 @@ exports.test = function(web3, accounts, token) {
});

it(`should not let ${utils.formatAccount(accounts[3])} revoke itself ` +
'as one of his own operators', async function() {
'as one of its own operators', async function() {
await utils.assertTotalSupply(web3, token, 10 * accounts.length);
await utils.assertBalance(web3, token, accounts[3], 10);

Expand Down
4 changes: 3 additions & 1 deletion test/utils/tokensSender.js
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,9 @@ exports.test = function(web3, accounts, token) {
assert.ok(sender.options.address);
});

it('should notify the sender before sending tokens', async function() {
it('should notify the token holder before sending tokens', async function() {
const sender = await deployTokensSender(true, accounts[4]);

await utils.assertTotalSupply(web3, token, 10 * accounts.length);
await utils.assertBalance(web3, token, accounts[4], 10);
await utils.assertBalance(web3, token, accounts[5], 10);
Expand Down

0 comments on commit 3092995

Please sign in to comment.