X-Git-Url: https://git.novaco.in/?a=blobdiff_plain;f=p2pool%2Fbitcoin%2Fnetworks.py;h=88314704eb92127d2f5c6921f6c445f066366b66;hb=b68358960962d67623aa95e63c107695a856fab1;hp=ea53f05a0ef7cd5034e53b565fd17c4b8f457fc4;hpb=77e7e2a1b36ab71566d82e39568088d77109e4ce;p=p2pool.git diff --git a/p2pool/bitcoin/networks.py b/p2pool/bitcoin/networks.py index ea53f05..8831470 100644 --- a/p2pool/bitcoin/networks.py +++ b/p2pool/bitcoin/networks.py @@ -5,156 +5,66 @@ from twisted.internet import defer from . import data from p2pool.util import math, pack +from operator import * + +def get_subsidy(nCap, nMaxSubsidy, bnTarget): + bnLowerBound = 0.01 + bnUpperBound = bnSubsidyLimit = nMaxSubsidy + bnTargetLimit = 0x00000fffff000000000000000000000000000000000000000000000000000000 + + while bnLowerBound + 0.01 <= bnUpperBound: + bnMidValue = (bnLowerBound + bnUpperBound) / 2 + if pow(bnMidValue, nCap) * bnTargetLimit > pow(bnSubsidyLimit, nCap) * bnTarget: + bnUpperBound = bnMidValue + else: + bnLowerBound = bnMidValue + + nSubsidy = round(bnMidValue, 2) + + if nSubsidy > bnMidValue: + nSubsidy = nSubsidy - 0.01 + + return int(nSubsidy * 1000000) nets = dict( - bitcoin=math.Object( - P2P_PREFIX='f9beb4d9'.decode('hex'), - P2P_PORT=8333, - ADDRESS_VERSION=0, - RPC_PORT=8332, + novacoin=math.Object( + P2P_PREFIX='e4e8e9e5'.decode('hex'), + P2P_PORT=7777, + ADDRESS_VERSION=8, + RPC_PORT=8344, RPC_CHECK=defer.inlineCallbacks(lambda bitcoind: defer.returnValue( - 'bitcoinaddress' in (yield bitcoind.rpc_help()) and + 'novacoinaddress' in (yield bitcoind.rpc_help()) and not (yield bitcoind.rpc_getinfo())['testnet'] )), - SUBSIDY_FUNC=lambda height: 50*100000000 >> (height + 1)//210000, - POW_FUNC=data.hash256, - BLOCK_PERIOD=600, # s - SYMBOL='BTC', - 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'), - BLOCK_EXPLORER_URL_PREFIX='http://blockexplorer.com/block/', - ADDRESS_EXPLORER_URL_PREFIX='http://blockexplorer.com/address/', - SANE_TARGET_RANGE=(2**256//2**32//1000 - 1, 2**256//2**32 - 1), - ), - bitcoin_testnet=math.Object( - P2P_PREFIX='0b110907'.decode('hex'), - P2P_PORT=18333, - ADDRESS_VERSION=111, - RPC_PORT=18332, - RPC_CHECK=defer.inlineCallbacks(lambda bitcoind: defer.returnValue( - 'bitcoinaddress' in (yield bitcoind.rpc_help()) and - (yield bitcoind.rpc_getinfo())['testnet'] - )), - SUBSIDY_FUNC=lambda height: 50*100000000 >> (height + 1)//210000, - POW_FUNC=data.hash256, - BLOCK_PERIOD=600, # s - SYMBOL='tBTC', - 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'), - BLOCK_EXPLORER_URL_PREFIX='http://blockexplorer.com/testnet/block/', - ADDRESS_EXPLORER_URL_PREFIX='http://blockexplorer.com/testnet/address/', - SANE_TARGET_RANGE=(2**256//2**32//1000 - 1, 2**256//2**32 - 1), - ), - - namecoin=math.Object( - P2P_PREFIX='f9beb4fe'.decode('hex'), - P2P_PORT=8334, - ADDRESS_VERSION=52, - RPC_PORT=8332, - RPC_CHECK=defer.inlineCallbacks(lambda bitcoind: defer.returnValue( - 'namecoinaddress' in (yield bitcoind.rpc_help()) and - not (yield bitcoind.rpc_getinfo())['testnet'] - )), - SUBSIDY_FUNC=lambda height: 50*100000000 >> (height + 1)//210000, - POW_FUNC=data.hash256, - BLOCK_PERIOD=600, # s - SYMBOL='NMC', - 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'), - BLOCK_EXPLORER_URL_PREFIX='http://explorer.dot-bit.org/b/', - ADDRESS_EXPLORER_URL_PREFIX='http://explorer.dot-bit.org/a/', - SANE_TARGET_RANGE=(2**256//2**32 - 1, 2**256//2**32 - 1), - ), - namecoin_testnet=math.Object( - P2P_PREFIX='fabfb5fe'.decode('hex'), - P2P_PORT=18334, - ADDRESS_VERSION=111, - RPC_PORT=8332, - RPC_CHECK=defer.inlineCallbacks(lambda bitcoind: defer.returnValue( - 'namecoinaddress' in (yield bitcoind.rpc_help()) and - (yield bitcoind.rpc_getinfo())['testnet'] - )), - SUBSIDY_FUNC=lambda height: 50*100000000 >> (height + 1)//210000, - POW_FUNC=data.hash256, - BLOCK_PERIOD=600, # s - SYMBOL='tNMC', - 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'), - BLOCK_EXPLORER_URL_PREFIX='http://testnet.explorer.dot-bit.org/b/', - ADDRESS_EXPLORER_URL_PREFIX='http://testnet.explorer.dot-bit.org/a/', - SANE_TARGET_RANGE=(2**256//2**32 - 1, 2**256//2**32 - 1), - ), - - litecoin=math.Object( - P2P_PREFIX='fbc0b6db'.decode('hex'), - P2P_PORT=9333, - ADDRESS_VERSION=48, - RPC_PORT=9332, - RPC_CHECK=defer.inlineCallbacks(lambda bitcoind: defer.returnValue( - 'litecoinaddress' in (yield bitcoind.rpc_help()) and - not (yield bitcoind.rpc_getinfo())['testnet'] - )), - SUBSIDY_FUNC=lambda height: 50*100000000 >> (height + 1)//840000, + SUBSIDY_FUNC=lambda target: get_subsidy(6, 100, target), + BLOCKHASH_FUNC=lambda data: pack.IntType(256).unpack(__import__('ltc_scrypt').getPoWHash(data)), POW_FUNC=lambda data: pack.IntType(256).unpack(__import__('ltc_scrypt').getPoWHash(data)), - BLOCK_PERIOD=150, # s - SYMBOL='LTC', - 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'), - BLOCK_EXPLORER_URL_PREFIX='http://explorer.litecoin.net/block/', - ADDRESS_EXPLORER_URL_PREFIX='http://explorer.litecoin.net/address/', + BLOCK_PERIOD=600, # s + SYMBOL='NVC', + 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'), + BLOCK_EXPLORER_URL_PREFIX='http://novacoin.ru/block/', + ADDRESS_EXPLORER_URL_PREFIX='http://novacoin.ru/address/', SANE_TARGET_RANGE=(2**256//1000000000 - 1, 2**256//1000 - 1), ), - litecoin_testnet=math.Object( - P2P_PREFIX='fcc1b7dc'.decode('hex'), - P2P_PORT=19333, + novacoin_testnet=math.Object( + P2P_PREFIX='cdf2c0ef'.decode('hex'), + P2P_PORT=17777, ADDRESS_VERSION=111, - RPC_PORT=19332, + RPC_PORT=8344, RPC_CHECK=defer.inlineCallbacks(lambda bitcoind: defer.returnValue( - 'litecoinaddress' in (yield bitcoind.rpc_help()) and + 'novacoinaddress' in (yield bitcoind.rpc_help()) and (yield bitcoind.rpc_getinfo())['testnet'] )), - SUBSIDY_FUNC=lambda height: 50*100000000 >> (height + 1)//840000, + SUBSIDY_FUNC=lambda target: get_subsidy(6, 100, target), + BLOCKHASH_FUNC=lambda data: pack.IntType(256).unpack(__import__('ltc_scrypt').getPoWHash(data)), POW_FUNC=lambda data: pack.IntType(256).unpack(__import__('ltc_scrypt').getPoWHash(data)), - BLOCK_PERIOD=150, # s - SYMBOL='tLTC', - 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'), - BLOCK_EXPLORER_URL_PREFIX='http://nonexistent-litecoin-testnet-explorer/block/', - ADDRESS_EXPLORER_URL_PREFIX='http://nonexistent-litecoin-testnet-explorer/address/', - SANE_TARGET_RANGE=(2**256//1000000000 - 1, 2**256 - 1), - ), - - terracoin=math.Object( - P2P_PREFIX='42babe56'.decode('hex'), - P2P_PORT=13333, - ADDRESS_VERSION=0, - RPC_PORT=13332, - RPC_CHECK=defer.inlineCallbacks(lambda bitcoind: defer.returnValue( - 'terracoinaddress' in (yield bitcoind.rpc_help()) and - not (yield bitcoind.rpc_getinfo())['testnet'] - )), - SUBSIDY_FUNC=lambda height: 20*100000000 >> (height + 1)//1050000, - POW_FUNC=data.hash256, - BLOCK_PERIOD=120, # s - SYMBOL='TRC', - 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'), - BLOCK_EXPLORER_URL_PREFIX='http://cryptocoinexplorer.com:3750/block/', - ADDRESS_EXPLORER_URL_PREFIX='http://cryptocoinexplorer.com:3750/address/', - SANE_TARGET_RANGE=(2**256//2**32//1000 - 1, 2**256//2**32 - 1), - ), - terracoin_testnet=math.Object( - P2P_PREFIX='41babe56'.decode('hex'), - P2P_PORT=23333, - ADDRESS_VERSION=111, - RPC_PORT=23332, - RPC_CHECK=defer.inlineCallbacks(lambda bitcoind: defer.returnValue( - 'terracoinaddress' in (yield bitcoind.rpc_help()) and - (yield bitcoind.rpc_getinfo())['testnet'] - )), - SUBSIDY_FUNC=lambda height: 20*100000000 >> (height + 1)//1050000, - POW_FUNC=data.hash256, - BLOCK_PERIOD=120, # s - SYMBOL='tTRC', - 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'), - BLOCK_EXPLORER_URL_PREFIX='http://cryptocoinexplorer.com:3750/testnet/block/', - ADDRESS_EXPLORER_URL_PREFIX='http://cryptocoinexplorer.com:3750/testnet/address/', - SANE_TARGET_RANGE=(2**256//2**32//1000 - 1, 2**256//2**32 - 1), + BLOCK_PERIOD=600, # s + SYMBOL='tNVC', + 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'), + BLOCK_EXPLORER_URL_PREFIX='http://nonexistent-novacoin-testnet-explorer/block/', + ADDRESS_EXPLORER_URL_PREFIX='http://nonexistent-novacoin-testnet-explorer/address/', + SANE_TARGET_RANGE=(2**256//1000000000 - 1, 2**256//1000 - 1), ), - ) for net_name, net in nets.iteritems(): net.NAME = net_name