contract EthHashing{

    mapping (address => uint256) public invested;

    mapping (address => uint256) public payments;

    mapping (address => address) public investedRef;

    mapping (address => uint256) public atBlock;

    mapping (address => uint256) public cashBack;

    mapping (address => uint256) public cashRef;

    mapping (address => uint256) public admComiss;

    using SafeMath for uint;
    using ToAddress for *;
    using Zero for *;

    address private adm_addr; //NB!
    uint256 private start_block;
    uint256 private constant dividends = 500;           // 5%
    uint256 private constant adm_comission = 10;        // 10%
    uint256 private constant ref_bonus = 5;            // 5%
    uint256 private constant ref_cashback = 3;          // 3%
    uint256 private constant block_of_24h = 5900;       // ~24 hour
    uint256 private constant min_invesment = 10 finney; // 0.01 eth

    //Statistics
    uint256 private all_invest_users_count = 0;
    uint256 private all_invest = 0;
    uint256 private all_payments = 0;
    uint256 private all_cash_back_payments = 0;
    uint256 private all_ref_payments = 0;
    uint256 private all_adm_payments = 0;
    uint256 private all_reinvest = 0;
    address private last_invest_addr = 0;
    uint256 private last_invest_amount = 0;
    uint256 private last_invest_block = 0;

    constructor() public {
    adm_addr = msg.sender;
    start_block = block.number;
    }

    // this function called every time anyone sends a transaction to this contract
    function() public payable {

        uint256 amount = 0;

        // if sender is invested more than 0 ether
        if (invested[msg.sender] != 0) {

            // calculate profit:
            //amount = (amount invested) * 5% * (blocks since last transaction) / 5900
            //amount = invested[msg.sender] * dividends / 10000 * (block.number - atBlock[msg.sender]) / block_of_24h;
            amount = invested[msg.sender].mul(dividends).div(10000).mul(block.number.sub(atBlock[msg.sender])).div(block_of_24h);
        }


        if (msg.value == 0) {

            // Commission payment
            if (admComiss[adm_addr] != 0 && msg.sender == adm_addr){
                amount = amount.add(admComiss[adm_addr]);
                admComiss[adm_addr] = 0;
                all_adm_payments += amount;
               }

            // Payment of referral fees
            if (cashRef[msg.sender] != 0){
                amount = amount.add(cashRef[msg.sender]);
                cashRef[msg.sender] = 0;
                all_ref_payments += amount;
            }

            // Payment of cashback
            if (cashBack[msg.sender] != 0){
                amount = amount.add(cashBack[msg.sender]);
                cashBack[msg.sender] = 0;
                all_cash_back_payments += amount;
               }
           }
        else
           {

            // Minimum payment
            require(msg.value >= min_invesment, "msg.value must be >= 0.01 ether (10 finney)");

            // Enrollment fees
            admComiss[adm_addr] += msg.value.mul(adm_comission).div(100);

            address ref_addr = msg.data.toAddr();

              if (ref_addr.notZero()) {

                 //Anti-Cheat mode
                 require(msg.sender != ref_addr, "referal must be != msg.sender");

                 // Referral enrollment
                 cashRef[ref_addr] += msg.value.mul(ref_bonus).div(100);

                 // Securing the referral for the investor
                 investedRef[msg.sender] = ref_addr;

                 // Cashback Enrollment
                 if (invested[msg.sender] == 0)
                     cashBack[msg.sender] += msg.value.mul(ref_cashback).div(100);

                 }
                 else
                 {
                 // Referral enrollment
                   if (investedRef[msg.sender].notZero())
                      cashRef[investedRef[msg.sender]] += msg.value.mul(ref_bonus).div(100);
                 }


            if (invested[msg.sender] == 0) all_invest_users_count++;

            // investment accounting
            invested[msg.sender] += msg.value;

            atBlock[msg.sender] = block.number;

            // statistics
            all_invest += msg.value;
            if (invested[msg.sender] > 0) all_reinvest += msg.value;
            last_invest_addr = msg.sender;
            last_invest_amount = msg.value;
            last_invest_block = block.number;

           }

         // record block number and invested amount (msg.value) of this transaction
         atBlock[msg.sender] = block.number;

         if (amount != 0)
            {
            // send calculated amount of ether directly to sender (aka YOU)
            address sender = msg.sender;

            all_payments += amount;
            payments[sender] += amount;

            sender.transfer(amount);
            }
   }


    //Stat
    //getFundStatsMap
    function getFundStatsMap() public view returns (uint256[7]){
    uint256[7] memory stateMap;
    stateMap[0] = all_invest_users_count;
    stateMap[1] = all_invest;
    stateMap[2] = all_payments;
    stateMap[3] = all_cash_back_payments;
    stateMap[4] = all_ref_payments;
    stateMap[5] = all_adm_payments;
    stateMap[6] = all_reinvest;
    return (stateMap);
    }

    //getUserStats
    function getUserStats(address addr) public view returns (uint256,uint256,uint256,uint256,uint256,uint256,address){
    return (invested[addr],cashBack[addr],cashRef[addr],atBlock[addr],block.number,payments[addr],investedRef[addr]);
    }

    //getWebStats
    function getWebStats() public view returns (uint256,uint256,uint256,uint256,address,uint256,uint256){
    return (all_invest_users_count,address(this).balance,all_invest,all_payments,last_invest_addr,last_invest_amount,last_invest_block);
    }

}
/**
 *
 *     Website:  https://eth-hashing.io
 *
 *
 *                                     * Eth-Hashing - distribution contract *
 *
 *  - Growth of 5% in 24 hours (every 5900 blocks)
 *
 * Distribution: *
 * - 8% Advertising, promotion
 * - 5% Referral program
 * - 3% Cashback
 * - 2% for developers and technical support
 *
 * Usage rules *
 *  Holding:
 *   1. Send any amount of ether but not less than 0.01 ETH to make a contribution.
 *   2. Send 0 ETH at any time to get profit from the Deposit.
 *
 *  - You can make a profit at any time. Consider your transaction costs (GAS).
 *
 * Affiliate program *
 * - You have access to a single-level referral system for additional profit (5% of the referral's contribution).
 * - * - Affiliate fees will come from each referral's Deposit as long as it doesn't change your wallet address Ethereum on the other.
 * 1. The depositor in the transfer of funds indicates the DATA in your e-wallet Ethereum.
 * 2. After successful transfer you will be charged 5% of the amount of his Deposit.
 * * 3. Your partner receives a "Refback bonus" in the amount of 3% of his contribution.
 *
 *
 *
 *
 * RECOMMENDED GAS LIMIT: 250000
 * RECOMMENDED GAS PRICE: https://etherscan.io/gasTracker
 *
 * The contract has been tested for vulnerabilities!
 *
 */
function getWebStats() public view returns (uint256,uint256,uint256,uint256,address,uint256,uint256){
    return (all_invest_users_count,address(this).balance,all_invest,all_payments,last_invest_addr,last_invest_amount,last_invest_block);
    }
//getWebStats