Created
July 24, 2017 14:49
-
-
Save computerphysicslab/627905013c265be34c2c7d90f755683d to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/* | |
Watafan asset Smart Contract v3.0 tiny and splitted part 1 | |
developed by: | |
MarketPay.io , 2017 | |
https://marketpay.io/ | |
http://lnked.in/blockchain | |
v1.0 https://gist.github.com/computerphysicslab/93405f03880b7eb422013cdbbc3d493f | |
+ ERC-20 tokens | |
+ Mobile interface | |
+ Issuable assets and tradable with tokens | |
v2.0 https://gist.github.com/computerphysicslab/f362383f9d3fed26becba48b934bbcfc | |
+ onlyOwner modifier | |
+ Haltable | |
+ safeMath | |
+ Added tokenExchangeRate | |
+ onlyIssuer modifier | |
+ asset state machine | |
v3.0 tiny https://gist.github.com/computerphysicslab/7438c8dfdba705faeb7c41af0ae036cc | |
+ Removes extra functionalities to make it deployable: | |
* Mortal | |
* Haltable | |
* Mobile interface | |
* Asset pointers | |
* timestamp | |
* onlyOwner, replaced by checking against hardcoded owner address | |
* safeMath | |
* allocated status for tokens | |
* onlyIssuers, replaced by checking against hardcoded issuer addresses | |
+ splitted token from asset functionality into two address linked contracts: | |
part 1: token => Watafan-Smart-Contract-Tokens-and-Assets-Tiny-Spliited-part1.sol | |
part 2: asset => Watafan-Smart-Contract-Tokens-and-Assets-Tiny-Spliited-part2.sol | |
*/ | |
pragma solidity ^0.4.13; | |
/* | |
* @title Standard Token Contract | |
* | |
* ERC20-compliant tokens => https://github.com/ethereum/EIPs/issues/20 | |
* A token is a fungible virtual good that can be traded. | |
* ERC-20 Tokens comply to the standard described in the Ethereum ERC-20 proposal. | |
* Basic, standardized Token contract. Defines the functions to check token balances | |
* send tokens, send tokens on behalf of a 3rd party and the corresponding approval process. | |
* | |
*/ | |
contract Token { | |
// **** BASE FUNCTIONALITY | |
// @notice For debugging purposes when using solidity online browser | |
function whoAmI() constant returns (address) { | |
return msg.sender; | |
} | |
// SC owners: | |
// 0xe5f68950d479fab12797dabbe5a4b0d88ec7a722 => metamask-ropsten | |
// address owner = 0x00e5f68950d479fab12797dabbe5a4b0d88ec7a722; | |
// 0xa7e3c7c227c72a60e5a2f9912448fb1c21078769 => nodo, juan | |
address owner = 0x00a7e3c7c227c72a60e5a2f9912448fb1c21078769; | |
// 0xca35b7d915458ef540ade6068dfe2f44e8fa733c => JS VM solidity-browser | |
// address owner = 0x00ca35b7d915458ef540ade6068dfe2f44e8fa733c; | |
function isOwner() returns (bool) { | |
if (msg.sender == owner) return true; | |
return false; | |
} | |
// **** EVENTS | |
// @notice A generic error log | |
event Error(string error); | |
// **** DATA | |
mapping (address => uint256) balances; | |
mapping (address => mapping (address => uint256)) allowed; | |
uint256 public initialSupply; // Initial and total token supply | |
uint256 public totalSupply; | |
// bool allocated = false; // True after defining token parameters and initial mint | |
// Public variables of the token, all used for display | |
// HumanStandardToken is a specialisation of ERC20 defining these parameters | |
string public name; | |
string public symbol; | |
uint8 public decimals; | |
string public standard = 'H0.1'; | |
// **** METHODS | |
// Get total amount of tokens, totalSupply is a public var actually | |
// function totalSupply() constant returns (uint256 totalSupply) {} | |
// Get the account balance of another account with address _owner | |
function balanceOf(address _owner) constant returns (uint256 balance) { | |
return balances[_owner]; | |
} | |
// Send _amount amount of tokens to address _to | |
function transfer(address _to, uint256 _amount) returns (bool success) { | |
if (balances[msg.sender] < _amount) { | |
Error('transfer: the amount to transfer is higher than your token balance'); | |
return false; | |
} | |
balances[msg.sender] -= _amount; | |
balances[_to] += _amount; | |
Transfer(msg.sender, _to, _amount); | |
return true; | |
} | |
// Send _amount amount of tokens from address _from to address _to | |
// The transferFrom method is used for a withdraw workflow, allowing contracts to send | |
// tokens on your behalf, for example to "deposit" to a contract address and/or to charge | |
// fees in sub-currencies; the command should fail unless the _from account has | |
// deliberately authorized the sender of the message via some mechanism | |
function transferFrom(address _from, address _to, uint256 _amount) returns (bool success) { | |
if (balances[_from] < _amount) { | |
Error('transfer: the amount to transfer is higher than the token balance of the source'); | |
return false; | |
} | |
if (allowed[_from][msg.sender] < _amount) { | |
Error('transfer: the amount to transfer is higher than the maximum token transfer allowed by the source'); | |
return false; | |
} | |
balances[_from] -= _amount; | |
balances[_to] += _amount; | |
allowed[_from][msg.sender] -= _amount; | |
Transfer(_from, _to, _amount); | |
return true; | |
} | |
// Allow _spender to withdraw from your account, multiple times, up to the _amount amount. | |
// If this function is called again it overwrites the current allowance with _amount. | |
function approve(address _spender, uint256 _amount) returns (bool success) { | |
allowed[msg.sender][_spender] = _amount; | |
Approval(msg.sender, _spender, _amount); | |
return true; | |
} | |
// Returns the amount which _spender is still allowed to withdraw from _owner | |
function allowance(address _owner, address _spender) constant returns (uint256 remaining) { | |
return allowed[_owner][_spender]; | |
} | |
// Constructor: set up token properties and owner token balance | |
function Token() { | |
// This is the constructor, so owner should be equal to msg.sender, and this method should be called just once | |
// make sure owner address is configured | |
// if(owner == 0x0) throw; | |
// owner address can call this function | |
// if (msg.sender != owner ) throw; | |
// call this function just once | |
// if (allocated) throw; | |
initialSupply = 1000000000; | |
totalSupply = initialSupply; | |
name = "Watafan"; | |
symbol = "FAN"; | |
decimals = 0; | |
balances[owner] = totalSupply; | |
Transfer(this, owner, totalSupply); | |
// allocated = true; | |
} | |
// **** EVENTS | |
// Triggered when tokens are transferred | |
event Transfer(address indexed _from, address indexed _to, uint256 _amount); | |
// Triggered whenever approve(address _spender, uint256 _amount) is called | |
event Approval(address indexed _owner, address indexed _spender, uint256 _amount); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment