UserStruct memory userStruct;
currUserID++;
userStruct = UserStruct({
isExist: true,
id: currUserID,
referrerID: 0,
referral: new address[](0)
});
users[ownerWallet] = userStruct;
userList[currUserID] = ownerWallet;
for(uint i = 1; i <= 10; i++) {
users[ownerWallet].levelExpired[i] = 55555555555;
}
}
function () external payable {
uint level;
if(msg.value == LEVEL_PRICE[1]) level = 1;
else if(msg.value == LEVEL_PRICE[2]) level = 2;
else if(msg.value == LEVEL_PRICE[3]) level = 3;
else if(msg.value == LEVEL_PRICE[4]) level = 4;
else if(msg.value == LEVEL_PRICE[5]) level = 5;
else if(msg.value == LEVEL_PRICE[6]) level = 6;
else if(msg.value == LEVEL_PRICE[7]) level = 7;
else if(msg.value == LEVEL_PRICE[8]) level = 8;
else if(msg.value == LEVEL_PRICE[9]) level = 9;
else if(msg.value == LEVEL_PRICE[10]) level = 10;
else revert('Incorrect Value send');
if(users[msg.sender].isExist) buyLevel(level);
else if(level == 1) {
uint refId = 0;
address referrer = bytesToAddress(msg.data);
if(users[referrer].isExist) refId = users[referrer].id;
else revert('Incorrect referrer');
regUser(refId);
}
else revert('Please buy first level for 0.03 ETH');
}
function regUser(uint _referrerID) public payable {
require(address(oldSC) == address(0), 'Initialize not finished');
require(!users[msg.sender].isExist, 'User exist');
require(_referrerID > 0 && _referrerID <= currUserID, 'Incorrect referrer Id');
require(msg.value == LEVEL_PRICE[1], 'Incorrect Value');
if(users[userList[_referrerID]].referral.length >= REFERRER_1_LEVEL_LIMIT) _referrerID = users[findFreeReferrer(userList[_referrerID])].id;
UserStruct memory userStruct;
currUserID++;
userStruct = UserStruct({
isExist: true,
id: currUserID,
referrerID: _referrerID,
referral: new address[](0)
});
users[msg.sender] = userStruct;
userList[currUserID] = msg.sender;
users[msg.sender].levelExpired[1] = now + PERIOD_LENGTH;
users[userList[_referrerID]].referral.push(msg.sender);
payForLevel(1, msg.sender);
emit regLevelEvent(msg.sender, userList[_referrerID], now);
}
function buyLevel(uint _level) public payable {
require(users[msg.sender].isExist, 'User not exist');
require(_level > 0 && _level <= 10, 'Incorrect level');
if(_level == 1) {
require(msg.value == LEVEL_PRICE[1], 'Incorrect Value');
users[msg.sender].levelExpired[1] += PERIOD_LENGTH;
}
else {
require(msg.value == LEVEL_PRICE[_level], 'Incorrect Value');
for(uint l =_level - 1; l > 0; l--) require(users[msg.sender].levelExpired[l] >= now, 'Buy the previous level');
if(users[msg.sender].levelExpired[_level] == 0) users[msg.sender].levelExpired[_level] = now + PERIOD_LENGTH;
else users[msg.sender].levelExpired[_level] += PERIOD_LENGTH;
}
payForLevel(_level, msg.sender);
emit buyLevelEvent(msg.sender, _level, now);
}
function syncWithOldSC(uint limit) public {
require(address(oldSC) != address(0), 'Initialize closed');
require(msg.sender == ownerWallet, 'Access denied');
for(uint i = 0; i < limit; i++) {
address user = oldSC.userList(oldSCUserId);
(bool isExist,, uint referrerID) = oldSC.users(user);
if(isExist) {
oldSCUserId++;
address ref = oldSC.userList(referrerID);
if(!users[user].isExist && users[ref].isExist) {
users[user].isExist = true;
users[user].id = ++currUserID;
users[user].referrerID = users[ref].id;
原创声明:本文系作者授权腾讯云开发者社区发表,未经许可,不得转载。
如有侵权,请联系 cloudcommunity@tencent.com 删除。
原创声明:本文系作者授权腾讯云开发者社区发表,未经许可,不得转载。
如有侵权,请联系 cloudcommunity@tencent.com 删除。