88314704eb92127d2f5c6921f6c445f066366b66
[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 from operator import *
9
10 def get_subsidy(nCap, nMaxSubsidy, bnTarget):
11     bnLowerBound = 0.01
12     bnUpperBound = bnSubsidyLimit = nMaxSubsidy
13     bnTargetLimit = 0x00000fffff000000000000000000000000000000000000000000000000000000
14
15     while bnLowerBound + 0.01 <= bnUpperBound:
16         bnMidValue = (bnLowerBound + bnUpperBound) / 2
17         if pow(bnMidValue, nCap) * bnTargetLimit > pow(bnSubsidyLimit, nCap) * bnTarget:
18             bnUpperBound = bnMidValue
19         else:
20             bnLowerBound = bnMidValue
21
22     nSubsidy = round(bnMidValue, 2)
23
24     if nSubsidy > bnMidValue:
25         nSubsidy = nSubsidy - 0.01
26
27     return int(nSubsidy * 1000000)
28
29 nets = dict(
30     novacoin=math.Object(
31         P2P_PREFIX='e4e8e9e5'.decode('hex'),
32         P2P_PORT=7777,
33         ADDRESS_VERSION=8,
34         RPC_PORT=8344,
35         RPC_CHECK=defer.inlineCallbacks(lambda bitcoind: defer.returnValue(
36             'novacoinaddress' in (yield bitcoind.rpc_help()) and
37             not (yield bitcoind.rpc_getinfo())['testnet']
38         )),
39         SUBSIDY_FUNC=lambda target: get_subsidy(6, 100, target),
40         BLOCKHASH_FUNC=lambda data: pack.IntType(256).unpack(__import__('ltc_scrypt').getPoWHash(data)),
41         POW_FUNC=lambda data: pack.IntType(256).unpack(__import__('ltc_scrypt').getPoWHash(data)),
42         BLOCK_PERIOD=600, # s
43         SYMBOL='NVC',
44         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'),
45         BLOCK_EXPLORER_URL_PREFIX='http://novacoin.ru/block/',
46         ADDRESS_EXPLORER_URL_PREFIX='http://novacoin.ru/address/',
47         SANE_TARGET_RANGE=(2**256//1000000000 - 1, 2**256//1000 - 1),
48     ),
49     novacoin_testnet=math.Object(
50         P2P_PREFIX='cdf2c0ef'.decode('hex'),
51         P2P_PORT=17777,
52         ADDRESS_VERSION=111,
53         RPC_PORT=8344,
54         RPC_CHECK=defer.inlineCallbacks(lambda bitcoind: defer.returnValue(
55             'novacoinaddress' in (yield bitcoind.rpc_help()) and
56             (yield bitcoind.rpc_getinfo())['testnet']
57         )),
58         SUBSIDY_FUNC=lambda target: get_subsidy(6, 100, target),
59         BLOCKHASH_FUNC=lambda data: pack.IntType(256).unpack(__import__('ltc_scrypt').getPoWHash(data)),
60         POW_FUNC=lambda data: pack.IntType(256).unpack(__import__('ltc_scrypt').getPoWHash(data)),
61         BLOCK_PERIOD=600, # s
62         SYMBOL='tNVC',
63         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'),
64         BLOCK_EXPLORER_URL_PREFIX='http://nonexistent-novacoin-testnet-explorer/block/',
65         ADDRESS_EXPLORER_URL_PREFIX='http://nonexistent-novacoin-testnet-explorer/address/',
66         SANE_TARGET_RANGE=(2**256//1000000000 - 1, 2**256//1000 - 1),
67     ),
68 )
69 for net_name, net in nets.iteritems():
70     net.NAME = net_name