TronChain smart contract system development and creation

Public chain: The public chain is a blockchain that can be read by anyone in the world. Anyone in the world can send transactions to it and expect to see whether the transaction is valid. Anyone in the world can participate in the consensus process-determine which blocks to transfer The process of adding to the chain and what is the current state. As an alternative to centralized or quasi-centralized trust, the public chain is protected by cryptoeconomics-a combination of economic incentives and cryptographic verification, using proof of work or proof of equity and other mechanisms, following the general principle, that is, the degree of consensus that someone can have The impact of the process is proportional to the amount of economic resources they can use. These blockchains are generally considered "fully decentralized."

TronChain TRON:
a DeFi support model built on smart contract technology, built by the people and for the people.
It is the most transparent, most p2p, and most decentralized support system in the world.
TronChain TRON smart contract is designed for everyone Provide DeFi support funds, based entirely on TRON blockchain and smart contract technology.
Any participant can donate TRX to the community fund and support TRONCHAIN ​​community members. By doing so, the contract code will be activated and supporters will start to get support from the community members themselves.
It is 100% decentralized and is a community-based project; this means that there is no guarantee or additional profit in this project.
All the information you receive from TRONCHAIN ​​is received from other community members because this is a P2P support model.
You support others, and others support you.
It can be regarded as a decentralized "third party", based on the algorithm code to ensure that everyone can be fair, transparent and just.
There are no mediators or middlemen, no controllers, no company or human interaction.
According to the rules of smart contracts, it effectively guarantees the fairness of funds of all participating partners and partners.

Programming languages ​​and programs
In order to write smart contracts, you must use the Smart Contract Language (SCL). These are programming languages ​​that write smart contracts directly or compile them into smart contracts. Solidity is a programming language for writing smart contracts, which runs on the Ethereum virtual machine. It is a high-level contract-oriented language with a syntax similar to JavaScript and is mainly aimed at Ethereum EVM.
The Ethereum Virtual Machine (EVM) is the operating environment for smart contracts on Ethereum. It is actually completely isolated, which means that the code running on the EVM cannot access the network, file system, and other processes. Smart contracts have limited access to other smart contracts and operate independently on the blockchain network.
There are three main steps in writing smart contracts on the Ethereum network:
writing
in high-level Ethereum language , compiling into bytecode with an EVM compiler, and
uploading to the blockchain network by the Ethereum client.
Those who are interested in smart contracts and open source coding, One of the well-known resources is GitHub. This is an online platform for developers to host software code. Each piece of your code will be stored in a repository, which is basically a folder that stores all code components.
Many people copy and paste other people's repositories into their accounts, then make minor adjustments to become their own. Browse the page by searching for projects and repositories to help you build your own projects. Once you find the repository you need, open it and search for the content, it will contain a lot of complex content with useful code. Using the above programs and resources, you can also create your own smart contract.
Smart contracts are written in SCL, and Ethereum smart contract functions are attributed to the Ethereum virtual machine. This is the operating environment of smart contracts on Ethereum.

pragma solidity >=0.4.23 <0.6.0;

contract SmartMatrixForsage {

struct User {
    uint id;
    address referrer;
    uint partnersCount;
    
    mapping(uint8 => bool) activeX3Levels;
    mapping(uint8 => bool) activeX6Levels;
    
    mapping(uint8 => X3) x3Matrix;
    mapping(uint8 => X6) x6Matrix;
}

struct X3 {
    address currentReferrer;
    address[] referrals;
    bool blocked;
    uint reinvestCount;
}

struct X6 {
    address currentReferrer;
    address[] firstLevelReferrals;
    address[] secondLevelReferrals;
    bool blocked;
    uint reinvestCount;

    address closedPart;
}

uint8 public constant LAST_LEVEL = 12;

mapping(address => User) public users;
mapping(uint => address) public idToAddress;
mapping(uint => address) public userIds;
mapping(address => uint) public balances; 

uint public lastUserId = 2;
address public owner;

mapping(uint8 => uint) public levelPrice;

event Registration(address indexed user, address indexed referrer, uint indexed userId, uint referrerId);
event Reinvest(address indexed user, address indexed currentReferrer, address indexed caller, uint8 matrix, uint8 level);
event Upgrade(address indexed user, address indexed referrer, uint8 matrix, uint8 level);
event NewUserPlace(address indexed user, address indexed referrer, uint8 matrix, uint8 level, uint8 place);
event MissedEthReceive(address indexed receiver, address indexed from, uint8 matrix, uint8 level);
event SentExtraEthDividends(address indexed from, address indexed receiver, uint8 matrix, uint8 level);


constructor(address ownerAddress) public {
    levelPrice[1] = 0.025 ether;
    for (uint8 i = 2; i <= LAST_LEVEL; i++) {
        levelPrice[i] = levelPrice[i-1] * 2;
    }
    
    owner = ownerAddress;
    
    User memory user = User({
        id: 1,
        referrer: address(0),
        partnersCount: uint(0)
    });
    
    users[ownerAddress] = user;
    idToAddress[1] = ownerAddress;
    
    for (uint8 i = 1; i <= LAST_LEVEL; i++) {
        users[ownerAddress].activeX3Levels[i] = true;
        users[ownerAddress].activeX6Levels[i] = true;
    }
    
    userIds[1] = ownerAddress;
}

function() external payable {
    if(msg.data.length == 0) {
        return registration(msg.sender, owner);
    }
    
    registration(msg.sender, bytesToAddress(msg.data));
}

function registrationExt(address referrerAddress) external payable {
    registration(msg.sender, referrerAddress);
}

function buyNewLevel(uint8 matrix, uint8 level) external payable {
    require(isUserExists(msg.sender), "user is not exists. Register first.");
    require(matrix == 1 || matrix == 2, "invalid matrix");
    require(msg.value == levelPrice[level], "invalid price");
    require(level > 1 && level <= LAST_LEVEL, "invalid level");

    if (matrix == 1) {
        require(!users[msg.sender].activeX3Levels[level], "level already activated");

        if (users[msg.sender].x3Matrix[level-1].blocked) {
            users[msg.sender].x3Matrix[level-1].blocked = false;
        }

        address freeX3Referrer = findFreeX3Referrer(msg.sender, level);
        users[msg.sender].x3Matrix[level].currentReferrer = freeX3Referrer;
        users[msg.sender].activeX3Levels[level] = true;
        updateX3Referrer(msg.sender, freeX3Referrer, level);
        
        emit Upgrade(msg.sender, freeX3Referrer, 1, level);

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

        if (users[msg.sender].x6Matrix[level-1].blocked) {
            users[msg.sender].x6Matrix[level-1].blocked = false;
        }

        address freeX6Referrer = findFreeX6Referrer(msg.sender, level);
        
        users[msg.sender].activeX6Levels[level] = true;
        updateX6Referrer(msg.sender, freeX6Referrer, level);
        
        emit Upgrade(msg.sender, freeX6Referrer, 2, level);
    }
}    
pragma solidity >=0.4.23 <0.6.0;

contract SmartMatrixForsage {

struct User {
    uint id;
    address referrer;
    uint partnersCount;
    
    mapping(uint8 => bool) activeX3Levels;
    mapping(uint8 => bool) activeX6Levels;
    
    mapping(uint8 => X3) x3Matrix;
    mapping(uint8 => X6) x6Matrix;
}

struct X3 {
    address currentReferrer;
    address[] referrals;
    bool blocked;
    uint reinvestCount;
}

struct X6 {
    address currentReferrer;
    address[] firstLevelReferrals;
    address[] secondLevelReferrals;
    bool blocked;
    uint reinvestCount;

    address closedPart;
}

uint8 public constant LAST_LEVEL = 12;

mapping(address => User) public users;
mapping(uint => address) public idToAddress;
mapping(uint => address) public userIds;
mapping(address => uint) public balances; 

uint public lastUserId = 2;
address public owner;

mapping(uint8 => uint) public levelPrice;

event Registration(address indexed user, address indexed referrer, uint indexed userId, uint referrerId);
event Reinvest(address indexed user, address indexed currentReferrer, address indexed caller, uint8 matrix, uint8 level);
event Upgrade(address indexed user, address indexed referrer, uint8 matrix, uint8 level);
event NewUserPlace(address indexed user, address indexed referrer, uint8 matrix, uint8 level, uint8 place);
event MissedEthReceive(address indexed receiver, address indexed from, uint8 matrix, uint8 level);
event SentExtraEthDividends(address indexed from, address indexed receiver, uint8 matrix, uint8 level);


constructor(address ownerAddress) public {
    levelPrice[1] = 0.025 ether;
    for (uint8 i = 2; i <= LAST_LEVEL; i++) {
        levelPrice[i] = levelPrice[i-1] * 2;
    }
    
    owner = ownerAddress;
    
    User memory user = User({
        id: 1,
        referrer: address(0),
        partnersCount: uint(0)
    });
    
    users[ownerAddress] = user;
    idToAddress[1] = ownerAddress;
    
    for (uint8 i = 1; i <= LAST_LEVEL; i++) {
        users[ownerAddress].activeX3Levels[i] = true;
        users[ownerAddress].activeX6Levels[i] = true;
    }
    
    userIds[1] = ownerAddress;
}

function() external payable {
    if(msg.data.length == 0) {
        return registration(msg.sender, owner);
    }
    
    registration(msg.sender, bytesToAddress(msg.data));
}

function registrationExt(address referrerAddress) external payable {
    registration(msg.sender, referrerAddress);
}

function buyNewLevel(uint8 matrix, uint8 level) external payable {
    require(isUserExists(msg.sender), "user is not exists. Register first.");
    require(matrix == 1 || matrix == 2, "invalid matrix");
    require(msg.value == levelPrice[level], "invalid price");
    require(level > 1 && level <= LAST_LEVEL, "invalid level");

    if (matrix == 1) {
        require(!users[msg.sender].activeX3Levels[level], "level already activated");

        if (users[msg.sender].x3Matrix[level-1].blocked) {
            users[msg.sender].x3Matrix[level-1].blocked = false;
        }

        address freeX3Referrer = findFreeX3Referrer(msg.sender, level);
        users[msg.sender].x3Matrix[level].currentReferrer = freeX3Referrer;
        users[msg.sender].activeX3Levels[level] = true;
        updateX3Referrer(msg.sender, freeX3Referrer, level);
        
        emit Upgrade(msg.sender, freeX3Referrer, 1, level);

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

        if (users[msg.sender].x6Matrix[level-1].blocked) {
            users[msg.sender].x6Matrix[level-1].blocked = false;
        }

        address freeX6Referrer = findFreeX6Referrer(msg.sender, level);
        
        users[msg.sender].activeX6Levels[level] = true;
        updateX6Referrer(msg.sender, freeX6Referrer, level);
        
        emit Upgrade(msg.sender, freeX6Referrer, 2, level);
    }
}    

Guess you like

Origin blog.csdn.net/T13242772558/article/details/109176257