Guest User

Untitled

a guest
Aug 18th, 2018
88
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.88 KB | None | 0 0
  1. //JDCoin ICO
  2.  
  3. pragma solidity ^0.4.0;
  4.  
  5. contract jdcoin_ico {
  6.  
  7. // Maximum number of JDCoins
  8. uint public max_jdcoins = 1000000;
  9.  
  10. // The USD to JDCoin Conversion Rate
  11. uint public usd_to_jdcoins = 1000;
  12.  
  13. // Total No. of JDCoins to be held by investors
  14. uint public total_jdcoins_bought = 0;
  15.  
  16. // Mapping from the investor address to its equity in JDCoins and USD
  17. mapping(address => uint) equity_jdcoins;
  18. mapping(address => uint) equity_usd;
  19.  
  20. // Check if an investor can buy JDCoins
  21. modifier can_buy_jdcoins(uint usd_invested) {
  22. require(usd_invested * usd_to_jdcoins + total_jdcoins_bought <= max_jdcoins);
  23. _;
  24. }
  25.  
  26. // Check if an investor can sell JDCoins
  27. modifier can_sell_jdcoins(uint jdcoins_sold) {
  28. require(jdcoins_sold <= total_jdcoins_bought);
  29. _;
  30. }
  31.  
  32. // Get the equity in JDCoins of an investor
  33. function equity_in_jdcoins(address investor) external constant returns(uint) {
  34. return equity_jdcoins[investor];
  35. }
  36.  
  37. // Get the equity in USD of an investor
  38. function equity_in_usd(address investor) external constant returns(uint) {
  39. return equity_usd[investor];
  40. }
  41.  
  42. // Buy JDCoin - No return value from this function
  43. function buy_jdcoins(address investor, uint usd_invested) external
  44. can_buy_jdcoins(usd_invested) {
  45. uint jdcoins_bought = usd_invested * usd_to_jdcoins;
  46. equity_jdcoins[investor] += jdcoins_bought;
  47. equity_usd[investor] = equity_jdcoins[investor] / usd_to_jdcoins;
  48. total_jdcoins_bought += jdcoins_bought;
  49. }
  50.  
  51. // Sell JDCoin
  52. function sell_jdcoins(address investor, uint jdcoins_sold) external
  53. can_sell_jdcoins(jdcoins_sold) {
  54. equity_jdcoins[investor] -= jdcoins_sold;
  55. equity_usd[investor] = equity_jdcoins[investor] / usd_to_jdcoins;
  56. total_jdcoins_bought -= jdcoins_sold;
  57. }
  58. }
Add Comment
Please, Sign In to add comment