These are chat archives for ethereum/tutorials

19th
Sep 2017
eddie2024
@eddie2024
Sep 19 2017 00:23
can someone send me some funds please on rinkeby: 0x6Ef4478444cEAd921fDCc409180f159b6FbfB98e
piethein1628
@piethein1628
Sep 19 2017 06:03
@piethein1628 Fixed: relocated last two lines to end of contract
eddie2024
@eddie2024
Sep 19 2017 12:10
I'm having some issues with this code, if anyone more knowledgeable could contribute thier 2 pence, it would be greatly appreciated:
  function validPurchase() internal constant returns (bool) {

    uint256 current = block.number;
    bool withinPeriod = current >= startBlock && current <= endBlock;
    bool nonZeroPurchase = msg.value != 0;
    bool withinCap = false;
/*  
    bool withinBonusThirtyCap = current <= thirtyPercentEnd && weiRaised.add(msg.value) <= bonusThirtyCap;
    bool withinBonusTwentyCap = current <= twentyPercentEnd && weiRaised.add(msg.value) <= bonusTwentyCap;
    bool withinBonusTenCap = current <= tenPercentEnd && weiRaised.add(msg.value) <= bonusTenCap;
    bool withinMaxCap = weiRaised.add(msg.value) <= cap;
    bool withinCap = (withinBonusThirtyCap || withinBonusTwentyCap||withinBonusTenCap|| withinMaxCap);
*/    
    if (current <= thirtyPercentEnd && weiRaised.add(msg.value) <= bonusThirtyCap){ 
      withinCap = true;
      } else if (current <= twentyPercentEnd && weiRaised.add(msg.value) <= sumTwenThirty){
      withinCap = true;
      } else if (current <= tenPercentEnd && weiRaised.add(msg.value) <= sumThiTwenTen){
      withinCap = true;
      } else if (current > tenPercentEnd && weiRaised.add(msg.value) <= cap){
      withinCap = true;
    }/* else { 
      withinCap = false;
      //return !withinCap;
    }   
*/
//    bool withinCap = (withinBonusThirtyCap || withinBonusTwentyCap||withinBonusTenCap|| withinMaxCap);
    return withinPeriod && nonZeroPurchase && withinCap;  
   }
other related code :
    blockShare = (endBlock - startBlock)/100;
    thirtyPercentEnd = (startBlock +(20 * blockShare));
    twentyPercentEnd = (thirtyPercentEnd +(20 * blockShare));
    tenPercentEnd = (twentyPercentEnd +(20 * blockShare));
    bonusThirtyCap = cap.div(5);
    bonusTwentyCap = cap.div(7);
    bonusTenCap = cap.div(10); 
    sumTwenThirty = (bonusTwentyCap + bonusThirtyCap);
    sumThiTwenTen = (bonusThirtyCap + bonusTwentyCap + bonusTenCap);