Ethereum Wallet shows "It seems this transaction will fail ......" even though I've used if/else inside contracts to ensure that transfer value does not go higher than contract balance.`
function mySales( address a) constant public canWithdraw returns (uint){
return totalSales[a];
}
function topSalesPerson() constant public returns ( address ){
return topsales;
}
event bonusDepleted(string);
function submitSales() public payable canWithdraw{
uint amount = msg.value;
uint bonus_temp;
if (this.balance >0){
if(amount > 50000000000000000000){
bonus_temp = amount/10; // 10% bonus
}
if(bonus_temp > 20000000000000000000){
bonus_temp = 20000000000000000000; // max bonus = 20 ether
}
if (this.balance > bonus_temp){
msg.sender.transfer(bonus_temp); // transfer bonus in case of enough balance
}
else{
msg.sender.transfer(this.balance); // else transfer remaining amount as Bonus
}
owner.transfer(amount);
Bonus[msg.sender] += bonus_temp;
totalSales[msg.sender] += msg.value;
if( totalSales[topsales] < totalSales[msg.sender]){
topsales = msg.sender;
}
}
if(this.balance == 0){
bonusDepleted("Bonus has reached its limit and no bonus will be provided for future sales");
}
}`
So if contract has 3 ethers then for 50 ether it allows txn but for 60 it shows warning and error "intrinsic gas too low" where as it should have just refunded last 3 ether.
Also for Readonly functions like "mySales", how to invoke them from "ethereum -wallet" as it does not return anything on entering address into this function under "Read from Contract Section". i'm able to use it from command-line.