Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

msg.value not transcribed correctly from VALUE in call dialog to contract #92

Open
DaveAppleton opened this issue Mar 20, 2017 · 0 comments

Comments

@DaveAppleton
Copy link

image

value = 28000000000000000000000000
address = 0xdedb49385ad5b94a16f236a6890cf9e0b1e30392

image

Zooming in ......

image

Where did the extra wei come from?

  uint256 public decimals = 8;
  uint256 coinsPerTier = 10000000000000;   // 100k x 10^8
  uint256 MaxCoins     = 100000000000000;  // 1M x 10^8
  uint256 startDate;
  uint256 endDate;
  

  // 1 ether = 1000 example tokens 
  uint256[8] prices = [153846153,142857142,142857142,125000000,117647058,
                      111111111,105263157,100000000];
event purchase(uint level,uint value, uint tokens);
  
  function createTokens(address recipient) payable {
    uint level;
    uint price;
    if (!funding()) throw;
    if (msg.value == 0) throw;
    
    uint256 val = msg.value;
    
    do {
      uint256 coinsLeftInThisTier = coinsPerTier - (totalSupply % coinsPerTier);
      (level,price) = getLevelAndPrice();
      uint tokens = safeMul(val, price); // (val in eth * 10^18) * #tokens per eth
      tokens = safeDiv(tokens, 1 ether);      // val is in ether, msg,value is in wei
    
      if (tokens <= coinsLeftInThisTier) {
        totalSupply = safeAdd(totalSupply, tokens);
        balances[recipient] = safeAdd(balances[recipient], tokens);
        purchase(level,val,tokens);
        return;
      }
      totalSupply = safeAdd(totalSupply, coinsLeftInThisTier);
      balances[recipient] = safeAdd(balances[recipient], coinsLeftInThisTier);
      
      
      uint weiCoinsLeftInThisTier = safeMul(coinsLeftInThisTier,1 ether);
      uint costOfTheseCoins = safeDiv(weiCoinsLeftInThisTier, price);
      purchase(level,costOfTheseCoins,coinsLeftInThisTier);
      val = safeSub(val,costOfTheseCoins);
    } while ((val > 0) && funding());
    if (val > 0){
      // return the remainder !
      if (!msg.sender.send(val)) throw; // if you can't return the balance, abort whole process
    }
  }
  
  // Our simple dropping price function  
  function getLevelAndPrice() constant returns (uint level,uint price) {
    level = totalSupply / coinsPerTier;
    return (level,prices[level]);
  }
}
@DaveAppleton DaveAppleton changed the title 28000000000000000000000000 not translated correctly msg.value not transcribed correctly from VALUE in call dialog to contract Mar 20, 2017
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant