Bugfix: bitcoin/script: Correctly interpret P2SH addresses, and reject anything unrec...
[bitcoin:eloipool.git] / util.py
1 from hashlib import sha256
2 from struct import unpack
3
4 def dblsha(b):
5         return sha256(sha256(b).digest()).digest()
6
7 def swap32(b):
8         o = b''
9         for i in range(0, len(b), 4):
10                 o += b[i + 3:i - 1 if i else None:-1]
11         return o
12
13 def Bits2Target(bits):
14         return unpack('<L', bits[:3] + b'\0')[0] * 2**(8*(bits[3] - 3))
15
16 def hash2int(h):
17         n = unpack('<QQQQ', h)
18         n = (n[3] << 192) | (n[2] << 128) | (n[1] << 64) | n[0]
19         return n
20
21 class RejectedShare(ValueError):
22         pass