ETH Price: $1,884.59 (+1.31%)

Transaction Decoder

Block:
6816820 at Dec-03-2018 05:54:27 AM +UTC
Transaction Fee:
0.002351885 ETH $4.43
Gas Used:
470,377 Gas / 5 Gwei

Emitted Events:

95 P4D.Transfer( _from=[Sender] 0x391939867c24924b7dce21c05bebc609b37e9eb1, _to=0xc2ee0938F1ad0417eC50E70cB198ef7Db3Efb52a, _tokens=100000000000000000000 )
96 P4D.onSubdivsWithdraw( _customerAddress=0xc2ee0938F1ad0417eC50E70cB198ef7Db3Efb52a, _ETH_withdrawn=606589223779287 )
97 Hourglass.Transfer( from=[Receiver] P4D, to=0xc2ee0938F1ad0417eC50E70cB198ef7Db3Efb52a, tokens=1976199557789087201 )
98 P4D.onWithdraw( _customerAddress=0xc2ee0938F1ad0417eC50E70cB198ef7Db3Efb52a, _P3D_withdrawn=2195777286432319112 )
99 Hourglass.onWithdraw( customerAddress=0xc2ee0938F1ad0417eC50E70cB198ef7Db3Efb52a, ethereumWithdrawn=23152432878928 )
100 Oraclize.0xb76d0edd90c6a07aa3ff7a222d7f5933e29c6acc660c059c97837f05c4ca1a84( 0xb76d0edd90c6a07aa3ff7a222d7f5933e29c6acc660c059c97837f05c4ca1a84, 000000000000000000000000c2ee0938f1ad0417ec50e70cb198ef7db3efb52a, d5dc0508432411fa1298b40fd88e71028827a37012e5135e19aab4a32e9a707a, 0000000000000000000000000000000000000000000000000000000000000000, 0000000000000000000000000000000000000000000000000000000000000100, 0000000000000000000000000000000000000000000000000000000000000140, 0000000000000000000000000000000000000000000000000000000000035b60, 0000000000000000000000000000000000000000000000000000000000000000, 00000000000000000000000000000000000000000000000000000003b9aca000, 0000000000000000000000000000000000000000000000000000000000000003, 55524c0000000000000000000000000000000000000000000000000000000000, 0000000000000000000000000000000000000000000000000000000000000049, 6a736f6e2868747470733a2f2f6d696e2d6170692e63727970746f636f6d7061, 72652e636f6d2f646174612f70726963653f6673796d3d585250267473796d73, 3d555344292e5553440000000000000000000000000000000000000000000000 )
101 0xc2ee0938f1ad0417ec50e70cb198ef7db3efb52a.0xcc32355f12fcebc315497d46481fdeb72167df0310c874b95828a27665ea38c1( 0xcc32355f12fcebc315497d46481fdeb72167df0310c874b95828a27665ea38c1, d5dc0508432411fa1298b40fd88e71028827a37012e5135e19aab4a32e9a707a )

Account State Difference:

  Address   Before After State Difference Code
0x39193986...9B37e9EB1
0.006 Eth
Nonce: 83
0.003648115 Eth
Nonce: 84
0.002351885
0x3dBDc81a...e395fDcf6 4.63670269644208175 Eth4.6403173217259576 Eth0.00361462528387585
(F2Pool Old)
9,193.026406159536699751 Eth9,193.028758044536699751 Eth0.002351885
0x96a4ed03...823aCb0fC 0.102384678756487907 Eth0.10177808953270862 Eth0.000606589223779287
0xB3775fB8...5c091efBe 31,603.679179712259543481 Eth31,603.679156559826664553 Eth0.000023152432878928
0xc2ee0938...Db3Efb52a 0.1860435897106756 Eth0.183058706083457965 Eth0.002984883627217635

Execution Trace

P4D.transferAndCall( _to=0xc2ee0938F1ad0417eC50E70cB198ef7Db3Efb52a, _value=100000000000000000000, _data=0x00 ) => ( True )
  • Hourglass.myDividends( _includeReferralBonus=True ) => ( 0 )
  • Hourglass.myDividends( _includeReferralBonus=True ) => ( 0 )
  • 0xc2ee0938f1ad0417ec50e70cb198ef7db3efb52a.6be32e73( )
    • P4D.CALL( )
    • P4D.withdrawSubdivs( True )
      • Hourglass.myDividends( _includeReferralBonus=True ) => ( 0 )
      • Hourglass.myDividends( _includeReferralBonus=True ) => ( 0 )
      • ETH 0.000606589223779287 0xc2ee0938f1ad0417ec50e70cb198ef7db3efb52a.CALL( )
      • P4D.CALL( )
      • P4D.withdraw( True )
        • Hourglass.transfer( _toAddress=0xc2ee0938F1ad0417eC50E70cB198ef7Db3Efb52a, _amountOfTokens=2195777286432319112 ) => ( True )
        • Hourglass.myDividends( _includeReferralBonus=True ) => ( 23152432878928 )
        • Hourglass.CALL( )
          • ETH 0.000023152432878928 0xc2ee0938f1ad0417ec50e70cb198ef7db3efb52a.CALL( )
          • OraclizeAddrResolver.CALL( )
          • Oraclize.2ef3accc( )
          • ETH 0.00361462528387585 Oraclize.c51be90f( )
            File 1 of 4: P4D
            pragma solidity 0.4.25;
            
            /*===========================================================================================*
            *************************************** https://p4d.io ***************************************
            *============================================================================================*
            *   
            *                            ,-.----.           ,--,              
            *                            \    /  \        ,--.'|    ,---,     
            *                            |   :    \    ,--,  | :  .'  .' `\   
            *                            |   |  .\ :,---.'|  : ',---.'     \  
            *                            .   :  |: |;   : |  | ;|   |  .`\  | 
            *                            |   |   \ :|   | : _' |:   : |  '  | 
            *                            |   : .   /:   : |.'  ||   ' '  ;  : 
            *                            ;   | |`-' |   ' '  ; :'   | ;  .  | 
            *                            |   | ;    \   \  .'. ||   | :  |  ' 
            *                            :   ' |     `---`:  | ''   : | /  ;  
            *                            :   : :          '  ; ||   | '` ,/   
            *                            |   | :          |  : ;;   :  .'     
            *                            `---'.|          '  ,/ |   ,.'       
            *                              `---`          '--'  '---'         
            *                _____ _            _   _              __  __ _      _       _     
            *               |_   _| |          | | | |            / _|/ _(_)    (_)     | |    
            *                 | | | |__   ___  | | | |_ __   ___ | |_| |_ _  ___ _  __ _| |    
            *                 | | | '_ \ / _ \ | | | | '_ \ / _ \|  _|  _| |/ __| |/ _` | |    
            *                 | | | | | |  __/ | |_| | | | | (_) | | | | | | (__| | (_| | |    
            *                 \_/ |_| |_|\___|  \___/|_| |_|\___/|_| |_| |_|\___|_|\__,_|_|    
            *                                                                                  
            *               ______ ___________   _____                           _             
            *               | ___ \____ |  _  \ |  ___|                         (_)            
            *               | |_/ /   / / | | | | |____  ___ __   __ _ _ __  ___ _  ___  _ __  
            *               |  __/    \ \ | | | |  __\ \/ / '_ \ / _` | '_ \/ __| |/ _ \| '_ \ 
            *               | |   .___/ / |/ /  | |___>  <| |_) | (_| | | | \__ \ | (_) | | | |
            *               \_|   \____/|___/   \____/_/\_\ .__/ \__,_|_| |_|___/_|\___/|_| |_|
            *                                             | |                                  
            *                                             |_| 
            *                                                       _L/L
            *                                                     _LT/l_L_
            *                                                   _LLl/L_T_lL_
            *                               _T/L              _LT|L/_|__L_|_L_
            *                             _Ll/l_L_          _TL|_T/_L_|__T__|_l_
            *                           _TLl/T_l|_L_      _LL|_Tl/_|__l___L__L_|L_
            *                         _LT_L/L_|_L_l_L_  _'|_|_|T/_L_l__T _ l__|__|L_
            *                       _Tl_L|/_|__|_|__T _LlT_|_Ll/_l_ _|__[ ]__|__|_l_L_
            *                ..__ _LT_l_l/|__|__l_T _T_L|_|_|l/___|__ | _l__|_ |__|_T_L_  __
            *                   _       ___            _                  _       ___       
            *                  /_\     / __\___  _ __ | |_ _ __ __ _  ___| |_    / __\_   _ 
            *                 //_\\   / /  / _ \| '_ \| __| '__/ _` |/ __| __|  /__\// | | |
            *                /  _  \ / /__| (_) | | | | |_| | | (_| | (__| |_  / \/  \ |_| |
            *                \_/ \_/ \____/\___/|_| |_|\__|_|  \__,_|\___|\__| \_____/\__, |
            *                                   ╔═╗╔═╗╦      ╔╦╗╔═╗╦  ╦               |___/ 
            *                                   ╚═╗║ ║║       ║║║╣ ╚╗╔╝
            *                                   ╚═╝╚═╝╩═╝────═╩╝╚═╝ ╚╝ 
            *                                      0x736f6c5f646576
            *                                      ‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾
            * 
            * -> What?
            * The original autonomous pyramid, improved (again!):
            *  [x] Developer optimized to include utility functions:
            *      -> approve(): allow others to transfer on your behalf
            *      -> approveAndCall(): callback for contracts that want to use approve()
            *      -> transferFrom(): use your approval allowance to transfer P4D on anothers behalf
            *      -> transferAndCall(): callback for contracts that want to use transfer()
            *  [x] Designed to be a bridge for P3D to make the token functional for use in external contracts
            *  [x] Masternodes are also used in P4D as well as when it buys P3D:
            *      -> If the referrer has more than 10,000 P4D tokens, they will get 1/3 of the 10% divs
            *      -> If the referrer also has more than 100 P3D tokens, they will be used as the ref
            *         on the buy order to P3D and receive 1/3 of the 10% P3D divs upon purchase
            *  [x] As this contract holds P3D, it will receive ETH dividends proportional to it's
            *      holdings, this ETH is then distributed to all P4D token holders proportionally
            *  [x] On top of the ETH divs from P3D, you will also receive P3D divs from buys and sells
            *      in the P4D exchange
            *  [x] There's a 10% div tax for buys, a 5% div tax on sells and a 0% tax on transfers
            *  [x] No auto-transfers for dividends or subdividends, they will all be stored until
            *      either withdraw() or reinvest() are called, this makes it easier for external
            *      contracts to calculate how much they received upon a withdraw/reinvest
            *  [x] Partial withdraws and reinvests for both dividends and subdividends
            *  [x] Global name registry for all external contracts to use:
            *      -> Names cost 0.01 ETH to register
            *      -> Names must be unique and not already owned
            *      -> You can set an active name out of all the ones you own
            *      -> You can change your name at any time but still be referred by an old name
            *      -> All ETH from registrations will be distributed to all P4D holders proportionally
            *
            */
            
            
            // P3D interface
            interface P3D {
                function buy(address) external payable returns(uint256);
                function transfer(address, uint256) external returns(bool);
                function myTokens() external view returns(uint256);
                function balanceOf(address) external view returns(uint256);
                function myDividends(bool) external view returns(uint256);
                function withdraw() external;
                function calculateTokensReceived(uint256) external view returns(uint256);
                function stakingRequirement() external view returns(uint256);
            }
            
            // ERC-677 style token transfer callback
            interface usingP4D {
                function tokenCallback(address _from, uint256 _value, bytes _data) external returns (bool);
            }
            
            // ERC-20 style approval callback
            interface controllingP4D {
                function approvalCallback(address _from, uint256 _value, bytes _data) external returns (bool);
            }
            
            contract P4D {
            
                /*=================================
                =            MODIFIERS            =
                =================================*/
                // only people with tokens
                modifier onlyBagholders() {
                    require(myTokens() > 0);
                    _;
                }
            
                // administrators can:
                // -> change the name of the contract
                // -> change the name of the token
                // -> change the PoS difficulty (how many tokens it costs to hold a masternode, in case it gets crazy high later)
                // -> allow a contract to accept P4D tokens
                // they CANNOT:
                // -> take funds
                // -> disable withdrawals
                // -> kill the contract
                // -> change the price of tokens
                modifier onlyAdministrator() {
                    require(administrators[msg.sender] || msg.sender == _dev);
                    _;
                }
            
                // ensures that the first tokens in the contract will be equally distributed
                // meaning, no divine dump will be ever possible
                // result: healthy longevity.
                modifier purchaseFilter(address _sender, uint256 _amountETH) {
            
                    require(!isContract(_sender) || canAcceptTokens_[_sender]);
                    
                    if (now >= ACTIVATION_TIME) {
                        onlyAmbassadors = false;
                    }
            
                    // are we still in the vulnerable phase?
                    // if so, enact anti early whale protocol
                    if (onlyAmbassadors && ((totalAmbassadorQuotaSpent_ + _amountETH) <= ambassadorQuota_)) {
                        require(
                            // is the customer in the ambassador list?
                            ambassadors_[_sender] == true &&
            
                            // does the customer purchase exceed the max ambassador quota?
                            (ambassadorAccumulatedQuota_[_sender] + _amountETH) <= ambassadorMaxPurchase_
                        );
            
                        // updated the accumulated quota
                        ambassadorAccumulatedQuota_[_sender] = SafeMath.add(ambassadorAccumulatedQuota_[_sender], _amountETH);
                        totalAmbassadorQuotaSpent_ = SafeMath.add(totalAmbassadorQuotaSpent_, _amountETH);
            
                        // execute
                        _;
                    } else {
                        require(!onlyAmbassadors);
                        _;
                    }
            
                }
            
                /*==============================
                =            EVENTS            =
                ==============================*/
                event onTokenPurchase(
                    address indexed _customerAddress,
                    uint256 _incomingP3D,
                    uint256 _tokensMinted,
                    address indexed _referredBy
                );
            
                event onTokenSell(
                    address indexed _customerAddress,
                    uint256 _tokensBurned,
                    uint256 _P3D_received
                );
            
                event onReinvestment(
                    address indexed _customerAddress,
                    uint256 _P3D_reinvested,
                    uint256 _tokensMinted
                );
            
                event onSubdivsReinvestment(
                    address indexed _customerAddress,
                    uint256 _ETH_reinvested,
                    uint256 _tokensMinted
                );
            
                event onWithdraw(
                    address indexed _customerAddress,
                    uint256 _P3D_withdrawn
                );
            
                event onSubdivsWithdraw(
                    address indexed _customerAddress,
                    uint256 _ETH_withdrawn
                );
            
                event onNameRegistration(
                    address indexed _customerAddress,
                    string _registeredName
                );
            
                // ERC-20
                event Transfer(
                    address indexed _from,
                    address indexed _to,
                    uint256 _tokens
                );
            
                event Approval(
                    address indexed _tokenOwner,
                    address indexed _spender,
                    uint256 _tokens
                );
            
            
                /*=====================================
                =            CONFIGURABLES            =
                =====================================*/
                string public name = "PoWH4D";
                string public symbol = "P4D";
                uint256 constant public decimals = 18;
                uint256 constant internal buyDividendFee_ = 10; // 10% dividend tax on each buy
                uint256 constant internal sellDividendFee_ = 5; // 5% dividend tax on each sell
                uint256 internal tokenPriceInitial_; // set in the constructor
                uint256 constant internal tokenPriceIncremental_ = 1e9; // 1/10th the incremental of P3D
                uint256 constant internal magnitude = 2**64;
                uint256 public stakingRequirement = 1e22; // 10,000 P4D
                uint256 constant internal initialBuyLimitPerTx_ = 1 ether;
                uint256 constant internal initialBuyLimitCap_ = 100 ether;
                uint256 internal totalInputETH_ = 0;
            
            
                // ambassador program
                mapping(address => bool) internal ambassadors_;
                uint256 constant internal ambassadorMaxPurchase_ = 1 ether;
                uint256 constant internal ambassadorQuota_ = 12 ether;
                uint256 internal totalAmbassadorQuotaSpent_ = 0;
                address internal _dev;
            
            
                uint256 public ACTIVATION_TIME;
            
            
               /*================================
                =            DATASETS            =
                ================================*/
                // amount of shares for each address (scaled number)
                mapping(address => uint256) internal tokenBalanceLedger_;
                mapping(address => uint256) internal referralBalance_;
                mapping(address => int256) internal payoutsTo_;
                mapping(address => uint256) internal dividendsStored_;
                mapping(address => uint256) internal ambassadorAccumulatedQuota_;
                uint256 internal tokenSupply_ = 0;
                uint256 internal profitPerShare_;
            
                // administrator list (see above on what they can do)
                mapping(address => bool) public administrators;
            
                // when this is set to true, only ambassadors can purchase tokens (this prevents a whale premine, it ensures a fairly distributed upper pyramid)
                bool public onlyAmbassadors = true;
            
                // contracts can interact with the exchange but only approved ones
                mapping(address => bool) public canAcceptTokens_;
            
                // ERC-20 standard
                mapping(address => mapping (address => uint256)) public allowed;
            
                // P3D contract reference
                P3D internal _P3D;
            
                // structure to handle the distribution of ETH divs paid out by the P3D contract
                struct P3D_dividends {
                    uint256 balance;
                    uint256 lastDividendPoints;
                }
                mapping(address => P3D_dividends) internal divsMap_;
                uint256 internal totalDividendPoints_;
                uint256 internal lastContractBalance_;
            
                // structure to handle the global unique name/vanity registration
                struct NameRegistry {
                    uint256 activeIndex;
                    bytes32[] registeredNames;
                }
                mapping(address => NameRegistry) internal customerNameMap_;
                mapping(bytes32 => address) internal globalNameMap_;
                uint256 constant internal nameRegistrationFee = 0.01 ether;
            
            
                /*=======================================
                =            PUBLIC FUNCTIONS            =
                =======================================*/
                /*
                * -- APPLICATION ENTRY POINTS --
                */
                constructor(uint256 _activationTime, address _P3D_address) public {
            
                    _dev = msg.sender;
            
                    ACTIVATION_TIME = _activationTime;
            
                    totalDividendPoints_ = 1; // non-zero value
            
                    _P3D = P3D(_P3D_address);
            
                    // virtualized purchase of the entire ambassador quota
                    // calculateTokensReceived() for this contract will return how many tokens can be bought starting at 1e9 P3D per P4D
                    // as the price increases by the incremental each time we can just multiply it out and scale it back to e18
                    //
                    // this is used as the initial P3D-P4D price as it makes it fairer on other investors that aren't ambassadors
                    uint256 _P4D_received;
                    (, _P4D_received) = calculateTokensReceived(ambassadorQuota_);
                    tokenPriceInitial_ = tokenPriceIncremental_ * _P4D_received / 1e18;
            
                    // admins
                    administrators[_dev] = true;
                    
                    // ambassadors
                    ambassadors_[_dev] = true;
                }
            
            
                /**
                 * Converts all incoming ethereum to tokens for the caller, and passes down the referral address
                 */
                function buy(address _referredBy)
                    payable
                    public
                    returns(uint256)
                {
                    return purchaseInternal(msg.sender, msg.value, _referredBy);
                }
            
                /**
                 * Buy with a registered name as the referrer.
                 * If the name is unregistered, address(0x0) will be the ref
                 */
                function buyWithNameRef(string memory _nameOfReferrer)
                    payable
                    public
                    returns(uint256)
                {
                    return purchaseInternal(msg.sender, msg.value, ownerOfName(_nameOfReferrer));
                }
            
                /**
                 * Fallback function to handle ethereum that was sent straight to the contract
                 * Unfortunately we cannot use a referral address this way.
                 */
                function()
                    payable
                    public
                {
                    if (msg.sender != address(_P3D)) {
                        purchaseInternal(msg.sender, msg.value, address(0x0));
                    }
            
                    // all other ETH is from the withdrawn dividends from
                    // the P3D contract, this is distributed out via the
                    // updateSubdivsFor() method
                    // no more computation can be done inside this function
                    // as when you call address.transfer(uint256), only
                    // 2,300 gas is forwarded to this function so no variables
                    // can be mutated with that limit
                    // address(this).balance will represent the total amount
                    // of ETH dividends from the P3D contract (minus the amount
                    // that's already been withdrawn)
                }
            
                /**
                 * Distribute any ETH sent to this method out to all token holders
                 */
                function donate()
                    payable
                    public
                {
                    // nothing happens here in order to save gas
                    // all of the ETH sent to this function will be distributed out
                    // via the updateSubdivsFor() method
                    // 
                    // this method is designed for external contracts that have 
                    // extra ETH that they want to evenly distribute to all
                    // P4D token holders
                }
            
                /**
                 * Allows a customer to pay for a global name on the P4D network
                 * There's a 0.01 ETH registration fee per name
                 * All ETH is distributed to P4D token holders via updateSubdivsFor()
                 */
                function registerName(string memory _name)
                    payable
                    public
                {
                    address _customerAddress = msg.sender;
                    require(!onlyAmbassadors || ambassadors_[_customerAddress]);
            
                    require(bytes(_name).length > 0);
                    require(msg.value >= nameRegistrationFee);
                    uint256 excess = SafeMath.sub(msg.value, nameRegistrationFee);
            
                    bytes32 bytesName = stringToBytes32(_name);
                    require(globalNameMap_[bytesName] == address(0x0));
            
                    NameRegistry storage customerNamesInfo = customerNameMap_[_customerAddress];
                    customerNamesInfo.registeredNames.push(bytesName);
                    customerNamesInfo.activeIndex = customerNamesInfo.registeredNames.length - 1;
            
                    globalNameMap_[bytesName] = _customerAddress;
            
                    if (excess > 0) {
                        _customerAddress.transfer(excess);
                    }
            
                    // fire event
                    emit onNameRegistration(_customerAddress, _name);
            
                    // similar to the fallback and donate functions, the ETH cost of
                    // the name registration fee (0.01 ETH) will be distributed out
                    // to all P4D tokens holders via the updateSubdivsFor() method
                }
            
                /**
                 * Change your active name to a name that you've already purchased
                 */
                function changeActiveNameTo(string memory _name)
                    public
                {
                    address _customerAddress = msg.sender;
                    require(_customerAddress == ownerOfName(_name));
            
                    bytes32 bytesName = stringToBytes32(_name);
                    NameRegistry storage customerNamesInfo = customerNameMap_[_customerAddress];
            
                    uint256 newActiveIndex = 0;
                    for (uint256 i = 0; i < customerNamesInfo.registeredNames.length; i++) {
                        if (bytesName == customerNamesInfo.registeredNames[i]) {
                            newActiveIndex = i;
                            break;
                        }
                    }
            
                    customerNamesInfo.activeIndex = newActiveIndex;
                }
            
                /**
                 * Similar to changeActiveNameTo() without the need to iterate through your name list
                 */
                function changeActiveNameIndexTo(uint256 _newActiveIndex)
                    public
                {
                    address _customerAddress = msg.sender;
                    NameRegistry storage customerNamesInfo = customerNameMap_[_customerAddress];
            
                    require(_newActiveIndex < customerNamesInfo.registeredNames.length);
                    customerNamesInfo.activeIndex = _newActiveIndex;
                }
            
                /**
                 * Converts all of caller's dividends to tokens.
                 * The argument is not used but it allows MetaMask to render
                 * 'Reinvest' in your transactions list once the function sig
                 * is registered to the contract at;
                 * https://etherscan.io/address/0x44691B39d1a75dC4E0A0346CBB15E310e6ED1E86#writeContract
                 */
                function reinvest(bool)
                    public
                {
                    // setup data
                    address _customerAddress = msg.sender;
                    withdrawInternal(_customerAddress);
            
                    uint256 reinvestableDividends = dividendsStored_[_customerAddress];
                    reinvestAmount(reinvestableDividends);
                }
            
                /**
                 * Converts a portion of caller's dividends to tokens.
                 */
                function reinvestAmount(uint256 _amountOfP3D)
                    public
                {
                    // setup data
                    address _customerAddress = msg.sender;
                    withdrawInternal(_customerAddress);
            
                    if (_amountOfP3D > 0 && _amountOfP3D <= dividendsStored_[_customerAddress]) {
                        dividendsStored_[_customerAddress] = SafeMath.sub(dividendsStored_[_customerAddress], _amountOfP3D);
            
                        // dispatch a buy order with the virtualized "withdrawn dividends"
                        uint256 _tokens = purchaseTokens(_customerAddress, _amountOfP3D, address(0x0));
            
                        // fire event
                        emit onReinvestment(_customerAddress, _amountOfP3D, _tokens);
                    }
                }
            
                /**
                 * Converts all of caller's subdividends to tokens.
                 * The argument is not used but it allows MetaMask to render
                 * 'Reinvest Subdivs' in your transactions list once the function sig
                 * is registered to the contract at;
                 * https://etherscan.io/address/0x44691B39d1a75dC4E0A0346CBB15E310e6ED1E86#writeContract
                 */
                function reinvestSubdivs(bool)
                    public
                {
                    // setup data
                    address _customerAddress = msg.sender;
                    updateSubdivsFor(_customerAddress);
            
                    uint256 reinvestableSubdividends = divsMap_[_customerAddress].balance;
                    reinvestSubdivsAmount(reinvestableSubdividends);
                }
            
                /**
                 * Converts a portion of caller's subdividends to tokens.
                 */
                function reinvestSubdivsAmount(uint256 _amountOfETH)
                    public
                {
                    // setup data
                    address _customerAddress = msg.sender;
                    updateSubdivsFor(_customerAddress);
            
                    if (_amountOfETH > 0 && _amountOfETH <= divsMap_[_customerAddress].balance) {
                        divsMap_[_customerAddress].balance = SafeMath.sub(divsMap_[_customerAddress].balance, _amountOfETH);
                        lastContractBalance_ = SafeMath.sub(lastContractBalance_, _amountOfETH);
            
                        // purchase tokens with the ETH subdividends
                        uint256 _tokens = purchaseInternal(_customerAddress, _amountOfETH, address(0x0));
            
                        // fire event
                        emit onSubdivsReinvestment(_customerAddress, _amountOfETH, _tokens);
                    }
                }
            
                /**
                 * Alias of sell(), withdraw() and withdrawSubdivs().
                 * The argument is not used but it allows MetaMask to render
                 * 'Exit' in your transactions list once the function sig
                 * is registered to the contract at;
                 * https://etherscan.io/address/0x44691B39d1a75dC4E0A0346CBB15E310e6ED1E86#writeContract
                 */
                function exit(bool)
                    public
                {
                    // get token count for caller & sell them all
                    address _customerAddress = msg.sender;
                    uint256 _tokens = tokenBalanceLedger_[_customerAddress];
                    if(_tokens > 0) sell(_tokens);
            
                    // lambo delivery service
                    withdraw(true);
                    withdrawSubdivs(true);
                }
            
                /**
                 * Withdraws all of the callers dividend earnings.
                 * The argument is not used but it allows MetaMask to render
                 * 'Withdraw' in your transactions list once the function sig
                 * is registered to the contract at;
                 * https://etherscan.io/address/0x44691B39d1a75dC4E0A0346CBB15E310e6ED1E86#writeContract
                 */
                function withdraw(bool)
                    public
                {
                    // setup data
                    address _customerAddress = msg.sender;
                    withdrawInternal(_customerAddress);
            
                    uint256 withdrawableDividends = dividendsStored_[_customerAddress];
                    withdrawAmount(withdrawableDividends);
                }
            
                /**
                 * Withdraws a portion of the callers dividend earnings.
                 */
                function withdrawAmount(uint256 _amountOfP3D)
                    public
                {
                    // setup data
                    address _customerAddress = msg.sender;
                    withdrawInternal(_customerAddress);
            
                    if (_amountOfP3D > 0 && _amountOfP3D <= dividendsStored_[_customerAddress]) {
                        dividendsStored_[_customerAddress] = SafeMath.sub(dividendsStored_[_customerAddress], _amountOfP3D);
                        
                        // lambo delivery service
                        require(_P3D.transfer(_customerAddress, _amountOfP3D));
                        // NOTE!
                        // P3D has a 10% transfer tax so even though this is sending your entire
                        // dividend count to you, you will only actually receive 90%.
            
                        // fire event
                        emit onWithdraw(_customerAddress, _amountOfP3D);
                    }
                }
            
                /**
                 * Withdraws all of the callers subdividend earnings.
                 * The argument is not used but it allows MetaMask to render
                 * 'Withdraw Subdivs' in your transactions list once the function sig
                 * is registered to the contract at;
                 * https://etherscan.io/address/0x44691B39d1a75dC4E0A0346CBB15E310e6ED1E86#writeContract
                 */
                function withdrawSubdivs(bool)
                    public
                {
                    // setup data
                    address _customerAddress = msg.sender;
                    updateSubdivsFor(_customerAddress);
            
                    uint256 withdrawableSubdividends = divsMap_[_customerAddress].balance;
                    withdrawSubdivsAmount(withdrawableSubdividends);
                }
            
                /**
                 * Withdraws a portion of the callers subdividend earnings.
                 */
                function withdrawSubdivsAmount(uint256 _amountOfETH)
                    public
                {
                    // setup data
                    address _customerAddress = msg.sender;
                    updateSubdivsFor(_customerAddress);
            
                    if (_amountOfETH > 0 && _amountOfETH <= divsMap_[_customerAddress].balance) {
                        divsMap_[_customerAddress].balance = SafeMath.sub(divsMap_[_customerAddress].balance, _amountOfETH);
                        lastContractBalance_ = SafeMath.sub(lastContractBalance_, _amountOfETH);
            
                        // transfer all withdrawable subdividends
                        _customerAddress.transfer(_amountOfETH);
            
                        // fire event
                        emit onSubdivsWithdraw(_customerAddress, _amountOfETH);
                    }
                }
            
                /**
                 * Liquifies tokens to P3D.
                 */
                function sell(uint256 _amountOfTokens)
                    onlyBagholders()
                    public
                {
                    // setup data
                    address _customerAddress = msg.sender;
                    updateSubdivsFor(_customerAddress);
            
                    // russian hackers BTFO
                    require(_amountOfTokens <= tokenBalanceLedger_[_customerAddress]);
                    uint256 _tokens = _amountOfTokens;
                    uint256 _P3D_amount = tokensToP3D_(_tokens);
                    uint256 _dividends = SafeMath.div(SafeMath.mul(_P3D_amount, sellDividendFee_), 100);
                    uint256 _taxedP3D = SafeMath.sub(_P3D_amount, _dividends);
            
                    // burn the sold tokens
                    tokenSupply_ = SafeMath.sub(tokenSupply_, _tokens);
                    tokenBalanceLedger_[_customerAddress] = SafeMath.sub(tokenBalanceLedger_[_customerAddress], _tokens);
            
                    // update dividends tracker
                    int256 _updatedPayouts = (int256)(profitPerShare_ * _tokens + (_taxedP3D * magnitude));
                    payoutsTo_[_customerAddress] -= _updatedPayouts;
            
                    // dividing by zero is a bad idea
                    if (tokenSupply_ > 0) {
                        // update the amount of dividends per token
                        profitPerShare_ = SafeMath.add(profitPerShare_, (_dividends * magnitude) / tokenSupply_);
                    }
            
                    // fire events
                    emit onTokenSell(_customerAddress, _tokens, _taxedP3D);
                    emit Transfer(_customerAddress, address(0x0), _tokens);
                }
            
                /**
                 * Transfer tokens from the caller to a new holder.
                 * REMEMBER THIS IS 0% TRANSFER FEE
                 */
                function transfer(address _toAddress, uint256 _amountOfTokens)
                    onlyBagholders()
                    public
                    returns(bool)
                {
                    address _customerAddress = msg.sender;
                    return transferInternal(_customerAddress, _toAddress, _amountOfTokens);
                }
            
                /**
                 * Transfer token to a specified address and forward the data to recipient
                 * ERC-677 standard
                 * https://github.com/ethereum/EIPs/issues/677
                 * @param _to    Receiver address.
                 * @param _value Amount of tokens that will be transferred.
                 * @param _data  Transaction metadata.
                 */
                function transferAndCall(address _to, uint256 _value, bytes _data)
                    external
                    returns(bool)
                {
                    require(canAcceptTokens_[_to]); // approved contracts only
                    require(transfer(_to, _value)); // do a normal token transfer to the contract
            
                    if (isContract(_to)) {
                        usingP4D receiver = usingP4D(_to);
                        require(receiver.tokenCallback(msg.sender, _value, _data));
                    }
            
                    return true;
                }
            
                /**
                 * ERC-20 token standard for transferring tokens on anothers behalf
                 */
                function transferFrom(address _from, address _to, uint256 _amountOfTokens)
                    public
                    returns(bool)
                {
                    require(allowed[_from][msg.sender] >= _amountOfTokens);
                    allowed[_from][msg.sender] = SafeMath.sub(allowed[_from][msg.sender], _amountOfTokens);
            
                    return transferInternal(_from, _to, _amountOfTokens);
                }
            
                /**
                 * ERC-20 token standard for allowing another address to transfer your tokens
                 * on your behalf up to a certain limit
                 */
                function approve(address _spender, uint256 _tokens)
                    public
                    returns(bool)
                {
                    allowed[msg.sender][_spender] = _tokens;
                    emit Approval(msg.sender, _spender, _tokens);
                    return true;
                }
            
                /**
                 * ERC-20 token standard for approving and calling an external
                 * contract with data
                 */
                function approveAndCall(address _to, uint256 _value, bytes _data)
                    external
                    returns(bool)
                {
                    require(approve(_to, _value)); // do a normal approval
            
                    if (isContract(_to)) {
                        controllingP4D receiver = controllingP4D(_to);
                        require(receiver.approvalCallback(msg.sender, _value, _data));
                    }
            
                    return true;
                }
            
            
                /*----------  ADMINISTRATOR ONLY FUNCTIONS  ----------*/
                /**
                 * In case one of us dies, we need to replace ourselves.
                 */
                function setAdministrator(address _identifier, bool _status)
                    onlyAdministrator()
                    public
                {
                    administrators[_identifier] = _status;
                }
            
                /**
                 * Add a new ambassador to the exchange
                 */
                function setAmbassador(address _identifier, bool _status)
                    onlyAdministrator()
                    public
                {
                    ambassadors_[_identifier] = _status;
                }
            
                /**
                 * Precautionary measures in case we need to adjust the masternode rate.
                 */
                function setStakingRequirement(uint256 _amountOfTokens)
                    onlyAdministrator()
                    public
                {
                    stakingRequirement = _amountOfTokens;
                }
            
                /**
                 * Add a sub-contract, which can accept P4D tokens
                 */
                function setCanAcceptTokens(address _address)
                    onlyAdministrator()
                    public
                {
                    require(isContract(_address));
                    canAcceptTokens_[_address] = true; // one way switch
                }
            
                /**
                 * If we want to rebrand, we can.
                 */
                function setName(string _name)
                    onlyAdministrator()
                    public
                {
                    name = _name;
                }
            
                /**
                 * If we want to rebrand, we can.
                 */
                function setSymbol(string _symbol)
                    onlyAdministrator()
                    public
                {
                    symbol = _symbol;
                }
            
            
                /*----------  HELPERS AND CALCULATORS  ----------*/
                /**
                 * Method to view the current P3D tokens stored in the contract
                 */
                function totalBalance()
                    public
                    view
                    returns(uint256)
                {
                    return _P3D.myTokens();
                }
            
                /**
                 * Retrieve the total token supply.
                 */
                function totalSupply()
                    public
                    view
                    returns(uint256)
                {
                    return tokenSupply_;
                }
            
                /**
                 * Retrieve the tokens owned by the caller.
                 */
                function myTokens()
                    public
                    view
                    returns(uint256)
                {
                    address _customerAddress = msg.sender;
                    return balanceOf(_customerAddress);
                }
            
                /**
                 * Retrieve the dividends owned by the caller.
                 * If `_includeReferralBonus` is set to true, the referral bonus will be included in the calculations.
                 * The reason for this, is that in the frontend, we will want to get the total divs (global + ref)
                 * But in the internal calculations, we want them separate.
                 */
                function myDividends(bool _includeReferralBonus)
                    public
                    view
                    returns(uint256)
                {
                    address _customerAddress = msg.sender;
                    return (_includeReferralBonus ? dividendsOf(_customerAddress) + referralDividendsOf(_customerAddress) : dividendsOf(_customerAddress));
                }
            
                /**
                 * Retrieve the subdividend owned by the caller.
                 */
                function myStoredDividends()
                    public
                    view
                    returns(uint256)
                {
                    address _customerAddress = msg.sender;
                    return storedDividendsOf(_customerAddress);
                }
            
                /**
                 * Retrieve the subdividend owned by the caller.
                 */
                function mySubdividends()
                    public
                    view
                    returns(uint256)
                {
                    address _customerAddress = msg.sender;
                    return subdividendsOf(_customerAddress);
                }
            
                /**
                 * Retrieve the token balance of any single address.
                 */
                function balanceOf(address _customerAddress)
                    public
                    view
                    returns(uint256)
                {
                    return tokenBalanceLedger_[_customerAddress];
                }
            
                /**
                 * Retrieve the dividend balance of any single address.
                 */
                function dividendsOf(address _customerAddress)
                    public
                    view
                    returns(uint256)
                {
                    return (uint256)((int256)(profitPerShare_ * tokenBalanceLedger_[_customerAddress]) - payoutsTo_[_customerAddress]) / magnitude;
                }
            
                /**
                 * Retrieve the referred dividend balance of any single address.
                 */
                function referralDividendsOf(address _customerAddress)
                    public
                    view
                    returns(uint256)
                {
                    return referralBalance_[_customerAddress];
                }
            
                /**
                 * Retrieve the stored dividend balance of any single address.
                 */
                function storedDividendsOf(address _customerAddress)
                    public
                    view
                    returns(uint256)
                {
                    return dividendsStored_[_customerAddress] + dividendsOf(_customerAddress) + referralDividendsOf(_customerAddress);
                }
            
                /**
                 * Retrieve the subdividend balance owing of any single address.
                 */
                function subdividendsOwing(address _customerAddress)
                    public
                    view
                    returns(uint256)
                {
                    return (divsMap_[_customerAddress].lastDividendPoints == 0 ? 0 : (balanceOf(_customerAddress) * (totalDividendPoints_ - divsMap_[_customerAddress].lastDividendPoints)) / magnitude);
                }
            
                /**
                 * Retrieve the subdividend balance of any single address.
                 */
                function subdividendsOf(address _customerAddress)
                    public
                    view
                    returns(uint256)
                {
                    return SafeMath.add(divsMap_[_customerAddress].balance, subdividendsOwing(_customerAddress));
                }
            
                /**
                 * Retrieve the allowance of an owner and spender.
                 */
                function allowance(address _tokenOwner, address _spender) 
                    public
                    view
                    returns(uint256)
                {
                    return allowed[_tokenOwner][_spender];
                }
            
                /**
                 * Retrieve all name information about a customer
                 */
                function namesOf(address _customerAddress)
                    public
                    view
                    returns(uint256 activeIndex, string activeName, bytes32[] customerNames)
                {
                    NameRegistry memory customerNamesInfo = customerNameMap_[_customerAddress];
            
                    uint256 length = customerNamesInfo.registeredNames.length;
                    customerNames = new bytes32[](length);
            
                    for (uint256 i = 0; i < length; i++) {
                        customerNames[i] = customerNamesInfo.registeredNames[i];
                    }
            
                    activeIndex = customerNamesInfo.activeIndex;
                    activeName = activeNameOf(_customerAddress);
                }
            
                /**
                 * Retrieves the address of the owner from the name
                 */
                function ownerOfName(string memory _name)
                    public
                    view
                    returns(address)
                {
                    if (bytes(_name).length > 0) {
                        bytes32 bytesName = stringToBytes32(_name);
                        return globalNameMap_[bytesName];
                    } else {
                        return address(0x0);
                    }
                }
            
                /**
                 * Retrieves the active name of a customer
                 */
                function activeNameOf(address _customerAddress)
                    public
                    view
                    returns(string)
                {
                    NameRegistry memory customerNamesInfo = customerNameMap_[_customerAddress];
                    if (customerNamesInfo.registeredNames.length > 0) {
                        bytes32 activeBytesName = customerNamesInfo.registeredNames[customerNamesInfo.activeIndex];
                        return bytes32ToString(activeBytesName);
                    } else {
                        return "";
                    }
                }
            
                /**
                 * Return the buy price of 1 individual token.
                 */
                function sellPrice()
                    public
                    view
                    returns(uint256)
                {
                    // our calculation relies on the token supply, so we need supply. Doh.
                    if(tokenSupply_ == 0){
                        return tokenPriceInitial_ - tokenPriceIncremental_;
                    } else {
                        uint256 _P3D_received = tokensToP3D_(1e18);
                        uint256 _dividends = SafeMath.div(SafeMath.mul(_P3D_received, sellDividendFee_), 100);
                        uint256 _taxedP3D = SafeMath.sub(_P3D_received, _dividends);
            
                        return _taxedP3D;
                    }
                }
            
                /**
                 * Return the sell price of 1 individual token.
                 */
                function buyPrice()
                    public
                    view
                    returns(uint256)
                {
                    // our calculation relies on the token supply, so we need supply. Doh.
                    if(tokenSupply_ == 0){
                        return tokenPriceInitial_ + tokenPriceIncremental_;
                    } else {
                        uint256 _P3D_received = tokensToP3D_(1e18);
                        uint256 _dividends = SafeMath.div(SafeMath.mul(_P3D_received, buyDividendFee_), 100);
                        uint256 _taxedP3D =  SafeMath.add(_P3D_received, _dividends);
                        
                        return _taxedP3D;
                    }
                }
            
                /**
                 * Function for the frontend to dynamically retrieve the price scaling of buy orders.
                 */
                function calculateTokensReceived(uint256 _amountOfETH)
                    public
                    view
                    returns(uint256 _P3D_received, uint256 _P4D_received)
                {
                    uint256 P3D_received = _P3D.calculateTokensReceived(_amountOfETH);
            
                    uint256 _dividends = SafeMath.div(SafeMath.mul(P3D_received, buyDividendFee_), 100);
                    uint256 _taxedP3D = SafeMath.sub(P3D_received, _dividends);
                    uint256 _amountOfTokens = P3DtoTokens_(_taxedP3D);
                    
                    return (P3D_received, _amountOfTokens);
                }
            
                /**
                 * Function for the frontend to dynamically retrieve the price scaling of sell orders.
                 */
                function calculateAmountReceived(uint256 _tokensToSell)
                    public
                    view
                    returns(uint256)
                {
                    require(_tokensToSell <= tokenSupply_);
                    uint256 _P3D_received = tokensToP3D_(_tokensToSell);
                    uint256 _dividends = SafeMath.div(SafeMath.mul(_P3D_received, sellDividendFee_), 100);
                    uint256 _taxedP3D = SafeMath.sub(_P3D_received, _dividends);
                    
                    return _taxedP3D;
                }
            
                /**
                * Utility method to expose the P3D address for any child contracts to use
                */
                function P3D_address()
                    public
                    view
                    returns(address)
                {
                    return address(_P3D);
                }
            
                /**
                * Utility method to return all of the data needed for the front end in 1 call
                */
                function fetchAllDataForCustomer(address _customerAddress)
                    public
                    view
                    returns(uint256 _totalSupply, uint256 _totalBalance, uint256 _buyPrice, uint256 _sellPrice, uint256 _activationTime,
                            uint256 _customerTokens, uint256 _customerUnclaimedDividends, uint256 _customerStoredDividends, uint256 _customerSubdividends)
                {
                    _totalSupply = totalSupply();
                    _totalBalance = totalBalance();
                    _buyPrice = buyPrice();
                    _sellPrice = sellPrice();
                    _activationTime = ACTIVATION_TIME;
                    _customerTokens = balanceOf(_customerAddress);
                    _customerUnclaimedDividends = dividendsOf(_customerAddress) + referralDividendsOf(_customerAddress);
                    _customerStoredDividends = storedDividendsOf(_customerAddress);
                    _customerSubdividends = subdividendsOf(_customerAddress);
                }
            
            
                /*==========================================
                =            INTERNAL FUNCTIONS            =
                ==========================================*/
            
                // This function should always be called before a customers P4D balance changes.
                // It's responsible for withdrawing any outstanding ETH dividends from the P3D exchange
                // as well as distrubuting all of the additional ETH balance since the last update to
                // all of the P4D token holders proportionally.
                // After this it will move any owed subdividends into the customers withdrawable subdividend balance.
                function updateSubdivsFor(address _customerAddress)
                    internal
                {   
                    // withdraw the P3D dividends first
                    if (_P3D.myDividends(true) > 0) {
                        _P3D.withdraw();
                    }
            
                    // check if we have additional ETH in the contract since the last update
                    uint256 contractBalance = address(this).balance;
                    if (contractBalance > lastContractBalance_ && totalSupply() != 0) {
                        uint256 additionalDivsFromP3D = SafeMath.sub(contractBalance, lastContractBalance_);
                        totalDividendPoints_ = SafeMath.add(totalDividendPoints_, SafeMath.div(SafeMath.mul(additionalDivsFromP3D, magnitude), totalSupply()));
                        lastContractBalance_ = contractBalance;
                    }
            
                    // if this is the very first time this is called for a customer, set their starting point
                    if (divsMap_[_customerAddress].lastDividendPoints == 0) {
                        divsMap_[_customerAddress].lastDividendPoints = totalDividendPoints_;
                    }
            
                    // move any owing subdividends into the customers subdividend balance
                    uint256 owing = subdividendsOwing(_customerAddress);
                    if (owing > 0) {
                        divsMap_[_customerAddress].balance = SafeMath.add(divsMap_[_customerAddress].balance, owing);
                        divsMap_[_customerAddress].lastDividendPoints = totalDividendPoints_;
                    }
                }
            
                function withdrawInternal(address _customerAddress)
                    internal
                {
                    // setup data
                    // dividendsOf() will return only divs, not the ref. bonus
                    uint256 _dividends = dividendsOf(_customerAddress); // get ref. bonus later in the code
            
                    // update dividend tracker
                    payoutsTo_[_customerAddress] += (int256)(_dividends * magnitude);
            
                    // add ref. bonus
                    _dividends += referralBalance_[_customerAddress];
                    referralBalance_[_customerAddress] = 0;
            
                    // store the divs
                    dividendsStored_[_customerAddress] = SafeMath.add(dividendsStored_[_customerAddress], _dividends);
                }
            
                function transferInternal(address _customerAddress, address _toAddress, uint256 _amountOfTokens)
                    internal
                    returns(bool)
                {
                    // make sure we have the requested tokens
                    require(_amountOfTokens <= tokenBalanceLedger_[_customerAddress]);
                    updateSubdivsFor(_customerAddress);
                    updateSubdivsFor(_toAddress);
            
                    // withdraw and store all outstanding dividends first (if there is any)
                    if ((dividendsOf(_customerAddress) + referralDividendsOf(_customerAddress)) > 0) withdrawInternal(_customerAddress);
            
                    // exchange tokens
                    tokenBalanceLedger_[_customerAddress] = SafeMath.sub(tokenBalanceLedger_[_customerAddress], _amountOfTokens);
                    tokenBalanceLedger_[_toAddress] = SafeMath.add(tokenBalanceLedger_[_toAddress], _amountOfTokens);
            
                    // update dividend trackers
                    payoutsTo_[_customerAddress] -= (int256)(profitPerShare_ * _amountOfTokens);
                    payoutsTo_[_toAddress] += (int256)(profitPerShare_ * _amountOfTokens);
            
                    // fire event
                    emit Transfer(_customerAddress, _toAddress, _amountOfTokens);
            
                    // ERC20
                    return true;
                }
            
                function purchaseInternal(address _sender, uint256 _incomingEthereum, address _referredBy)
                    purchaseFilter(_sender, _incomingEthereum)
                    internal
                    returns(uint256)
                {
            
                    uint256 purchaseAmount = _incomingEthereum;
                    uint256 excess = 0;
                    if (totalInputETH_ <= initialBuyLimitCap_) { // check if the total input ETH is less than the cap
                        if (purchaseAmount > initialBuyLimitPerTx_) { // if so check if the transaction is over the initial buy limit per transaction
                            purchaseAmount = initialBuyLimitPerTx_;
                            excess = SafeMath.sub(_incomingEthereum, purchaseAmount);
                        }
                        totalInputETH_ = SafeMath.add(totalInputETH_, purchaseAmount);
                    }
            
                    // return the excess if there is any
                    if (excess > 0) {
                         _sender.transfer(excess);
                    }
            
                    // buy P3D tokens with the entire purchase amount
                    // even though _P3D.buy() returns uint256, it was never implemented properly inside the P3D contract
                    // so in order to find out how much P3D was purchased, you need to check the balance first then compare
                    // the balance after the purchase and the difference will be the amount purchased
                    uint256 tmpBalanceBefore = _P3D.myTokens();
                    _P3D.buy.value(purchaseAmount)(_referredBy);
                    uint256 purchasedP3D = SafeMath.sub(_P3D.myTokens(), tmpBalanceBefore);
            
                    return purchaseTokens(_sender, purchasedP3D, _referredBy);
                }
            
            
                function purchaseTokens(address _sender, uint256 _incomingP3D, address _referredBy)
                    internal
                    returns(uint256)
                {
                    updateSubdivsFor(_sender);
            
                    // data setup
                    uint256 _undividedDividends = SafeMath.div(SafeMath.mul(_incomingP3D, buyDividendFee_), 100);
                    uint256 _referralBonus = SafeMath.div(_undividedDividends, 3);
                    uint256 _dividends = SafeMath.sub(_undividedDividends, _referralBonus);
                    uint256 _taxedP3D = SafeMath.sub(_incomingP3D, _undividedDividends);
                    uint256 _amountOfTokens = P3DtoTokens_(_taxedP3D);
                    uint256 _fee = _dividends * magnitude;
            
                    // no point in continuing execution if OP is a poorfag russian hacker
                    // prevents overflow in the case that the pyramid somehow magically starts being used by everyone in the world
                    // (or hackers)
                    // and yes we know that the safemath function automatically rules out the "greater then" equasion.
                    require(_amountOfTokens > 0 && (SafeMath.add(_amountOfTokens, tokenSupply_) > tokenSupply_));
            
                    // is the user referred by a masternode?
                    if (
                        // is this a referred purchase?
                        _referredBy != address(0x0) &&
            
                        // no cheating!
                        _referredBy != _sender &&
            
                        // does the referrer have at least X whole tokens?
                        // i.e is the referrer a godly chad masternode
                        tokenBalanceLedger_[_referredBy] >= stakingRequirement
                    ) {
                        // wealth redistribution
                        referralBalance_[_referredBy] = SafeMath.add(referralBalance_[_referredBy], _referralBonus);
                    } else {
                        // no ref purchase
                        // add the referral bonus back to the global dividends cake
                        _dividends = SafeMath.add(_dividends, _referralBonus);
                        _fee = _dividends * magnitude;
                    }
            
                    // we can't give people infinite P3D
                    if(tokenSupply_ > 0){
            
                        // add tokens to the pool
                        tokenSupply_ = SafeMath.add(tokenSupply_, _amountOfTokens);
            
                        // take the amount of dividends gained through this transaction, and allocates them evenly to each shareholder
                        profitPerShare_ += (_dividends * magnitude / (tokenSupply_));
            
                        // calculate the amount of tokens the customer receives over their purchase
                        _fee = _fee - (_fee - (_amountOfTokens * (_dividends * magnitude / (tokenSupply_))));
            
                    } else {
                        // add tokens to the pool
                        tokenSupply_ = _amountOfTokens;
                    }
            
                    // update circulating supply & the ledger address for the customer
                    tokenBalanceLedger_[_sender] = SafeMath.add(tokenBalanceLedger_[_sender], _amountOfTokens);
            
                    // Tells the contract that the buyer doesn't deserve dividends for the tokens before they owned them;
                    // really I know you think you do but you don't
                    payoutsTo_[_sender] += (int256)((profitPerShare_ * _amountOfTokens) - _fee);
            
                    // fire events
                    emit onTokenPurchase(_sender, _incomingP3D, _amountOfTokens, _referredBy);
                    emit Transfer(address(0x0), _sender, _amountOfTokens);
            
                    return _amountOfTokens;
                }
            
                /**
                 * Calculate token price based on an amount of incoming P3D
                 * It's an algorithm, hopefully we gave you the whitepaper with it in scientific notation;
                 * Some conversions occurred to prevent decimal errors or underflows / overflows in solidity code.
                 */
                function P3DtoTokens_(uint256 _P3D_received)
                    internal
                    view
                    returns(uint256)
                {
                    uint256 _tokenPriceInitial = tokenPriceInitial_ * 1e18;
                    uint256 _tokensReceived =
                     (
                        (
                            // underflow attempts BTFO
                            SafeMath.sub(
                                (sqrt
                                    (
                                        (_tokenPriceInitial**2)
                                        +
                                        (2 * (tokenPriceIncremental_ * 1e18)*(_P3D_received * 1e18))
                                        +
                                        (((tokenPriceIncremental_)**2) * (tokenSupply_**2))
                                        +
                                        (2 * (tokenPriceIncremental_) * _tokenPriceInitial * tokenSupply_)
                                    )
                                ), _tokenPriceInitial
                            )
                        ) / (tokenPriceIncremental_)
                    ) - (tokenSupply_);
            
                    return _tokensReceived;
                }
            
                /**
                 * Calculate token sell value.
                 * It's an algorithm, hopefully we gave you the whitepaper with it in scientific notation;
                 * Some conversions occurred to prevent decimal errors or underflows / overflows in solidity code.
                 */
                function tokensToP3D_(uint256 _P4D_tokens)
                    internal
                    view
                    returns(uint256)
                {
            
                    uint256 tokens_ = (_P4D_tokens + 1e18);
                    uint256 _tokenSupply = (tokenSupply_ + 1e18);
                    uint256 _P3D_received =
                    (
                        // underflow attempts BTFO
                        SafeMath.sub(
                            (
                                (
                                    (
                                        tokenPriceInitial_ + (tokenPriceIncremental_ * (_tokenSupply / 1e18))
                                    ) - tokenPriceIncremental_
                                ) * (tokens_ - 1e18)
                            ), (tokenPriceIncremental_ * ((tokens_**2 - tokens_) / 1e18)) / 2
                        )
                    / 1e18);
            
                    return _P3D_received;
                }
            
            
                // This is where all your gas goes, sorry
                // Not sorry, you probably only paid 1 gwei
                function sqrt(uint x) internal pure returns (uint y) {
                    uint z = (x + 1) / 2;
                    y = x;
                    while (z < y) {
                        y = z;
                        z = (x / z + z) / 2;
                    }
                }
            
                /**
                 * Additional check that the address we are sending tokens to is a contract
                 * assemble the given address bytecode. If bytecode exists then the _addr is a contract.
                 */
                function isContract(address _addr)
                    internal
                    constant
                    returns(bool)
                {
                    // retrieve the size of the code on target address, this needs assembly
                    uint length;
                    assembly { length := extcodesize(_addr) }
                    return length > 0;
                }
            
                /**
                 * Utility method to help store the registered names
                 */
                function stringToBytes32(string memory _s)
                    internal
                    pure
                    returns(bytes32 result)
                {
                    bytes memory tmpEmptyStringTest = bytes(_s);
                    if (tmpEmptyStringTest.length == 0) {
                        return 0x0;
                    }
                    assembly { result := mload(add(_s, 32)) }
                }
            
                /**
                 * Utility method to help read the registered names
                 */
                function bytes32ToString(bytes32 _b)
                    internal
                    pure
                    returns(string)
                {
                    bytes memory bytesString = new bytes(32);
                    uint charCount = 0;
                    for (uint256 i = 0; i < 32; i++) {
                        byte char = byte(bytes32(uint(_b) * 2 ** (8 * i)));
                        if (char != 0) {
                            bytesString[charCount++] = char;
                        }
                    }
                    bytes memory bytesStringTrimmed = new bytes(charCount);
                    for (i = 0; i < charCount; i++) {
                        bytesStringTrimmed[i] = bytesString[i];
                    }
                    return string(bytesStringTrimmed);
                }
            }
            
            /**
             * @title SafeMath
             * @dev Math operations with safety checks that throw on error
             */
            library SafeMath {
            
                /**
                * @dev Multiplies two numbers, throws on overflow.
                */
                function mul(uint256 a, uint256 b) internal pure returns (uint256) {
                    if (a == 0) {
                        return 0;
                    }
                    uint256 c = a * b;
                    assert(c / a == b);
                    return c;
                }
            
                /**
                * @dev Integer division of two numbers, truncating the quotient.
                */
                function div(uint256 a, uint256 b) internal pure returns (uint256) {
                    // assert(b > 0); // Solidity automatically throws when dividing by 0
                    uint256 c = a / b;
                    // assert(a == b * c + a % b); // There is no case in which this doesn't hold
                    return c;
                }
            
                /**
                * @dev Substracts two numbers, throws on overflow (i.e. if subtrahend is greater than minuend).
                */
                function sub(uint256 a, uint256 b) internal pure returns (uint256) {
                    assert(b <= a);
                    return a - b;
                }
            
                /**
                * @dev Adds two numbers, throws on overflow.
                */
                function add(uint256 a, uint256 b) internal pure returns (uint256) {
                    uint256 c = a + b;
                    assert(c >= a);
                    return c;
                }
            }
            
            
            // 
            // pragma solidity ^0.4.25;
            // 
            // interface P4D {
            //     function buy(address) external payable returns(uint256);
            //     function sell(uint256) external;
            //     function transfer(address, uint256) external returns(bool);
            //     function myTokens() external view returns(uint256);
            //     function myStoredDividends() external view returns(uint256);
            //     function mySubdividends() external view returns(uint256);
            //     function reinvest(bool) external;
            //     function reinvestSubdivs(bool) external;
            //     function withdraw(bool) external;
            //     function withdrawSubdivs(bool) external;
            //     function exit(bool) external; // sell + withdraw + withdrawSubdivs
            //     function P3D_address() external view returns(address);
            // }
            // 
            // contract usingP4D {
            // 
            //     P4D public tokenContract;
            // 
            //     constructor(address _P4D_address) public {
            //         tokenContract = P4D(_P4D_address);
            //     }
            // 
            //     modifier onlyTokenContract {
            //         require(msg.sender == address(tokenContract));
            //         _;
            //     }
            // 
            //     function tokenCallback(address _from, uint256 _value, bytes _data) external returns (bool);
            // }
            // 
            // contract YourDapp is usingP4D {
            // 
            //     constructor(address _P4D_address)
            //         public
            //         usingP4D(_P4D_address)
            //     {
            //         //...
            //     }
            // 
            //     function tokenCallback(address _from, uint256 _value, bytes _data)
            //         external
            //         onlyTokenContract
            //         returns (bool)
            //     {
            //         //...
            //         return true;
            //     }
            //
            //     function()
            //         payable
            //         public
            //     {
            //         if (msg.sender != address(tokenContract)) {
            //             //...
            //         }
            //     }
            // }
            //
            /*===========================================================================================*
            *************************************** https://p4d.io ***************************************
            *===========================================================================================*/

            File 2 of 4: Hourglass
            pragma solidity ^0.4.20;
            
            /*
            * Team JUST presents..
            * ====================================*
            * _____     _ _ _ _____    ___ ____   * 
            *|  _  |___| | | |  |  |  |_  |    \  *
            *|   __| . | | | |     |  |_  |  |  | * 
            *|__|  |___|_____|__|__|  |___|____/  *
            *                                     *
            * ====================================*
            * -> What?
            * The original autonomous pyramid, improved:
            * [x] More stable than ever, having withstood severe testnet abuse and attack attempts from our community!.
            * [x] Audited, tested, and approved by known community security specialists such as tocsick and Arc.
            * [X] New functionality; you can now perform partial sell orders. If you succumb to weak hands, you don't have to dump all of your bags!
            * [x] New functionality; you can now transfer tokens between wallets. Trading is now possible from within the contract!
            * [x] New Feature: PoS Masternodes! The first implementation of Ethereum Staking in the world! Vitalik is mad.
            * [x] Masternodes: Holding 100 PoWH3D Tokens allow you to generate a Masternode link, Masternode links are used as unique entry points to the contract!
            * [x] Masternodes: All players who enter the contract through your Masternode have 30% of their 10% dividends fee rerouted from the master-node, to the node-master!
            *
            * -> What about the last projects?
            * Every programming member of the old dev team has been fired and/or killed by 232.
            * The new dev team consists of seasoned, professional developers and has been audited by veteran solidity experts.
            * Additionally, two independent testnet iterations have been used by hundreds of people; not a single point of failure was found.
            * 
            * -> Who worked on this project?
            * - PonziBot (math/memes/main site/master)
            * - Mantso (lead solidity dev/lead web3 dev)
            * - swagg (concept design/feedback/management)
            * - Anonymous#1 (main site/web3/test cases)
            * - Anonymous#2 (math formulae/whitepaper)
            *
            * -> Who has audited & approved the projected:
            * - Arc
            * - tocisck
            * - sumpunk
            */
            
            contract Hourglass {
                /*=================================
                =            MODIFIERS            =
                =================================*/
                // only people with tokens
                modifier onlyBagholders() {
                    require(myTokens() > 0);
                    _;
                }
                
                // only people with profits
                modifier onlyStronghands() {
                    require(myDividends(true) > 0);
                    _;
                }
                
                // administrators can:
                // -> change the name of the contract
                // -> change the name of the token
                // -> change the PoS difficulty (How many tokens it costs to hold a masternode, in case it gets crazy high later)
                // they CANNOT:
                // -> take funds
                // -> disable withdrawals
                // -> kill the contract
                // -> change the price of tokens
                modifier onlyAdministrator(){
                    address _customerAddress = msg.sender;
                    require(administrators[keccak256(_customerAddress)]);
                    _;
                }
                
                
                // ensures that the first tokens in the contract will be equally distributed
                // meaning, no divine dump will be ever possible
                // result: healthy longevity.
                modifier antiEarlyWhale(uint256 _amountOfEthereum){
                    address _customerAddress = msg.sender;
                    
                    // are we still in the vulnerable phase?
                    // if so, enact anti early whale protocol 
                    if( onlyAmbassadors && ((totalEthereumBalance() - _amountOfEthereum) <= ambassadorQuota_ )){
                        require(
                            // is the customer in the ambassador list?
                            ambassadors_[_customerAddress] == true &&
                            
                            // does the customer purchase exceed the max ambassador quota?
                            (ambassadorAccumulatedQuota_[_customerAddress] + _amountOfEthereum) <= ambassadorMaxPurchase_
                            
                        );
                        
                        // updated the accumulated quota    
                        ambassadorAccumulatedQuota_[_customerAddress] = SafeMath.add(ambassadorAccumulatedQuota_[_customerAddress], _amountOfEthereum);
                    
                        // execute
                        _;
                    } else {
                        // in case the ether count drops low, the ambassador phase won't reinitiate
                        onlyAmbassadors = false;
                        _;    
                    }
                    
                }
                
                
                /*==============================
                =            EVENTS            =
                ==============================*/
                event onTokenPurchase(
                    address indexed customerAddress,
                    uint256 incomingEthereum,
                    uint256 tokensMinted,
                    address indexed referredBy
                );
                
                event onTokenSell(
                    address indexed customerAddress,
                    uint256 tokensBurned,
                    uint256 ethereumEarned
                );
                
                event onReinvestment(
                    address indexed customerAddress,
                    uint256 ethereumReinvested,
                    uint256 tokensMinted
                );
                
                event onWithdraw(
                    address indexed customerAddress,
                    uint256 ethereumWithdrawn
                );
                
                // ERC20
                event Transfer(
                    address indexed from,
                    address indexed to,
                    uint256 tokens
                );
                
                
                /*=====================================
                =            CONFIGURABLES            =
                =====================================*/
                string public name = "PowH3D";
                string public symbol = "P3D";
                uint8 constant public decimals = 18;
                uint8 constant internal dividendFee_ = 10;
                uint256 constant internal tokenPriceInitial_ = 0.0000001 ether;
                uint256 constant internal tokenPriceIncremental_ = 0.00000001 ether;
                uint256 constant internal magnitude = 2**64;
                
                // proof of stake (defaults at 100 tokens)
                uint256 public stakingRequirement = 100e18;
                
                // ambassador program
                mapping(address => bool) internal ambassadors_;
                uint256 constant internal ambassadorMaxPurchase_ = 1 ether;
                uint256 constant internal ambassadorQuota_ = 20 ether;
                
                
                
               /*================================
                =            DATASETS            =
                ================================*/
                // amount of shares for each address (scaled number)
                mapping(address => uint256) internal tokenBalanceLedger_;
                mapping(address => uint256) internal referralBalance_;
                mapping(address => int256) internal payoutsTo_;
                mapping(address => uint256) internal ambassadorAccumulatedQuota_;
                uint256 internal tokenSupply_ = 0;
                uint256 internal profitPerShare_;
                
                // administrator list (see above on what they can do)
                mapping(bytes32 => bool) public administrators;
                
                // when this is set to true, only ambassadors can purchase tokens (this prevents a whale premine, it ensures a fairly distributed upper pyramid)
                bool public onlyAmbassadors = true;
                
            
            
                /*=======================================
                =            PUBLIC FUNCTIONS            =
                =======================================*/
                /*
                * -- APPLICATION ENTRY POINTS --  
                */
                function Hourglass()
                    public
                {
                    // add administrators here
                    administrators[0xdd8bb99b13fe33e1c32254dfb8fff3e71193f6b730a89dd33bfe5dedc6d83002] = true;
                    
                    // add the ambassadors here.
                    // mantso - lead solidity dev & lead web dev. 
                    ambassadors_[0x8b4DA1827932D71759687f925D17F81Fc94e3A9D] = true;
                    
                    // ponzibot - mathematics & website, and undisputed meme god.
                    ambassadors_[0x8e0d985f3Ec1857BEc39B76aAabDEa6B31B67d53] = true;
                    
                    // swagg - concept design, feedback, management.
                    ambassadors_[0x7563A35d5610eE7c9CD330E255Da0e779a644C19] = true;
                    
                    // k-dawgz - shilling machine, meme maestro, bizman.
                    ambassadors_[0x215e3C713BADb158A457e61f99325bBB5d278E57] = true;
                    
                    // elmojo - all those pretty .GIFs & memes you see? you can thank this man for that.
                    ambassadors_[0xaFF8B5CDCB339eEf5e1100597740a394C7B9c6cA] = true;
                    
                    // capex - community moderator.
                    ambassadors_[0x8dc6569c28521560EAF1890bC41b2F3FC2010E1b] = true;
                    
                    // jörmungandr - pentests & twitter trendsetter.
                    ambassadors_[0xf14BE3662FE4c9215c27698166759Db6967De94f] = true;
                    
                    // inventor - the source behind the non-intrusive referral model.
                    ambassadors_[0x18E90Fc6F70344f53EBd4f6070bf6Aa23e2D748C] = true;
                    
                    // tocsick - pentesting, contract auditing.
                    ambassadors_[0x49Aae4D923207e80Fc91E626BCb6532502264dfC] = true;
                    
                    // arc - pentesting, contract auditing.
                    ambassadors_[0x3a0cca1A832644B60730E5D4c27947C5De609d62] = true;
                    
                    // sumpunk - contract auditing.
                    ambassadors_[0x7ac74Fcc1a71b106F12c55ee8F802C9F672Ce40C] = true;
                    
                    // randall - charts & sheets, data dissector, advisor.
                    ambassadors_[0x2b219C2178f099dE4E9A3667d5cCc2cc64da0763] = true;
                    
                    // ambius - 3d chart visualization.
                    ambassadors_[0x2A04C7335f90a6bd4e9c4F713DD792200e27F2E6] = true;
                    
                    // contributors that need to remain private out of security concerns.
                    ambassadors_[0x35668818ba8F768D4C21787a6f45C86C69394dfD] = true; //dp
                    ambassadors_[0xa3120da52e604aC3Fc80A63813Ef15476e0B6AbD] = true; //tc
                    ambassadors_[0x924E71bA600372e2410285423F1Fe66799b717EC] = true; //ja
                    ambassadors_[0x6Ed450e062C20F929CB7Ee72fCc53e9697980a18] = true; //sf
                    ambassadors_[0x18864A6682c8EB79EEA5B899F11bC94ef9a85ADb] = true; //tb
                    ambassadors_[0x9cC1BdC994b7a847705D19106287C0BF94EF04B5] = true; //sm
                    ambassadors_[0x6926572813ec1438088963f208C61847df435a74] = true; //mc
                    ambassadors_[0xE16Ab764a02Ae03681E351Ac58FE79717c0eE8C6] = true; //et
                    ambassadors_[0x276F4a79F22D1BfC51Bd8dc5b27Bfd934C823932] = true; //sn
                    ambassadors_[0xA2b4ed3E2f4beF09FB35101B76Ef4cB9D3eeCaCf] = true; //bt
                    ambassadors_[0x147fc6b04c95BCE47D013c8d7a200ee434323669] = true; //al
                    
            
                }
                
                 
                /**
                 * Converts all incoming ethereum to tokens for the caller, and passes down the referral addy (if any)
                 */
                function buy(address _referredBy)
                    public
                    payable
                    returns(uint256)
                {
                    purchaseTokens(msg.value, _referredBy);
                }
                
                /**
                 * Fallback function to handle ethereum that was send straight to the contract
                 * Unfortunately we cannot use a referral address this way.
                 */
                function()
                    payable
                    public
                {
                    purchaseTokens(msg.value, 0x0);
                }
                
                /**
                 * Converts all of caller's dividends to tokens.
                 */
                function reinvest()
                    onlyStronghands()
                    public
                {
                    // fetch dividends
                    uint256 _dividends = myDividends(false); // retrieve ref. bonus later in the code
                    
                    // pay out the dividends virtually
                    address _customerAddress = msg.sender;
                    payoutsTo_[_customerAddress] +=  (int256) (_dividends * magnitude);
                    
                    // retrieve ref. bonus
                    _dividends += referralBalance_[_customerAddress];
                    referralBalance_[_customerAddress] = 0;
                    
                    // dispatch a buy order with the virtualized "withdrawn dividends"
                    uint256 _tokens = purchaseTokens(_dividends, 0x0);
                    
                    // fire event
                    onReinvestment(_customerAddress, _dividends, _tokens);
                }
                
                /**
                 * Alias of sell() and withdraw().
                 */
                function exit()
                    public
                {
                    // get token count for caller & sell them all
                    address _customerAddress = msg.sender;
                    uint256 _tokens = tokenBalanceLedger_[_customerAddress];
                    if(_tokens > 0) sell(_tokens);
                    
                    // lambo delivery service
                    withdraw();
                }
            
                /**
                 * Withdraws all of the callers earnings.
                 */
                function withdraw()
                    onlyStronghands()
                    public
                {
                    // setup data
                    address _customerAddress = msg.sender;
                    uint256 _dividends = myDividends(false); // get ref. bonus later in the code
                    
                    // update dividend tracker
                    payoutsTo_[_customerAddress] +=  (int256) (_dividends * magnitude);
                    
                    // add ref. bonus
                    _dividends += referralBalance_[_customerAddress];
                    referralBalance_[_customerAddress] = 0;
                    
                    // lambo delivery service
                    _customerAddress.transfer(_dividends);
                    
                    // fire event
                    onWithdraw(_customerAddress, _dividends);
                }
                
                /**
                 * Liquifies tokens to ethereum.
                 */
                function sell(uint256 _amountOfTokens)
                    onlyBagholders()
                    public
                {
                    // setup data
                    address _customerAddress = msg.sender;
                    // russian hackers BTFO
                    require(_amountOfTokens <= tokenBalanceLedger_[_customerAddress]);
                    uint256 _tokens = _amountOfTokens;
                    uint256 _ethereum = tokensToEthereum_(_tokens);
                    uint256 _dividends = SafeMath.div(_ethereum, dividendFee_);
                    uint256 _taxedEthereum = SafeMath.sub(_ethereum, _dividends);
                    
                    // burn the sold tokens
                    tokenSupply_ = SafeMath.sub(tokenSupply_, _tokens);
                    tokenBalanceLedger_[_customerAddress] = SafeMath.sub(tokenBalanceLedger_[_customerAddress], _tokens);
                    
                    // update dividends tracker
                    int256 _updatedPayouts = (int256) (profitPerShare_ * _tokens + (_taxedEthereum * magnitude));
                    payoutsTo_[_customerAddress] -= _updatedPayouts;       
                    
                    // dividing by zero is a bad idea
                    if (tokenSupply_ > 0) {
                        // update the amount of dividends per token
                        profitPerShare_ = SafeMath.add(profitPerShare_, (_dividends * magnitude) / tokenSupply_);
                    }
                    
                    // fire event
                    onTokenSell(_customerAddress, _tokens, _taxedEthereum);
                }
                
                
                /**
                 * Transfer tokens from the caller to a new holder.
                 * Remember, there's a 10% fee here as well.
                 */
                function transfer(address _toAddress, uint256 _amountOfTokens)
                    onlyBagholders()
                    public
                    returns(bool)
                {
                    // setup
                    address _customerAddress = msg.sender;
                    
                    // make sure we have the requested tokens
                    // also disables transfers until ambassador phase is over
                    // ( we dont want whale premines )
                    require(!onlyAmbassadors && _amountOfTokens <= tokenBalanceLedger_[_customerAddress]);
                    
                    // withdraw all outstanding dividends first
                    if(myDividends(true) > 0) withdraw();
                    
                    // liquify 10% of the tokens that are transfered
                    // these are dispersed to shareholders
                    uint256 _tokenFee = SafeMath.div(_amountOfTokens, dividendFee_);
                    uint256 _taxedTokens = SafeMath.sub(_amountOfTokens, _tokenFee);
                    uint256 _dividends = tokensToEthereum_(_tokenFee);
              
                    // burn the fee tokens
                    tokenSupply_ = SafeMath.sub(tokenSupply_, _tokenFee);
            
                    // exchange tokens
                    tokenBalanceLedger_[_customerAddress] = SafeMath.sub(tokenBalanceLedger_[_customerAddress], _amountOfTokens);
                    tokenBalanceLedger_[_toAddress] = SafeMath.add(tokenBalanceLedger_[_toAddress], _taxedTokens);
                    
                    // update dividend trackers
                    payoutsTo_[_customerAddress] -= (int256) (profitPerShare_ * _amountOfTokens);
                    payoutsTo_[_toAddress] += (int256) (profitPerShare_ * _taxedTokens);
                    
                    // disperse dividends among holders
                    profitPerShare_ = SafeMath.add(profitPerShare_, (_dividends * magnitude) / tokenSupply_);
                    
                    // fire event
                    Transfer(_customerAddress, _toAddress, _taxedTokens);
                    
                    // ERC20
                    return true;
                   
                }
                
                /*----------  ADMINISTRATOR ONLY FUNCTIONS  ----------*/
                /**
                 * In case the amassador quota is not met, the administrator can manually disable the ambassador phase.
                 */
                function disableInitialStage()
                    onlyAdministrator()
                    public
                {
                    onlyAmbassadors = false;
                }
                
                /**
                 * In case one of us dies, we need to replace ourselves.
                 */
                function setAdministrator(bytes32 _identifier, bool _status)
                    onlyAdministrator()
                    public
                {
                    administrators[_identifier] = _status;
                }
                
                /**
                 * Precautionary measures in case we need to adjust the masternode rate.
                 */
                function setStakingRequirement(uint256 _amountOfTokens)
                    onlyAdministrator()
                    public
                {
                    stakingRequirement = _amountOfTokens;
                }
                
                /**
                 * If we want to rebrand, we can.
                 */
                function setName(string _name)
                    onlyAdministrator()
                    public
                {
                    name = _name;
                }
                
                /**
                 * If we want to rebrand, we can.
                 */
                function setSymbol(string _symbol)
                    onlyAdministrator()
                    public
                {
                    symbol = _symbol;
                }
            
                
                /*----------  HELPERS AND CALCULATORS  ----------*/
                /**
                 * Method to view the current Ethereum stored in the contract
                 * Example: totalEthereumBalance()
                 */
                function totalEthereumBalance()
                    public
                    view
                    returns(uint)
                {
                    return this.balance;
                }
                
                /**
                 * Retrieve the total token supply.
                 */
                function totalSupply()
                    public
                    view
                    returns(uint256)
                {
                    return tokenSupply_;
                }
                
                /**
                 * Retrieve the tokens owned by the caller.
                 */
                function myTokens()
                    public
                    view
                    returns(uint256)
                {
                    address _customerAddress = msg.sender;
                    return balanceOf(_customerAddress);
                }
                
                /**
                 * Retrieve the dividends owned by the caller.
                 * If `_includeReferralBonus` is to to 1/true, the referral bonus will be included in the calculations.
                 * The reason for this, is that in the frontend, we will want to get the total divs (global + ref)
                 * But in the internal calculations, we want them separate. 
                 */ 
                function myDividends(bool _includeReferralBonus) 
                    public 
                    view 
                    returns(uint256)
                {
                    address _customerAddress = msg.sender;
                    return _includeReferralBonus ? dividendsOf(_customerAddress) + referralBalance_[_customerAddress] : dividendsOf(_customerAddress) ;
                }
                
                /**
                 * Retrieve the token balance of any single address.
                 */
                function balanceOf(address _customerAddress)
                    view
                    public
                    returns(uint256)
                {
                    return tokenBalanceLedger_[_customerAddress];
                }
                
                /**
                 * Retrieve the dividend balance of any single address.
                 */
                function dividendsOf(address _customerAddress)
                    view
                    public
                    returns(uint256)
                {
                    return (uint256) ((int256)(profitPerShare_ * tokenBalanceLedger_[_customerAddress]) - payoutsTo_[_customerAddress]) / magnitude;
                }
                
                /**
                 * Return the buy price of 1 individual token.
                 */
                function sellPrice() 
                    public 
                    view 
                    returns(uint256)
                {
                    // our calculation relies on the token supply, so we need supply. Doh.
                    if(tokenSupply_ == 0){
                        return tokenPriceInitial_ - tokenPriceIncremental_;
                    } else {
                        uint256 _ethereum = tokensToEthereum_(1e18);
                        uint256 _dividends = SafeMath.div(_ethereum, dividendFee_  );
                        uint256 _taxedEthereum = SafeMath.sub(_ethereum, _dividends);
                        return _taxedEthereum;
                    }
                }
                
                /**
                 * Return the sell price of 1 individual token.
                 */
                function buyPrice() 
                    public 
                    view 
                    returns(uint256)
                {
                    // our calculation relies on the token supply, so we need supply. Doh.
                    if(tokenSupply_ == 0){
                        return tokenPriceInitial_ + tokenPriceIncremental_;
                    } else {
                        uint256 _ethereum = tokensToEthereum_(1e18);
                        uint256 _dividends = SafeMath.div(_ethereum, dividendFee_  );
                        uint256 _taxedEthereum = SafeMath.add(_ethereum, _dividends);
                        return _taxedEthereum;
                    }
                }
                
                /**
                 * Function for the frontend to dynamically retrieve the price scaling of buy orders.
                 */
                function calculateTokensReceived(uint256 _ethereumToSpend) 
                    public 
                    view 
                    returns(uint256)
                {
                    uint256 _dividends = SafeMath.div(_ethereumToSpend, dividendFee_);
                    uint256 _taxedEthereum = SafeMath.sub(_ethereumToSpend, _dividends);
                    uint256 _amountOfTokens = ethereumToTokens_(_taxedEthereum);
                    
                    return _amountOfTokens;
                }
                
                /**
                 * Function for the frontend to dynamically retrieve the price scaling of sell orders.
                 */
                function calculateEthereumReceived(uint256 _tokensToSell) 
                    public 
                    view 
                    returns(uint256)
                {
                    require(_tokensToSell <= tokenSupply_);
                    uint256 _ethereum = tokensToEthereum_(_tokensToSell);
                    uint256 _dividends = SafeMath.div(_ethereum, dividendFee_);
                    uint256 _taxedEthereum = SafeMath.sub(_ethereum, _dividends);
                    return _taxedEthereum;
                }
                
                
                /*==========================================
                =            INTERNAL FUNCTIONS            =
                ==========================================*/
                function purchaseTokens(uint256 _incomingEthereum, address _referredBy)
                    antiEarlyWhale(_incomingEthereum)
                    internal
                    returns(uint256)
                {
                    // data setup
                    address _customerAddress = msg.sender;
                    uint256 _undividedDividends = SafeMath.div(_incomingEthereum, dividendFee_);
                    uint256 _referralBonus = SafeMath.div(_undividedDividends, 3);
                    uint256 _dividends = SafeMath.sub(_undividedDividends, _referralBonus);
                    uint256 _taxedEthereum = SafeMath.sub(_incomingEthereum, _undividedDividends);
                    uint256 _amountOfTokens = ethereumToTokens_(_taxedEthereum);
                    uint256 _fee = _dividends * magnitude;
             
                    // no point in continuing execution if OP is a poorfag russian hacker
                    // prevents overflow in the case that the pyramid somehow magically starts being used by everyone in the world
                    // (or hackers)
                    // and yes we know that the safemath function automatically rules out the "greater then" equasion.
                    require(_amountOfTokens > 0 && (SafeMath.add(_amountOfTokens,tokenSupply_) > tokenSupply_));
                    
                    // is the user referred by a masternode?
                    if(
                        // is this a referred purchase?
                        _referredBy != 0x0000000000000000000000000000000000000000 &&
            
                        // no cheating!
                        _referredBy != _customerAddress &&
                        
                        // does the referrer have at least X whole tokens?
                        // i.e is the referrer a godly chad masternode
                        tokenBalanceLedger_[_referredBy] >= stakingRequirement
                    ){
                        // wealth redistribution
                        referralBalance_[_referredBy] = SafeMath.add(referralBalance_[_referredBy], _referralBonus);
                    } else {
                        // no ref purchase
                        // add the referral bonus back to the global dividends cake
                        _dividends = SafeMath.add(_dividends, _referralBonus);
                        _fee = _dividends * magnitude;
                    }
                    
                    // we can't give people infinite ethereum
                    if(tokenSupply_ > 0){
                        
                        // add tokens to the pool
                        tokenSupply_ = SafeMath.add(tokenSupply_, _amountOfTokens);
             
                        // take the amount of dividends gained through this transaction, and allocates them evenly to each shareholder
                        profitPerShare_ += (_dividends * magnitude / (tokenSupply_));
                        
                        // calculate the amount of tokens the customer receives over his purchase 
                        _fee = _fee - (_fee-(_amountOfTokens * (_dividends * magnitude / (tokenSupply_))));
                    
                    } else {
                        // add tokens to the pool
                        tokenSupply_ = _amountOfTokens;
                    }
                    
                    // update circulating supply & the ledger address for the customer
                    tokenBalanceLedger_[_customerAddress] = SafeMath.add(tokenBalanceLedger_[_customerAddress], _amountOfTokens);
                    
                    // Tells the contract that the buyer doesn't deserve dividends for the tokens before they owned them;
                    //really i know you think you do but you don't
                    int256 _updatedPayouts = (int256) ((profitPerShare_ * _amountOfTokens) - _fee);
                    payoutsTo_[_customerAddress] += _updatedPayouts;
                    
                    // fire event
                    onTokenPurchase(_customerAddress, _incomingEthereum, _amountOfTokens, _referredBy);
                    
                    return _amountOfTokens;
                }
            
                /**
                 * Calculate Token price based on an amount of incoming ethereum
                 * It's an algorithm, hopefully we gave you the whitepaper with it in scientific notation;
                 * Some conversions occurred to prevent decimal errors or underflows / overflows in solidity code.
                 */
                function ethereumToTokens_(uint256 _ethereum)
                    internal
                    view
                    returns(uint256)
                {
                    uint256 _tokenPriceInitial = tokenPriceInitial_ * 1e18;
                    uint256 _tokensReceived = 
                     (
                        (
                            // underflow attempts BTFO
                            SafeMath.sub(
                                (sqrt
                                    (
                                        (_tokenPriceInitial**2)
                                        +
                                        (2*(tokenPriceIncremental_ * 1e18)*(_ethereum * 1e18))
                                        +
                                        (((tokenPriceIncremental_)**2)*(tokenSupply_**2))
                                        +
                                        (2*(tokenPriceIncremental_)*_tokenPriceInitial*tokenSupply_)
                                    )
                                ), _tokenPriceInitial
                            )
                        )/(tokenPriceIncremental_)
                    )-(tokenSupply_)
                    ;
              
                    return _tokensReceived;
                }
                
                /**
                 * Calculate token sell value.
                 * It's an algorithm, hopefully we gave you the whitepaper with it in scientific notation;
                 * Some conversions occurred to prevent decimal errors or underflows / overflows in solidity code.
                 */
                 function tokensToEthereum_(uint256 _tokens)
                    internal
                    view
                    returns(uint256)
                {
            
                    uint256 tokens_ = (_tokens + 1e18);
                    uint256 _tokenSupply = (tokenSupply_ + 1e18);
                    uint256 _etherReceived =
                    (
                        // underflow attempts BTFO
                        SafeMath.sub(
                            (
                                (
                                    (
                                        tokenPriceInitial_ +(tokenPriceIncremental_ * (_tokenSupply/1e18))
                                    )-tokenPriceIncremental_
                                )*(tokens_ - 1e18)
                            ),(tokenPriceIncremental_*((tokens_**2-tokens_)/1e18))/2
                        )
                    /1e18);
                    return _etherReceived;
                }
                
                
                //This is where all your gas goes, sorry
                //Not sorry, you probably only paid 1 gwei
                function sqrt(uint x) internal pure returns (uint y) {
                    uint z = (x + 1) / 2;
                    y = x;
                    while (z < y) {
                        y = z;
                        z = (x / z + z) / 2;
                    }
                }
            }
            
            /**
             * @title SafeMath
             * @dev Math operations with safety checks that throw on error
             */
            library SafeMath {
            
                /**
                * @dev Multiplies two numbers, throws on overflow.
                */
                function mul(uint256 a, uint256 b) internal pure returns (uint256) {
                    if (a == 0) {
                        return 0;
                    }
                    uint256 c = a * b;
                    assert(c / a == b);
                    return c;
                }
            
                /**
                * @dev Integer division of two numbers, truncating the quotient.
                */
                function div(uint256 a, uint256 b) internal pure returns (uint256) {
                    // assert(b > 0); // Solidity automatically throws when dividing by 0
                    uint256 c = a / b;
                    // assert(a == b * c + a % b); // There is no case in which this doesn't hold
                    return c;
                }
            
                /**
                * @dev Substracts two numbers, throws on overflow (i.e. if subtrahend is greater than minuend).
                */
                function sub(uint256 a, uint256 b) internal pure returns (uint256) {
                    assert(b <= a);
                    return a - b;
                }
            
                /**
                * @dev Adds two numbers, throws on overflow.
                */
                function add(uint256 a, uint256 b) internal pure returns (uint256) {
                    uint256 c = a + b;
                    assert(c >= a);
                    return c;
                }
            }

            File 3 of 4: Oraclize
            /*
            Copyright (c) 2015-2016 Oraclize SRL
            Copyright (c) 2016-2017 Oraclize LTD
            */
            
            /*
            Oraclize Connector v1.2.0
            */
            
            // 'compressed' alternative, where all modifiers have been changed to FUNCTIONS
            // which is cheaper for deployment, potentially cheaper execution
            
            pragma solidity ^0.4.11;
            
            contract Oraclize {
                mapping (address => uint) reqc;
            
                mapping (address => byte) public cbAddresses;
            
                mapping (address => bool) public offchainPayment;
            
                event Log1(address sender, bytes32 cid, uint timestamp, string datasource, string arg, uint gaslimit, byte proofType, uint gasPrice);
                event Log2(address sender, bytes32 cid, uint timestamp, string datasource, string arg1, string arg2, uint gaslimit, byte proofType, uint gasPrice);
                event LogN(address sender, bytes32 cid, uint timestamp, string datasource, bytes args, uint gaslimit, byte proofType, uint gasPrice);
                event Log1_fnc(address sender, bytes32 cid, uint timestamp, string datasource, string arg, function() external callback, uint gaslimit, byte proofType, uint gasPrice);
                event Log2_fnc(address sender, bytes32 cid, uint timestamp, string datasource, string arg1, string arg2, function() external callback, uint gaslimit, byte proofType, uint gasPrice);
                event LogN_fnc(address sender, bytes32 cid, uint timestamp, string datasource, bytes args, function() external callback, uint gaslimit, byte proofType, uint gasPrice);
            
                event Emit_OffchainPaymentFlag(address indexed idx_sender, address sender, bool indexed idx_flag, bool flag);
            
                address owner;
                address paymentFlagger;
            
                function changeAdmin(address _newAdmin)
                external
                {
                    onlyadmin();
                    owner = _newAdmin;
                }
            
                function changePaymentFlagger(address _newFlagger)
                external
                {
                    onlyadmin();
                    paymentFlagger = _newFlagger;
                }
            
                function addCbAddress(address newCbAddress, byte addressType)
                external
                {
                    onlyadmin();
                    //bytes memory nil = '';
                    addCbAddress(newCbAddress, addressType, hex'');
                }
            
                // proof is currently a placeholder for when associated proof for addressType is added
                function addCbAddress(address newCbAddress, byte addressType, bytes proof)
                public
                {
                    onlyadmin();
                    cbAddresses[newCbAddress] = addressType;
                }
            
                function removeCbAddress(address newCbAddress)
                external
                {
                    onlyadmin();
                    delete cbAddresses[newCbAddress];
                }
            
                function cbAddress()
                constant
                returns (address _cbAddress)
                {
                    if (cbAddresses[tx.origin] != 0)
                        _cbAddress = tx.origin;
                }
            
                function addDSource(string dsname, uint multiplier)
                external
                {
                    addDSource(dsname, 0x00, multiplier);
                }
            
                function addDSource(string dsname, byte proofType, uint multiplier)
                public
                {
                    onlyadmin();
                    bytes32 dsname_hash = sha3(dsname, proofType);
                    dsources[dsources.length++] = dsname_hash;
                    price_multiplier[dsname_hash] = multiplier;
                }
            
                // Utilized by bridge
                function multiAddDSource(bytes32[] dsHash, uint256[] multiplier)
                external
                {
                    onlyadmin();
                    // dsHash -> sha3(DATASOURCE_NAME, PROOF_TYPE);
                    for (uint i=0; i<dsHash.length; i++) {
                        dsources[dsources.length++] = dsHash[i];
                        price_multiplier[dsHash[i]] = multiplier[i];
                    }
                }
            
                function multisetProofType(uint[] _proofType, address[] _addr)
                external
                {
                    onlyadmin();
                    for (uint i=0; i<_addr.length; i++) addr_proofType[_addr[i]] = byte(_proofType[i]);
                }
            
                function multisetCustomGasPrice(uint[] _gasPrice, address[] _addr)
                external
                {
                    onlyadmin();
                    for (uint i=0; i<_addr.length; i++) addr_gasPrice[_addr[i]] = _gasPrice[i];
                }
            
                uint gasprice = 20000000000;
            
                function setGasPrice(uint newgasprice)
                external
                {
                    onlyadmin();
                    gasprice = newgasprice;
                }
            
                function setBasePrice(uint new_baseprice)
                external
                { //0.001 usd in ether
                    onlyadmin();
                    baseprice = new_baseprice;
                    for (uint i=0; i<dsources.length; i++) price[dsources[i]] = new_baseprice*price_multiplier[dsources[i]];
                }
            
                function setBasePrice(uint new_baseprice, bytes proofID)
                external
                { //0.001 usd in ether
                    onlyadmin();
                    baseprice = new_baseprice;
                    for (uint i=0; i<dsources.length; i++) price[dsources[i]] = new_baseprice*price_multiplier[dsources[i]];
                }
            
                function setOffchainPayment(address _addr, bool _flag)
                external
                {
                  if (msg.sender != paymentFlagger) throw;
                  offchainPayment[_addr] = _flag;
                  Emit_OffchainPaymentFlag(_addr, _addr, _flag, _flag);
                }
            
                function withdrawFunds(address _addr)
                external
                {
                    onlyadmin();
                    _addr.send(this.balance);
                }
            
                // unnecessary?
                //function() {}
            
                function Oraclize() {
                    owner = msg.sender;
                }
            
                // Pesudo-modifiers
            
                function onlyadmin()
                private {
                    if (msg.sender != owner) throw;
                }
            
                function costs(string datasource, uint gaslimit)
                private
                returns (uint price) {
                    price = getPrice(datasource, gaslimit, msg.sender);
            
                    if (msg.value >= price){
                        uint diff = msg.value - price;
                        if (diff > 0) {
                            // added for correct query cost to be returned
                            if(!msg.sender.send(diff)) {
                                throw;
                            }
                        }
                    } else throw;
                }
            
                mapping (address => byte) addr_proofType;
                mapping (address => uint) addr_gasPrice;
                uint public baseprice;
                mapping (bytes32 => uint) price;
                mapping (bytes32 => uint) price_multiplier;
                bytes32[] dsources;
            
                bytes32[] public randomDS_sessionPubKeysHash;
            
                function randomDS_updateSessionPubKeysHash(bytes32[] _newSessionPubKeysHash)
                external
                {
                    onlyadmin();
                    randomDS_sessionPubKeysHash.length = 0;
                    for (uint i=0; i<_newSessionPubKeysHash.length; i++) randomDS_sessionPubKeysHash.push(_newSessionPubKeysHash[i]);
                }
            
                function randomDS_getSessionPubKeyHash()
                external
                constant
                returns (bytes32) {
                    uint i = uint(sha3(reqc[msg.sender]))%randomDS_sessionPubKeysHash.length;
                    return randomDS_sessionPubKeysHash[i];
                }
            
                function setProofType(byte _proofType)
                external
                {
                    addr_proofType[msg.sender] = _proofType;
                }
            
                function setCustomGasPrice(uint _gasPrice)
                external
                {
                    addr_gasPrice[msg.sender] = _gasPrice;
                }
            
                function getPrice(string _datasource)
                public
                returns (uint _dsprice)
                {
                    return getPrice(_datasource, msg.sender);
                }
            
                function getPrice(string _datasource, uint _gaslimit)
                public
                returns (uint _dsprice)
                {
                    return getPrice(_datasource, _gaslimit, msg.sender);
                }
            
                function getPrice(string _datasource, address _addr)
                private
                returns (uint _dsprice)
                {
                    return getPrice(_datasource, 200000, _addr);
                }
            
                function getPrice(string _datasource, uint _gaslimit, address _addr)
                private
                returns (uint _dsprice)
                {
                    uint gasprice_ = addr_gasPrice[_addr];
                    if (
                            (offchainPayment[_addr])
                        ||(
                            (_gaslimit <= 200000)&&
                            (reqc[_addr] == 0)&&
                            (gasprice_ <= gasprice)&&
                            (tx.origin != cbAddress())
                        )
                    ) return 0;
            
                    if (gasprice_ == 0) gasprice_ = gasprice;
                    _dsprice = price[sha3(_datasource, addr_proofType[_addr])];
                    _dsprice += _gaslimit*gasprice_;
                    return _dsprice;
                }
            
                function getCodeSize(address _addr)
                private
                constant
                returns(uint _size)
                {
                    assembly {
                        _size := extcodesize(_addr)
                    }
                }
            
                function query(string _datasource, string _arg)
                payable
                external
                returns (bytes32 _id)
                {
                    return query1(0, _datasource, _arg, 200000);
                }
            
                function query1(string _datasource, string _arg)
                payable
                external
                returns (bytes32 _id)
                {
                    return query1(0, _datasource, _arg, 200000);
                }
            
                function query2(string _datasource, string _arg1, string _arg2)
                payable
                external
                returns (bytes32 _id)
                {
                    return query2(0, _datasource, _arg1, _arg2, 200000);
                }
            
                function queryN(string _datasource, bytes _args)
                payable
                external
                returns (bytes32 _id)
                {
                    return queryN(0, _datasource, _args, 200000);
                }
            
                function query(uint _timestamp, string _datasource, string _arg)
                payable
                external
                returns (bytes32 _id)
                {
                    return query1(_timestamp, _datasource, _arg, 200000);
                }
            
                function query1(uint _timestamp, string _datasource, string _arg)
                payable
                external
                returns (bytes32 _id)
                {
                    return query1(_timestamp, _datasource, _arg, 200000);
                }
            
                function query2(uint _timestamp, string _datasource, string _arg1, string _arg2)
                payable
                external
                returns (bytes32 _id)
                {
                    return query2(_timestamp, _datasource, _arg1, _arg2, 200000);
                }
            
                function queryN(uint _timestamp, string _datasource, bytes _args)
                payable
                external
                returns (bytes32 _id)
                {
                    return queryN(_timestamp, _datasource, _args, 200000);
                }
            
            /*  Needless?
                function query(uint _timestamp, string _datasource, string _arg, uint _gaslimit)
                payable
                external
                returns (bytes32 _id)
                {
                    return query1(_timestamp, _datasource, _arg, _gaslimit);
                }
            */
                function query_withGasLimit(uint _timestamp, string _datasource, string _arg, uint _gaslimit)
                payable
                external
                returns (bytes32 _id)
                {
                    return query1(_timestamp, _datasource, _arg, _gaslimit);
                }
            
                function query1_withGasLimit(uint _timestamp, string _datasource, string _arg, uint _gaslimit)
                payable
                external
                returns (bytes32 _id)
                {
                    return query1(_timestamp, _datasource, _arg, _gaslimit);
                }
            
                function query2_withGasLimit(uint _timestamp, string _datasource, string _arg1, string _arg2, uint _gaslimit)
                payable
                external
                returns (bytes32 _id)
                {
                    return query2(_timestamp, _datasource, _arg1, _arg2, _gaslimit);
                }
            
                function queryN_withGasLimit(uint _timestamp, string _datasource, bytes _args, uint _gaslimit)
                payable
                external
                returns (bytes32 _id)
                {
                    return queryN(_timestamp, _datasource, _args, _gaslimit);
                }
            
                function query1(uint _timestamp, string _datasource, string _arg, uint _gaslimit)
                payable
                public
                returns (bytes32 _id)
                {
                    costs(_datasource, _gaslimit);
                	if ((_timestamp > now+3600*24*60)||(_gaslimit > block.gaslimit)) throw;
            
                    _id = sha3(this, msg.sender, reqc[msg.sender]);
                    reqc[msg.sender]++;
                    Log1(msg.sender, _id, _timestamp, _datasource, _arg, _gaslimit, addr_proofType[msg.sender], addr_gasPrice[msg.sender]);
                    return _id;
                }
            
                function query2(uint _timestamp, string _datasource, string _arg1, string _arg2, uint _gaslimit)
                payable
                public
                returns (bytes32 _id)
                {
                    costs(_datasource, _gaslimit);
                	if ((_timestamp > now+3600*24*60)||(_gaslimit > block.gaslimit)) throw;
            
                    _id = sha3(this, msg.sender, reqc[msg.sender]);
                    reqc[msg.sender]++;
                    Log2(msg.sender, _id, _timestamp, _datasource, _arg1, _arg2, _gaslimit, addr_proofType[msg.sender], addr_gasPrice[msg.sender]);
                    return _id;
                }
            
                function queryN(uint _timestamp, string _datasource, bytes _args, uint _gaslimit)
                payable
                public
                returns (bytes32 _id)
                {
                    costs(_datasource, _gaslimit);
                	if ((_timestamp > now+3600*24*60)||(_gaslimit > block.gaslimit)) throw;
            
                    _id = sha3(this, msg.sender, reqc[msg.sender]);
                    reqc[msg.sender]++;
                    LogN(msg.sender, _id, _timestamp, _datasource, _args, _gaslimit, addr_proofType[msg.sender], addr_gasPrice[msg.sender]);
                    return _id;
                }
            
                function query1_fnc(uint _timestamp, string _datasource, string _arg, function() external _fnc, uint _gaslimit)
                payable
                public
                returns (bytes32 _id)
                {
                    costs(_datasource, _gaslimit);
                    if ((_timestamp > now+3600*24*60)||(_gaslimit > block.gaslimit)||address(_fnc) != msg.sender) throw;
            
                    _id = sha3(this, msg.sender, reqc[msg.sender]);
                    reqc[msg.sender]++;
                    Log1_fnc(msg.sender, _id, _timestamp, _datasource, _arg, _fnc, _gaslimit, addr_proofType[msg.sender], addr_gasPrice[msg.sender]);
                    return _id;
                }
            
                function query2_fnc(uint _timestamp, string _datasource, string _arg1, string _arg2, function() external _fnc, uint _gaslimit)
                payable
                public
                returns (bytes32 _id)
                {
                    costs(_datasource, _gaslimit);
                    if ((_timestamp > now+3600*24*60)||(_gaslimit > block.gaslimit)||address(_fnc) != msg.sender) throw;
            
                    _id = sha3(this, msg.sender, reqc[msg.sender]);
                    reqc[msg.sender]++;
                    Log2_fnc(msg.sender, _id, _timestamp, _datasource, _arg1, _arg2, _fnc,  _gaslimit, addr_proofType[msg.sender], addr_gasPrice[msg.sender]);
                    return _id;
                }
            
                function queryN_fnc(uint _timestamp, string _datasource, bytes _args, function() external _fnc, uint _gaslimit)
                payable
                public
                returns (bytes32 _id)
                {
                    costs(_datasource, _gaslimit);
                    if ((_timestamp > now+3600*24*60)||(_gaslimit > block.gaslimit)||address(_fnc) != msg.sender) throw;
            
                    _id = sha3(this, msg.sender, reqc[msg.sender]);
                    reqc[msg.sender]++;
                    LogN_fnc(msg.sender, _id, _timestamp, _datasource, _args, _fnc, _gaslimit, addr_proofType[msg.sender], addr_gasPrice[msg.sender]);
                    return _id;
                }
            }

            File 4 of 4: OraclizeAddrResolver
            /*
              Copyright (c) 2015-2016 Oraclize SRL
              Copyright (c) 2016 Oraclize LTD
            */
            
            contract OraclizeAddrResolver {
            
                address public addr;
            
                address owner;
            
                function OraclizeAddrResolver(){
                    owner = msg.sender;
                }
            
                function changeOwner(address newowner){
                    if (msg.sender != owner) throw;
                    owner = newowner;
                }
            
                function getAddress() returns (address oaddr){
                    return addr;
                }
            
                function setAddr(address newaddr){
                    if (msg.sender != owner) throw;
                    addr = newaddr;
                }
            
            }