1 # Eloipool - Python Bitcoin pool server
2 # Copyright (C) 2011-2012 Luke Dashjr <luke-jr+eloipool@utopios.org>
4 # This program is free software: you can redistribute it and/or modify
5 # it under the terms of the GNU Affero General Public License as
6 # published by the Free Software Foundation, either version 3 of the
7 # License, or (at your option) any later version.
9 # This program is distributed in the hope that it will be useful,
10 # but WITHOUT ANY WARRANTY; without even the implied warranty of
11 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 # GNU Affero General Public License for more details.
14 # You should have received a copy of the GNU Affero General Public License
15 # along with this program. If not, see <http://www.gnu.org/licenses/>.
17 from base58 import b58decode
18 from util import dblsha
20 def _Address2PKH(addr):
22 addr = b58decode(addr, 25)
29 cksumB = dblsha(addr[:-4])[:4]
32 return (ver, addr[1:-4])
36 def toAddress(cls, addr):
37 d = _Address2PKH(addr)
39 raise ValueError('invalid address')
41 return b'\x76\xa9\x14' + pubkeyhash + b'\x88\xac'
44 # FIXME: don't count data as ops
49 elif 0xae == ch & 0xfe:
53 # NOTE: This does not work for signed numbers (set the high bit) or zero (use b'\0')
68 s = encodeUNum(abs(n))
75 assert b'\0' == encodeNum(0)
76 assert b'\1\x55' == encodeNum(0x55)
77 assert b'\2\xfd\0' == encodeNum(0xfd)
78 assert b'\3\xff\xff\0' == encodeNum(0xffff)
79 assert b'\3\0\0\x01' == encodeNum(0x10000)
80 assert b'\5\xff\xff\xff\xff\0' == encodeNum(0xffffffff)