Guest User

Untitled

a guest
Jan 23rd, 2018
75
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 5.91 KB | None | 0 0
  1. pragma solidity ^0.4.11;
  2.  
  3. import "./WILDToken.sol";
  4.  
  5. contract Bakery {
  6.  
  7. // index of created contracts
  8.  
  9. address[] public contracts;
  10.  
  11. // useful to know the row count in contracts index
  12.  
  13. function getContractCount()
  14. public
  15. constant
  16. returns(uint contractCount)
  17. {
  18. return contracts.length;
  19. }
  20.  
  21. // deploy a new contract
  22.  
  23. function newToken()
  24. public
  25. returns(address newContract)
  26. {
  27. WILDToken c = new WILDToken();
  28. contracts.push(c);
  29. return c;
  30. }
  31. }
  32.  
  33. pragma solidity ^0.4.11;
  34.  
  35. /**
  36. * @title SafeMath
  37. * @dev Math operations with safety checks that throw on error
  38. */
  39. library SafeMath {
  40. function mul(uint256 a, uint256 b) internal constant returns (uint256) {
  41. uint256 c = a * b;
  42. assert(a == 0 || c / a == b);
  43. return c;
  44. }
  45.  
  46. function div(uint256 a, uint256 b) internal constant returns (uint256) {
  47. // assert(b > 0); // Solidity automatically throws when dividing by 0
  48. uint256 c = a / b;
  49. // assert(a == b * c + a % b); // There is no case in which this doesn't hold
  50. return c;
  51. }
  52.  
  53. function sub(uint256 a, uint256 b) internal constant returns (uint256) {
  54. assert(b <= a);
  55. return a - b;
  56. }
  57.  
  58. function add(uint256 a, uint256 b) internal constant returns (uint256) {
  59. uint256 c = a + b;
  60. assert(c >= a);
  61. return c;
  62. }
  63. }
  64.  
  65. /**
  66. * @title ERC20Basic
  67. * @dev Simpler version of ERC20 interface
  68. * @dev see https://github.com/ethereum/EIPs/issues/179
  69. */
  70. contract ERC20Basic {
  71. uint256 public totalSupply;
  72. function balanceOf(address who) constant returns (uint256);
  73. function transfer(address to, uint256 value) returns (bool);
  74. event Transfer(address indexed from, address indexed to, uint256 value);
  75. }
  76.  
  77. /**
  78. * @title Basic token
  79. * @dev Basic version of StandardToken, with no allowances.
  80. */
  81. contract BasicToken is ERC20Basic {
  82. using SafeMath for uint256;
  83.  
  84. mapping(address => uint256) balances;
  85.  
  86. /**
  87. * @dev transfer token for a specified address
  88. * @param _to The address to transfer to.
  89. * @param _value The amount to be transferred.
  90. */
  91. function transfer(address _to, uint256 _value) returns (bool) {
  92. balances[msg.sender] = balances[msg.sender].sub(_value);
  93. balances[_to] = balances[_to].add(_value);
  94. Transfer(msg.sender, _to, _value);
  95. return true;
  96. }
  97.  
  98. /**
  99. * @dev Gets the balance of the specified address.
  100. * @param _owner The address to query the the balance of.
  101. * @return An uint256 representing the amount owned by the passed address.
  102. */
  103. function balanceOf(address _owner) constant returns (uint256 balance) {
  104. return balances[_owner];
  105. }
  106.  
  107. }
  108.  
  109. /**
  110. * @title ERC20 interface
  111. * @dev see https://github.com/ethereum/EIPs/issues/20
  112. */
  113. contract ERC20 is ERC20Basic {
  114. function allowance(address owner, address spender) constant returns (uint256);
  115. function transferFrom(address from, address to, uint256 value) returns (bool);
  116. function approve(address spender, uint256 value) returns (bool);
  117. event Approval(address indexed owner, address indexed spender, uint256 value);
  118. }
  119.  
  120. /**
  121. * @title Standard ERC20 token
  122. *
  123. * @dev Implementation of the basic standard token.
  124. * @dev https://github.com/ethereum/EIPs/issues/20
  125. * @dev Based on code by FirstBlood: https://github.com/Firstbloodio/token/blob/master/smart_contract/FirstBloodToken.sol
  126. */
  127. contract StandardToken is ERC20, BasicToken {
  128.  
  129. mapping (address => mapping (address => uint256)) allowed;
  130.  
  131.  
  132. /**
  133. * @dev Transfer tokens from one address to another
  134. * @param _from address The address which you want to send tokens from
  135. * @param _to address The address which you want to transfer to
  136. * @param _value uint256 the amout of tokens to be transfered
  137. */
  138. function transferFrom(address _from, address _to, uint256 _value) returns (bool) {
  139. var _allowance = allowed[_from][msg.sender];
  140.  
  141. // Check is not needed because sub(_allowance, _value) will already throw if this condition is not met
  142. // require (_value <= _allowance);
  143.  
  144. balances[_to] = balances[_to].add(_value);
  145. balances[_from] = balances[_from].sub(_value);
  146. allowed[_from][msg.sender] = _allowance.sub(_value);
  147. Transfer(_from, _to, _value);
  148. return true;
  149. }
  150.  
  151. /**
  152. * @dev Aprove the passed address to spend the specified amount of tokens on behalf of msg.sender.
  153. * @param _spender The address which will spend the funds.
  154. * @param _value The amount of tokens to be spent.
  155. */
  156. function approve(address _spender, uint256 _value) returns (bool) {
  157.  
  158. // To change the approve amount you first have to reduce the addresses`
  159. // allowance to zero by calling `approve(_spender, 0)` if it is not
  160. // already 0 to mitigate the race condition described here:
  161. // https://github.com/ethereum/EIPs/issues/20#issuecomment-263524729
  162. require((_value == 0) || (allowed[msg.sender][_spender] == 0));
  163.  
  164. allowed[msg.sender][_spender] = _value;
  165. Approval(msg.sender, _spender, _value);
  166. return true;
  167. }
  168.  
  169. /**
  170. * @dev Function to check the amount of tokens that an owner allowed to a spender.
  171. * @param _owner address The address which owns the funds.
  172. * @param _spender address The address which will spend the funds.
  173. * @return A uint256 specifing the amount of tokens still available for the spender.
  174. */
  175. function allowance(address _owner, address _spender) constant returns (uint256 remaining) {
  176. return allowed[_owner][_spender];
  177. }
  178.  
  179. }
  180.  
  181.  
  182. /**
  183. * @title SimpleToken
  184. * @dev Very simple ERC20 Token example, where all tokens are pre-assigned to the creator.
  185. * Note they can later distribute these tokens as they wish using `transfer` and other
  186. * `StandardToken` functions.
  187. */
  188. contract WILDToken is StandardToken {
  189.  
  190. string public constant name = "Marshmellow Token";
  191. string public constant symbol = "MMT";
  192. uint256 public constant decimals = 18;
  193.  
  194. uint256 public constant INITIAL_SUPPLY = 300000000 * 10**18;
  195.  
  196. /**
  197. * @dev Contructor that gives msg.sender all of existing tokens.
  198. */
  199. function WILDToken() {
  200. totalSupply = INITIAL_SUPPLY;
  201. balances[msg.sender] = INITIAL_SUPPLY;
  202. }
  203.  
  204. }
Add Comment
Please, Sign In to add comment