// SPDX-License-Identifier: MIT // Compatible with OpenZeppelin Contracts ^5.0.0 pragma solidity ^0.8.20; import "@openzeppelin/contracts-upgradeable/access/OwnableUpgradeable.sol"; import "@openzeppelin/contracts-upgradeable/proxy/utils/Initializable.sol"; struct Profile { bool status; address referral; uint directDown; } contract Network is Initializable, OwnableUpgradeable { mapping(address => Profile) public profile; /// @custom:oz-upgrades-unsafe-allow constructor constructor() { _disableInitializers(); } function initialize(address[] memory _newGroup) public initializer { __Ownable_init(); for (uint i = 0; i < _newGroup.length; i++) { profile[_newGroup[i]].status = true; if (i > 0) { profile[_newGroup[i]].referral = _newGroup[i - 1]; profile[_newGroup[i - 1]].directDown += 1; } else { profile[_newGroup[i]].referral = address(0); } } } function register(address _referral) public { // referral checking bool isRegisteredReferral = profile[_referral].status; // check user already register bool isRegisteredSelf = profile[msg.sender].status; require(isRegisteredReferral, "referral should registered"); require(!isRegisteredSelf, "address already registered"); profile[msg.sender].status = true; profile[msg.sender].referral = _referral; profile[_referral].directDown += 1; } function getReferral(address _myAddress) public view returns (address) { return profile[_myAddress].referral; } function getStatus(address _myAddress) public view returns (bool) { return profile[_myAddress].status; } function getDirect(address _myAddress) public view returns (uint) { return profile[_myAddress].directDown; } }