Make p2pool's stratum implementation match the dumb de facto diff standard of scrypt...
[p2pool.git] / p2pool / bitcoin / networks.py
1 import os
2 import platform
3
4 from twisted.internet import defer
5
6 from . import data
7 from p2pool.util import math, pack
8
9 nets = dict(
10     bitcoin=math.Object(
11         P2P_PREFIX='f9beb4d9'.decode('hex'),
12         P2P_PORT=8333,
13         ADDRESS_VERSION=0,
14         RPC_PORT=8332,
15         RPC_CHECK=defer.inlineCallbacks(lambda bitcoind: defer.returnValue(
16             'bitcoinaddress' in (yield bitcoind.rpc_help()) and
17             not (yield bitcoind.rpc_getinfo())['testnet']
18         )),
19         SUBSIDY_FUNC=lambda height: 50*100000000 >> (height + 1)//210000,
20         POW_FUNC=data.hash256,
21         BLOCK_PERIOD=600, # s
22         SYMBOL='BTC',
23         CONF_FILE_FUNC=lambda: os.path.join(os.path.join(os.environ['APPDATA'], 'Bitcoin') if platform.system() == 'Windows' else os.path.expanduser('~/Library/Application Support/Bitcoin/') if platform.system() == 'Darwin' else os.path.expanduser('~/.bitcoin'), 'bitcoin.conf'),
24         BLOCK_EXPLORER_URL_PREFIX='http://blockexplorer.com/block/',
25         ADDRESS_EXPLORER_URL_PREFIX='http://blockexplorer.com/address/',
26         SANE_TARGET_RANGE=(2**256//2**32//1000 - 1, 2**256//2**32 - 1),
27         DUMB_SCRYPT_DIFF=1,
28     ),
29     bitcoin_testnet=math.Object(
30         P2P_PREFIX='0b110907'.decode('hex'),
31         P2P_PORT=18333,
32         ADDRESS_VERSION=111,
33         RPC_PORT=18332,
34         RPC_CHECK=defer.inlineCallbacks(lambda bitcoind: defer.returnValue(
35             'bitcoinaddress' in (yield bitcoind.rpc_help()) and
36             (yield bitcoind.rpc_getinfo())['testnet']
37         )),
38         SUBSIDY_FUNC=lambda height: 50*100000000 >> (height + 1)//210000,
39         POW_FUNC=data.hash256,
40         BLOCK_PERIOD=600, # s
41         SYMBOL='tBTC',
42         CONF_FILE_FUNC=lambda: os.path.join(os.path.join(os.environ['APPDATA'], 'Bitcoin') if platform.system() == 'Windows' else os.path.expanduser('~/Library/Application Support/Bitcoin/') if platform.system() == 'Darwin' else os.path.expanduser('~/.bitcoin'), 'bitcoin.conf'),
43         BLOCK_EXPLORER_URL_PREFIX='http://blockexplorer.com/testnet/block/',
44         ADDRESS_EXPLORER_URL_PREFIX='http://blockexplorer.com/testnet/address/',
45         SANE_TARGET_RANGE=(2**256//2**32//1000 - 1, 2**256//2**32 - 1),
46         DUMB_SCRYPT_DIFF=1,
47     ),
48     
49     namecoin=math.Object(
50         P2P_PREFIX='f9beb4fe'.decode('hex'),
51         P2P_PORT=8334,
52         ADDRESS_VERSION=52,
53         RPC_PORT=8332,
54         RPC_CHECK=defer.inlineCallbacks(lambda bitcoind: defer.returnValue(
55             'namecoinaddress' in (yield bitcoind.rpc_help()) and
56             not (yield bitcoind.rpc_getinfo())['testnet']
57         )),
58         SUBSIDY_FUNC=lambda height: 50*100000000 >> (height + 1)//210000,
59         POW_FUNC=data.hash256,
60         BLOCK_PERIOD=600, # s
61         SYMBOL='NMC',
62         CONF_FILE_FUNC=lambda: os.path.join(os.path.join(os.environ['APPDATA'], 'Namecoin') if platform.system() == 'Windows' else os.path.expanduser('~/Library/Application Support/Namecoin/') if platform.system() == 'Darwin' else os.path.expanduser('~/.namecoin'), 'bitcoin.conf'),
63         BLOCK_EXPLORER_URL_PREFIX='http://explorer.dot-bit.org/b/',
64         ADDRESS_EXPLORER_URL_PREFIX='http://explorer.dot-bit.org/a/',
65         SANE_TARGET_RANGE=(2**256//2**32 - 1, 2**256//2**32 - 1),
66         DUMB_SCRYPT_DIFF=1,
67     ),
68     namecoin_testnet=math.Object(
69         P2P_PREFIX='fabfb5fe'.decode('hex'),
70         P2P_PORT=18334,
71         ADDRESS_VERSION=111,
72         RPC_PORT=8332,
73         RPC_CHECK=defer.inlineCallbacks(lambda bitcoind: defer.returnValue(
74             'namecoinaddress' in (yield bitcoind.rpc_help()) and
75             (yield bitcoind.rpc_getinfo())['testnet']
76         )),
77         SUBSIDY_FUNC=lambda height: 50*100000000 >> (height + 1)//210000,
78         POW_FUNC=data.hash256,
79         BLOCK_PERIOD=600, # s
80         SYMBOL='tNMC',
81         CONF_FILE_FUNC=lambda: os.path.join(os.path.join(os.environ['APPDATA'], 'Namecoin') if platform.system() == 'Windows' else os.path.expanduser('~/Library/Application Support/Namecoin/') if platform.system() == 'Darwin' else os.path.expanduser('~/.namecoin'), 'bitcoin.conf'),
82         BLOCK_EXPLORER_URL_PREFIX='http://testnet.explorer.dot-bit.org/b/',
83         ADDRESS_EXPLORER_URL_PREFIX='http://testnet.explorer.dot-bit.org/a/',
84         SANE_TARGET_RANGE=(2**256//2**32 - 1, 2**256//2**32 - 1),
85         DUMB_SCRYPT_DIFF=1,
86     ),
87     
88     litecoin=math.Object(
89         P2P_PREFIX='fbc0b6db'.decode('hex'),
90         P2P_PORT=9333,
91         ADDRESS_VERSION=48,
92         RPC_PORT=9332,
93         RPC_CHECK=defer.inlineCallbacks(lambda bitcoind: defer.returnValue(
94             'litecoinaddress' in (yield bitcoind.rpc_help()) and
95             not (yield bitcoind.rpc_getinfo())['testnet']
96         )),
97         SUBSIDY_FUNC=lambda height: 50*100000000 >> (height + 1)//840000,
98         POW_FUNC=lambda data: pack.IntType(256).unpack(__import__('ltc_scrypt').getPoWHash(data)),
99         BLOCK_PERIOD=150, # s
100         SYMBOL='LTC',
101         CONF_FILE_FUNC=lambda: os.path.join(os.path.join(os.environ['APPDATA'], 'Litecoin') if platform.system() == 'Windows' else os.path.expanduser('~/Library/Application Support/Litecoin/') if platform.system() == 'Darwin' else os.path.expanduser('~/.litecoin'), 'litecoin.conf'),
102         BLOCK_EXPLORER_URL_PREFIX='http://explorer.litecoin.net/block/',
103         ADDRESS_EXPLORER_URL_PREFIX='http://explorer.litecoin.net/address/',
104         SANE_TARGET_RANGE=(2**256//1000000000 - 1, 2**256//1000 - 1),
105         DUMB_SCRYPT_DIFF=2**16,
106     ),
107     litecoin_testnet=math.Object(
108         P2P_PREFIX='fcc1b7dc'.decode('hex'),
109         P2P_PORT=19333,
110         ADDRESS_VERSION=111,
111         RPC_PORT=19332,
112         RPC_CHECK=defer.inlineCallbacks(lambda bitcoind: defer.returnValue(
113             'litecoinaddress' in (yield bitcoind.rpc_help()) and
114             (yield bitcoind.rpc_getinfo())['testnet']
115         )),
116         SUBSIDY_FUNC=lambda height: 50*100000000 >> (height + 1)//840000,
117         POW_FUNC=lambda data: pack.IntType(256).unpack(__import__('ltc_scrypt').getPoWHash(data)),
118         BLOCK_PERIOD=150, # s
119         SYMBOL='tLTC',
120         CONF_FILE_FUNC=lambda: os.path.join(os.path.join(os.environ['APPDATA'], 'Litecoin') if platform.system() == 'Windows' else os.path.expanduser('~/Library/Application Support/Litecoin/') if platform.system() == 'Darwin' else os.path.expanduser('~/.litecoin'), 'litecoin.conf'),
121         BLOCK_EXPLORER_URL_PREFIX='http://nonexistent-litecoin-testnet-explorer/block/',
122         ADDRESS_EXPLORER_URL_PREFIX='http://nonexistent-litecoin-testnet-explorer/address/',
123         SANE_TARGET_RANGE=(2**256//1000000000 - 1, 2**256 - 1),
124         DUMB_SCRYPT_DIFF=2**16,
125     ),
126
127     terracoin=math.Object(
128         P2P_PREFIX='42babe56'.decode('hex'),
129         P2P_PORT=13333,
130         ADDRESS_VERSION=0,
131         RPC_PORT=13332,
132         RPC_CHECK=defer.inlineCallbacks(lambda bitcoind: defer.returnValue(
133             'terracoinaddress' in (yield bitcoind.rpc_help()) and
134             not (yield bitcoind.rpc_getinfo())['testnet']
135         )),
136         SUBSIDY_FUNC=lambda height: 20*100000000 >> (height + 1)//1050000,
137         POW_FUNC=data.hash256,
138         BLOCK_PERIOD=120, # s
139         SYMBOL='TRC',
140         CONF_FILE_FUNC=lambda: os.path.join(os.path.join(os.environ['APPDATA'], 'Terracoin') if platform.system() == 'Windows' else os.path.expanduser('~/Library/Application Support/Terracoin/') if platform.system() == 'Darwin' else os.path.expanduser('~/.terracoin'), 'terracoin.conf'),
141         BLOCK_EXPLORER_URL_PREFIX='http://cryptocoinexplorer.com:3750/block/',
142         ADDRESS_EXPLORER_URL_PREFIX='http://cryptocoinexplorer.com:3750/address/',
143         SANE_TARGET_RANGE=(2**256//2**32//1000 - 1, 2**256//2**32 - 1),
144         DUMB_SCRYPT_DIFF=1,
145     ),
146     terracoin_testnet=math.Object(
147         P2P_PREFIX='41babe56'.decode('hex'),
148         P2P_PORT=23333,
149         ADDRESS_VERSION=111,
150         RPC_PORT=23332,
151         RPC_CHECK=defer.inlineCallbacks(lambda bitcoind: defer.returnValue(
152             'terracoinaddress' in (yield bitcoind.rpc_help()) and
153             (yield bitcoind.rpc_getinfo())['testnet']
154         )),
155         SUBSIDY_FUNC=lambda height: 20*100000000 >> (height + 1)//1050000,
156         POW_FUNC=data.hash256,
157         BLOCK_PERIOD=120, # s
158         SYMBOL='tTRC',
159         CONF_FILE_FUNC=lambda: os.path.join(os.path.join(os.environ['APPDATA'], 'Terracoin') if platform.system() == 'Windows' else os.path.expanduser('~/Library/Application Support/Terracoin/') if platform.system() == 'Darwin' else os.path.expanduser('~/.terracoin'), 'terracoin.conf'),
160         BLOCK_EXPLORER_URL_PREFIX='http://cryptocoinexplorer.com:3750/testnet/block/',
161         ADDRESS_EXPLORER_URL_PREFIX='http://cryptocoinexplorer.com:3750/testnet/address/',
162         SANE_TARGET_RANGE=(2**256//2**32//1000 - 1, 2**256//2**32 - 1),
163         DUMB_SCRYPT_DIFF=1,
164     ),
165
166 )
167 for net_name, net in nets.iteritems():
168     net.NAME = net_name