blockchain: bits_to_target: small clean-up
note: why is the first byte cut unconditionally? what if it's non-zero? Maybe the intention of cutting the first two chars in the hex case intended to cut a "0x" prefix?? But there was no such prefix with the given format string...
This commit is contained in:
@@ -552,10 +552,11 @@ class Blockchain(Logger):
|
|||||||
|
|
||||||
@classmethod
|
@classmethod
|
||||||
def target_to_bits(cls, target: int) -> int:
|
def target_to_bits(cls, target: int) -> int:
|
||||||
c = ("%064x" % target)[2:]
|
c = target.to_bytes(length=32, byteorder='big')
|
||||||
while c[:2] == '00' and len(c) > 6:
|
c = c[1:] # FIXME why is this done unconditionally?
|
||||||
c = c[2:]
|
while c[0] == 0 and len(c) > 3:
|
||||||
bitsN, bitsBase = len(c) // 2, int.from_bytes(bfh(c[:6]), byteorder='big')
|
c = c[1:]
|
||||||
|
bitsN, bitsBase = len(c), int.from_bytes(c[:3], byteorder='big')
|
||||||
if bitsBase >= 0x800000:
|
if bitsBase >= 0x800000:
|
||||||
bitsN += 1
|
bitsN += 1
|
||||||
bitsBase >>= 8
|
bitsBase >>= 8
|
||||||
|
|||||||
Reference in New Issue
Block a user