Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- pragma solidity ^0.4.9;
- contract HeadersRelay {
- mapping(uint=>uint) public merklesOfHeaders;
- uint lastRelayedBlock;
- function HeadersRelay() {
- lastRelayedBlock = 1;
- }
- function relayExpensive() {
- uint firstBlock = block.number - 129;
- for( uint index = 0 ; index < 128 ; index++ ) {
- merklesOfHeaders[index] = block.blockhash(firstBlock + index);;
- }
- }
- function relay() {
- // just test 128 blocks relay
- bytes32[128] memory scratchpad;
- uint firstBlock = block.number - 129;
- uint index;
- for( index = 0 ; index < 128 ; index++ ) {
- scratchpad[index] = block.blockhash(firstBlock + index);
- }
- uint arraySize = 128;
- while( arraySize > 1 ) {
- uint halfSize = arraySize / 2;
- for( index = 0 ; index < halfSize ; index++ ) {
- scratchpad[index] = sha3(scratchpad[2*index], scratchpad[2*index+1]);
- }
- arraySize = arraySize / 2;
- }
- merklesOfHeaders[firstBlock] = uint(scratchpad[0]);
- lastRelayedBlock = firstBlock + 128;
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement