Calculate difficulty from nBits target
(nBits)
| 532 | |
| 533 | @staticmethod |
| 534 | def calc_difficulty(nBits): |
| 535 | """Calculate difficulty from nBits target""" |
| 536 | nShift = (nBits >> 24) & 0xff |
| 537 | dDiff = float(0x0000ffff) / float(nBits & 0x00ffffff) |
| 538 | while nShift < 29: |
| 539 | dDiff *= 256.0 |
| 540 | nShift += 1 |
| 541 | while nShift > 29: |
| 542 | dDiff /= 256.0 |
| 543 | nShift -= 1 |
| 544 | return dDiff |
| 545 | difficulty = property(lambda self: CBlockHeader.calc_difficulty(self.nBits)) |
| 546 | |
| 547 | def __repr__(self): |