Advertisement
Guest User

Untitled

a guest
Mar 23rd, 2017
62
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.19 KB | None | 0 0
  1. pragma solidity ^0.4.9;
  2.  
  3. contract HeadersRelay {
  4. mapping(uint=>uint) public merklesOfHeaders;
  5. uint lastRelayedBlock;
  6.  
  7. function HeadersRelay() {
  8. lastRelayedBlock = 1;
  9. }
  10.  
  11. function relayExpensive() {
  12. uint firstBlock = block.number - 129;
  13. for( uint index = 0 ; index < 128 ; index++ ) {
  14. merklesOfHeaders[index] = block.blockhash(firstBlock + index);;
  15. }
  16. }
  17.  
  18. function relay() {
  19. // just test 128 blocks relay
  20. bytes32[128] memory scratchpad;
  21. uint firstBlock = block.number - 129;
  22. uint index;
  23.  
  24. for( index = 0 ; index < 128 ; index++ ) {
  25. scratchpad[index] = block.blockhash(firstBlock + index);
  26. }
  27.  
  28. uint arraySize = 128;
  29. while( arraySize > 1 ) {
  30. uint halfSize = arraySize / 2;
  31. for( index = 0 ; index < halfSize ; index++ ) {
  32. scratchpad[index] = sha3(scratchpad[2*index], scratchpad[2*index+1]);
  33. }
  34.  
  35. arraySize = arraySize / 2;
  36. }
  37.  
  38. merklesOfHeaders[firstBlock] = uint(scratchpad[0]);
  39. lastRelayedBlock = firstBlock + 128;
  40. }
  41.  
  42.  
  43. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement