made iongchun's genesis block patch handle failure correctly
[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, jsonrpc
8
9 @defer.inlineCallbacks
10 def check_genesis_block(bitcoind, genesis_block_hash):
11     try:
12         yield bitcoind.rpc_getblock(genesis_block_hash)
13     except jsonrpc.Error_for_code(-5):
14         defer.returnValue(False)
15     else:
16         defer.returnValue(True)
17
18 nets = dict(
19     bitcoin=math.Object(
20         P2P_PREFIX='f9beb4d9'.decode('hex'),
21         P2P_PORT=8333,
22         ADDRESS_VERSION=0,
23         RPC_PORT=8332,
24         RPC_CHECK=defer.inlineCallbacks(lambda bitcoind: defer.returnValue(
25             (yield check_genesis_block(bitcoind, '000000000019d6689c085ae165831e934ff763ae46a2a6c172b3f1b60a8ce26f')) and
26             not (yield bitcoind.rpc_getinfo())['testnet']
27         )),
28         SUBSIDY_FUNC=lambda height: 50*100000000 >> (height + 1)//210000,
29         POW_FUNC=data.hash256,
30         BLOCK_PERIOD=600, # s
31         SYMBOL='BTC',
32         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'),
33         BLOCK_EXPLORER_URL_PREFIX='https://blockchain.info/block/',
34         ADDRESS_EXPLORER_URL_PREFIX='https://blockchain.info/address/',
35         TX_EXPLORER_URL_PREFIX='https://blockchain.info/tx/',
36         SANE_TARGET_RANGE=(2**256//2**32//1000 - 1, 2**256//2**32 - 1),
37         DUMB_SCRYPT_DIFF=1,
38         DUST_THRESHOLD=0.001e8,
39     ),
40     bitcoin_testnet=math.Object(
41         P2P_PREFIX='0b110907'.decode('hex'),
42         P2P_PORT=18333,
43         ADDRESS_VERSION=111,
44         RPC_PORT=18332,
45         RPC_CHECK=defer.inlineCallbacks(lambda bitcoind: defer.returnValue(
46             'bitcoinaddress' in (yield bitcoind.rpc_help()) and
47             (yield bitcoind.rpc_getinfo())['testnet']
48         )),
49         SUBSIDY_FUNC=lambda height: 50*100000000 >> (height + 1)//210000,
50         POW_FUNC=data.hash256,
51         BLOCK_PERIOD=600, # s
52         SYMBOL='tBTC',
53         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'),
54         BLOCK_EXPLORER_URL_PREFIX='http://blockexplorer.com/testnet/block/',
55         ADDRESS_EXPLORER_URL_PREFIX='http://blockexplorer.com/testnet/address/',
56         TX_EXPLORER_URL_PREFIX='http://blockexplorer.com/testnet/tx/',
57         SANE_TARGET_RANGE=(2**256//2**32//1000 - 1, 2**256//2**32 - 1),
58         DUMB_SCRYPT_DIFF=1,
59         DUST_THRESHOLD=1e8,
60     ),
61     
62     namecoin=math.Object(
63         P2P_PREFIX='f9beb4fe'.decode('hex'),
64         P2P_PORT=8334,
65         ADDRESS_VERSION=52,
66         RPC_PORT=8332,
67         RPC_CHECK=defer.inlineCallbacks(lambda bitcoind: defer.returnValue(
68             'namecoinaddress' in (yield bitcoind.rpc_help()) and
69             not (yield bitcoind.rpc_getinfo())['testnet']
70         )),
71         SUBSIDY_FUNC=lambda height: 50*100000000 >> (height + 1)//210000,
72         POW_FUNC=data.hash256,
73         BLOCK_PERIOD=600, # s
74         SYMBOL='NMC',
75         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'),
76         BLOCK_EXPLORER_URL_PREFIX='http://explorer.dot-bit.org/b/',
77         ADDRESS_EXPLORER_URL_PREFIX='http://explorer.dot-bit.org/a/',
78         TX_EXPLORER_URL_PREFIX='http://explorer.dot-bit.org/tx/',
79         SANE_TARGET_RANGE=(2**256//2**32 - 1, 2**256//2**32 - 1),
80         DUMB_SCRYPT_DIFF=1,
81         DUST_THRESHOLD=0.2e8,
82     ),
83     namecoin_testnet=math.Object(
84         P2P_PREFIX='fabfb5fe'.decode('hex'),
85         P2P_PORT=18334,
86         ADDRESS_VERSION=111,
87         RPC_PORT=8332,
88         RPC_CHECK=defer.inlineCallbacks(lambda bitcoind: defer.returnValue(
89             'namecoinaddress' in (yield bitcoind.rpc_help()) and
90             (yield bitcoind.rpc_getinfo())['testnet']
91         )),
92         SUBSIDY_FUNC=lambda height: 50*100000000 >> (height + 1)//210000,
93         POW_FUNC=data.hash256,
94         BLOCK_PERIOD=600, # s
95         SYMBOL='tNMC',
96         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'),
97         BLOCK_EXPLORER_URL_PREFIX='http://testnet.explorer.dot-bit.org/b/',
98         ADDRESS_EXPLORER_URL_PREFIX='http://testnet.explorer.dot-bit.org/a/',
99         TX_EXPLORER_URL_PREFIX='http://testnet.explorer.dot-bit.org/tx/',
100         SANE_TARGET_RANGE=(2**256//2**32 - 1, 2**256//2**32 - 1),
101         DUMB_SCRYPT_DIFF=1,
102         DUST_THRESHOLD=1e8,
103     ),
104     
105     litecoin=math.Object(
106         P2P_PREFIX='fbc0b6db'.decode('hex'),
107         P2P_PORT=9333,
108         ADDRESS_VERSION=48,
109         RPC_PORT=9332,
110         RPC_CHECK=defer.inlineCallbacks(lambda bitcoind: defer.returnValue(
111             'litecoinaddress' in (yield bitcoind.rpc_help()) and
112             not (yield bitcoind.rpc_getinfo())['testnet']
113         )),
114         SUBSIDY_FUNC=lambda height: 50*100000000 >> (height + 1)//840000,
115         POW_FUNC=lambda data: pack.IntType(256).unpack(__import__('ltc_scrypt').getPoWHash(data)),
116         BLOCK_PERIOD=150, # s
117         SYMBOL='LTC',
118         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'),
119         BLOCK_EXPLORER_URL_PREFIX='http://explorer.litecoin.net/block/',
120         ADDRESS_EXPLORER_URL_PREFIX='http://explorer.litecoin.net/address/',
121         TX_EXPLORER_URL_PREFIX='http://explorer.litecoin.net/tx/',
122         SANE_TARGET_RANGE=(2**256//1000000000 - 1, 2**256//1000 - 1),
123         DUMB_SCRYPT_DIFF=2**16,
124         DUST_THRESHOLD=0.03e8,
125     ),
126     litecoin_testnet=math.Object(
127         P2P_PREFIX='fcc1b7dc'.decode('hex'),
128         P2P_PORT=19333,
129         ADDRESS_VERSION=111,
130         RPC_PORT=19332,
131         RPC_CHECK=defer.inlineCallbacks(lambda bitcoind: defer.returnValue(
132             'litecoinaddress' in (yield bitcoind.rpc_help()) and
133             (yield bitcoind.rpc_getinfo())['testnet']
134         )),
135         SUBSIDY_FUNC=lambda height: 50*100000000 >> (height + 1)//840000,
136         POW_FUNC=lambda data: pack.IntType(256).unpack(__import__('ltc_scrypt').getPoWHash(data)),
137         BLOCK_PERIOD=150, # s
138         SYMBOL='tLTC',
139         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'),
140         BLOCK_EXPLORER_URL_PREFIX='http://nonexistent-litecoin-testnet-explorer/block/',
141         ADDRESS_EXPLORER_URL_PREFIX='http://nonexistent-litecoin-testnet-explorer/address/',
142         TX_EXPLORER_URL_PREFIX='http://nonexistent-litecoin-testnet-explorer/tx/',
143         SANE_TARGET_RANGE=(2**256//1000000000 - 1, 2**256 - 1),
144         DUMB_SCRYPT_DIFF=2**16,
145         DUST_THRESHOLD=1e8,
146     ),
147
148     terracoin=math.Object(
149         P2P_PREFIX='42babe56'.decode('hex'),
150         P2P_PORT=13333,
151         ADDRESS_VERSION=0,
152         RPC_PORT=13332,
153         RPC_CHECK=defer.inlineCallbacks(lambda bitcoind: defer.returnValue(
154             'terracoinaddress' in (yield bitcoind.rpc_help()) and
155             not (yield bitcoind.rpc_getinfo())['testnet']
156         )),
157         SUBSIDY_FUNC=lambda height: 20*100000000 >> (height + 1)//1050000,
158         POW_FUNC=data.hash256,
159         BLOCK_PERIOD=120, # s
160         SYMBOL='TRC',
161         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'),
162         BLOCK_EXPLORER_URL_PREFIX='http://trc.cryptocoinexplorer.com/block/',
163         ADDRESS_EXPLORER_URL_PREFIX='http://trc.cryptocoinexplorer.com/address/',
164         TX_EXPLORER_URL_PREFIX='http://trc.cryptocoinexplorer.com/tx/',
165         SANE_TARGET_RANGE=(2**256//2**32//1000 - 1, 2**256//2**32 - 1),
166         DUMB_SCRYPT_DIFF=1,
167         DUST_THRESHOLD=1e8,
168     ),
169     terracoin_testnet=math.Object(
170         P2P_PREFIX='41babe56'.decode('hex'),
171         P2P_PORT=23333,
172         ADDRESS_VERSION=111,
173         RPC_PORT=23332,
174         RPC_CHECK=defer.inlineCallbacks(lambda bitcoind: defer.returnValue(
175             'terracoinaddress' in (yield bitcoind.rpc_help()) and
176             (yield bitcoind.rpc_getinfo())['testnet']
177         )),
178         SUBSIDY_FUNC=lambda height: 20*100000000 >> (height + 1)//1050000,
179         POW_FUNC=data.hash256,
180         BLOCK_PERIOD=120, # s
181         SYMBOL='tTRC',
182         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'),
183         BLOCK_EXPLORER_URL_PREFIX='http://trc.cryptocoinexplorer.com/testnet/block/',
184         ADDRESS_EXPLORER_URL_PREFIX='http://trc.cryptocoinexplorer.com/testnet/address/',
185         TX_EXPLORER_URL_PREFIX='http://trc.cryptocoinexplorer.com/testnet/tx/',
186         SANE_TARGET_RANGE=(2**256//2**32//1000 - 1, 2**256//2**32 - 1),
187         DUMB_SCRYPT_DIFF=1,
188         DUST_THRESHOLD=1e8,
189     ),
190
191 )
192 for net_name, net in nets.iteritems():
193     net.NAME = net_name