Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
18 changes: 18 additions & 0 deletions CODE_STYLE.md
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,24 @@ Any exception or additions specific to our project are documented below.
}
```

* Internal and private state variables should have an underscore suffix.

```
contract TestContract {
uint256 internal internalVar_;
uint256 private privateVar_;
}
```

Variables declared in a function should not follow this rule.

```
function test() {
uint256 functionVar;
...
}
```

* Events should be emitted immediately after the state change that they
represent, and consequently they should be named in past tense.

Expand Down
14 changes: 7 additions & 7 deletions contracts/crowdsale/distribution/RefundableCrowdsale.sol
Original file line number Diff line number Diff line change
Expand Up @@ -18,15 +18,15 @@ contract RefundableCrowdsale is FinalizableCrowdsale {
uint256 public goal;

// refund escrow used to hold funds while crowdsale is running
RefundEscrow private escrow;
RefundEscrow private escrow_;

/**
* @dev Constructor, creates RefundEscrow.
* @param _goal Funding goal
*/
constructor(uint256 _goal) public {
require(_goal > 0);
escrow = new RefundEscrow(wallet);
escrow_ = new RefundEscrow(wallet);
goal = _goal;
}

Expand All @@ -37,7 +37,7 @@ contract RefundableCrowdsale is FinalizableCrowdsale {
require(isFinalized);
require(!goalReached());

escrow.withdraw(msg.sender);
escrow_.withdraw(msg.sender);
}

/**
Expand All @@ -53,10 +53,10 @@ contract RefundableCrowdsale is FinalizableCrowdsale {
*/
function finalization() internal {
if (goalReached()) {
escrow.close();
escrow.beneficiaryWithdraw();
escrow_.close();
escrow_.beneficiaryWithdraw();
} else {
escrow.enableRefunds();
escrow_.enableRefunds();
}

super.finalization();
Expand All @@ -66,7 +66,7 @@ contract RefundableCrowdsale is FinalizableCrowdsale {
* @dev Overrides Crowdsale fund forwarding, sending funds to escrow.
*/
function _forwardFunds() internal {
escrow.deposit.value(msg.value)(msg.sender);
escrow_.deposit.value(msg.value)(msg.sender);
}

}
6 changes: 3 additions & 3 deletions contracts/introspection/SupportsInterfaceWithLookup.sol
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ contract SupportsInterfaceWithLookup is ERC165 {
/**
* @dev a mapping of interface id to whether or not it's supported
*/
mapping(bytes4 => bool) internal supportedInterfaces;
mapping(bytes4 => bool) internal supportedInterfaces_;

/**
* @dev A contract implementing SupportsInterfaceWithLookup
Expand All @@ -39,7 +39,7 @@ contract SupportsInterfaceWithLookup is ERC165 {
view
returns (bool)
{
return supportedInterfaces[_interfaceId];
return supportedInterfaces_[_interfaceId];
}

/**
Expand All @@ -49,6 +49,6 @@ contract SupportsInterfaceWithLookup is ERC165 {
internal
{
require(_interfaceId != 0xffffffff);
supportedInterfaces[_interfaceId] = true;
supportedInterfaces_[_interfaceId] = true;
}
}
12 changes: 6 additions & 6 deletions contracts/mocks/ERC721ReceiverMock.sol
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,8 @@ import "../token/ERC721/ERC721Receiver.sol";


contract ERC721ReceiverMock is ERC721Receiver {
bytes4 retval;
bool reverts;
bytes4 retval_;
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can we make the visibility explicit here (and add a Solium rule if possible)?

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

That should be a separate issue:
#1250

bool reverts_;

event Received(
address _operator,
Expand All @@ -16,8 +16,8 @@ contract ERC721ReceiverMock is ERC721Receiver {
);

constructor(bytes4 _retval, bool _reverts) public {
retval = _retval;
reverts = _reverts;
retval_ = _retval;
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Reading this made me die a little on the inside 😒

reverts_ = _reverts;
}

function onERC721Received(
Expand All @@ -29,14 +29,14 @@ contract ERC721ReceiverMock is ERC721Receiver {
public
returns(bytes4)
{
require(!reverts);
require(!reverts_);
emit Received(
_operator,
_from,
_tokenId,
_data,
gasleft() // msg.gas was deprecated in solidityv0.4.21
);
return retval;
return retval_;
}
}
10 changes: 5 additions & 5 deletions contracts/payment/Escrow.sol
Original file line number Diff line number Diff line change
Expand Up @@ -17,10 +17,10 @@ contract Escrow is Ownable {
event Deposited(address indexed payee, uint256 weiAmount);
event Withdrawn(address indexed payee, uint256 weiAmount);

mapping(address => uint256) private deposits;
mapping(address => uint256) private deposits_;

function depositsOf(address _payee) public view returns (uint256) {
return deposits[_payee];
return deposits_[_payee];
}

/**
Expand All @@ -29,7 +29,7 @@ contract Escrow is Ownable {
*/
function deposit(address _payee) public onlyOwner payable {
uint256 amount = msg.value;
deposits[_payee] = deposits[_payee].add(amount);
deposits_[_payee] = deposits_[_payee].add(amount);

emit Deposited(_payee, amount);
}
Expand All @@ -39,10 +39,10 @@ contract Escrow is Ownable {
* @param _payee The address whose funds will be withdrawn and transferred to.
*/
function withdraw(address _payee) public onlyOwner {
uint256 payment = deposits[_payee];
uint256 payment = deposits_[_payee];
assert(address(this).balance >= payment);

deposits[_payee] = 0;
deposits_[_payee] = 0;

_payee.transfer(payment);

Expand Down
55 changes: 28 additions & 27 deletions contracts/token/ERC20/StandardToken.sol
Original file line number Diff line number Diff line change
Expand Up @@ -14,9 +14,9 @@ import "../../math/SafeMath.sol";
contract StandardToken is ERC20 {
using SafeMath for uint256;

mapping (address => uint256) private balances;
mapping (address => uint256) private balances_;

mapping (address => mapping (address => uint256)) private allowed;
mapping (address => mapping (address => uint256)) private allowed_;

uint256 private totalSupply_;

Expand All @@ -33,7 +33,7 @@ contract StandardToken is ERC20 {
* @return An uint256 representing the amount owned by the passed address.
*/
function balanceOf(address _owner) public view returns (uint256) {
return balances[_owner];
return balances_[_owner];
}

/**
Expand All @@ -50,7 +50,7 @@ contract StandardToken is ERC20 {
view
returns (uint256)
{
return allowed[_owner][_spender];
return allowed_[_owner][_spender];
}

/**
Expand All @@ -59,11 +59,11 @@ contract StandardToken is ERC20 {
* @param _value The amount to be transferred.
*/
function transfer(address _to, uint256 _value) public returns (bool) {
require(_value <= balances[msg.sender]);
require(_value <= balances_[msg.sender]);
require(_to != address(0));

balances[msg.sender] = balances[msg.sender].sub(_value);
balances[_to] = balances[_to].add(_value);
balances_[msg.sender] = balances_[msg.sender].sub(_value);
balances_[_to] = balances_[_to].add(_value);
emit Transfer(msg.sender, _to, _value);
return true;
}
Expand All @@ -78,7 +78,7 @@ contract StandardToken is ERC20 {
* @param _value The amount of tokens to be spent.
*/
function approve(address _spender, uint256 _value) public returns (bool) {
allowed[msg.sender][_spender] = _value;
allowed_[msg.sender][_spender] = _value;
emit Approval(msg.sender, _spender, _value);
return true;
}
Expand All @@ -97,20 +97,20 @@ contract StandardToken is ERC20 {
public
returns (bool)
{
require(_value <= balances[_from]);
require(_value <= allowed[_from][msg.sender]);
require(_value <= balances_[_from]);
require(_value <= allowed_[_from][msg.sender]);
require(_to != address(0));

balances[_from] = balances[_from].sub(_value);
balances[_to] = balances[_to].add(_value);
allowed[_from][msg.sender] = allowed[_from][msg.sender].sub(_value);
balances_[_from] = balances_[_from].sub(_value);
balances_[_to] = balances_[_to].add(_value);
allowed_[_from][msg.sender] = allowed_[_from][msg.sender].sub(_value);
emit Transfer(_from, _to, _value);
return true;
}

/**
* @dev Increase the amount of tokens that an owner allowed to a spender.
* approve should be called when allowed[_spender] == 0. To increment
* approve should be called when allowed_[_spender] == 0. To increment
* allowed value is better to use this function to avoid 2 calls (and wait until
* the first transaction is mined)
* From MonolithDAO Token.sol
Expand All @@ -124,15 +124,15 @@ contract StandardToken is ERC20 {
public
returns (bool)
{
allowed[msg.sender][_spender] = (
allowed[msg.sender][_spender].add(_addedValue));
emit Approval(msg.sender, _spender, allowed[msg.sender][_spender]);
allowed_[msg.sender][_spender] = (
allowed_[msg.sender][_spender].add(_addedValue));
emit Approval(msg.sender, _spender, allowed_[msg.sender][_spender]);
return true;
}

/**
* @dev Decrease the amount of tokens that an owner allowed to a spender.
* approve should be called when allowed[_spender] == 0. To decrement
* approve should be called when allowed_[_spender] == 0. To decrement
* allowed value is better to use this function to avoid 2 calls (and wait until
* the first transaction is mined)
* From MonolithDAO Token.sol
Expand All @@ -146,13 +146,13 @@ contract StandardToken is ERC20 {
public
returns (bool)
{
uint256 oldValue = allowed[msg.sender][_spender];
uint256 oldValue = allowed_[msg.sender][_spender];
if (_subtractedValue >= oldValue) {
allowed[msg.sender][_spender] = 0;
allowed_[msg.sender][_spender] = 0;
} else {
allowed[msg.sender][_spender] = oldValue.sub(_subtractedValue);
allowed_[msg.sender][_spender] = oldValue.sub(_subtractedValue);
}
emit Approval(msg.sender, _spender, allowed[msg.sender][_spender]);
emit Approval(msg.sender, _spender, allowed_[msg.sender][_spender]);
return true;
}

Expand All @@ -166,7 +166,7 @@ contract StandardToken is ERC20 {
function _mint(address _account, uint256 _amount) internal {
require(_account != 0);
totalSupply_ = totalSupply_.add(_amount);
balances[_account] = balances[_account].add(_amount);
balances_[_account] = balances_[_account].add(_amount);
emit Transfer(address(0), _account, _amount);
}

Expand All @@ -178,10 +178,10 @@ contract StandardToken is ERC20 {
*/
function _burn(address _account, uint256 _amount) internal {
require(_account != 0);
require(_amount <= balances[_account]);
require(_amount <= balances_[_account]);

totalSupply_ = totalSupply_.sub(_amount);
balances[_account] = balances[_account].sub(_amount);
balances_[_account] = balances_[_account].sub(_amount);
emit Transfer(_account, address(0), _amount);
}

Expand All @@ -193,11 +193,12 @@ contract StandardToken is ERC20 {
* @param _amount The amount that will be burnt.
*/
function _burnFrom(address _account, uint256 _amount) internal {
require(_amount <= allowed[_account][msg.sender]);
require(_amount <= allowed_[_account][msg.sender]);

// Should https://github.com/OpenZeppelin/zeppelin-solidity/issues/707 be accepted,
// this function needs to emit an event with the updated approval.
allowed[_account][msg.sender] = allowed[_account][msg.sender].sub(_amount);
allowed_[_account][msg.sender] = allowed_[_account][msg.sender].sub(
_amount);
_burn(_account, _amount);
}
}