Advertisement
Guest User

Untitled

a guest
Nov 16th, 2018
122
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.58 KB | None | 0 0
  1. pragma solidity ^0.4.24;
  2.  
  3. /*
  4. Реализация смарт контракта по типу 6 кошельков
  5. */
  6.  
  7. contract SixWallets {
  8.  
  9. //Адресс владельца
  10. address public ownerAddress = 0xAd230476dAF40056f90C8B21d8574C665d144411;
  11.  
  12. //Количество участников
  13. uint hexagons = 0;
  14. bool cfw = false;
  15.  
  16. uint256 min = .03 ether;
  17.  
  18. mapping(address => bytes32[]) public Addresses; //Адресс => уникальными ссылки
  19. mapping(bytes32 => address[6]) public Hexagons; //Уникальная ссылка (keccak256) => 6 кошельков
  20.  
  21. //Проверяет что сумма перевода достаточна
  22. modifier enoughMoney() {
  23. require (msg.value >= min, "Insufficient funds");
  24. _;
  25. }
  26.  
  27. //Проверяет что тот кто перевел владелец кошелька
  28. modifier onlyOwner {
  29. require (msg.sender == ownerAddress, "Olny owner");
  30. _;
  31. }
  32. modifier allreadyCreate {
  33. require (cfw == false);
  34. _;
  35. }
  36. //Функция для оплаты
  37. function pay(bytes32 ref) public payable {
  38. //Перевожу деньги
  39. for(uint8 i = 0; i < 6; i++)
  40. Hexagons[ref][i].transfer(msg.value/6);
  41.  
  42. createHexagons(ref); //Передаю текущую ref, добавляю новые 6 кошельков
  43. }
  44.  
  45. //Передаю переданную рефку и добавляю новый гексагон
  46. function createHexagons(bytes32 ref) internal {
  47. bytes32 new_ref = createRef(hexagons + 1);
  48.  
  49. //Прохожу по переданной рефке и создаю кошельки
  50. for(uint8 i = 0; i < 6; i++)
  51. Hexagons[new_ref][i] = Hexagons[ref][i + 1];
  52. Hexagons[new_ref][5] = msg.sender;
  53.  
  54. Addresses[msg.sender].push(new_ref); //Добавляю статистику
  55. hexagons++; //Увеличиваю счетчик
  56. }
  57.  
  58. //Создаю самый первый гексагон для трех типов кошельков
  59. function createFirstWallets() public onlyOwner allreadyCreate {
  60.  
  61. Hexagons[createRef(1)] = [ownerAddress, ownerAddress, ownerAddress, ownerAddress, ownerAddress, ownerAddress];
  62. Addresses[ownerAddress].push(createRef(1));
  63.  
  64. hexagons++;
  65. cfw = true;
  66. }
  67.  
  68. function createRef(uint hx) internal returns (bytes32 ref) {
  69. uint256 _unixTimestamp;
  70. uint256 _timeExpired;
  71. ref = keccak256(abi.encodePacked(hx, _unixTimestamp, _timeExpired));
  72. }
  73. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement