block template class
This commit is contained in:
parent
6396fe8e3a
commit
a87a19a230
@ -902,6 +902,7 @@ class BlockTemplate():
|
|||||||
nonce = s2rh(nonce)
|
nonce = s2rh(nonce)
|
||||||
cbh = double_sha256(unhexlify(cb))
|
cbh = double_sha256(unhexlify(cb))
|
||||||
merkle_root = merkleroot_from_branches(self.merkle_branches, cbh)
|
merkle_root = merkleroot_from_branches(self.merkle_branches, cbh)
|
||||||
|
print("merkle_root ", hexlify(merkle_root))
|
||||||
header = version + prev_hash + merkle_root + time + bits + nonce
|
header = version + prev_hash + merkle_root + time + bits + nonce
|
||||||
block = hexlify(header).decode()
|
block = hexlify(header).decode()
|
||||||
block += hexlify(to_var_int(len (self.transactions)+1)).decode()
|
block += hexlify(to_var_int(len (self.transactions)+1)).decode()
|
||||||
|
|||||||
@ -450,14 +450,21 @@ def is_valid_signature_encoding(sig):
|
|||||||
def bits2target(bits):
|
def bits2target(bits):
|
||||||
if type(bits) == str:
|
if type(bits) == str:
|
||||||
bits = unhexlify(bits)
|
bits = unhexlify(bits)
|
||||||
return int.from_bytes(bits[1:], 'big') * (2 ** (8 * (bits[0] - 3)))
|
if type(bits) == bytes:
|
||||||
|
return int.from_bytes(bits[1:], 'big') * (2 ** (8 * (bits[0] - 3)))
|
||||||
|
else:
|
||||||
|
shift = bits >> 24
|
||||||
|
target = (bits & 0xffffff) * (1 << (8 * (shift - 3)))
|
||||||
|
return target
|
||||||
|
|
||||||
def target2diff(target):
|
def target2difficulty(target):
|
||||||
return 0x00000000FFFF0000000000000000000000000000000000000000000000000000 / target
|
return 0x00000000FFFF0000000000000000000000000000000000000000000000000000 / target
|
||||||
|
|
||||||
def bits2diff(bits):
|
def bits2difficulty(bits):
|
||||||
return target2diff(bits2target(bits))
|
return target2difficulty(bits2target(bits))
|
||||||
|
|
||||||
|
def difficulty2target(difficulty):
|
||||||
|
return int(0x00000000FFFF0000000000000000000000000000000000000000000000000000 / difficulty)
|
||||||
|
|
||||||
def rh2s(tthash):
|
def rh2s(tthash):
|
||||||
return hexlify(tthash[::-1]).decode()
|
return hexlify(tthash[::-1]).decode()
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user