Add support for the Terracoin network.
[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     ),
28     bitcoin_testnet=math.Object(
29         P2P_PREFIX='0b110907'.decode('hex'),
30         P2P_PORT=18333,
31         ADDRESS_VERSION=111,
32         RPC_PORT=18332,
33         RPC_CHECK=defer.inlineCallbacks(lambda bitcoind: defer.returnValue(
34             'bitcoinaddress' in (yield bitcoind.rpc_help()) and
35             (yield bitcoind.rpc_getinfo())['testnet']
36         )),
37         SUBSIDY_FUNC=lambda height: 50*100000000 >> (height + 1)//210000,
38         POW_FUNC=data.hash256,
39         BLOCK_PERIOD=600, # s
40         SYMBOL='tBTC',
41         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'),
42         BLOCK_EXPLORER_URL_PREFIX='http://blockexplorer.com/testnet/block/',
43         ADDRESS_EXPLORER_URL_PREFIX='http://blockexplorer.com/testnet/address/',
44         SANE_TARGET_RANGE=(2**256//2**32//1000 - 1, 2**256//2**32 - 1),
45     ),
46     
47     namecoin=math.Object(
48         P2P_PREFIX='f9beb4fe'.decode('hex'),
49         P2P_PORT=8334,
50         ADDRESS_VERSION=52,
51         RPC_PORT=8332,
52         RPC_CHECK=defer.inlineCallbacks(lambda bitcoind: defer.returnValue(
53             'namecoinaddress' in (yield bitcoind.rpc_help()) and
54             not (yield bitcoind.rpc_getinfo())['testnet']
55         )),
56         SUBSIDY_FUNC=lambda height: 50*100000000 >> (height + 1)//210000,
57         POW_FUNC=data.hash256,
58         BLOCK_PERIOD=600, # s
59         SYMBOL='NMC',
60         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'),
61         BLOCK_EXPLORER_URL_PREFIX='http://explorer.dot-bit.org/b/',
62         ADDRESS_EXPLORER_URL_PREFIX='http://explorer.dot-bit.org/a/',
63         SANE_TARGET_RANGE=(2**256//2**32 - 1, 2**256//2**32 - 1),
64     ),
65     namecoin_testnet=math.Object(
66         P2P_PREFIX='fabfb5fe'.decode('hex'),
67         P2P_PORT=18334,
68         ADDRESS_VERSION=111,
69         RPC_PORT=8332,
70         RPC_CHECK=defer.inlineCallbacks(lambda bitcoind: defer.returnValue(
71             'namecoinaddress' in (yield bitcoind.rpc_help()) and
72             (yield bitcoind.rpc_getinfo())['testnet']
73         )),
74         SUBSIDY_FUNC=lambda height: 50*100000000 >> (height + 1)//210000,
75         POW_FUNC=data.hash256,
76         BLOCK_PERIOD=600, # s
77         SYMBOL='tNMC',
78         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'),
79         BLOCK_EXPLORER_URL_PREFIX='http://testnet.explorer.dot-bit.org/b/',
80         ADDRESS_EXPLORER_URL_PREFIX='http://testnet.explorer.dot-bit.org/a/',
81         SANE_TARGET_RANGE=(2**256//2**32 - 1, 2**256//2**32 - 1),
82     ),
83     
84     litecoin=math.Object(
85         P2P_PREFIX='fbc0b6db'.decode('hex'),
86         P2P_PORT=9333,
87         ADDRESS_VERSION=48,
88         RPC_PORT=9332,
89         RPC_CHECK=defer.inlineCallbacks(lambda bitcoind: defer.returnValue(
90             'litecoinaddress' in (yield bitcoind.rpc_help()) and
91             not (yield bitcoind.rpc_getinfo())['testnet']
92         )),
93         SUBSIDY_FUNC=lambda height: 50*100000000 >> (height + 1)//840000,
94         POW_FUNC=lambda data: pack.IntType(256).unpack(__import__('ltc_scrypt').getPoWHash(data)),
95         BLOCK_PERIOD=150, # s
96         SYMBOL='LTC',
97         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'),
98         BLOCK_EXPLORER_URL_PREFIX='http://explorer.litecoin.net/block/',
99         ADDRESS_EXPLORER_URL_PREFIX='http://explorer.litecoin.net/address/',
100         SANE_TARGET_RANGE=(2**256//1000000000 - 1, 2**256//1000 - 1),
101     ),
102     litecoin_testnet=math.Object(
103         P2P_PREFIX='fcc1b7dc'.decode('hex'),
104         P2P_PORT=19333,
105         ADDRESS_VERSION=111,
106         RPC_PORT=19332,
107         RPC_CHECK=defer.inlineCallbacks(lambda bitcoind: defer.returnValue(
108             'litecoinaddress' in (yield bitcoind.rpc_help()) and
109             (yield bitcoind.rpc_getinfo())['testnet']
110         )),
111         SUBSIDY_FUNC=lambda height: 50*100000000 >> (height + 1)//840000,
112         POW_FUNC=lambda data: pack.IntType(256).unpack(__import__('ltc_scrypt').getPoWHash(data)),
113         BLOCK_PERIOD=150, # s
114         SYMBOL='tLTC',
115         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'),
116         BLOCK_EXPLORER_URL_PREFIX='http://nonexistent-litecoin-testnet-explorer/block/',
117         ADDRESS_EXPLORER_URL_PREFIX='http://nonexistent-litecoin-testnet-explorer/address/',
118         SANE_TARGET_RANGE=(2**256//1000000000 - 1, 2**256 - 1),
119     ),
120
121     terracoin=math.Object(
122         P2P_PREFIX='42babe56'.decode('hex'),
123         P2P_PORT=13333,
124         ADDRESS_VERSION=0,
125         RPC_PORT=13332,
126         RPC_CHECK=defer.inlineCallbacks(lambda bitcoind: defer.returnValue(
127             'terracoinaddress' in (yield bitcoind.rpc_help()) and
128             not (yield bitcoind.rpc_getinfo())['testnet']
129         )),
130         SUBSIDY_FUNC=lambda height: 20*100000000 >> (height + 1)//1050000,
131         POW_FUNC=data.hash256,
132         BLOCK_PERIOD=120, # s
133         SYMBOL='TRC',
134         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'),
135         BLOCK_EXPLORER_URL_PREFIX='http://cryptocoinexplorer.com:3750/block/',
136         ADDRESS_EXPLORER_URL_PREFIX='http://cryptocoinexplorer.com:3750/address/',
137         SANE_TARGET_RANGE=(2**256//2**32//1000 - 1, 2**256//2**32 - 1),
138     ),
139     terracoin_testnet=math.Object(
140         P2P_PREFIX='41babe56'.decode('hex'),
141         P2P_PORT=23333,
142         ADDRESS_VERSION=111,
143         RPC_PORT=23332,
144         RPC_CHECK=defer.inlineCallbacks(lambda bitcoind: defer.returnValue(
145             'terracoinaddress' in (yield bitcoind.rpc_help()) and
146             (yield bitcoind.rpc_getinfo())['testnet']
147         )),
148         SUBSIDY_FUNC=lambda height: 20*100000000 >> (height + 1)//1050000,
149         POW_FUNC=data.hash256,
150         BLOCK_PERIOD=120, # s
151         SYMBOL='tTRC',
152         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'),
153         BLOCK_EXPLORER_URL_PREFIX='http://cryptocoinexplorer.com:3750/testnet/block/',
154         ADDRESS_EXPLORER_URL_PREFIX='http://cryptocoinexplorer.com:3750/testnet/address/',
155         SANE_TARGET_RANGE=(2**256//2**32//1000 - 1, 2**256//2**32 - 1),
156     ),
157
158 )
159 for net_name, net in nets.iteritems():
160     net.NAME = net_name