First set of comments, testing for conflicts

This commit is contained in:
Griff Green
2016-11-10 14:54:33 +01:00
committed by GitHub
parent 7076645d5f
commit e435143aa7

View File

@@ -15,10 +15,12 @@
along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
pragma solidity ^0.4.4;
contract Owned {
/// Allows only the owner to call a function
/// @notice The address of the owner is the only address that can call a
/// function with this modifier
modifier onlyOwner { if (msg.sender != owner) throw; _; }
address public owner;
@@ -39,22 +41,37 @@ contract TokenCreation {
contract MiniMeToken is Owned {
string public name; //fancy name: eg Simon Bucks
uint8 public decimals; //How many decimals to show. ie. There could 1000 base units with 3 decimals. Meaning 0.980 SBX = 980 base units. It's like comparing 1 wei to 1 ether.
string public symbol; //An identifier: eg SBX
string public version = 'H0.1'; //human 0.1 standard. Just an arbitrary versioning scheme.
string public name; //The Token's name: e.g. DigixDAO Tokens
uint8 public decimals; //Number of decimals of the smallest unit
string public symbol; //An identifier: e.g. REP
string public version = 'H0.1'; //An arbitrary versioning scheme.
/// @dev `Checkpoint` is the structure that attaches a block number to the a
/// given token attribute
struct Checkpoint {
// snapshot when starts to take effect this value
// `fromBlock` is the block number that the value was generated from
uint fromBlock;
// value used from the block
// `value` is the attribute in question at a specific block number
uint value;
}
MiniMeToken public parentToken; // Parent token contract. 0x0 for a root token
uint public parentSnapShotBlock; // Block used as the initial ditstribution of the parent token.
uint public creationBlock; // Timestamp when the token was created
mapping (address => Checkpoint[]) balances;
// `parentToken` is the Token address that was cloned. 0x0 for a root token
MiniMeToken public parentToken;
// `parentSnapShotBlock` is the Block number from the Parent Token that was
// used to determine the initial distribution of the Cloned Token.
uint public parentSnapShotBlock;
// `creationBlock` is the block number that the Cloned Token was created
uint public creationBlock;
// `balances` is the map that tracks the balance of each address
mapping (address => Checkpoint[]) balances;
// `allowed` tracks any extra transfer rights as in all ERC20 tokens
mapping (address => mapping (address => uint256)) allowed;
Checkpoint[] totalSupplyHistory;
bool public isConstant;
@@ -66,16 +83,16 @@ contract MiniMeToken is Owned {
////////////////
/// @notice Constructor to create a MiniMeToken
/// @param _tokenFactory address of the MiniMeTokenFactory that will create
/// the child contracts
/// @param _parentToken Address of the parent token, Set to 0 if it is a
/// new token.
/// @param _parentSnapShotBlock Block where the initail distribution of the
/// parent token will be taked.
/// @param _tokenName Name of the token
/// @param _decimalUnits Number of decimals of the token
/// @param _tokenSymbol Token Symbol
/// @param _isConstant If true, the tokens will not be able to be transfered
/// @param _tokenFactory The address of the MiniMeTokenFactory contract that
/// will create the Cloned token contracts
/// @param _parentToken Address of the parent token, set to 0x0 if it is a
/// new token
/// @param _parentSnapShotBlock Block of the parent token that will
/// determine the initial distribution of the cloned token
/// @param _tokenName Name of the new token
/// @param _decimalUnits Number of decimals of the new token
/// @param _tokenSymbol Token Symbol for the new token
/// @param _isConstant If true, tokens will not be able to be transferred
function MiniMeToken(
address _tokenFactory,
address _parentToken,
@@ -86,9 +103,9 @@ contract MiniMeToken is Owned {
bool _isConstant
) {
tokenFactory = MiniMeTokenFactory(_tokenFactory);
name = _tokenName; // Set the name for display purposes
decimals = _decimalUnits; // Amount of decimals for display purposes
symbol = _tokenSymbol; // Set the symbol for display purposes
name = _tokenName; // Set the name
decimals = _decimalUnits; // Set the decimals
symbol = _tokenSymbol; // Set the symbol
parentToken = MiniMeToken(_parentToken);
parentSnapShotBlock = _parentSnapShotBlock;
isConstant = _isConstant;
@@ -96,27 +113,36 @@ contract MiniMeToken is Owned {
}
////////////////
// ERC20 Interface
////////////////
///////////////////
// ERC20 Functions
///////////////////
/// @notice Send `_amount` tokens to `_to` from `msg.sender`
/// @param _to The address of the recipient
/// @param _amount The amount of tokens to be transferred
/// @return Whether the transfer was successful or not
function transfer(address _to, uint256 _amount) returns (bool success) {
if (isConstant) throw;
return doTransfer(msg.sender, _to, _amount);
}
/// @notice Send `_amount` tokens to `_to` from `_from` on the condition it
/// is approved by `_from`
/// @param _from The address of the origin of the transfer
/// @param _from The address holding the tokens being transferred
/// @param _to The address of the recipient
/// @param _amount The amount of tokens to be transferred
/// @return Whether the transfer was successful or not
function transferFrom(address _from, address _to, uint256 _amount) returns (bool success) {
if (isConstant) throw;
/// @return True if the transfer was successful
function transferFrom(address _from, address _to, uint256 _amount)
returns (bool success) {
// The owner of this contract can move tokens around at will, this is
// important to recognize! Confirm that you trust the owner of this
// contract, which in most situations should be another open source
// smart contract or 0x0
if (msg.sender != owner) {
if (isConstant) throw;
// The standard ERC 20 transferFrom functionality
if (allowed[_from][msg.sender] < _amount) return false;
allowed[_from][msg.sender] -= _amount;
}
@@ -129,20 +155,26 @@ contract MiniMeToken is Owned {
return true;
}
// Do not allow transfer to this
// Do not allow transfer to 0x0 or the token contract itself
if ((_to == 0) || (_to == address(this))) throw;
// Remove _from votes
// If the amount being transfered is more than the balance of the
// account the transfer returns false
var previousBalanceFrom = balanceOfAt(_from, block.number);
if (previousBalanceFrom < _amount) {
return false;
}
// First update the balance array with the new value for the address
// sending the tokens
updateValueAtNow(balances[_from], previousBalanceFrom - _amount);
// Then update the balance array with the new value for the address
// receiving the tokens
var previousBalanceTo = balanceOfAt(_to, block.number);
updateValueAtNow(balances[_to], previousBalanceTo + _amount);
// An event to make the transfer easy to find on the blockchain
Transfer(_from, _to, _amount);
return true;
@@ -200,17 +232,28 @@ contract MiniMeToken is Owned {
/// @notice Queries the balance of `_owner` at a specific `_blockNumber`.
/// @param _owner The address from which the balance will be retrieved
/// @param _blockNumber block number when the balance is queried
/// @return The balance
function balanceOfAt(address _owner, uint _blockNumber) constant returns (uint) {
/// @return The balance at `_blockNumber`
function balanceOfAt(address _owner, uint _blockNumber) constant
returns (uint) {
// If the _blockNumber requested is before the genesis block for the
// `parentToken` the value returned is 0
if (_blockNumber < creationBlock) {
return 0;
} else if ((balances[_owner].length == 0) || (balances[_owner][0].fromBlock > _blockNumber)) {
// These next few lines are used when the balance of the token is
// requested before a check point was ever created for this token, it
// requires that the `parentToken.balanceOfAt` be queried at the genesis
// block for this token as this contains initial balance of this token.
} else if ((balances[_owner].length == 0)
|| (balances[_owner][0].fromBlock > _blockNumber)) {
if (address(parentToken) != 0) {
return parentToken.balanceOfAt(_owner, parentSnapShotBlock);
} else {
return 0;
}
// This will return the expected balance during normal situations
} else {
return getValueAt( balances[_owner], _blockNumber);
}