Skip to main content
added 1 character in body
Source Link

Any help?? Thanks.

Any help? Thanks.

Any help?? Thanks.

added 3826 characters in body
Source Link

I added the code and a screenshot. As I said. Once I started commenting out 'oraclize' function at some point it starts to work just fine...

pragma solidity ^0.4.20;
import "./oraclize.sol";

contract Casino is usingOraclize {
   address owner;
   uint public betAmount = 30 finney; //Equal to 0.01 Ether
   uint public totalBet; //Amount of Ether bet for current game
   uint public numberOfBets; //Total number of current bets
   //uint public maxAmountOfBets = 1 //Maximum amount of bets can be made for each game by each user
   uint public limitAmountOfBets = 3; //Maximum amount of bets for each game
   uint public numberWinner; //Number that won last game
   address[] public players; //Players
   mapping(uint => address[]) numberBetPlayers; //Who bet for which number
   mapping(address => uint) playerBetsNumber; //Number bet by each player
   
   modifier onEndGame() {
       if(numberOfBets >= limitAmountOfBets) _;
   }
   
   //constructor - set bet amount and max bets in each game
   function Casino(uint _betAmount, uint _limitAmountOfBets) {
       owner = msg.sender; //set creator of contract to owner
       
       if(_betAmount > 0) betAmount = _betAmount;
       if(_limitAmountOfBets > 0) limitAmountOfBets = _limitAmountOfBets;
       
       oraclize_setProof(proofType_Ledger); //arge
   }
   
   //check if player exists in current game
   function checkPlayerExists(address player) public returns(bool) {
       if(playerBetsNumber[player] > 0) return true;
       else return false;
   }
   
   //bet function
   function bet(uint numberToBet) payable {
       require(numberOfBets <= limitAmountOfBets); //check if limit has been reached
       require(!checkPlayerExists(msg.sender)); //check that player hasn't bet before
       require(numberToBet >=1 && numberToBet <= 10); //check that the bet is between 1 and 10
       require(msg.value == betAmount); //check that ether send by sender is equal to bet amount
       
       playerBetsNumber[msg.sender] = numberToBet;
       numberBetPlayers[numberToBet].push(msg.sender);
       
       numberOfBets += 1;
       totalBet += msg.value;
       
       if(numberOfBets >= limitAmountOfBets) generateNumberWinner();
   }
   
   //generate random numbers using oraclize_newRandomDSQuery function
   function generateNumberWinner() payable onEndGame {
       uint numberRandomBytes = 4;
       uint delay = 0;
       uint callbackGas = 200000;
       
       bytes32 queryId = oraclize_newRandomDSQuery(delay, numberRandomBytes, callbackGas);
   }
   
   function __calback(bytes32 _queryId, string _result, bytes _proof) oraclize_randomDS_proofVerify(_queryId, _result, _proof) onEndGame {
       assert(msg.sender == oraclize_cbAddress());
       
       numberWinner = (uint(sha3(_result))%10+1);
       distributePrizes();
   }
   
   function distributePrizes() onEndGame {
       uint winnerEtherAmount = totalBet / numberBetPlayers[numberWinner].length; //how much each winner will get
       
       for(uint i = 0; i < numberBetPlayers[numberWinner].length; i++) { //sent ether to addresses
           numberBetPlayers[numberWinner][i].transfer(winnerEtherAmount);
       }
       
       for(uint j = 1; j <= 10; j++) {
           numberBetPlayers[j].length = 0;
       }
       
       totalBet = 0;
       numberOfBets = 0;
   }
}

Gas limit problem?

Any help? Thanks.

Any help? Thanks.

I added the code and a screenshot. As I said. Once I started commenting out 'oraclize' function at some point it starts to work just fine...

pragma solidity ^0.4.20;
import "./oraclize.sol";

contract Casino is usingOraclize {
   address owner;
   uint public betAmount = 30 finney; //Equal to 0.01 Ether
   uint public totalBet; //Amount of Ether bet for current game
   uint public numberOfBets; //Total number of current bets
   //uint public maxAmountOfBets = 1 //Maximum amount of bets can be made for each game by each user
   uint public limitAmountOfBets = 3; //Maximum amount of bets for each game
   uint public numberWinner; //Number that won last game
   address[] public players; //Players
   mapping(uint => address[]) numberBetPlayers; //Who bet for which number
   mapping(address => uint) playerBetsNumber; //Number bet by each player
   
   modifier onEndGame() {
       if(numberOfBets >= limitAmountOfBets) _;
   }
   
   //constructor - set bet amount and max bets in each game
   function Casino(uint _betAmount, uint _limitAmountOfBets) {
       owner = msg.sender; //set creator of contract to owner
       
       if(_betAmount > 0) betAmount = _betAmount;
       if(_limitAmountOfBets > 0) limitAmountOfBets = _limitAmountOfBets;
       
       oraclize_setProof(proofType_Ledger); //arge
   }
   
   //check if player exists in current game
   function checkPlayerExists(address player) public returns(bool) {
       if(playerBetsNumber[player] > 0) return true;
       else return false;
   }
   
   //bet function
   function bet(uint numberToBet) payable {
       require(numberOfBets <= limitAmountOfBets); //check if limit has been reached
       require(!checkPlayerExists(msg.sender)); //check that player hasn't bet before
       require(numberToBet >=1 && numberToBet <= 10); //check that the bet is between 1 and 10
       require(msg.value == betAmount); //check that ether send by sender is equal to bet amount
       
       playerBetsNumber[msg.sender] = numberToBet;
       numberBetPlayers[numberToBet].push(msg.sender);
       
       numberOfBets += 1;
       totalBet += msg.value;
       
       if(numberOfBets >= limitAmountOfBets) generateNumberWinner();
   }
   
   //generate random numbers using oraclize_newRandomDSQuery function
   function generateNumberWinner() payable onEndGame {
       uint numberRandomBytes = 4;
       uint delay = 0;
       uint callbackGas = 200000;
       
       bytes32 queryId = oraclize_newRandomDSQuery(delay, numberRandomBytes, callbackGas);
   }
   
   function __calback(bytes32 _queryId, string _result, bytes _proof) oraclize_randomDS_proofVerify(_queryId, _result, _proof) onEndGame {
       assert(msg.sender == oraclize_cbAddress());
       
       numberWinner = (uint(sha3(_result))%10+1);
       distributePrizes();
   }
   
   function distributePrizes() onEndGame {
       uint winnerEtherAmount = totalBet / numberBetPlayers[numberWinner].length; //how much each winner will get
       
       for(uint i = 0; i < numberBetPlayers[numberWinner].length; i++) { //sent ether to addresses
           numberBetPlayers[numberWinner][i].transfer(winnerEtherAmount);
       }
       
       for(uint j = 1; j <= 10; j++) {
           numberBetPlayers[j].length = 0;
       }
       
       totalBet = 0;
       numberOfBets = 0;
   }
}

Gas limit problem?

Any help? Thanks.

Source Link

Creating Contract Gas Problem

When I create my contract on remix using metamask (injected web3) it asks me to lower my gas fee. Once I lower it (if I don't I can't create it) the contract gets created BUT my variables inside the contract are not initialized. For example a var a = 10; is returning 0. When I comment out some oraclize functions and lower the gas need then my contract deploys fine. I have no idea what's going on.

Any help? Thanks.