Browse Source

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...
patch-4
SomberNight 3 years ago
parent
commit
ee10e8e4d3
No known key found for this signature in database GPG Key ID: B33B5F232C6271E9
  1. 9
      electrum/blockchain.py

9
electrum/blockchain.py

@ -552,10 +552,11 @@ class Blockchain(Logger):
@classmethod
def target_to_bits(cls, target: int) -> int:
c = ("%064x" % target)[2:]
while c[:2] == '00' and len(c) > 6:
c = c[2:]
bitsN, bitsBase = len(c) // 2, int.from_bytes(bfh(c[:6]), byteorder='big')
c = target.to_bytes(length=32, byteorder='big')
c = c[1:] # FIXME why is this done unconditionally?
while c[0] == 0 and len(c) > 3:
c = c[1:]
bitsN, bitsBase = len(c), int.from_bytes(c[:3], byteorder='big')
if bitsBase >= 0x800000:
bitsN += 1
bitsBase >>= 8

Loading…
Cancel
Save