implement solium recommendations

pull/146/head
Manuel Araoz 8 years ago
parent 9ab997d788
commit b1cb7b5975
  1. 4
      contracts/SafeMath.sol
  2. 13
      contracts/lifecycle/Pausable.sol
  3. 4
      contracts/ownership/DelayedClaimable.sol
  4. 7
      contracts/ownership/Ownable.sol
  5. 54
      contracts/ownership/Shareable.sol
  6. 10
      contracts/payment/PullPayment.sol
  7. 6
      contracts/token/CrowdsaleToken.sol
  8. 56
      contracts/token/VestedToken.sol

@ -46,6 +46,8 @@ contract SafeMath {
}
function assert(bool assertion) internal {
if (!assertion) throw;
if (!assertion) {
throw;
}
}
}

@ -12,8 +12,17 @@ import "../ownership/Ownable.sol";
contract Pausable is Ownable {
bool public stopped;
modifier stopInEmergency { if (!stopped) _; }
modifier onlyInEmergency { if (stopped) _; }
modifier stopInEmergency {
if (!stopped) {
_;
}
}
modifier onlyInEmergency {
if (stopped) {
_;
}
}
// called by the owner on emergency, triggers stopped state
function emergencyStop() external onlyOwner {

@ -1,12 +1,14 @@
pragma solidity ^0.4.4;
import './Ownable.sol';
import './Claimable.sol';
/*
* DelayedClaimable
* Extension for the Claimable contract, where the ownership needs to be claimed before/after certain block number
*/
contract DelayedClaimable is Ownable, Claimable {
uint public end;

@ -15,12 +15,15 @@ contract Ownable {
}
modifier onlyOwner() {
if (msg.sender == owner)
if (msg.sender == owner) {
_;
}
}
function transferOwnership(address newOwner) onlyOwner {
if (newOwner != address(0)) owner = newOwner;
if (newOwner != address(0)) {
owner = newOwner;
}
}
}

@ -12,8 +12,6 @@ pragma solidity ^0.4.4;
* use modifiers onlyowner (just own owned) or onlymanyowners(hash), whereby the same hash must be provided by some number (specified in constructor) of the set of owners (specified in the constructor) before the interior is executed.
*/
contract Shareable {
// TYPES
// struct for the status of a pending operation.
struct PendingState {
uint yetNeeded;
@ -21,15 +19,11 @@ contract Shareable {
uint index;
}
// FIELDS
// the number of owners that must confirm the same operation before it is run.
uint public required;
// list of owners
uint[256] owners;
uint constant c_maxOwners = 250;
// index on the list of owners to allow reverse lookup
mapping(uint => uint) ownerIndex;
// the ongoing operations.
@ -37,33 +31,28 @@ contract Shareable {
bytes32[] pendingsIndex;
// EVENTS
// this contract only has six types of events: it can accept a confirmation, in which case
// we record owner and operation (hash) alongside it.
event Confirmation(address owner, bytes32 operation);
event Revoke(address owner, bytes32 operation);
// MODIFIERS
// simple single-sig function modifier.
modifier onlyOwner {
if (isOwner(msg.sender))
if (isOwner(msg.sender)) {
_;
}
}
// multi-sig function modifier: the operation must have an intrinsic hash in order
// that later attempts can be realised as the same underlying operation and
// thus count as confirmations.
modifier onlymanyowners(bytes32 _operation) {
if (confirmAndCheck(_operation))
if (confirmAndCheck(_operation)) {
_;
}
}
// CONSTRUCTOR
// constructor is given number of sigs required to do protected "onlymanyowners" transactions
// as well as the selection of addresses capable of confirming them.
function Shareable(address[] _owners, uint _required) {
@ -76,14 +65,13 @@ contract Shareable {
required = _required;
}
// METHODS
// Revokes a prior confirmation of the given operation
function revoke(bytes32 _operation) external {
uint index = ownerIndex[uint(msg.sender)];
// make sure they're an owner
if (index == 0) return;
if (index == 0) {
return;
}
uint ownerIndexBit = 2**index;
var pending = pendings[_operation];
if (pending.ownersDone & ownerIndexBit > 0) {
@ -107,20 +95,22 @@ contract Shareable {
uint index = ownerIndex[uint(_owner)];
// make sure they're an owner
if (index == 0) return false;
if (index == 0) {
return false;
}
// determine the bit to set for this owner.
uint ownerIndexBit = 2**index;
return !(pending.ownersDone & ownerIndexBit == 0);
}
// INTERNAL METHODS
function confirmAndCheck(bytes32 _operation) internal returns (bool) {
// determine what index the present sender is:
uint index = ownerIndex[uint(msg.sender)];
// make sure they're an owner
if (index == 0) return;
if (index == 0) {
return;
}
var pending = pendings[_operation];
// if we're not yet working on this operation, switch over and reset the confirmation status.
@ -143,21 +133,21 @@ contract Shareable {
delete pendingsIndex[pendings[_operation].index];
delete pendings[_operation];
return true;
} else {
// not enough: record that this owner in particular confirmed.
pending.yetNeeded--;
pending.ownersDone |= ownerIndexBit;
}
else
{
// not enough: record that this owner in particular confirmed.
pending.yetNeeded--;
pending.ownersDone |= ownerIndexBit;
}
}
}
function clearPending() internal {
uint length = pendingsIndex.length;
for (uint i = 0; i < length; ++i)
if (pendingsIndex[i] != 0)
delete pendings[pendingsIndex[i]];
for (uint i = 0; i < length; ++i) {
if (pendingsIndex[i] != 0) {
delete pendings[pendingsIndex[i]];
}
}
delete pendingsIndex;
}

@ -19,10 +19,16 @@ contract PullPayment {
address payee = msg.sender;
uint payment = payments[payee];
if (payment == 0) throw;
if (this.balance < payment) throw;
if (payment == 0) {
throw;
}
if (this.balance < payment) {
throw;
}
payments[payee] = 0;
if (!payee.send(payment)) {
throw;
}

@ -23,7 +23,9 @@ contract CrowdsaleToken is StandardToken {
}
function createTokens(address recipient) payable {
if (msg.value == 0) throw;
if (msg.value == 0) {
throw;
}
uint tokens = safeMul(msg.value, getPrice());
@ -32,7 +34,7 @@ contract CrowdsaleToken is StandardToken {
}
// replace this with any other price function
function getPrice() constant returns (uint result){
function getPrice() constant returns (uint result) {
return PRICE;
}
}

@ -1,7 +1,9 @@
pragma solidity ^0.4.8;
import "./StandardToken.sol";
contract VestedToken is StandardToken {
struct TokenGrant {
address granter;
@ -13,10 +15,22 @@ contract VestedToken is StandardToken {
mapping (address => TokenGrant[]) public grants;
function grantVestedTokens(address _to, uint256 _value, uint64 _start, uint64 _cliff, uint64 _vesting) {
if (_cliff < _start) throw;
if (_vesting < _start) throw;
if (_vesting < _cliff) throw;
function grantVestedTokens(
address _to,
uint256 _value,
uint64 _start,
uint64 _cliff,
uint64 _vesting) {
if (_cliff < _start) {
throw;
}
if (_vesting < _start) {
throw;
}
if (_vesting < _cliff) {
throw;
}
TokenGrant memory grant = TokenGrant({start: _start, value: _value, cliff: _cliff, vesting: _vesting, granter: msg.sender});
grants[_to].push(grant);
@ -27,7 +41,9 @@ contract VestedToken is StandardToken {
function revokeTokenGrant(address _holder, uint _grantId) {
TokenGrant grant = grants[_holder][_grantId];
if (grant.granter != msg.sender) throw;
if (grant.granter != msg.sender) {
throw;
}
uint256 nonVested = nonVestedTokens(grant, uint64(now));
// remove grant from array
@ -57,12 +73,28 @@ contract VestedToken is StandardToken {
}
function vestedTokens(TokenGrant grant, uint64 time) private constant returns (uint256) {
return calculateVestedTokens(grant.value, uint256(time), uint256(grant.start), uint256(grant.cliff), uint256(grant.vesting));
return calculateVestedTokens(grant.value,
uint256(time)
uint256(grant.start),
uint256(grant.cliff),
uint256(grant.vesting)
);
}
function calculateVestedTokens(uint256 tokens, uint256 time, uint256 start, uint256 cliff, uint256 vesting) constant returns (uint256 vestedTokens) {
if (time < cliff) return 0;
if (time > vesting) return tokens;
function calculateVestedTokens(
uint256 tokens,
uint256 time,
uint256 start,
uint256 cliff,
uint256 vesting) constant returns (uint256 vestedTokens)
{
if (time < cliff) {
return 0;
}
if (time > vesting) {
return tokens;
}
uint256 cliffTokens = safeDiv(safeMul(tokens, safeSub(cliff, start)), safeSub(vesting, start));
vestedTokens = cliffTokens;
@ -94,8 +126,10 @@ contract VestedToken is StandardToken {
return safeSub(balances[holder], nonVested);
}
function transfer(address _to, uint _value) returns (bool success){
if (_value > transferableTokens(msg.sender, uint64(now))) throw;
function transfer(address _to, uint _value) returns (bool success) {
if (_value > transferableTokens(msg.sender, uint64(now))) {
throw;
}
return super.transfer(_to, _value);
}

Loading…
Cancel
Save