implement solium recommendations
This commit is contained in:
@ -46,6 +46,8 @@ contract SafeMath {
|
|||||||
}
|
}
|
||||||
|
|
||||||
function assert(bool assertion) internal {
|
function assert(bool assertion) internal {
|
||||||
if (!assertion) throw;
|
if (!assertion) {
|
||||||
|
throw;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@ -12,8 +12,17 @@ import "../ownership/Ownable.sol";
|
|||||||
contract Pausable is Ownable {
|
contract Pausable is Ownable {
|
||||||
bool public stopped;
|
bool public stopped;
|
||||||
|
|
||||||
modifier stopInEmergency { if (!stopped) _; }
|
modifier stopInEmergency {
|
||||||
modifier onlyInEmergency { if (stopped) _; }
|
if (!stopped) {
|
||||||
|
_;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
modifier onlyInEmergency {
|
||||||
|
if (stopped) {
|
||||||
|
_;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
// called by the owner on emergency, triggers stopped state
|
// called by the owner on emergency, triggers stopped state
|
||||||
function emergencyStop() external onlyOwner {
|
function emergencyStop() external onlyOwner {
|
||||||
|
|||||||
@ -1,12 +1,14 @@
|
|||||||
pragma solidity ^0.4.4;
|
pragma solidity ^0.4.4;
|
||||||
|
|
||||||
|
|
||||||
import './Ownable.sol';
|
import './Ownable.sol';
|
||||||
import './Claimable.sol';
|
import './Claimable.sol';
|
||||||
|
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* DelayedClaimable
|
* DelayedClaimable
|
||||||
* Extension for the Claimable contract, where the ownership needs to be claimed before/after certain block number
|
* Extension for the Claimable contract, where the ownership needs to be claimed before/after certain block number
|
||||||
*/
|
*/
|
||||||
|
|
||||||
contract DelayedClaimable is Ownable, Claimable {
|
contract DelayedClaimable is Ownable, Claimable {
|
||||||
|
|
||||||
uint public end;
|
uint public end;
|
||||||
|
|||||||
@ -15,12 +15,15 @@ contract Ownable {
|
|||||||
}
|
}
|
||||||
|
|
||||||
modifier onlyOwner() {
|
modifier onlyOwner() {
|
||||||
if (msg.sender == owner)
|
if (msg.sender == owner) {
|
||||||
_;
|
_;
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
function transferOwnership(address newOwner) onlyOwner {
|
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.
|
* 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 {
|
contract Shareable {
|
||||||
// TYPES
|
|
||||||
|
|
||||||
// struct for the status of a pending operation.
|
// struct for the status of a pending operation.
|
||||||
struct PendingState {
|
struct PendingState {
|
||||||
uint yetNeeded;
|
uint yetNeeded;
|
||||||
@ -21,15 +19,11 @@ contract Shareable {
|
|||||||
uint index;
|
uint index;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
// FIELDS
|
|
||||||
|
|
||||||
// the number of owners that must confirm the same operation before it is run.
|
// the number of owners that must confirm the same operation before it is run.
|
||||||
uint public required;
|
uint public required;
|
||||||
|
|
||||||
// list of owners
|
// list of owners
|
||||||
uint[256] owners;
|
uint[256] owners;
|
||||||
uint constant c_maxOwners = 250;
|
|
||||||
// index on the list of owners to allow reverse lookup
|
// index on the list of owners to allow reverse lookup
|
||||||
mapping(uint => uint) ownerIndex;
|
mapping(uint => uint) ownerIndex;
|
||||||
// the ongoing operations.
|
// the ongoing operations.
|
||||||
@ -37,32 +31,27 @@ contract Shareable {
|
|||||||
bytes32[] pendingsIndex;
|
bytes32[] pendingsIndex;
|
||||||
|
|
||||||
|
|
||||||
// EVENTS
|
|
||||||
|
|
||||||
// this contract only has six types of events: it can accept a confirmation, in which case
|
// this contract only has six types of events: it can accept a confirmation, in which case
|
||||||
// we record owner and operation (hash) alongside it.
|
// we record owner and operation (hash) alongside it.
|
||||||
event Confirmation(address owner, bytes32 operation);
|
event Confirmation(address owner, bytes32 operation);
|
||||||
event Revoke(address owner, bytes32 operation);
|
event Revoke(address owner, bytes32 operation);
|
||||||
|
|
||||||
|
|
||||||
// MODIFIERS
|
|
||||||
|
|
||||||
// simple single-sig function modifier.
|
// simple single-sig function modifier.
|
||||||
modifier onlyOwner {
|
modifier onlyOwner {
|
||||||
if (isOwner(msg.sender))
|
if (isOwner(msg.sender)) {
|
||||||
_;
|
_;
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
// multi-sig function modifier: the operation must have an intrinsic hash in order
|
// 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
|
// that later attempts can be realised as the same underlying operation and
|
||||||
// thus count as confirmations.
|
// thus count as confirmations.
|
||||||
modifier onlymanyowners(bytes32 _operation) {
|
modifier onlymanyowners(bytes32 _operation) {
|
||||||
if (confirmAndCheck(_operation))
|
if (confirmAndCheck(_operation)) {
|
||||||
_;
|
_;
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
// CONSTRUCTOR
|
|
||||||
|
|
||||||
// constructor is given number of sigs required to do protected "onlymanyowners" transactions
|
// constructor is given number of sigs required to do protected "onlymanyowners" transactions
|
||||||
// as well as the selection of addresses capable of confirming them.
|
// as well as the selection of addresses capable of confirming them.
|
||||||
@ -76,14 +65,13 @@ contract Shareable {
|
|||||||
required = _required;
|
required = _required;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
// METHODS
|
|
||||||
|
|
||||||
// Revokes a prior confirmation of the given operation
|
// Revokes a prior confirmation of the given operation
|
||||||
function revoke(bytes32 _operation) external {
|
function revoke(bytes32 _operation) external {
|
||||||
uint index = ownerIndex[uint(msg.sender)];
|
uint index = ownerIndex[uint(msg.sender)];
|
||||||
// make sure they're an owner
|
// make sure they're an owner
|
||||||
if (index == 0) return;
|
if (index == 0) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
uint ownerIndexBit = 2**index;
|
uint ownerIndexBit = 2**index;
|
||||||
var pending = pendings[_operation];
|
var pending = pendings[_operation];
|
||||||
if (pending.ownersDone & ownerIndexBit > 0) {
|
if (pending.ownersDone & ownerIndexBit > 0) {
|
||||||
@ -107,20 +95,22 @@ contract Shareable {
|
|||||||
uint index = ownerIndex[uint(_owner)];
|
uint index = ownerIndex[uint(_owner)];
|
||||||
|
|
||||||
// make sure they're an 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.
|
// determine the bit to set for this owner.
|
||||||
uint ownerIndexBit = 2**index;
|
uint ownerIndexBit = 2**index;
|
||||||
return !(pending.ownersDone & ownerIndexBit == 0);
|
return !(pending.ownersDone & ownerIndexBit == 0);
|
||||||
}
|
}
|
||||||
|
|
||||||
// INTERNAL METHODS
|
|
||||||
|
|
||||||
function confirmAndCheck(bytes32 _operation) internal returns (bool) {
|
function confirmAndCheck(bytes32 _operation) internal returns (bool) {
|
||||||
// determine what index the present sender is:
|
// determine what index the present sender is:
|
||||||
uint index = ownerIndex[uint(msg.sender)];
|
uint index = ownerIndex[uint(msg.sender)];
|
||||||
// make sure they're an owner
|
// make sure they're an owner
|
||||||
if (index == 0) return;
|
if (index == 0) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
var pending = pendings[_operation];
|
var pending = pendings[_operation];
|
||||||
// if we're not yet working on this operation, switch over and reset the confirmation status.
|
// if we're not yet working on this operation, switch over and reset the confirmation status.
|
||||||
@ -143,9 +133,7 @@ contract Shareable {
|
|||||||
delete pendingsIndex[pendings[_operation].index];
|
delete pendingsIndex[pendings[_operation].index];
|
||||||
delete pendings[_operation];
|
delete pendings[_operation];
|
||||||
return true;
|
return true;
|
||||||
}
|
} else {
|
||||||
else
|
|
||||||
{
|
|
||||||
// not enough: record that this owner in particular confirmed.
|
// not enough: record that this owner in particular confirmed.
|
||||||
pending.yetNeeded--;
|
pending.yetNeeded--;
|
||||||
pending.ownersDone |= ownerIndexBit;
|
pending.ownersDone |= ownerIndexBit;
|
||||||
@ -155,9 +143,11 @@ contract Shareable {
|
|||||||
|
|
||||||
function clearPending() internal {
|
function clearPending() internal {
|
||||||
uint length = pendingsIndex.length;
|
uint length = pendingsIndex.length;
|
||||||
for (uint i = 0; i < length; ++i)
|
for (uint i = 0; i < length; ++i) {
|
||||||
if (pendingsIndex[i] != 0)
|
if (pendingsIndex[i] != 0) {
|
||||||
delete pendings[pendingsIndex[i]];
|
delete pendings[pendingsIndex[i]];
|
||||||
|
}
|
||||||
|
}
|
||||||
delete pendingsIndex;
|
delete pendingsIndex;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@ -19,10 +19,16 @@ contract PullPayment {
|
|||||||
address payee = msg.sender;
|
address payee = msg.sender;
|
||||||
uint payment = payments[payee];
|
uint payment = payments[payee];
|
||||||
|
|
||||||
if (payment == 0) throw;
|
if (payment == 0) {
|
||||||
if (this.balance < payment) throw;
|
throw;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (this.balance < payment) {
|
||||||
|
throw;
|
||||||
|
}
|
||||||
|
|
||||||
payments[payee] = 0;
|
payments[payee] = 0;
|
||||||
|
|
||||||
if (!payee.send(payment)) {
|
if (!payee.send(payment)) {
|
||||||
throw;
|
throw;
|
||||||
}
|
}
|
||||||
|
|||||||
@ -23,7 +23,9 @@ contract CrowdsaleToken is StandardToken {
|
|||||||
}
|
}
|
||||||
|
|
||||||
function createTokens(address recipient) payable {
|
function createTokens(address recipient) payable {
|
||||||
if (msg.value == 0) throw;
|
if (msg.value == 0) {
|
||||||
|
throw;
|
||||||
|
}
|
||||||
|
|
||||||
uint tokens = safeMul(msg.value, getPrice());
|
uint tokens = safeMul(msg.value, getPrice());
|
||||||
|
|
||||||
@ -32,7 +34,7 @@ contract CrowdsaleToken is StandardToken {
|
|||||||
}
|
}
|
||||||
|
|
||||||
// replace this with any other price function
|
// replace this with any other price function
|
||||||
function getPrice() constant returns (uint result){
|
function getPrice() constant returns (uint result) {
|
||||||
return PRICE;
|
return PRICE;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@ -1,7 +1,9 @@
|
|||||||
pragma solidity ^0.4.8;
|
pragma solidity ^0.4.8;
|
||||||
|
|
||||||
|
|
||||||
import "./StandardToken.sol";
|
import "./StandardToken.sol";
|
||||||
|
|
||||||
|
|
||||||
contract VestedToken is StandardToken {
|
contract VestedToken is StandardToken {
|
||||||
struct TokenGrant {
|
struct TokenGrant {
|
||||||
address granter;
|
address granter;
|
||||||
@ -13,10 +15,22 @@ contract VestedToken is StandardToken {
|
|||||||
|
|
||||||
mapping (address => TokenGrant[]) public grants;
|
mapping (address => TokenGrant[]) public grants;
|
||||||
|
|
||||||
function grantVestedTokens(address _to, uint256 _value, uint64 _start, uint64 _cliff, uint64 _vesting) {
|
function grantVestedTokens(
|
||||||
if (_cliff < _start) throw;
|
address _to,
|
||||||
if (_vesting < _start) throw;
|
uint256 _value,
|
||||||
if (_vesting < _cliff) throw;
|
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});
|
TokenGrant memory grant = TokenGrant({start: _start, value: _value, cliff: _cliff, vesting: _vesting, granter: msg.sender});
|
||||||
grants[_to].push(grant);
|
grants[_to].push(grant);
|
||||||
@ -27,7 +41,9 @@ contract VestedToken is StandardToken {
|
|||||||
function revokeTokenGrant(address _holder, uint _grantId) {
|
function revokeTokenGrant(address _holder, uint _grantId) {
|
||||||
TokenGrant grant = grants[_holder][_grantId];
|
TokenGrant grant = grants[_holder][_grantId];
|
||||||
|
|
||||||
if (grant.granter != msg.sender) throw;
|
if (grant.granter != msg.sender) {
|
||||||
|
throw;
|
||||||
|
}
|
||||||
uint256 nonVested = nonVestedTokens(grant, uint64(now));
|
uint256 nonVested = nonVestedTokens(grant, uint64(now));
|
||||||
|
|
||||||
// remove grant from array
|
// remove grant from array
|
||||||
@ -57,12 +73,28 @@ contract VestedToken is StandardToken {
|
|||||||
}
|
}
|
||||||
|
|
||||||
function vestedTokens(TokenGrant grant, uint64 time) private constant returns (uint256) {
|
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) {
|
function calculateVestedTokens(
|
||||||
if (time < cliff) return 0;
|
uint256 tokens,
|
||||||
if (time > vesting) return 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));
|
uint256 cliffTokens = safeDiv(safeMul(tokens, safeSub(cliff, start)), safeSub(vesting, start));
|
||||||
vestedTokens = cliffTokens;
|
vestedTokens = cliffTokens;
|
||||||
@ -94,8 +126,10 @@ contract VestedToken is StandardToken {
|
|||||||
return safeSub(balances[holder], nonVested);
|
return safeSub(balances[holder], nonVested);
|
||||||
}
|
}
|
||||||
|
|
||||||
function transfer(address _to, uint _value) returns (bool success){
|
function transfer(address _to, uint _value) returns (bool success) {
|
||||||
if (_value > transferableTokens(msg.sender, uint64(now))) throw;
|
if (_value > transferableTokens(msg.sender, uint64(now))) {
|
||||||
|
throw;
|
||||||
|
}
|
||||||
|
|
||||||
return super.transfer(_to, _value);
|
return super.transfer(_to, _value);
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user