Advertisement
Guest User

Untitled

a guest
Oct 20th, 2019
94
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.77 KB | None | 0 0
  1. pragma solidity ^0.4.11;
  2.  
  3. contract hadcoin_ico{
  4.  
  5. // Introducing the total number of hadcoin tokens available for sealed
  6. uint public max_hadcoins = 1000000;
  7.  
  8. // Introducing the USD to hadcoin conversion rate
  9. uint public usd_to_hadcoins = 1000;
  10.  
  11. // Introducing the total number of hadcoins that have been bought by the investors
  12. uint public total_hadcoins_bought = 0;
  13.  
  14. // Mapping from the investor address to its equity in hadcoins and USD
  15. mapping(address => uint) equity_hadcoins;
  16. mapping(address => uint) equity_usd;
  17.  
  18. // Checking if an investor can buy Hadcoins
  19. modifier can_buy_hadcoins(uint usd_invested) {
  20. require(usd_invested * usd_to_hadcoins + total_hadcoins_bought <= max_hadcoins);
  21. _;
  22. }
  23.  
  24. // Getting the equity in Hadcoins of an investor
  25. function equity_in_hadcoins(address investor) external constant returns(uint){
  26. return equity_hadcoins[investor];
  27. }
  28.  
  29.  
  30. // Getting the equity in USD of an investor
  31. function equity_in_usd(address investor) external constant returns(uint){
  32. return equity_usd[investor];
  33. }
  34.  
  35. //Buy Hadcoins
  36. function buy_hadcoins(address investor ,uint usd_invested) external
  37. can_buy_hadcoins(usd_invested)
  38. {
  39. uint hadcoins_bought = usd_invested * usd_to_hadcoins;
  40. equity_hadcoins[investor] += hadcoins_bought;
  41. equity_usd[investor] = equity_hadcoins[investor] / 1000;
  42. total_hadcoins_bought += hadcoins_bought;
  43. }
  44.  
  45. // Selling Hadcoin
  46. function sell_hadcoins(address investor,uint hadcoins_sold) external{
  47. equity_hadcoins[investor] -= hadcoins_sold;
  48. equity_usd[investor] = equity_hadcoins[investor] / 1000;
  49. total_hadcoins_bought -= hadcoins_sold;
  50. }
  51.  
  52.  
  53. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement