Add timestamp offset for block header
[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 @defer.inlineCallbacks
19 def get_subsidy(bitcoind, target):
20     res = yield bitcoind.rpc_getblock(target)
21
22     defer.returnValue(res)
23
24 nets = dict(
25     novacoin=math.Object(
26         P2P_PREFIX='e4e8e9e5'.decode('hex'),
27         P2P_PORT=7777,
28         ADDRESS_VERSION=8,
29         RPC_PORT=8344,
30         RPC_CHECK=defer.inlineCallbacks(lambda bitcoind: defer.returnValue(
31             0 == (yield bitcoind.rpc_getblock('00000a060336cbb72fe969666d337b87198b1add2abaa59cca226820b32933a4'))['height'] and
32             not (yield bitcoind.rpc_getinfo())['testnet']
33         )),
34         SUBSIDY_FUNC=lambda bitcoind, target: get_subsidy(bitcoind, target),
35         BLOCK_PERIOD=600, # s
36         SYMBOL='NVC',
37         CONF_FILE_FUNC=lambda: os.path.join(os.path.join(os.environ['APPDATA'], 'NovaCoin') if platform.system() == 'Windows' else os.path.expanduser('~/Library/Application Support/NovaCoin/') if platform.system() == 'Darwin' else os.path.expanduser('~/.novacoin'), 'novacoin.conf'),
38         BLOCK_EXPLORER_URL_PREFIX='http://explorer.novaco.in/block/',
39         ADDRESS_EXPLORER_URL_PREFIX='http://explorer.novaco.in/address/',
40         TX_EXPLORER_URL_PREFIX='http://explorer.novaco.in/tx/',
41         SANE_TARGET_RANGE=(2**256//1000000000 - 1, 2**256//1000 - 1),
42         DUMB_SCRYPT_DIFF=2**16,
43         DUST_THRESHOLD=0.01e6,
44     ),
45     novacoin_testnet=math.Object(
46         P2P_PREFIX='cdf2c0ef'.decode('hex'),
47         P2P_PORT=17777,
48         ADDRESS_VERSION=111,
49         RPC_PORT=18344,
50         RPC_CHECK=defer.inlineCallbacks(lambda bitcoind: defer.returnValue(
51             0 == (yield bitcoind.rpc_getblock('0000c763e402f2436da9ed36c7286f62c3f6e5dbafce9ff289bd43d7459327eb'))['height'] and
52             (yield bitcoind.rpc_getinfo())['testnet']
53         )),
54         SUBSIDY_FUNC=lambda bitcoind, target: get_subsidy(bitcoind, target),
55         BLOCK_PERIOD=600, # s
56         SYMBOL='tNVC',
57         CONF_FILE_FUNC=lambda: os.path.join(os.path.join(os.environ['APPDATA'], 'NovaCoin') if platform.system() == 'Windows' else os.path.expanduser('~/Library/Application Support/NovaCoin/') if platform.system() == 'Darwin' else os.path.expanduser('~/.novacoin'), 'novacoin.conf'),
58         BLOCK_EXPLORER_URL_PREFIX='http://novacoin.su/block/',
59         ADDRESS_EXPLORER_URL_PREFIX='http://novacoin.su/address/',
60         TX_EXPLORER_URL_PREFIX='http://novacoin.su/tx/',
61         SANE_TARGET_RANGE=(2**256//1000000000 - 1, 2**256//1000 - 1),
62         DUMB_SCRYPT_DIFF=2**16,
63         DUST_THRESHOLD=0.01e6,
64     ),
65 )
66 for net_name, net in nets.iteritems():
67     net.NAME = net_name