pragma solidity ^0.4.24; contract Test { uint FEE = 0.01 ether; uint LIST_SIZE = 5; struct Participant { address[] refererList; uint amountEarned; address[] acceptedInvites; } mapping(address => Participant) participants; constructor () public { for(uint i = 0; i < LIST_SIZE; i++) participants[msg.sender].refererList.push(msg.sender); } function getRefererList(address addr) public view returns(address[]) { return participants[addr].refererList; } function getAcceptedInvites(address addr) public view returns(address[]) { return participants[addr].acceptedInvites; } function acceptInvite(address inviteFrom) public payable { require(participants[inviteFrom].refererList.length > 0); require(participants[msg.sender].refererList.length == 0); require(msg.value >= FEE * LIST_SIZE); //pay to referers for(uint i = 0; i < participants[msg.sender].refererList.length; i++) { if (participants[msg.sender].refererList[i] != address(0)) { participants[msg.sender].refererList[i].transfer(FEE); participants[participants[msg.sender].refererList[i]].amountEarned += FEE; } } // create new user list participants[msg.sender] = participants[inviteFrom]; for(i = LIST_SIZE - 1; i > 0; i--) { participants[msg.sender].refererList[i] = participants[msg.sender].refererList[i-1]; } participants[msg.sender].refererList[0] = msg.sender; // update referer accept list participants[inviteFrom].acceptedInvites.push(msg.sender); } function getBalance(address addr) public view returns(uint) { return addr.balance; } }
0.4.24