• 发文
  • 评论
  • 微博
  • 空间
  • 微信

Forsage系统开发(成品案例,快速搭建)


  1. Forsage系统开发源码搭建:


  2. pragma solidity >=0.4.23 <0.6.0;//此处为版本号

  3. contract SmartMatrixForsage {

  4. struct User {

  5. uint id;

  6. address referrer;

  7. uint partnersCount;

  8. mapping(uint8 => bool) activeX3Levels;

  9. mapping(uint8 => bool) activeX6Levels;

  10. mapping(uint8 => X3) x3Matrix;

  11. mapping(uint8 => X6) x6Matrix;

  12. }

  13. struct X3 {

  14. address currentReferrer;

  15. address[] referrals;

  16. bool blocked;

  17. uint reinvestCount;

  18. }

  19. struct X6 {

  20. address currentReferrer;

  21. address[] firstLevelReferrals;

  22. address[] secondLevelReferrals;

  23. bool blocked;

  24. uint reinvestCount;

  25. address closedPart;

  26. }

  27. uint8 public constant LAST_LEVEL = 12;

  28. mapping(address => User) public users;

  29. mapping(uint => address) public idToAddress;

  30. mapping(uint => address) public userIds;

  31. mapping(address => uint) public balances;

  32. uint public lastUserId = 2;

  33. address public owner;

  34. mapping(uint8 => uint) public levelPrice;

  35. event Registration(address indexed user, address indexed referrer, uint indexed userId, uint referrerId);

  36. event Reinvest(address indexed user, address indexed currentReferrer, address indexed caller, uint8 matrix, uint8 level);

  37. event Upgrade(address indexed user, address indexed referrer, uint8 matrix, uint8 level);

  38. event NewUserPlace(address indexed user, address indexed referrer, uint8 matrix, uint8 level, uint8 place);

  39. event MissedEthReceive(address indexed receiver, address indexed from, uint8 matrix, uint8 level);

  40. event SentExtraEthDividends(address indexed from, address indexed receiver, uint8 matrix, uint8 level);

  41. constructor(address ownerAddress) public {

  42. levelPrice[1] = 0.025 ether;

  43. for (uint8 i = 2; i <= LAST_LEVEL; i++) {

  44. levelPrice[i] = levelPrice[i-1] * 2;

  45. }

  46. owner = ownerAddress;

  47. User memory user = User({

  48. id: 1,

  49. referrer: address(0),

  50. partnersCount: uint(0)

  51. });

  52. users[ownerAddress] = user;

  53. idToAddress[1] = ownerAddress;

  54. for (uint8 i = 1; i <= LAST_LEVEL; i++) {

  55. users[ownerAddress].activeX3Levels[i] = true;

  56. users[ownerAddress].activeX6Levels[i] = true;

  57. }

  58. userIds[1] = ownerAddress;

  59. }

  60. function() external payable {

  61. if(msg.data.length == 0) {

  62. return registration(msg.sender, owner);

  63. }

  64. registration(msg.sender, bytesToAddress(msg.data));

  65. }

  66. function registrationExt(address referrerAddress) external payable {

  67. registration(msg.sender, referrerAddress);

  68. }

  69. function buyNewLevel(uint8 matrix, uint8 level) external payable {

  70. require(isUserExists(msg.sender), "user is not exists. Register first.");

  71. require(matrix == 1 || matrix == 2, "invalid matrix");

  72. require(msg.value == levelPrice[level], "invalid price");

  73. require(level > 1 && level <= LAST_LEVEL, "invalid level");

  74. if (matrix == 1) {

  75. require(!users[msg.sender].activeX3Levels[level], "level already activated");

  76. if (users[msg.sender].x3Matrix[level-1].blocked) {

  77. users[msg.sender].x3Matrix[level-1].blocked = false;

  78. }

  79. address freeX3Referrer = findFreeX3Referrer(msg.sender, level);

  80. users[msg.sender].x3Matrix[level].currentReferrer = freeX3Referrer;

  81. users[msg.sender].activeX3Levels[level] = true;

  82. updateX3Referrer(msg.sender, freeX3Referrer, level);

  83. emit Upgrade(msg.sender, freeX3Referrer, 1, level);

  84. } else {

  85. require(!users[msg.sender].activeX6Levels[level], "level already activated");

  86. if (users[msg.sender].x6Matrix[level-1].blocked) {

  87. users[msg.sender].x6Matrix[level-1].blocked = false;

  88. }

  89. address freeX6Referrer = findFreeX6Referrer(msg.sender, level);

  90. users[msg.sender].activeX6Levels[level] = true;

  91. updateX6Referrer(msg.sender, freeX6Referrer, level);

  92. emit Upgrade(msg.sender, freeX6Referrer, 2, level);

  93. }

  94. }

  95. function registration(address userAddress, address referrerAddress) private {

  96. require(msg.value == 0.05 ether, "registration cost 0.05");

  97. require(!isUserExists(userAddress), "user exists");

  98. require(isUserExists(referrerAddress), "referrer not exists");

  99. uint32 size;

  100. assembly {

  101. size := extcodesize(userAddress)

  102. }

  103. require(size == 0, "cannot be a contract");

  104. User memory user = User({

  105. id: lastUserId,

  106. referrer: referrerAddress,

  107. partnersCount: 0

  108. });

  109. users[userAddress] = user;

  110. idToAddress[lastUserId] = userAddress;

  111. users[userAddress].referrer = referrerAddress;

  112. users[userAddress].activeX3Levels[1] = true;

  113. users[userAddress].activeX6Levels[1] = true;

  114. userIds[lastUserId] = userAddress;

  115. lastUserId++;

  116. users[referrerAddress].partnersCount++;

  117. address freeX3Referrer = findFreeX3Referrer(userAddress, 1);

  118. users[userAddress].x3Matrix[1].currentReferrer = freeX3Referrer;

  119. updateX3Referrer(userAddress, freeX3Referrer, 1);

  120. updateX6Referrer(userAddress, findFreeX6Referrer(userAddress, 1), 1);

  121. emit Registration(userAddress, referrerAddress, users[userAddress].id, users[referrerAddress].id);

  122. }

  123. function sendETHDividends(address userAddress, address _from, uint8 matrix, uint8 level) private {

  124. (address receiver, bool isExtraDividends) = findEthReceiver(userAddress, _from, matrix, level);

  125. if (!address(uint160(receiver)).send(levelPrice[level])) {

  126. return address(uint160(receiver)).transfer(address(this).balance);

  127. }

  128. if (isExtraDividends) {

  129. emit SentExtraEthDividends(_from, receiver, matrix, level);

  130. }

  131. }

  132. function bytesToAddress(bytes memory bys) private pure returns (address addr) {

  133. assembly {

  134. addr := mload(add(bys, 20))

  135. }

  136. }

  137. }



声明:本文为OFweek维科号作者发布,不代表OFweek维科号立场。如有侵权或其他问题,请及时联系我们举报。
2
评论

评论

    相关阅读

      暂无数据

      柳暗花明又一村

      专注于互联网科技系统软件开发技术...

      举报文章问题

      ×
      • 营销广告
      • 重复、旧闻
      • 格式问题
      • 低俗
      • 标题夸张
      • 与事实不符
      • 疑似抄袭
      • 我有话要说
      确定取消

      举报评论问题

      ×
      • 淫秽色情
      • 营销广告
      • 恶意攻击谩骂
      • 我要吐槽
      确定取消

      用户登录×

      请输入用户名/手机/邮箱

      请输入密码