block hashes

Loading...
event Error(x:str)

# Add one of the most recent 256 blocks
def add_recent(n):
   h = block.prevhash(block.number - n)
   if h == 0: 
       log(type=Error, text("block.prevhash failed"))
   else: 
       self.storage[n] = h

# Add a block at any height, as long as we have the child
def add_old(header:str, n):
   with h = self.storage[n+1]:
    with p = sha3(header:str):
     with parent = ~calldataload(72+32):  # I don't know how calldataload works
      if h - p == 0:
        self.storage[n] = parent
      else:
        log(type=Error, text("sha3 hash does not match"))

# Returns the blockhash, or 0
def get_blockhash(n):
   h = block.prevhash(block.number - n)
   if h == 0: return self.storage[n]

Serpent contract for Ethereum

My Serpent code description.

Preferences

Note: Your changes won't be saved, because not Logged-in.

Create your own Contract