Exemplo n.º 1
0
 def check_pow(self):
     '''Returns whether this block satisfies proof of work'''
     # get the hash256 of the serialization of this block
     h256 = hash256(self.serialize())
     # interpret this hash as a little-endian number
     proof = little_endian_to_int(h256)
     # return whether this integer is less than the target
     return proof < self.target()
Exemplo n.º 2
0
 def sig_hash(self, input_index):
     '''Returns the integer representation of the hash that needs to get
     signed for index input_index'''
     s = int_to_little_endian(self.version, 4)
     s += encode_varint(len(self.tx_ins))
     for i, tx_in in enumerate(self.tx_ins):
         if i == input_index:
             s += TxIn(prev_tx=tx_in.prev_tx,
                       prev_index=tx_in.prev_index,
                       script_sig=tx_in.script_pubkey(self.testnet),
                       sequence=tx_in.sequence).serialize()
         else:
             s += TxIn(prev_tx=tx_in.prev_tx,
                       prev_index=tx_in.prev_index,
                       sequence=tx_in.sequence).serialize()
     s += encode_varint(len(self.tx_outs))
     for tx_out in self.tx_outs:
         s += tx_out.serialize()
     s += int_to_little_endian(self.locktime, 4)
     # Should set various sighash
     s += int_to_little_endian(SIGHASH_ALL, 4)
     h256 = hash256(s)
     return int.from_bytes(h256, 'big')
Exemplo n.º 3
0
def op_hash256(stack):
    if len(stack) < 1:
        return False
    element = stack.pop()
    stack.append(hash256(element))
    return True
Exemplo n.º 4
0
 def hash(self):
     s = self.serialize()
     sha = hash256(s)
     return sha[::-1]
Exemplo n.º 5
0
 def hash(self):
     '''Binary hash of the legacy serialization'''
     return hash256(self.serialize())[::-1]