2017-04-26 06:36:26 +00:00
|
|
|
# Setting the block hash
|
|
|
|
if msg.sender == 2**160 - 2:
|
|
|
|
with prev_block_number = block.number - 1:
|
|
|
|
# Use storage fields 0..255 to store the last 256 hashes
|
|
|
|
~sstore(prev_block_number % 256, ~calldataload(0))
|
|
|
|
# Use storage fields 256..511 to store the hashes of the last 256
|
|
|
|
# blocks with block.number % 256 == 0
|
2017-04-26 07:15:07 +00:00
|
|
|
if not (prev_block_number % 256):
|
2017-04-26 06:36:26 +00:00
|
|
|
~sstore(256 + (prev_block_number / 256) % 256, ~calldataload(0))
|
|
|
|
# Use storage fields 512..767 to store the hashes of the last 256
|
|
|
|
# blocks with block.number % 65536 == 0
|
2017-04-26 07:15:07 +00:00
|
|
|
if not (prev_block_number % 65536):
|
2017-04-26 06:36:26 +00:00
|
|
|
~sstore(512 + (prev_block_number / 65536) % 256, ~calldataload(0))
|
|
|
|
# Getting the block hash
|
|
|
|
else:
|
2017-04-26 07:15:07 +00:00
|
|
|
if ~calldataload(0) >= block.number:
|
|
|
|
return(0)
|
|
|
|
elif block.number - ~calldataload(0) <= 256:
|
2017-04-26 06:36:26 +00:00
|
|
|
return(~sload(~calldataload(0) % 256))
|
2017-04-26 07:15:07 +00:00
|
|
|
elif (not (~calldataload(0) % 256) and block.number - ~calldataload(0) <= 65536):
|
2017-04-26 06:36:26 +00:00
|
|
|
return(~sload(256 + (~calldataload(0) / 256) % 256))
|
2017-04-26 07:15:07 +00:00
|
|
|
elif (not (~calldataload(0) % 65536) and block.number - ~calldataload(0) <= 16777216):
|
2017-04-26 06:36:26 +00:00
|
|
|
return(~sload(512 + (~calldataload(0) / 65536) % 256))
|
|
|
|
else:
|
2017-04-26 09:20:29 +00:00
|
|
|
return(0)
|