Transaction Hash:
Block:
8810733 at Oct-25-2019 06:38:24 PM +UTC
Transaction Fee:
0.000052672 ETH
$0.11
Gas Used:
52,672 Gas / 1 Gwei
Emitted Events:
| 103 |
DRPToken.Transfer( _from=[Sender] 0xbcf3b183147ee2c83ee8b05d237bda5e1da401ed, _to=[Receiver] DRPUTokenConverter, _value=59500 )
|
| 104 |
DRPUToken.Transfer( _from=0x0000000000000000000000000000000000000000, _to=DRPUToken, _value=119000000000 )
|
| 105 |
DRPUToken.Transfer( _from=DRPUToken, _to=[Sender] 0xbcf3b183147ee2c83ee8b05d237bda5e1da401ed, _value=119000000000 )
|
Account State Difference:
| Address | Before | After | State Difference | ||
|---|---|---|---|---|---|
| 0x621d78f2...79F59B3Ed | |||||
| 0xBcF3b183...e1da401eD |
0.009717400687338538 Eth
Nonce: 27
|
0.009664728687338538 Eth
Nonce: 28
| 0.000052672 | ||
| 0xe30e02f0...fB2c321bA | |||||
|
0xEEa5B82B...2d0D25Bfb
Miner
| (BTC.com Pool) | 218.210329336705497084 Eth | 218.210382008705497084 Eth | 0.000052672 |
Execution Trace
DRPUTokenConverter.requestConversion( _value=59500 )
-
Whitelist.authenticate( _account=0xBcF3b183147eE2C83eE8b05D237bDa5e1da401eD ) => ( True ) -
DRPToken.transferFrom( _from=0xBcF3b183147eE2C83eE8b05D237bDa5e1da401eD, _to=0xee2972a6177C28F3EFaCb1862A1a8507c3f10fAa, _value=59500 ) => ( success=True )
-
DRPUToken.issue( _to=0xBcF3b183147eE2C83eE8b05D237bDa5e1da401eD, _value=119000000000 ) => ( True )
requestConversion[DRPUTokenConverter (ln:841)]
authenticate[DRPUTokenConverter (ln:846)]getLeftToken[DRPUTokenConverter (ln:848)]transferFrom[DRPUTokenConverter (ln:849)]convert[DRPUTokenConverter (ln:850)]
File 1 of 4: DRPUTokenConverter
File 2 of 4: DRPToken
File 3 of 4: DRPUToken
File 4 of 4: Whitelist
pragma solidity ^0.4.15;
/**
* @title Ownership interface
*
* Perminent ownership
*
* #created 01/10/2017
* #author Frank Bonnet
*/
contract IOwnership {
/**
* Returns true if `_account` is the current owner
*
* @param _account The address to test against
*/
function isOwner(address _account) constant returns (bool);
/**
* Gets the current owner
*
* @return address The current owner
*/
function getOwner() constant returns (address);
}
/**
* @title Ownership
*
* Perminent ownership
*
* #created 01/10/2017
* #author Frank Bonnet
*/
contract Ownership is IOwnership {
// Owner
address internal owner;
/**
* The publisher is the inital owner
*/
function Ownership() {
owner = msg.sender;
}
/**
* Access is restricted to the current owner
*/
modifier only_owner() {
require(msg.sender == owner);
_;
}
/**
* Returns true if `_account` is the current owner
*
* @param _account The address to test against
*/
function isOwner(address _account) public constant returns (bool) {
return _account == owner;
}
/**
* Gets the current owner
*
* @return address The current owner
*/
function getOwner() public constant returns (address) {
return owner;
}
}
/**
* @title Transferable ownership interface
*
* Enhances ownership by allowing the current owner to
* transfer ownership to a new owner
*
* #created 01/10/2017
* #author Frank Bonnet
*/
contract ITransferableOwnership {
/**
* Transfer ownership to `_newOwner`
*
* @param _newOwner The address of the account that will become the new owner
*/
function transferOwnership(address _newOwner);
}
/**
* @title Transferable ownership
*
* Enhances ownership by allowing the current owner to
* transfer ownership to a new owner
*
* #created 01/10/2017
* #author Frank Bonnet
*/
contract TransferableOwnership is ITransferableOwnership, Ownership {
/**
* Transfer ownership to `_newOwner`
*
* @param _newOwner The address of the account that will become the new owner
*/
function transferOwnership(address _newOwner) public only_owner {
owner = _newOwner;
}
}
/**
* @title Pausable interface
*
* Simple interface to pause and resume
*
* #created 11/10/2017
* #author Frank Bonnet
*/
contract IPausable {
/**
* Returns whether the implementing contract is
* currently paused or not
*
* @return Whether the paused state is active
*/
function isPaused() constant returns (bool);
/**
* Change the state to paused
*/
function pause();
/**
* Change the state to resume, undo the effects
* of calling pause
*/
function resume();
}
/**
* @title IAuthenticationManager
*
* Allows the authentication process to be enabled and disabled
*
* #created 15/10/2017
* #author Frank Bonnet
*/
contract IAuthenticationManager {
/**
* Returns true if authentication is enabled and false
* otherwise
*
* @return Whether the converter is currently authenticating or not
*/
function isAuthenticating() constant returns (bool);
/**
* Enable authentication
*/
function enableAuthentication();
/**
* Disable authentication
*/
function disableAuthentication();
}
/**
* @title IAuthenticator
*
* Authenticator interface
*
* #created 15/10/2017
* #author Frank Bonnet
*/
contract IAuthenticator {
/**
* Authenticate
*
* Returns whether `_account` is authenticated or not
*
* @param _account The account to authenticate
* @return whether `_account` is successfully authenticated
*/
function authenticate(address _account) constant returns (bool);
}
/**
* @title IWhitelist
*
* Whitelist authentication interface
*
* #created 04/10/2017
* #author Frank Bonnet
*/
contract IWhitelist is IAuthenticator {
/**
* Returns whether an entry exists for `_account`
*
* @param _account The account to check
* @return whether `_account` is has an entry in the whitelist
*/
function hasEntry(address _account) constant returns (bool);
/**
* Add `_account` to the whitelist
*
* If an account is currently disabled, the account is reenabled, otherwise
* a new entry is created
*
* @param _account The account to add
*/
function add(address _account);
/**
* Remove `_account` from the whitelist
*
* Will not actually remove the entry but disable it by updating
* the accepted record
*
* @param _account The account to remove
*/
function remove(address _account);
}
/**
* @title Token retrieve interface
*
* Allows tokens to be retrieved from a contract
*
* #created 29/09/2017
* #author Frank Bonnet
*/
contract ITokenRetriever {
/**
* Extracts tokens from the contract
*
* @param _tokenContract The address of ERC20 compatible token
*/
function retrieveTokens(address _tokenContract);
}
/**
* @title Token retrieve
*
* Allows tokens to be retrieved from a contract
*
* #created 18/10/2017
* #author Frank Bonnet
*/
contract TokenRetriever is ITokenRetriever {
/**
* Extracts tokens from the contract
*
* @param _tokenContract The address of ERC20 compatible token
*/
function retrieveTokens(address _tokenContract) public {
IToken tokenInstance = IToken(_tokenContract);
uint tokenBalance = tokenInstance.balanceOf(this);
if (tokenBalance > 0) {
tokenInstance.transfer(msg.sender, tokenBalance);
}
}
}
/**
* @title Token observer interface
*
* Allows a token smart-contract to notify observers
* when tokens are received
*
* #created 09/10/2017
* #author Frank Bonnet
*/
contract ITokenObserver {
/**
* Called by the observed token smart-contract in order
* to notify the token observer when tokens are received
*
* @param _from The address that the tokens where send from
* @param _value The amount of tokens that was received
*/
function notifyTokensReceived(address _from, uint _value);
}
/**
* @title Abstract token observer
*
* Allows observers to be notified by an observed token smart-contract
* when tokens are received
*
* #created 09/10/2017
* #author Frank Bonnet
*/
contract TokenObserver is ITokenObserver {
/**
* Called by the observed token smart-contract in order
* to notify the token observer when tokens are received
*
* @param _from The address that the tokens where send from
* @param _value The amount of tokens that was received
*/
function notifyTokensReceived(address _from, uint _value) public {
onTokensReceived(msg.sender, _from, _value);
}
/**
* Event handler
*
* Called by `_token` when a token amount is received
*
* @param _token The token contract that received the transaction
* @param _from The account or contract that send the transaction
* @param _value The value of tokens that where received
*/
function onTokensReceived(address _token, address _from, uint _value) internal;
}
/**
* @title ERC20 compatible token interface
*
* - Implements ERC 20 Token standard
* - Implements short address attack fix
*
* #created 29/09/2017
* #author Frank Bonnet
*/
contract IToken {
/**
* Get the total supply of tokens
*
* @return The total supply
*/
function totalSupply() constant returns (uint);
/**
* Get balance of `_owner`
*
* @param _owner The address from which the balance will be retrieved
* @return The balance
*/
function balanceOf(address _owner) constant returns (uint);
/**
* Send `_value` token to `_to` from `msg.sender`
*
* @param _to The address of the recipient
* @param _value The amount of token to be transferred
* @return Whether the transfer was successful or not
*/
function transfer(address _to, uint _value) returns (bool);
/**
* Send `_value` token to `_to` from `_from` on the condition it is approved by `_from`
*
* @param _from The address of the sender
* @param _to The address of the recipient
* @param _value The amount of token to be transferred
* @return Whether the transfer was successful or not
*/
function transferFrom(address _from, address _to, uint _value) returns (bool);
/**
* `msg.sender` approves `_spender` to spend `_value` tokens
*
* @param _spender The address of the account able to transfer the tokens
* @param _value The amount of tokens to be approved for transfer
* @return Whether the approval was successful or not
*/
function approve(address _spender, uint _value) returns (bool);
/**
* Get the amount of remaining tokens that `_spender` is allowed to spend from `_owner`
*
* @param _owner The address of the account owning tokens
* @param _spender The address of the account able to transfer the tokens
* @return Amount of remaining tokens allowed to spent
*/
function allowance(address _owner, address _spender) constant returns (uint);
}
/**
* @title ManagedToken interface
*
* Adds the following functionality to the basic ERC20 token
* - Locking
* - Issuing
* - Burning
*
* #created 29/09/2017
* #author Frank Bonnet
*/
contract IManagedToken is IToken {
/**
* Returns true if the token is locked
*
* @return Whether the token is locked
*/
function isLocked() constant returns (bool);
/**
* Locks the token so that the transfering of value is disabled
*
* @return Whether the unlocking was successful or not
*/
function lock() returns (bool);
/**
* Unlocks the token so that the transfering of value is enabled
*
* @return Whether the unlocking was successful or not
*/
function unlock() returns (bool);
/**
* Issues `_value` new tokens to `_to`
*
* @param _to The address to which the tokens will be issued
* @param _value The amount of new tokens to issue
* @return Whether the tokens where sucessfully issued or not
*/
function issue(address _to, uint _value) returns (bool);
/**
* Burns `_value` tokens of `_from`
*
* @param _from The address that owns the tokens to be burned
* @param _value The amount of tokens to be burned
* @return Whether the tokens where sucessfully burned or not
*/
function burn(address _from, uint _value) returns (bool);
}
/**
* @title Token Changer interface
*
* Basic token changer public interface
*
* #created 06/10/2017
* #author Frank Bonnet
*/
contract ITokenChanger {
/**
* Returns true if '_token' is on of the tokens that are
* managed by this token changer
*
* @param _token The address being tested
* @return Whether the '_token' is part of this token changer
*/
function isToken(address _token) constant returns (bool);
/**
* Returns the address of the left token
*
* @return Left token address
*/
function getLeftToken() constant returns (address);
/**
* Returns the address of the right token
*
* @return Right token address
*/
function getRightToken() constant returns (address);
/**
* Returns the fee that is paid in tokens when using
* the token changer
*
* @return The percentage of tokens that is charged
*/
function getFee() constant returns (uint);
/**
* Returns the rate that is used to change between tokens
*
* @return The rate used when changing tokens
*/
function getRate() constant returns (uint);
/**
* Returns the precision of the rate and fee params
*
* @return The amount of decimals used
*/
function getPrecision() constant returns (uint);
/**
* Calculates and returns the fee based on `_value` of tokens
*
* @return The actual fee
*/
function calculateFee(uint _value) constant returns (uint);
}
/**
* @title Token Changer
*
* Provides a generic way to convert between two tokens using a fixed
* ratio and an optional fee.
*
* #created 06/10/2017
* #author Frank Bonnet
*/
contract TokenChanger is ITokenChanger, IPausable {
IManagedToken private tokenLeft; // tokenLeft = tokenRight * rate / precision
IManagedToken private tokenRight; // tokenRight = tokenLeft / rate * precision
uint private rate; // Ratio between tokens
uint private fee; // Percentage lost in transfer
uint private precision; // Precision
bool private paused; // Paused state
bool private burn; // Whether the changer should burn tokens
/**
* Only if '_token' is the left or right token
* that of the token changer
*/
modifier is_token(address _token) {
require(_token == address(tokenLeft) || _token == address(tokenRight));
_;
}
/**
* Construct token changer
*
* @param _tokenLeft Ref to the 'left' token smart-contract
* @param _tokenRight Ref to the 'right' token smart-contract
* @param _rate The rate used when changing tokens
* @param _fee The percentage of tokens that is charged
* @param _decimals The amount of decimals used for _rate and _fee
* @param _paused Whether the token changer starts in the paused state or not
* @param _burn Whether the changer should burn tokens or not
*/
function TokenChanger(address _tokenLeft, address _tokenRight, uint _rate, uint _fee, uint _decimals, bool _paused, bool _burn) {
tokenLeft = IManagedToken(_tokenLeft);
tokenRight = IManagedToken(_tokenRight);
rate = _rate;
fee = _fee;
precision = _decimals > 0 ? 10**_decimals : 1;
paused = _paused;
burn = _burn;
}
/**
* Returns true if '_token' is on of the tokens that are
* managed by this token changer
*
* @param _token The address being tested
* @return Whether the '_token' is part of this token changer
*/
function isToken(address _token) public constant returns (bool) {
return _token == address(tokenLeft) || _token == address(tokenRight);
}
/**
* Returns the address of the left token
*
* @return Left token address
*/
function getLeftToken() public constant returns (address) {
return tokenLeft;
}
/**
* Returns the address of the right token
*
* @return Right token address
*/
function getRightToken() public constant returns (address) {
return tokenRight;
}
/**
* Returns the fee that is paid in tokens when using
* the token changer
*
* @return The percentage of tokens that is charged
*/
function getFee() public constant returns (uint) {
return fee;
}
/**
* Returns the rate that is used to change between tokens
*
* @return The rate used when changing tokens
*/
function getRate() public constant returns (uint) {
return rate;
}
/**
* Returns the precision of the rate and fee params
*
* @return The amount of decimals used
*/
function getPrecision() public constant returns (uint) {
return precision;
}
/**
* Returns whether the token changer is currently
* paused or not. While being in the paused state
* the contract should revert the transaction instead
* of converting tokens
*
* @return Whether the token changer is in the paused state
*/
function isPaused() public constant returns (bool) {
return paused;
}
/**
* Pause the token changer making the contract
* revert the transaction instead of converting
*/
function pause() public {
paused = true;
}
/**
* Resume the token changer making the contract
* convert tokens instead of reverting the transaction
*/
function resume() public {
paused = false;
}
/**
* Calculates and returns the fee based on `_value` of tokens
*
* @param _value The amount of tokens that is being converted
* @return The actual fee
*/
function calculateFee(uint _value) public constant returns (uint) {
return fee == 0 ? 0 : _value * fee / precision;
}
/**
* Converts tokens by burning the tokens received at the token smart-contact
* located at `_from` and by issuing tokens at the opposite token smart-contract
*
* @param _from The token smart-contract that received the tokens
* @param _sender The account that send the tokens (token owner)
* @param _value The amount of tokens that where received
*/
function convert(address _from, address _sender, uint _value) internal {
require(!paused);
require(_value > 0);
uint amountToIssue;
if (_from == address(tokenLeft)) {
amountToIssue = _value * rate / precision;
tokenRight.issue(_sender, amountToIssue - calculateFee(amountToIssue));
if (burn) {
tokenLeft.burn(this, _value);
}
}
else if (_from == address(tokenRight)) {
amountToIssue = _value * precision / rate;
tokenLeft.issue(_sender, amountToIssue - calculateFee(amountToIssue));
if (burn) {
tokenRight.burn(this, _value);
}
}
}
}
/**
* @title DRPU Converter
*
* Will allow DRP token holders to convert their DRP Balance into DRPU at the ratio of 1:2, locking all recieved DRP into the converter.
*
* DRPU as indicated by its ‘U’ designation is Dcorp’s utility token for those who are under strict
* compliance within their country of residence, and does not entitle holders to profit sharing.
*
* https://www.dcorp.it/drpu
*
* #created 11/10/2017
* #author Frank Bonnet
*/
contract DRPUTokenConverter is TokenChanger, IAuthenticationManager, TransferableOwnership, TokenRetriever {
// Authentication
IWhitelist private whitelist;
bool private requireAuthentication;
/**
* Construct drp - drpu token changer
*
* Rate is multiplied by 10**6 taking into account the difference in
* decimals between (old) DRP (2) and DRPU (8)
*
* @param _whitelist The address of the whitelist authenticator
* @param _drp Ref to the (old) DRP token smart-contract
* @param _drpu Ref to the DRPU token smart-contract https://www.dcorp.it/drpu
*/
function DRPUTokenConverter(address _whitelist, address _drp, address _drpu)
TokenChanger(_drp, _drpu, 2 * 10**6, 0, 0, false, false) {
whitelist = IWhitelist(_whitelist);
requireAuthentication = true;
}
/**
* Returns true if authentication is enabled and false
* otherwise
*
* @return Whether the converter is currently authenticating or not
*/
function isAuthenticating() public constant returns (bool) {
return requireAuthentication;
}
/**
* Enable authentication
*/
function enableAuthentication() public only_owner {
requireAuthentication = true;
}
/**
* Disable authentication
*/
function disableAuthentication() public only_owner {
requireAuthentication = false;
}
/**
* Pause the token changer making the contract
* revert the transaction instead of converting
*/
function pause() public only_owner {
super.pause();
}
/**
* Resume the token changer making the contract
* convert tokens instead of reverting the transaction
*/
function resume() public only_owner {
super.resume();
}
/**
* Request that the (old) drp smart-contract transfers `_value` worth
* of (old) drp to the drpu token converter to be converted
*
* Note! This function requires the drpu token converter smart-contract
* to be approved to spend at least `_value` worth of (old) drp by the
* owner of the tokens by calling the approve() function in the (old)
* dpr token smart-contract
*
* @param _value The amount of tokens to transfer and convert
*/
function requestConversion(uint _value) public {
require(_value > 0);
address sender = msg.sender;
// Authenticate
require(!requireAuthentication || whitelist.authenticate(sender));
IToken drpToken = IToken(getLeftToken());
drpToken.transferFrom(sender, this, _value); // Transfer old drp from sender to converter
convert(drpToken, sender, _value); // Convert to drps
}
/**
* Failsafe mechanism
*
* Allows the owner to retrieve tokens from the contract that
* might have been send there by accident
*
* @param _tokenContract The address of ERC20 compatible token
*/
function retrieveTokens(address _tokenContract) public only_owner {
require(getLeftToken() != _tokenContract); // Ensure that the (old) drp token stays locked
super.retrieveTokens(_tokenContract);
}
/**
* Prevents the accidental sending of ether
*/
function () payable {
revert();
}
}File 2 of 4: DRPToken
contract Owned {
// The address of the account that is the current owner
address public owner;
// The publiser is the inital owner
function Owned() {
owner = msg.sender;
}
/**
* Access is restricted to the current owner
*/
modifier onlyOwner() {
if (msg.sender != owner) throw;
_;
}
/**
* Transfer ownership to `_newOwner`
*
* @param _newOwner The address of the account that will become the new owner
*/
function transferOwnership(address _newOwner) onlyOwner {
owner = _newOwner;
}
}
// Abstract contract for the full ERC 20 Token standard
// https://github.com/ethereum/EIPs/issues/20
contract Token {
/* This is a slight change to the ERC20 base standard.
function totalSupply() constant returns (uint256 supply);
is replaced with:
uint256 public totalSupply;
This automatically creates a getter function for the totalSupply.
This is moved to the base contract since public getter functions are not
currently recognised as an implementation of the matching abstract
function by the compiler.
*/
/// total amount of tokens
uint256 public totalSupply;
/// @param _owner The address from which the balance will be retrieved
/// @return The balance
function balanceOf(address _owner) constant returns (uint256 balance);
/// @notice send `_value` token to `_to` from `msg.sender`
/// @param _to The address of the recipient
/// @param _value The amount of token to be transferred
/// @return Whether the transfer was successful or not
function transfer(address _to, uint256 _value) returns (bool success);
/// @notice send `_value` token to `_to` from `_from` on the condition it is approved by `_from`
/// @param _from The address of the sender
/// @param _to The address of the recipient
/// @param _value The amount of token to be transferred
/// @return Whether the transfer was successful or not
function transferFrom(address _from, address _to, uint256 _value) returns (bool success);
/// @notice `msg.sender` approves `_spender` to spend `_value` tokens
/// @param _spender The address of the account able to transfer the tokens
/// @param _value The amount of tokens to be approved for transfer
/// @return Whether the approval was successful or not
function approve(address _spender, uint256 _value) returns (bool success);
/// @param _owner The address of the account owning tokens
/// @param _spender The address of the account able to transfer the tokens
/// @return Amount of remaining tokens allowed to spent
function allowance(address _owner, address _spender) constant returns (uint256 remaining);
event Transfer(address indexed _from, address indexed _to, uint256 _value);
event Approval(address indexed _owner, address indexed _spender, uint256 _value);
}
/**
* Implements ERC 20 Token standard: https://github.com/ethereum/EIPs/issues/20
*
* Modified version of https://github.com/ConsenSys/Tokens that implements the
* original Token contract, an abstract contract for the full ERC 20 Token standard
*/
contract StandardToken is Token {
// Token starts if the locked state restricting transfers
bool public locked;
// DCORP token balances
mapping (address => uint256) balances;
// DCORP token allowances
mapping (address => mapping (address => uint256)) allowed;
/**
* Get balance of `_owner`
*
* @param _owner The address from which the balance will be retrieved
* @return The balance
*/
function balanceOf(address _owner) constant returns (uint256 balance) {
return balances[_owner];
}
/**
* Send `_value` token to `_to` from `msg.sender`
*
* @param _to The address of the recipient
* @param _value The amount of token to be transferred
* @return Whether the transfer was successful or not
*/
function transfer(address _to, uint256 _value) returns (bool success) {
// Unable to transfer while still locked
if (locked) {
throw;
}
// Check if the sender has enough tokens
if (balances[msg.sender] < _value) {
throw;
}
// Check for overflows
if (balances[_to] + _value < balances[_to]) {
throw;
}
// Transfer tokens
balances[msg.sender] -= _value;
balances[_to] += _value;
// Notify listners
Transfer(msg.sender, _to, _value);
return true;
}
/**
* Send `_value` token to `_to` from `_from` on the condition it is approved by `_from`
*
* @param _from The address of the sender
* @param _to The address of the recipient
* @param _value The amount of token to be transferred
* @return Whether the transfer was successful or not
*/
function transferFrom(address _from, address _to, uint256 _value) returns (bool success) {
// Unable to transfer while still locked
if (locked) {
throw;
}
// Check if the sender has enough
if (balances[_from] < _value) {
throw;
}
// Check for overflows
if (balances[_to] + _value < balances[_to]) {
throw;
}
// Check allowance
if (_value > allowed[_from][msg.sender]) {
throw;
}
// Transfer tokens
balances[_to] += _value;
balances[_from] -= _value;
// Update allowance
allowed[_from][msg.sender] -= _value;
// Notify listners
Transfer(_from, _to, _value);
return true;
}
/**
* `msg.sender` approves `_spender` to spend `_value` tokens
*
* @param _spender The address of the account able to transfer the tokens
* @param _value The amount of tokens to be approved for transfer
* @return Whether the approval was successful or not
*/
function approve(address _spender, uint256 _value) returns (bool success) {
// Unable to approve while still locked
if (locked) {
throw;
}
// Update allowance
allowed[msg.sender][_spender] = _value;
// Notify listners
Approval(msg.sender, _spender, _value);
return true;
}
/**
* Get the amount of remaining tokens that `_spender` is allowed to spend from `_owner`
*
* @param _owner The address of the account owning tokens
* @param _spender The address of the account able to transfer the tokens
* @return Amount of remaining tokens allowed to spent
*/
function allowance(address _owner, address _spender) constant returns (uint256 remaining) {
return allowed[_owner][_spender];
}
}
/**
* @title DRP (DCorp) token
*
* Implements ERC 20 Token standard: https://github.com/ethereum/EIPs/issues/20 with the addition
* of ownership, a lock and issuing.
*
* #created 05/03/2017
* #author Frank Bonnet
*/
contract DRPToken is Owned, StandardToken {
// Ethereum token standaard
string public standard = "Token 0.1";
// Full name
string public name = "DCORP";
// Symbol
string public symbol = "DRP";
// No decimal points
uint8 public decimals = 2;
// Core team insentive distribution
bool public incentiveDistributionStarted = false;
uint256 public incentiveDistributionDate = 0;
uint256 public incentiveDistributionRound = 1;
uint256 public incentiveDistributionMaxRounds = 3;
uint256 public incentiveDistributionInterval = 1 years;
uint256 public incentiveDistributionRoundDenominator = 2;
// Core team incentives
struct Incentive {
address recipient;
uint8 percentage;
}
Incentive[] public incentives;
/**
* Starts with a total supply of zero and the creator starts with
* zero tokens (just like everyone else)
*/
function DRPToken() {
balances[msg.sender] = 0;
totalSupply = 0;
locked = true;
incentives.push(Incentive(0x3cAf983aCCccc2551195e0809B7824DA6FDe4EC8, 49)); // 0.049 * 10^3 founder
incentives.push(Incentive(0x11666F3492F03c930682D0a11c93BF708d916ad7, 19)); // 0.019 * 10^3 core angel
incentives.push(Incentive(0x6c31dE34b5df94F681AFeF9757eC3ed1594F7D9e, 19)); // 0.019 * 10^3 core angel
incentives.push(Incentive(0x5becE8B6Cb3fB8FAC39a09671a9c32872ACBF267, 9)); // 0.009 * 10^3 core early
incentives.push(Incentive(0x00DdD4BB955e0C93beF9b9986b5F5F330Fd016c6, 5)); // 0.005 * 10^3 misc
}
/**
* Starts incentive distribution
*
* Called by the crowdsale contract when tokenholders voted
* for the transfer of ownership of the token contract to DCorp
*
* @return Whether the incentive distribution was started
*/
function startIncentiveDistribution() onlyOwner returns (bool success) {
if (!incentiveDistributionStarted) {
incentiveDistributionDate = now + incentiveDistributionInterval;
incentiveDistributionStarted = true;
}
return incentiveDistributionStarted;
}
/**
* Distributes incentives over the core team members as
* described in the whitepaper
*/
function withdrawIncentives() {
// Crowdsale triggers incentive distribution
if (!incentiveDistributionStarted) {
throw;
}
// Enforce max distribution rounds
if (incentiveDistributionRound > incentiveDistributionMaxRounds) {
throw;
}
// Enforce time interval
if (now < incentiveDistributionDate) {
throw;
}
uint256 totalSupplyToDate = totalSupply;
uint256 denominator = 1;
// Incentive decreased each round
if (incentiveDistributionRound > 1) {
denominator = incentiveDistributionRoundDenominator**(incentiveDistributionRound - 1);
}
for (uint256 i = 0; i < incentives.length; i++) {
// totalSupplyToDate * (percentage * 10^3) / 10^3 / denominator
uint256 amount = totalSupplyToDate * incentives[i].percentage / 10**3 / denominator;
address recipient = incentives[i].recipient;
// Create tokens
balances[recipient] += amount;
totalSupply += amount;
// Notify listners
Transfer(0, this, amount);
Transfer(this, recipient, amount);
}
// Next round
incentiveDistributionDate = now + incentiveDistributionInterval;
incentiveDistributionRound++;
}
/**
* Unlocks the token irreversibly so that the transfering of value is enabled
*
* @return Whether the unlocking was successful or not
*/
function unlock() onlyOwner returns (bool success) {
locked = false;
return true;
}
/**
* Issues `_value` new tokens to `_recipient` (_value < 0 guarantees that tokens are never removed)
*
* @param _recipient The address to which the tokens will be issued
* @param _value The amount of new tokens to issue
* @return Whether the approval was successful or not
*/
function issue(address _recipient, uint256 _value) onlyOwner returns (bool success) {
// Guarantee positive
if (_value < 0) {
throw;
}
// Create tokens
balances[_recipient] += _value;
totalSupply += _value;
// Notify listners
Transfer(0, owner, _value);
Transfer(owner, _recipient, _value);
return true;
}
/**
* Prevents accidental sending of ether
*/
function () {
throw;
}
}File 3 of 4: DRPUToken
pragma solidity ^0.4.15;
/**
* @title Input validation
*
* - Validates argument length
*
* #created 01/10/2017
* #author Frank Bonnet
*/
contract InputValidator {
/**
* ERC20 Short Address Attack fix
*/
modifier safe_arguments(uint _numArgs) {
assert(msg.data.length == _numArgs * 32 + 4);
_;
}
}
/**
* @title Multi-owned interface
*
* Interface that allows multiple owners
*
* #created 09/10/2017
* #author Frank Bonnet
*/
contract IMultiOwned {
/**
* Returns true if `_account` is an owner
*
* @param _account The address to test against
*/
function isOwner(address _account) constant returns (bool);
/**
* Returns the amount of owners
*
* @return The amount of owners
*/
function getOwnerCount() constant returns (uint);
/**
* Gets the owner at `_index`
*
* @param _index The index of the owner
* @return The address of the owner found at `_index`
*/
function getOwnerAt(uint _index) constant returns (address);
/**
* Adds `_account` as a new owner
*
* @param _account The account to add as an owner
*/
function addOwner(address _account);
/**
* Removes `_account` as an owner
*
* @param _account The account to remove as an owner
*/
function removeOwner(address _account);
}
/**
* @title Multi-owned
*
* Allows multiple owners
*
* #created 09/10/2017
* #author Frank Bonnet
*/
contract MultiOwned is IMultiOwned {
// Owners
mapping (address => uint) private owners;
address[] private ownersIndex;
/**
* Access is restricted to owners only
*/
modifier only_owner() {
require(isOwner(msg.sender));
_;
}
/**
* The publisher is the initial owner
*/
function MultiOwned() {
ownersIndex.push(msg.sender);
owners[msg.sender] = 0;
}
/**
* Returns true if `_account` is the current owner
*
* @param _account The address to test against
*/
function isOwner(address _account) public constant returns (bool) {
return owners[_account] < ownersIndex.length && _account == ownersIndex[owners[_account]];
}
/**
* Returns the amount of owners
*
* @return The amount of owners
*/
function getOwnerCount() public constant returns (uint) {
return ownersIndex.length;
}
/**
* Gets the owner at `_index`
*
* @param _index The index of the owner
* @return The address of the owner found at `_index`
*/
function getOwnerAt(uint _index) public constant returns (address) {
return ownersIndex[_index];
}
/**
* Adds `_account` as a new owner
*
* @param _account The account to add as an owner
*/
function addOwner(address _account) public only_owner {
if (!isOwner(_account)) {
owners[_account] = ownersIndex.push(_account) - 1;
}
}
/**
* Removes `_account` as an owner
*
* @param _account The account to remove as an owner
*/
function removeOwner(address _account) public only_owner {
if (isOwner(_account)) {
uint indexToDelete = owners[_account];
address keyToMove = ownersIndex[ownersIndex.length - 1];
ownersIndex[indexToDelete] = keyToMove;
owners[keyToMove] = indexToDelete;
ownersIndex.length--;
}
}
}
/**
* @title Token retrieve interface
*
* Allows tokens to be retrieved from a contract
*
* #created 29/09/2017
* #author Frank Bonnet
*/
contract ITokenRetriever {
/**
* Extracts tokens from the contract
*
* @param _tokenContract The address of ERC20 compatible token
*/
function retrieveTokens(address _tokenContract);
}
/**
* @title Token retrieve
*
* Allows tokens to be retrieved from a contract
*
* #created 18/10/2017
* #author Frank Bonnet
*/
contract TokenRetriever is ITokenRetriever {
/**
* Extracts tokens from the contract
*
* @param _tokenContract The address of ERC20 compatible token
*/
function retrieveTokens(address _tokenContract) public {
IToken tokenInstance = IToken(_tokenContract);
uint tokenBalance = tokenInstance.balanceOf(this);
if (tokenBalance > 0) {
tokenInstance.transfer(msg.sender, tokenBalance);
}
}
}
/**
* @title Observable interface
*
* Allows observers to register and unregister with the
* implementing smart-contract that is observable
*
* #created 09/10/2017
* #author Frank Bonnet
*/
contract IObservable {
/**
* Returns true if `_account` is a registered observer
*
* @param _account The account to test against
* @return Whether the account is a registered observer
*/
function isObserver(address _account) constant returns (bool);
/**
* Gets the amount of registered observers
*
* @return The amount of registered observers
*/
function getObserverCount() constant returns (uint);
/**
* Gets the observer at `_index`
*
* @param _index The index of the observer
* @return The observers address
*/
function getObserverAtIndex(uint _index) constant returns (address);
/**
* Register `_observer` as an observer
*
* @param _observer The account to add as an observer
*/
function registerObserver(address _observer);
/**
* Unregister `_observer` as an observer
*
* @param _observer The account to remove as an observer
*/
function unregisterObserver(address _observer);
}
/**
* @title Abstract Observable
*
* Allows observers to register and unregister with the the
* implementing smart-contract that is observable
*
* #created 09/10/2017
* #author Frank Bonnet
*/
contract Observable is IObservable {
// Observers
mapping(address => uint) private observers;
address[] private observerIndex;
/**
* Returns true if `_account` is a registered observer
*
* @param _account The account to test against
* @return Whether the account is a registered observer
*/
function isObserver(address _account) public constant returns (bool) {
return observers[_account] < observerIndex.length && _account == observerIndex[observers[_account]];
}
/**
* Gets the amount of registered observers
*
* @return The amount of registered observers
*/
function getObserverCount() public constant returns (uint) {
return observerIndex.length;
}
/**
* Gets the observer at `_index`
*
* @param _index The index of the observer
* @return The observers address
*/
function getObserverAtIndex(uint _index) public constant returns (address) {
return observerIndex[_index];
}
/**
* Register `_observer` as an observer
*
* @param _observer The account to add as an observer
*/
function registerObserver(address _observer) public {
require(canRegisterObserver(_observer));
if (!isObserver(_observer)) {
observers[_observer] = observerIndex.push(_observer) - 1;
}
}
/**
* Unregister `_observer` as an observer
*
* @param _observer The account to remove as an observer
*/
function unregisterObserver(address _observer) public {
require(canUnregisterObserver(_observer));
if (isObserver(_observer)) {
uint indexToDelete = observers[_observer];
address keyToMove = observerIndex[observerIndex.length - 1];
observerIndex[indexToDelete] = keyToMove;
observers[keyToMove] = indexToDelete;
observerIndex.length--;
}
}
/**
* Returns whether it is allowed to register `_observer` by calling
* canRegisterObserver() in the implementing smart-contract
*
* @param _observer The address to register as an observer
* @return Whether the sender is allowed or not
*/
function canRegisterObserver(address _observer) internal constant returns (bool);
/**
* Returns whether it is allowed to unregister `_observer` by calling
* canRegisterObserver() in the implementing smart-contract
*
* @param _observer The address to unregister as an observer
* @return Whether the sender is allowed or not
*/
function canUnregisterObserver(address _observer) internal constant returns (bool);
}
/**
* @title Token observer interface
*
* Allows a token smart-contract to notify observers
* when tokens are received
*
* #created 09/10/2017
* #author Frank Bonnet
*/
contract ITokenObserver {
/**
* Called by the observed token smart-contract in order
* to notify the token observer when tokens are received
*
* @param _from The address that the tokens where send from
* @param _value The amount of tokens that was received
*/
function notifyTokensReceived(address _from, uint _value);
}
/**
* @title ERC20 compatible token interface
*
* - Implements ERC 20 Token standard
* - Implements short address attack fix
*
* #created 29/09/2017
* #author Frank Bonnet
*/
contract IToken {
/**
* Get the total supply of tokens
*
* @return The total supply
*/
function totalSupply() constant returns (uint);
/**
* Get balance of `_owner`
*
* @param _owner The address from which the balance will be retrieved
* @return The balance
*/
function balanceOf(address _owner) constant returns (uint);
/**
* Send `_value` token to `_to` from `msg.sender`
*
* @param _to The address of the recipient
* @param _value The amount of token to be transferred
* @return Whether the transfer was successful or not
*/
function transfer(address _to, uint _value) returns (bool);
/**
* Send `_value` token to `_to` from `_from` on the condition it is approved by `_from`
*
* @param _from The address of the sender
* @param _to The address of the recipient
* @param _value The amount of token to be transferred
* @return Whether the transfer was successful or not
*/
function transferFrom(address _from, address _to, uint _value) returns (bool);
/**
* `msg.sender` approves `_spender` to spend `_value` tokens
*
* @param _spender The address of the account able to transfer the tokens
* @param _value The amount of tokens to be approved for transfer
* @return Whether the approval was successful or not
*/
function approve(address _spender, uint _value) returns (bool);
/**
* Get the amount of remaining tokens that `_spender` is allowed to spend from `_owner`
*
* @param _owner The address of the account owning tokens
* @param _spender The address of the account able to transfer the tokens
* @return Amount of remaining tokens allowed to spent
*/
function allowance(address _owner, address _spender) constant returns (uint);
}
/**
* @title ERC20 compatible token
*
* - Implements ERC 20 Token standard
* - Implements short address attack fix
*
* #created 29/09/2017
* #author Frank Bonnet
*/
contract Token is IToken, InputValidator {
// Ethereum token standard
string public standard = "Token 0.3";
string public name;
string public symbol;
uint8 public decimals;
// Token state
uint internal totalTokenSupply;
// Token balances
mapping (address => uint) internal balances;
// Token allowances
mapping (address => mapping (address => uint)) internal allowed;
// Events
event Transfer(address indexed _from, address indexed _to, uint _value);
event Approval(address indexed _owner, address indexed _spender, uint _value);
/**
* Construct ERC20 token
*
* @param _name The full token name
* @param _symbol The token symbol (aberration)
* @param _decimals The token precision
*/
function Token(string _name, string _symbol, uint8 _decimals) {
name = _name;
symbol = _symbol;
decimals = _decimals;
balances[msg.sender] = 0;
totalTokenSupply = 0;
}
/**
* Get the total token supply
*
* @return The total supply
*/
function totalSupply() public constant returns (uint) {
return totalTokenSupply;
}
/**
* Get balance of `_owner`
*
* @param _owner The address from which the balance will be retrieved
* @return The balance
*/
function balanceOf(address _owner) public constant returns (uint) {
return balances[_owner];
}
/**
* Send `_value` token to `_to` from `msg.sender`
*
* @param _to The address of the recipient
* @param _value The amount of token to be transferred
* @return Whether the transfer was successful or not
*/
function transfer(address _to, uint _value) public safe_arguments(2) returns (bool) {
// Check if the sender has enough tokens
require(balances[msg.sender] >= _value);
// Check for overflows
require(balances[_to] + _value >= balances[_to]);
// Transfer tokens
balances[msg.sender] -= _value;
balances[_to] += _value;
// Notify listeners
Transfer(msg.sender, _to, _value);
return true;
}
/**
* Send `_value` token to `_to` from `_from` on the condition it is approved by `_from`
*
* @param _from The address of the sender
* @param _to The address of the recipient
* @param _value The amount of token to be transferred
* @return Whether the transfer was successful or not
*/
function transferFrom(address _from, address _to, uint _value) public safe_arguments(3) returns (bool) {
// Check if the sender has enough
require(balances[_from] >= _value);
// Check for overflows
require(balances[_to] + _value >= balances[_to]);
// Check allowance
require(_value <= allowed[_from][msg.sender]);
// Transfer tokens
balances[_to] += _value;
balances[_from] -= _value;
// Update allowance
allowed[_from][msg.sender] -= _value;
// Notify listeners
Transfer(_from, _to, _value);
return true;
}
/**
* `msg.sender` approves `_spender` to spend `_value` tokens
*
* @param _spender The address of the account able to transfer the tokens
* @param _value The amount of tokens to be approved for transfer
* @return Whether the approval was successful or not
*/
function approve(address _spender, uint _value) public safe_arguments(2) returns (bool) {
// Update allowance
allowed[msg.sender][_spender] = _value;
// Notify listeners
Approval(msg.sender, _spender, _value);
return true;
}
/**
* Get the amount of remaining tokens that `_spender` is allowed to spend from `_owner`
*
* @param _owner The address of the account owning tokens
* @param _spender The address of the account able to transfer the tokens
* @return Amount of remaining tokens allowed to spent
*/
function allowance(address _owner, address _spender) public constant returns (uint) {
return allowed[_owner][_spender];
}
}
/**
* @title ManagedToken interface
*
* Adds the following functionality to the basic ERC20 token
* - Locking
* - Issuing
* - Burning
*
* #created 29/09/2017
* #author Frank Bonnet
*/
contract IManagedToken is IToken {
/**
* Returns true if the token is locked
*
* @return Whether the token is locked
*/
function isLocked() constant returns (bool);
/**
* Locks the token so that the transfering of value is disabled
*
* @return Whether the unlocking was successful or not
*/
function lock() returns (bool);
/**
* Unlocks the token so that the transfering of value is enabled
*
* @return Whether the unlocking was successful or not
*/
function unlock() returns (bool);
/**
* Issues `_value` new tokens to `_to`
*
* @param _to The address to which the tokens will be issued
* @param _value The amount of new tokens to issue
* @return Whether the tokens where sucessfully issued or not
*/
function issue(address _to, uint _value) returns (bool);
/**
* Burns `_value` tokens of `_from`
*
* @param _from The address that owns the tokens to be burned
* @param _value The amount of tokens to be burned
* @return Whether the tokens where sucessfully burned or not
*/
function burn(address _from, uint _value) returns (bool);
}
/**
* @title ManagedToken
*
* Adds the following functionality to the basic ERC20 token
* - Locking
* - Issuing
* - Burning
*
* #created 29/09/2017
* #author Frank Bonnet
*/
contract ManagedToken is IManagedToken, Token, MultiOwned {
// Token state
bool internal locked;
/**
* Allow access only when not locked
*/
modifier only_when_unlocked() {
require(!locked);
_;
}
/**
* Construct managed ERC20 token
*
* @param _name The full token name
* @param _symbol The token symbol (aberration)
* @param _decimals The token precision
* @param _locked Whether the token should be locked initially
*/
function ManagedToken(string _name, string _symbol, uint8 _decimals, bool _locked)
Token(_name, _symbol, _decimals) {
locked = _locked;
}
/**
* Send `_value` token to `_to` from `msg.sender`
*
* @param _to The address of the recipient
* @param _value The amount of token to be transferred
* @return Whether the transfer was successful or not
*/
function transfer(address _to, uint _value) public only_when_unlocked returns (bool) {
return super.transfer(_to, _value);
}
/**
* Send `_value` token to `_to` from `_from` on the condition it is approved by `_from`
*
* @param _from The address of the sender
* @param _to The address of the recipient
* @param _value The amount of token to be transferred
* @return Whether the transfer was successful or not
*/
function transferFrom(address _from, address _to, uint _value) public only_when_unlocked returns (bool) {
return super.transferFrom(_from, _to, _value);
}
/**
* `msg.sender` approves `_spender` to spend `_value` tokens
*
* @param _spender The address of the account able to transfer the tokens
* @param _value The amount of tokens to be approved for transfer
* @return Whether the approval was successful or not
*/
function approve(address _spender, uint _value) public returns (bool) {
return super.approve(_spender, _value);
}
/**
* Returns true if the token is locked
*
* @return Whether the token is locked
*/
function isLocked() public constant returns (bool) {
return locked;
}
/**
* Locks the token so that the transfering of value is enabled
*
* @return Whether the locking was successful or not
*/
function lock() public only_owner returns (bool) {
locked = true;
return locked;
}
/**
* Unlocks the token so that the transfering of value is enabled
*
* @return Whether the unlocking was successful or not
*/
function unlock() public only_owner returns (bool) {
locked = false;
return !locked;
}
/**
* Issues `_value` new tokens to `_to`
*
* @param _to The address to which the tokens will be issued
* @param _value The amount of new tokens to issue
* @return Whether the approval was successful or not
*/
function issue(address _to, uint _value) public only_owner safe_arguments(2) returns (bool) {
// Check for overflows
require(balances[_to] + _value >= balances[_to]);
// Create tokens
balances[_to] += _value;
totalTokenSupply += _value;
// Notify listeners
Transfer(0, this, _value);
Transfer(this, _to, _value);
return true;
}
/**
* Burns `_value` tokens of `_recipient`
*
* @param _from The address that owns the tokens to be burned
* @param _value The amount of tokens to be burned
* @return Whether the tokens where sucessfully burned or not
*/
function burn(address _from, uint _value) public only_owner safe_arguments(2) returns (bool) {
// Check if the token owner has enough tokens
require(balances[_from] >= _value);
// Check for overflows
require(balances[_from] - _value <= balances[_from]);
// Burn tokens
balances[_from] -= _value;
totalTokenSupply -= _value;
// Notify listeners
Transfer(_from, 0, _value);
return true;
}
}
/**
* @title DRP Utility token (DRPU)
*
* DRPU as indicated by its ‘U’ designation is Dcorp’s utility token for those who are under strict
* compliance within their country of residence, and does not entitle holders to profit sharing.
*
* https://www.dcorp.it/drpu
*
* #created 01/10/2017
* #author Frank Bonnet
*/
contract DRPUToken is ManagedToken, Observable, TokenRetriever {
/**
* Construct the managed utility token
*/
function DRPUToken() ManagedToken("DRP Utility", "DRPU", 8, false) {}
/**
* Returns whether sender is allowed to register `_observer`
*
* @param _observer The address to register as an observer
* @return Whether the sender is allowed or not
*/
function canRegisterObserver(address _observer) internal constant returns (bool) {
return _observer != address(this) && isOwner(msg.sender);
}
/**
* Returns whether sender is allowed to unregister `_observer`
*
* @param _observer The address to unregister as an observer
* @return Whether the sender is allowed or not
*/
function canUnregisterObserver(address _observer) internal constant returns (bool) {
return msg.sender == _observer || isOwner(msg.sender);
}
/**
* Send `_value` token to `_to` from `msg.sender`
* - Notifies registered observers when the observer receives tokens
*
* @param _to The address of the recipient
* @param _value The amount of token to be transferred
* @return Whether the transfer was successful or not
*/
function transfer(address _to, uint _value) public returns (bool) {
bool result = super.transfer(_to, _value);
if (isObserver(_to)) {
ITokenObserver(_to).notifyTokensReceived(msg.sender, _value);
}
return result;
}
/**
* Send `_value` token to `_to` from `_from` on the condition it is approved by `_from`
* - Notifies registered observers when the observer receives tokens
*
* @param _from The address of the sender
* @param _to The address of the recipient
* @param _value The amount of token to be transferred
* @return Whether the transfer was successful or not
*/
function transferFrom(address _from, address _to, uint _value) public returns (bool) {
bool result = super.transferFrom(_from, _to, _value);
if (isObserver(_to)) {
ITokenObserver(_to).notifyTokensReceived(_from, _value);
}
return result;
}
/**
* Failsafe mechanism
*
* Allows the owner to retrieve tokens from the contract that
* might have been send there by accident
*
* @param _tokenContract The address of ERC20 compatible token
*/
function retrieveTokens(address _tokenContract) public only_owner {
super.retrieveTokens(_tokenContract);
}
/**
* Prevents the accidental sending of ether
*/
function () payable {
revert();
}
}File 4 of 4: Whitelist
pragma solidity ^0.4.15;
/**
* @title Ownership interface
*
* Perminent ownership
*
* #created 01/10/2017
* #author Frank Bonnet
*/
contract IOwnership {
/**
* Returns true if `_account` is the current owner
*
* @param _account The address to test against
*/
function isOwner(address _account) constant returns (bool);
/**
* Gets the current owner
*
* @return address The current owner
*/
function getOwner() constant returns (address);
}
/**
* @title Ownership
*
* Perminent ownership
*
* #created 01/10/2017
* #author Frank Bonnet
*/
contract Ownership is IOwnership {
// Owner
address internal owner;
/**
* The publisher is the inital owner
*/
function Ownership() {
owner = msg.sender;
}
/**
* Access is restricted to the current owner
*/
modifier only_owner() {
require(msg.sender == owner);
_;
}
/**
* Returns true if `_account` is the current owner
*
* @param _account The address to test against
*/
function isOwner(address _account) public constant returns (bool) {
return _account == owner;
}
/**
* Gets the current owner
*
* @return address The current owner
*/
function getOwner() public constant returns (address) {
return owner;
}
}
/**
* @title Transferable ownership interface
*
* Enhances ownership by allowing the current owner to
* transfer ownership to a new owner
*
* #created 01/10/2017
* #author Frank Bonnet
*/
contract ITransferableOwnership {
/**
* Transfer ownership to `_newOwner`
*
* @param _newOwner The address of the account that will become the new owner
*/
function transferOwnership(address _newOwner);
}
/**
* @title Transferable ownership
*
* Enhances ownership by allowing the current owner to
* transfer ownership to a new owner
*
* #created 01/10/2017
* #author Frank Bonnet
*/
contract TransferableOwnership is ITransferableOwnership, Ownership {
/**
* Transfer ownership to `_newOwner`
*
* @param _newOwner The address of the account that will become the new owner
*/
function transferOwnership(address _newOwner) public only_owner {
owner = _newOwner;
}
}
/**
* @title IAuthenticator
*
* Authenticator interface
*
* #created 15/10/2017
* #author Frank Bonnet
*/
contract IAuthenticator {
/**
* Authenticate
*
* Returns whether `_account` is authenticated or not
*
* @param _account The account to authenticate
* @return whether `_account` is successfully authenticated
*/
function authenticate(address _account) constant returns (bool);
}
/**
* @title IWhitelist
*
* Whitelist authentication interface
*
* #created 04/10/2017
* #author Frank Bonnet
*/
contract IWhitelist is IAuthenticator {
/**
* Returns whether an entry exists for `_account`
*
* @param _account The account to check
* @return whether `_account` is has an entry in the whitelist
*/
function hasEntry(address _account) constant returns (bool);
/**
* Add `_account` to the whitelist
*
* If an account is currently disabled, the account is reenabled, otherwise
* a new entry is created
*
* @param _account The account to add
*/
function add(address _account);
/**
* Remove `_account` from the whitelist
*
* Will not actually remove the entry but disable it by updating
* the accepted record
*
* @param _account The account to remove
*/
function remove(address _account);
}
/**
* @title Whitelist
*
* Whitelist authentication list
*
* #created 04/10/2017
* #author Frank Bonnet
*/
contract Whitelist is IWhitelist, TransferableOwnership {
struct Entry {
uint datetime;
bool accepted;
uint index;
}
mapping (address => Entry) internal list;
address[] internal listIndex;
/**
* Returns whether an entry exists for `_account`
*
* @param _account The account to check
* @return whether `_account` is has an entry in the whitelist
*/
function hasEntry(address _account) public constant returns (bool) {
return listIndex.length > 0 && _account == listIndex[list[_account].index];
}
/**
* Add `_account` to the whitelist
*
* If an account is currently disabled, the account is reenabled, otherwise
* a new entry is created
*
* @param _account The account to add
*/
function add(address _account) public only_owner {
if (!hasEntry(_account)) {
list[_account] = Entry(
now, true, listIndex.push(_account) - 1);
} else {
Entry storage entry = list[_account];
if (!entry.accepted) {
entry.accepted = true;
entry.datetime = now;
}
}
}
/**
* Remove `_account` from the whitelist
*
* Will not acctually remove the entry but disable it by updating
* the accepted record
*
* @param _account The account to remove
*/
function remove(address _account) public only_owner {
if (hasEntry(_account)) {
Entry storage entry = list[_account];
entry.accepted = false;
entry.datetime = now;
}
}
/**
* Authenticate
*
* Returns whether `_account` is on the whitelist
*
* @param _account The account to authenticate
* @return whether `_account` is successfully authenticated
*/
function authenticate(address _account) public constant returns (bool) {
return list[_account].accepted;
}
}