6

Essentially, is there a SetTimeout in Solidity?

creationTime = now;

lastBlockNumberA = block.number - 1; 

first = lastBlockNumberA;

if(now >= creationTime + 1 days){
  lastBlockNumberB = block.number - 1; 
  second = lastBlockNumberB;
  if(first == second){
     doSomething();
  }
}

function doSomething(){ };

Assuming a block has been mined over the course of the time period, does first == second? Does the doSomething function fire?

Preferably, is there a way to wait (x) number of blocks before running the if statement? I would like to wait a certain number of blocks (or time) before I get a new lastBlockNumber- is it even possible (without invoking the contract again - just from the one contract invocation, in this example 1 day ago).

From my tests it would appear as though the invocation of a contract does not allow for functions/if statements within it to be called (x) units of time or blocks in the future, without having to invoke the contract again, is that correct? If not, how would one do that?

I found this: https://solidity.readthedocs.org/en/latest/common-patterns.html#state-machine

It talks of stages, but does one have to interact with the contract to perform the stage 'guard tests' or do these happen automatically regardless?

5
  • The code block after return first; will never execute. This is probably not what you mean, so can you clarify your question by providing a larger snippit from your contract? – Joris Bontje Feb 6 '16 at 2:59
  • sorry about that, updated. – user2890278 Feb 6 '16 at 3:34
  • agreed. sorry. feel free to delete. – user2890278 Feb 6 '16 at 5:34
  • It's not a problem, it's good to have different ways of phrasing the question available. We generally just close the question, which disables additional answers and redirects users to the original question. – Tjaden Hess Feb 6 '16 at 5:57
  • @user2890278 you could contribute your findings as answer to the other question thread instead. – Afr Feb 6 '16 at 13:40

Browse other questions tagged or ask your own question.