1

I'm testing using Remix against web3 provider (Ganache).

Here is my code:

when "Startup = false" is uncommented, it runs out of gas. It works fine on Javascript VM in Remix, but not on Ganache Testnet. Any idea why?

function setClaimTimes(uint _claimtime, uint _claimchecktime) onlyOwner public returns(bool) {
        //Check to be sure we are in Statup Mode
        require(StartUp == true);
        //Set our ClaimTime requirements
        ClaimTime = _claimtime;
        ClaimCheckTime = _claimchecktime;

        //Set Startup to False, thus ending the startup time. Forever.        
        //StartUp = false;  ///<-OFFENDING ASSIGNMENT
        return(true);
    }

Startup is declared as a bool normally at the start of my program. Nothing fancy.

For Reference here is the entire code- it is(or will be if I can get it working!) a WhistleBlower/Wikileaks style script.

pragma solidity ^0.4.18;

contract WhistleBlower {

//ContractOwner
address Owner;

uint ClaimTime ; //How long to wait to reclaim funds in Block Numbers
uint ClaimCheckTime ; //How long to wait between claim checks in Block Number

uint StartUp = 1; //Are we in Startup Mode?

//donation pools
uint Donations;

mapping(string => uint) numberOfClaims; //number of claims per hash
mapping(string => mapping(uint => string)) detailsOfClaim; //details of claim

mapping(address => string) onePerAddress; //Track One Type of Claim per address


//Track the amount Claiments Stake
struct claims {
    uint date;
    uint amount;
    bool claimed;
}

//Track amount of time between addresses checking
mapping(address => uint) LastChecked; //The Uint is time or blocknumber.
mapping(address => mapping(string => claims)) Refundtracker;

//Money sent to contract goes to donation pool.
//Consider adding "Ownable" as well. 
function WhistleBlower() payable public {
    //Money sent to the contract is taken as donation.
    Donations += msg.value;

    //Set Startup Mode //maybe we don't need to set this.
    //StartUp = 1;

    //Setup Claim Times
    ClaimTime = 0;
    ClaimCheckTime = 0;

    //Setup Owner of the contract
    Owner = msg.sender;
    return();
}
modifier onlyOwner {
    require(msg.sender == Owner);
    _;
}

function makeClaim(string _hash, string _details) public payable {
    //Require Staking Payment
    //Require Strings are not Empty
    //Maybe there is a more effecient way to do this.
    require(msg.value >= 500 finney);
    require(keccak256(_hash) != keccak256(""));
    require(keccak256(_details) != keccak256(""));


    //Log Time of Claim
    uint _timeofclaim = block.number;
    var _refundtracker = Refundtracker[msg.sender][_hash];
    _refundtracker.date = _timeofclaim;
    //Log amount Staked by user
    _refundtracker.amount = msg.value;

    //Number of Claims made against particular individual
    uint _index = numberOfClaims[_hash];


    //Details of Claim
    detailsOfClaim[_hash][_index] = _details;

    //Total Number of Claims
    numberOfClaims[_hash] += 1;

}

//////////////////// //Helper Functions// ////////////////////

function returnClaimedCoins(address _claiment, string _hash) public {
    //You can only request the return of your own coins.
    require(msg.sender == _claiment);
    //Check that this has not already been redeemed
    require(Refundtracker[msg.sender][_hash].claimed == false);
    //Check that enough time has elapsed to redeem coins
    uint _claimCreatedTime = Refundtracker[msg.sender][_hash].date;

    uint _currentBlockNumber = block.number;

    require(_claimCreatedTime <= (_currentBlockNumber + ClaimTime));

    uint _amountToSend;
    _amountToSend = Refundtracker[msg.sender][_hash].amount;
    Refundtracker[msg.sender][_hash].claimed = true;
    msg.sender.transfer(_amountToSend);
}


function getClaimTimes() view public returns(uint,uint){
    return(ClaimTime, ClaimCheckTime);

}
function setClaimTimes(uint _claimtime, uint _claimchecktime) onlyOwner public /*returns()*/ {
    //Check to be sure we are in Statup Mode
    require(StartUp == 1);

    //Set our ClaimTime requirements
    ClaimTime = _claimtime;
    ClaimCheckTime = _claimchecktime;

    //Set Startup to False, thus ending the startup time. Forever.
    StartUp = 0;
    //return();
}

function areWeInSetup() view public returns(uint){
   return(StartUp);
}

function withdrawDonation(address _withdrawlAddress, uint _amount) onlyOwner public returns(bool){
    //Transfer Donations out
    _withdrawlAddress.transfer(_amount);
}

function makeDonation() public payable{
    Donations += msg.value;
}

function checkDonationBalance() view public returns(uint){
    return(Donations);
}

function checkContractBalance() view public returns(uint){
    return(address(this).balance);
}

function setLastCheckedTime(address _address) public {
    LastChecked[_address] = now;
}

function getNumberofClaims(string _name) view public returns (uint){
    return(numberOfClaims[_name]);
}

function getDetails(string _name, uint _claimnumber) view public returns (string){

    string memory _details = detailsOfClaim[_name][_claimnumber];
    return(_details);
}

}

16
  • 1
    I don't see why it's failing, but as a note, you don't need to do require(variable == true), here, require cna directly check the variable, require(variable). If it's true, it continues, otherwise it reverts. Mar 28, 2018 at 22:38
  • Thanks for the tip. I've changed it on my code, but it still doesn't work unfortunately. There must be something I'm entirely over looking if such a simple assignment runs out of gas....
    – Dennison
    Mar 28, 2018 at 22:48
  • You say it works when deployed through Remix? Maybe add the entire code? Mar 28, 2018 at 22:55
  • Maybe this is related ? ethereum.stackexchange.com/questions/39085/… Mar 28, 2018 at 22:56
  • 1
    @ElishaDrion - I'm not able to get testnet tx right now because of another problem: I'm on my dev computer and my metamask is using the stock "ganache" seed words- hence every time I get testEther, someone steals them. haha. I haven't yet figured out how to reset Metamask on Brave (doesn't seem to be possible, need to reinstall). In the meantime, I've figured out a simpler solution to avoid needing to set anything at all. However I'm still going to focus to see what the real source of the problem is. AdamKipnis has a very interesting thread I need to check.
    – Dennison
    Mar 28, 2018 at 23:34

0

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Browse other questions tagged or ask your own question.