pragmasolidity 0.5.8;import"./ERC644Balances.sol";
import { ERC1820Client } from"./ERC1820Client.sol";
/**
* @title ERC644 Database Contract
* @author Panos
*/contractCStoreisERC644Balances, ERC1820Client{
address[] internal mDefaultOperators;
mapping(address=>bool) internal mIsDefaultOperator;
mapping(address=>mapping(address=>bool)) internal mRevokedDefaultOperator;
mapping(address=>mapping(address=>bool)) internal mAuthorizedOperators;
/**
* @notice Database construction
* @param _totalSupply The total supply of the token
*/constructor(uint256 _totalSupply, address _initialOwner, address[] memory _defaultOperators) public{
balances[_initialOwner] = _totalSupply;
totalSupply = _totalSupply;
mDefaultOperators = _defaultOperators;
for (uint256 i =0; i < mDefaultOperators.length; i++) { mIsDefaultOperator[mDefaultOperators[i]] =true; }
setInterfaceImplementation("ERC644Balances", address(this));
}
/**
* @notice Increase total supply by `_val`
* @param _val Value to increase
* @return Operation status
*/// solhint-disable-next-line no-unused-varsfunctionincTotalSupply(uint _val) externalonlyModulereturns (bool) {
returnfalse;
}
/**
* @notice Decrease total supply by `_val`
* @param _val Value to decrease
* @return Operation status
*/// solhint-disable-next-line no-unused-varsfunctiondecTotalSupply(uint _val) externalonlyModulereturns (bool) {
returnfalse;
}
/**
* @notice moving `_amount` from `_from` to `_to`
* @param _from The sender address
* @param _to The receiving address
* @param _amount The moving amount
* @return bool The move result
*/functionmove(address _from, address _to, uint256 _amount) externalonlyModulereturns (bool) {
balances[_from] = balances[_from].sub(_amount);
emit BalanceAdj(msg.sender, _from, _amount, "-");
balances[_to] = balances[_to].add(_amount);
emit BalanceAdj(msg.sender, _to, _amount, "+");
returntrue;
}
/**
* @notice Setting operator `_operator` for `_tokenHolder`
* @param _operator The operator to set status
* @param _tokenHolder The token holder to set operator
* @param _status The operator status
* @return bool Status of operation
*/functionsetAuthorizedOperator(address _operator, address _tokenHolder, bool _status) externalonlyModulereturns (bool) {
mAuthorizedOperators[_operator][_tokenHolder] = _status;
returntrue;
}
/**
* @notice Set revoke status for default operator `_operator` for `_tokenHolder`
* @param _operator The default operator to set status
* @param _tokenHolder The token holder to set operator
* @param _status The operator status
* @return bool Status of operation
*/functionsetRevokedDefaultOperator(address _operator, address _tokenHolder, bool _status) externalonlyModulereturns (bool) {
mRevokedDefaultOperator[_operator][_tokenHolder] = _status;
returntrue;
}
/**
* @notice Getting operator `_operator` for `_tokenHolder`
* @param _operator The operator address to get status
* @param _tokenHolder The token holder address
* @return bool Operator status
*/functiongetAuthorizedOperator(address _operator, address _tokenHolder) externalviewreturns (bool) {
return mAuthorizedOperators[_operator][_tokenHolder];
}
/**
* @notice Getting default operator `_operator`
* @param _operator The default operator address to get status
* @return bool Default operator status
*/functiongetDefaultOperator(address _operator) externalviewreturns (bool) {
return mIsDefaultOperator[_operator];
}
/**
* @notice Getting default operators
* @return address[] Default operator addresses
*/functiongetDefaultOperators() externalviewreturns (address[] memory) {
return mDefaultOperators;
}
functiongetRevokedDefaultOperator(address _operator, address _tokenHolder) externalviewreturns (bool) {
return mRevokedDefaultOperator[_operator][_tokenHolder];
}
/**
* @notice Increment `_acct` balance by `_val`
* @param _acct Target account to increment balance.
* @param _val Value to increment
* @return Operation status
*/// solhint-disable-next-line no-unused-varsfunctionincBalance(address _acct, uint _val) publiconlyModulereturns (bool) {
returnfalse;
}
/**
* @notice Decrement `_acct` balance by `_val`
* @param _acct Target account to decrement balance.
* @param _val Value to decrement
* @return Operation status
*/// solhint-disable-next-line no-unused-varsfunctiondecBalance(address _acct, uint _val) publiconlyModulereturns (bool) {
returnfalse;
}
}
Contract Source Code
File 2 of 8: Context.sol
pragmasolidity ^0.5.0;/*
* @dev Provides information about the current execution context, including the
* sender of the transaction and its data. While these are generally available
* via msg.sender and msg.data, they should not be accessed in such a direct
* manner, since when dealing with GSN meta-transactions the account sending and
* paying for execution may not be the actual sender (as far as an application
* is concerned).
*
* This contract is only required for intermediate, library-like contracts.
*/contractContext{
// Empty internal constructor, to prevent people from mistakenly deploying// an instance of this contract, which should be used via inheritance.constructor () internal{ }
// solhint-disable-previous-line no-empty-blocksfunction_msgSender() internalviewreturns (addresspayable) {
returnmsg.sender;
}
function_msgData() internalviewreturns (bytesmemory) {
this; // silence state mutability warning without generating bytecode - see https://github.com/ethereum/solidity/issues/2691returnmsg.data;
}
}
pragmasolidity ^0.5.0;import"./Context.sol";
/**
* @dev Contract module which provides a basic access control mechanism, where
* there is an account (an owner) that can be granted exclusive access to
* specific functions.
*
* This module is used through inheritance. It will make available the modifier
* `onlyOwner`, which can be applied to your functions to restrict their use to
* the owner.
*/contractOwnableisContext{
addressprivate _owner;
eventOwnershipTransferred(addressindexed previousOwner, addressindexed newOwner);
/**
* @dev Initializes the contract setting the deployer as the initial owner.
*/constructor () internal{
address msgSender = _msgSender();
_owner = msgSender;
emit OwnershipTransferred(address(0), msgSender);
}
/**
* @dev Returns the address of the current owner.
*/functionowner() publicviewreturns (address) {
return _owner;
}
/**
* @dev Throws if called by any account other than the owner.
*/modifieronlyOwner() {
require(isOwner(), "Ownable: caller is not the owner");
_;
}
/**
* @dev Returns true if the caller is the current owner.
*/functionisOwner() publicviewreturns (bool) {
return _msgSender() == _owner;
}
/**
* @dev Leaves the contract without owner. It will not be possible to call
* `onlyOwner` functions anymore. Can only be called by the current owner.
*
* NOTE: Renouncing ownership will leave the contract without an owner,
* thereby removing any functionality that is only available to the owner.
*/functionrenounceOwnership() publiconlyOwner{
emit OwnershipTransferred(_owner, address(0));
_owner =address(0);
}
/**
* @dev Transfers ownership of the contract to a new account (`newOwner`).
* Can only be called by the current owner.
*/functiontransferOwnership(address newOwner) publiconlyOwner{
_transferOwnership(newOwner);
}
/**
* @dev Transfers ownership of the contract to a new account (`newOwner`).
*/function_transferOwnership(address newOwner) internal{
require(newOwner !=address(0), "Ownable: new owner is the zero address");
emit OwnershipTransferred(_owner, newOwner);
_owner = newOwner;
}
}
Contract Source Code
File 7 of 8: SafeGuard.sol
pragmasolidity 0.5.8;import"./Ownable.sol";
/**
* @title Safe Guard Contract
* @author Panos
*/contractSafeGuardisOwnable{
eventTransaction(addressindexed destination, uint value, bytes data);
/**
* @dev Allows owner to execute a transaction.
*/functionexecuteTransaction(address destination, uint value, bytesmemory data)
publiconlyOwner{
require(externalCall(destination, value, data.length, data));
emit Transaction(destination, value, data);
}
/**
* @dev call has been separated into its own function in order to take advantage
* of the Solidity's code generator to produce a loop that copies tx.data into memory.
*/functionexternalCall(address destination, uint value, uint dataLength, bytesmemory data)
privatereturns (bool) {
bool result;
assembly { // solhint-disable-line no-inline-assemblylet x :=mload(0x40) // "Allocate" memory for output// (0x40 is where "free memory" pointer is stored by convention)let d :=add(data, 32) // First 32 bytes are the padded length of data, so exclude that
result :=call(
sub(gas, 34710), // 34710 is the value that solidity is currently emitting// It includes callGas (700) + callVeryLow (3, to pay for SUB) + callValueTransferGas (9000) +// callNewAccountGas (25000, in case the destination address does not exist and needs creating)
destination,
value,
d,
dataLength, // Size of the input (in bytes) - this is what fixes the padding problem
x,
0// Output is ignored, therefore the output size is zero
)
}
return result;
}
}
Contract Source Code
File 8 of 8: SafeMath.sol
pragmasolidity ^0.5.0;/**
* @dev Wrappers over Solidity's arithmetic operations with added overflow
* checks.
*
* Arithmetic operations in Solidity wrap on overflow. This can easily result
* in bugs, because programmers usually assume that an overflow raises an
* error, which is the standard behavior in high level programming languages.
* `SafeMath` restores this intuition by reverting the transaction when an
* operation overflows.
*
* Using this library instead of the unchecked operations eliminates an entire
* class of bugs, so it's recommended to use it always.
*/librarySafeMath{
/**
* @dev Returns the addition of two unsigned integers, reverting on
* overflow.
*
* Counterpart to Solidity's `+` operator.
*
* Requirements:
* - Addition cannot overflow.
*/functionadd(uint256 a, uint256 b) internalpurereturns (uint256) {
uint256 c = a + b;
require(c >= a, "SafeMath: addition overflow");
return c;
}
/**
* @dev Returns the subtraction of two unsigned integers, reverting on
* overflow (when the result is negative).
*
* Counterpart to Solidity's `-` operator.
*
* Requirements:
* - Subtraction cannot overflow.
*/functionsub(uint256 a, uint256 b) internalpurereturns (uint256) {
return sub(a, b, "SafeMath: subtraction overflow");
}
/**
* @dev Returns the subtraction of two unsigned integers, reverting with custom message on
* overflow (when the result is negative).
*
* Counterpart to Solidity's `-` operator.
*
* Requirements:
* - Subtraction cannot overflow.
*
* NOTE: This is a feature of the next version of OpenZeppelin Contracts.
* @dev Get it via `npm install @openzeppelin/contracts@next`.
*/functionsub(uint256 a, uint256 b, stringmemory errorMessage) internalpurereturns (uint256) {
require(b <= a, errorMessage);
uint256 c = a - b;
return c;
}
/**
* @dev Returns the multiplication of two unsigned integers, reverting on
* overflow.
*
* Counterpart to Solidity's `*` operator.
*
* Requirements:
* - Multiplication cannot overflow.
*/functionmul(uint256 a, uint256 b) internalpurereturns (uint256) {
// Gas optimization: this is cheaper than requiring 'a' not being zero, but the// benefit is lost if 'b' is also tested.// See: https://github.com/OpenZeppelin/openzeppelin-contracts/pull/522if (a ==0) {
return0;
}
uint256 c = a * b;
require(c / a == b, "SafeMath: multiplication overflow");
return c;
}
/**
* @dev Returns the integer division of two unsigned integers. Reverts on
* division by zero. The result is rounded towards zero.
*
* Counterpart to Solidity's `/` operator. Note: this function uses a
* `revert` opcode (which leaves remaining gas untouched) while Solidity
* uses an invalid opcode to revert (consuming all remaining gas).
*
* Requirements:
* - The divisor cannot be zero.
*/functiondiv(uint256 a, uint256 b) internalpurereturns (uint256) {
return div(a, b, "SafeMath: division by zero");
}
/**
* @dev Returns the integer division of two unsigned integers. Reverts with custom message on
* division by zero. The result is rounded towards zero.
*
* Counterpart to Solidity's `/` operator. Note: this function uses a
* `revert` opcode (which leaves remaining gas untouched) while Solidity
* uses an invalid opcode to revert (consuming all remaining gas).
*
* Requirements:
* - The divisor cannot be zero.
* NOTE: This is a feature of the next version of OpenZeppelin Contracts.
* @dev Get it via `npm install @openzeppelin/contracts@next`.
*/functiondiv(uint256 a, uint256 b, stringmemory errorMessage) internalpurereturns (uint256) {
// Solidity only automatically asserts when dividing by 0require(b >0, errorMessage);
uint256 c = a / b;
// assert(a == b * c + a % b); // There is no case in which this doesn't holdreturn c;
}
/**
* @dev Returns the remainder of dividing two unsigned integers. (unsigned integer modulo),
* Reverts when dividing by zero.
*
* Counterpart to Solidity's `%` operator. This function uses a `revert`
* opcode (which leaves remaining gas untouched) while Solidity uses an
* invalid opcode to revert (consuming all remaining gas).
*
* Requirements:
* - The divisor cannot be zero.
*/functionmod(uint256 a, uint256 b) internalpurereturns (uint256) {
return mod(a, b, "SafeMath: modulo by zero");
}
/**
* @dev Returns the remainder of dividing two unsigned integers. (unsigned integer modulo),
* Reverts with custom message when dividing by zero.
*
* Counterpart to Solidity's `%` operator. This function uses a `revert`
* opcode (which leaves remaining gas untouched) while Solidity uses an
* invalid opcode to revert (consuming all remaining gas).
*
* Requirements:
* - The divisor cannot be zero.
*
* NOTE: This is a feature of the next version of OpenZeppelin Contracts.
* @dev Get it via `npm install @openzeppelin/contracts@next`.
*/functionmod(uint256 a, uint256 b, stringmemory errorMessage) internalpurereturns (uint256) {
require(b !=0, errorMessage);
return a % b;
}
}