function firstBlockAfter (uint timepoint) returns (uint) {
    // returns the first block number after timepoint

Is there any solution except iterating the latest 256 blocks?


No. In solidity, you have the hash of the 256 lastest blocks but not the timestamp of them. You only have access to the time stamp of the latest block.

However, you can make an educated guess by taking

b = (block.timestamp - timepoint)/(15 seconds)

I am using 15 seconds as the average time between block. This gives you an approximation of the number of blocks between your time point and the current timestamp. So your estimate of the block after your time point is block.number - b + 1

Hope this helps.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.