from . import data
from p2pool.util import math, pack
-BitcoinMainnet = math.Object(
- P2P_PREFIX='f9beb4d9'.decode('hex'),
- P2P_PORT=8333,
- ADDRESS_VERSION=0,
- RPC_PORT=8332,
- RPC_CHECK=defer.inlineCallbacks(lambda bitcoind: defer.returnValue(
- 'bitcoinaddress' in (yield bitcoind.rpc_help()) and
- not (yield bitcoind.rpc_getinfo())['testnet']
- )),
- POW_FUNC=data.hash256,
- 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'),
-)
-BitcoinTestnet = math.Object(
- P2P_PREFIX='fabfb5da'.decode('hex'),
- P2P_PORT=18333,
- ADDRESS_VERSION=111,
- RPC_PORT=8332,
- RPC_CHECK=defer.inlineCallbacks(lambda bitcoind: defer.returnValue(
- 'bitcoinaddress' in (yield bitcoind.rpc_help()) and
- (yield bitcoind.rpc_getinfo())['testnet']
- )),
- POW_FUNC=data.hash256,
- SYMBOL='tBTC',
- CONF_FILE_FUNC=BitcoinMainnet.CONF_FILE_FUNC,
-)
-
-NamecoinMainnet = 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']
- )),
- POW_FUNC=data.hash256,
- 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'),
-)
-NamecoinTestnet = 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']
- )),
- POW_FUNC=data.hash256,
- SYMBOL='tNMC',
- CONF_FILE_FUNC=NamecoinMainnet.CONF_FILE_FUNC,
-)
-
-LitecoinMainnet = 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']
- )),
- POW_FUNC=lambda data: pack.IntType(256).unpack(__import__('ltc_scrypt').getPoWHash(data)),
- 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'),
-)
-LitecoinTestnet = math.Object(
- P2P_PREFIX='fcc1b7dc'.decode('hex'),
- P2P_PORT=19333,
- ADDRESS_VERSION=111,
- RPC_PORT=19332,
- RPC_CHECK=defer.inlineCallbacks(lambda bitcoind: defer.returnValue(
- 'litecoinaddress' in (yield bitcoind.rpc_help()) and
- (yield bitcoind.rpc_getinfo())['testnet']
- )),
- POW_FUNC=lambda data: pack.IntType(256).unpack(__import__('ltc_scrypt').getPoWHash(data)),
- SYMBOL='tLTC',
- CONF_FILE_FUNC=LitecoinMainnet.CONF_FILE_FUNC,
+nets = dict(
+ bitcoin=math.Object(
+ P2P_PREFIX='f9beb4d9'.decode('hex'),
+ P2P_PORT=8333,
+ ADDRESS_VERSION=0,
+ RPC_PORT=8332,
+ RPC_CHECK=defer.inlineCallbacks(lambda bitcoind: defer.returnValue(
+ 'bitcoinaddress' in (yield bitcoind.rpc_help()) and
+ not (yield bitcoind.rpc_getinfo())['testnet']
+ )),
+ POW_FUNC=data.hash256,
+ 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'),
+ ),
+ bitcoin_testnet=math.Object(
+ P2P_PREFIX='fabfb5da'.decode('hex'),
+ P2P_PORT=18333,
+ ADDRESS_VERSION=111,
+ RPC_PORT=8332,
+ RPC_CHECK=defer.inlineCallbacks(lambda bitcoind: defer.returnValue(
+ 'bitcoinaddress' in (yield bitcoind.rpc_help()) and
+ (yield bitcoind.rpc_getinfo())['testnet']
+ )),
+ POW_FUNC=data.hash256,
+ 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'),
+ ),
+
+ nameecoin=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']
+ )),
+ POW_FUNC=data.hash256,
+ 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'),
+ ),
+ 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']
+ )),
+ POW_FUNC=data.hash256,
+ 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'),
+ ),
+
+ 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']
+ )),
+ POW_FUNC=lambda data: pack.IntType(256).unpack(__import__('ltc_scrypt').getPoWHash(data)),
+ 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'),
+ ),
+ litecoin_testnet=math.Object(
+ P2P_PREFIX='fcc1b7dc'.decode('hex'),
+ P2P_PORT=19333,
+ ADDRESS_VERSION=111,
+ RPC_PORT=19332,
+ RPC_CHECK=defer.inlineCallbacks(lambda bitcoind: defer.returnValue(
+ 'litecoinaddress' in (yield bitcoind.rpc_help()) and
+ (yield bitcoind.rpc_getinfo())['testnet']
+ )),
+ POW_FUNC=lambda data: pack.IntType(256).unpack(__import__('ltc_scrypt').getPoWHash(data)),
+ 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'),
+ ),
)
def convert_arg_line_to_args(self, arg_line):
return [arg for arg in arg_line.split() if arg.strip()]
+
+ realnets=dict((name, net) for name, net in networks.nets.iteritems() if '_testnet' not in name)
+
parser = FixedArgumentParser(description='p2pool (version %s)' % (p2pool.__version__,), fromfile_prefix_chars='@')
parser.add_argument('--version', action='version', version=p2pool.__version__)
parser.add_argument('--net',
help='use specified network (default: bitcoin)',
- action='store', choices=sorted(networks.realnets), default='bitcoin', dest='net_name')
+ action='store', choices=sorted(realnets), default='bitcoin', dest='net_name')
parser.add_argument('--testnet',
help='''use the network's testnet''',
action='store_const', const=True, default=False, dest='testnet')
p2pool_group = parser.add_argument_group('p2pool interface')
p2pool_group.add_argument('--p2pool-port', metavar='PORT',
- help='use port PORT to listen for connections (forward this port from your router!) (default: %s)' % ', '.join('%s:%i' % (n.NAME, n.P2P_PORT) for _, n in sorted(networks.realnets.items())),
+ help='use port PORT to listen for connections (forward this port from your router!) (default: %s)' % ', '.join('%s:%i' % (name, net.P2P_PORT) for name, net in sorted(realnets.items())),
type=int, action='store', default=None, dest='p2pool_port')
p2pool_group.add_argument('-n', '--p2pool-node', metavar='ADDR[:PORT]',
help='connect to existing p2pool node at ADDR listening on port PORT (defaults to default p2pool P2P port) in addition to builtin addresses',
worker_group = parser.add_argument_group('worker interface')
worker_group.add_argument('-w', '--worker-port', metavar='PORT',
- help='listen on PORT for RPC connections from miners (default: %s)' % ', '.join('%s:%i' % (n.NAME, n.WORKER_PORT) for _, n in sorted(networks.realnets.items())),
+ help='listen on PORT for RPC connections from miners (default: %s)' % ', '.join('%s:%i' % (name, net.WORKER_PORT) for name, net in sorted(realnets.items())),
type=int, action='store', default=None, dest='worker_port')
worker_group.add_argument('-f', '--fee', metavar='FEE_PERCENTAGE',
help='''charge workers mining to their own bitcoin address (by setting their miner's username to a bitcoin address) this percentage fee to mine on your p2pool instance. Amount displayed at http://127.0.0.1:WORKER_PORT/fee (default: 0)''',
help='connect to this address (default: 127.0.0.1)',
type=str, action='store', default='127.0.0.1', dest='bitcoind_address')
bitcoind_group.add_argument('--bitcoind-rpc-port', metavar='BITCOIND_RPC_PORT',
- help='''connect to JSON-RPC interface at this port (default: %s <read from bitcoin.conf if password not provided>)''' % ', '.join('%s:%i' % (n.NAME, n.PARENT.RPC_PORT) for _, n in sorted(networks.realnets.items())),
+ help='''connect to JSON-RPC interface at this port (default: %s <read from bitcoin.conf if password not provided>)''' % ', '.join('%s:%i' % (name, net.PARENT.RPC_PORT) for name, net in sorted(realnets.items())),
type=int, action='store', default=None, dest='bitcoind_rpc_port')
bitcoind_group.add_argument('--bitcoind-p2p-port', metavar='BITCOIND_P2P_PORT',
- help='''connect to P2P interface at this port (default: %s <read from bitcoin.conf if password not provided>)''' % ', '.join('%s:%i' % (n.NAME, n.PARENT.P2P_PORT) for _, n in sorted(networks.realnets.items())),
+ help='''connect to P2P interface at this port (default: %s <read from bitcoin.conf if password not provided>)''' % ', '.join('%s:%i' % (name, net.PARENT.P2P_PORT) for name, net in sorted(realnets.items())),
type=int, action='store', default=None, dest='bitcoind_p2p_port')
bitcoind_group.add_argument(metavar='BITCOIND_RPCUSERPASS',
if args.debug:
p2pool.DEBUG = True
- net = networks.nets[args.net_name + ('_testnet' if args.testnet else '')]
+ net_name = args.net_name + ('_testnet' if args.testnet else '')
+ net = networks.nets[net_name]
- datadir_path = os.path.join(os.path.dirname(sys.argv[0]), 'data', net.NAME)
+ datadir_path = os.path.join(os.path.dirname(sys.argv[0]), 'data', net_name)
if not os.path.exists(datadir_path):
os.makedirs(datadir_path)
# REAL_CHAIN_LENGTH must be changed in sync with all other clients
# changes can be done by changing one, then the other
-BitcoinMainnet = math.Object(
- PARENT=networks.BitcoinMainnet,
- SHARE_PERIOD=10, # seconds
- CHAIN_LENGTH=24*60*60//10, # shares
- REAL_CHAIN_LENGTH=24*60*60//10, # shares
- TARGET_LOOKBEHIND=200, # shares
- SPREAD=3, # blocks
- IDENTIFIER='fc70035c7a81bc6f'.decode('hex'),
- PREFIX='2472ef181efcd37b'.decode('hex'),
- NAME='bitcoin',
- P2P_PORT=9333,
- MAX_TARGET=2**256//2**32 - 1,
- PERSIST=True,
- WORKER_PORT=9332,
- BOOTSTRAP_ADDRS='74.220.242.6:9334 93.97.192.93 66.90.73.83 67.83.108.0 219.84.64.174 24.167.17.248 109.74.195.142 83.211.86.49 89.78.212.44 94.23.34.145 168.7.116.243 72.14.191.28 94.174.40.189:9344'.split(' '),
+nets = dict(
+ bitcoin=math.Object(
+ PARENT=networks.nets['bitcoin'],
+ SHARE_PERIOD=10, # seconds
+ CHAIN_LENGTH=24*60*60//10, # shares
+ REAL_CHAIN_LENGTH=24*60*60//10, # shares
+ TARGET_LOOKBEHIND=200, # shares
+ SPREAD=3, # blocks
+ IDENTIFIER='fc70035c7a81bc6f'.decode('hex'),
+ PREFIX='2472ef181efcd37b'.decode('hex'),
+ P2P_PORT=9333,
+ MAX_TARGET=2**256//2**32 - 1,
+ PERSIST=True,
+ WORKER_PORT=9332,
+ BOOTSTRAP_ADDRS='74.220.242.6:9334 93.97.192.93 66.90.73.83 67.83.108.0 219.84.64.174 24.167.17.248 109.74.195.142 83.211.86.49 89.78.212.44 94.23.34.145 168.7.116.243 72.14.191.28 94.174.40.189:9344'.split(' '),
+ ),
+ bitcoin_testnet=math.Object(
+ PARENT=networks.nets['bitcoin_testnet'],
+ SHARE_PERIOD=10, # seconds
+ CHAIN_LENGTH=24*60*60//10, # shares
+ REAL_CHAIN_LENGTH=24*60*60//10, # shares
+ TARGET_LOOKBEHIND=200, # shares
+ SPREAD=3, # blocks
+ IDENTIFIER='5fc2be2d4f0d6bfb'.decode('hex'),
+ PREFIX='3f6057a15036f441'.decode('hex'),
+ P2P_PORT=19333,
+ MAX_TARGET=2**256//2**32 - 1,
+ PERSIST=False,
+ WORKER_PORT=19332,
+ BOOTSTRAP_ADDRS='72.14.191.28'.split(' '),
+ ),
+
+ litecoin=math.Object(
+ PARENT=networks.nets['litecoin'],
+ SHARE_PERIOD=10, # seconds
+ CHAIN_LENGTH=24*60*60//10, # shares
+ REAL_CHAIN_LENGTH=24*60*60//10, # shares
+ TARGET_LOOKBEHIND=200, # shares
+ SPREAD=12, # blocks
+ IDENTIFIER='e037d5b8c6923410'.decode('hex'),
+ PREFIX='7208c1a53ef629b0'.decode('hex'),
+ P2P_PORT=9338,
+ MAX_TARGET=2**256//2**20 - 1,
+ PERSIST=True,
+ WORKER_PORT=9327,
+ BOOTSTRAP_ADDRS='76.26.53.101 124.205.120.178 190.195.79.161 173.167.113.73 82.161.65.210 67.83.108.0 78.101.67.239 78.100.161.252 87.58.117.233 78.100.162.223 216.239.45.4 78.101.131.221 72.14.191.28 97.81.163.217 69.126.183.240 219.84.64.174 78.101.119.27 89.211.228.244 178.152.122.30 172.16.0.3 76.26.53.101:51319'.split(' '),
+ ),
+ litecoin_testnet=math.Object(
+ PARENT=networks.nets['litecoin_testnet'],
+ SHARE_PERIOD=10, # seconds
+ CHAIN_LENGTH=24*60*60//10, # shares
+ REAL_CHAIN_LENGTH=24*60*60//10, # shares
+ TARGET_LOOKBEHIND=200, # shares
+ SPREAD=12, # blocks
+ IDENTIFIER='cca5e24ec6408b1e'.decode('hex'),
+ PREFIX='ad9614f6466a39cf'.decode('hex'),
+ P2P_PORT=19338,
+ MAX_TARGET=2**256//2**17 - 1,
+ PERSIST=False,
+ WORKER_PORT=19327,
+ BOOTSTRAP_ADDRS='72.14.191.28'.split(' '),
+ ),
)
-BitcoinTestnet = math.Object(
- PARENT=networks.BitcoinTestnet,
- SHARE_PERIOD=10, # seconds
- CHAIN_LENGTH=24*60*60//10, # shares
- REAL_CHAIN_LENGTH=24*60*60//10, # shares
- TARGET_LOOKBEHIND=200, # shares
- SPREAD=3, # blocks
- IDENTIFIER='5fc2be2d4f0d6bfb'.decode('hex'),
- PREFIX='3f6057a15036f441'.decode('hex'),
- NAME='bitcoin_testnet',
- P2P_PORT=19333,
- MAX_TARGET=2**256//2**32 - 1,
- PERSIST=False,
- WORKER_PORT=19332,
- BOOTSTRAP_ADDRS='72.14.191.28'.split(' '),
-)
-
-LitecoinMainnet = math.Object(
- PARENT=networks.LitecoinMainnet,
- SHARE_PERIOD=10, # seconds
- CHAIN_LENGTH=24*60*60//10, # shares
- REAL_CHAIN_LENGTH=24*60*60//10, # shares
- TARGET_LOOKBEHIND=200, # shares
- SPREAD=12, # blocks
- IDENTIFIER='e037d5b8c6923410'.decode('hex'),
- PREFIX='7208c1a53ef629b0'.decode('hex'),
- NAME='litecoin',
- P2P_PORT=9338,
- MAX_TARGET=2**256//2**20 - 1,
- PERSIST=True,
- WORKER_PORT=9327,
- BOOTSTRAP_ADDRS='76.26.53.101 124.205.120.178 190.195.79.161 173.167.113.73 82.161.65.210 67.83.108.0 78.101.67.239 78.100.161.252 87.58.117.233 78.100.162.223 216.239.45.4 78.101.131.221 72.14.191.28 97.81.163.217 69.126.183.240 219.84.64.174 78.101.119.27 89.211.228.244 178.152.122.30 172.16.0.3 76.26.53.101:51319'.split(' '),
-)
-LitecoinTestnet = math.Object(
- PARENT=networks.LitecoinTestnet,
- SHARE_PERIOD=10, # seconds
- CHAIN_LENGTH=24*60*60//10, # shares
- REAL_CHAIN_LENGTH=24*60*60//10, # shares
- TARGET_LOOKBEHIND=200, # shares
- SPREAD=12, # blocks
- IDENTIFIER='cca5e24ec6408b1e'.decode('hex'),
- PREFIX='ad9614f6466a39cf'.decode('hex'),
- NAME='litecoin_testnet',
- P2P_PORT=19338,
- MAX_TARGET=2**256//2**17 - 1,
- PERSIST=False,
- WORKER_PORT=19327,
- BOOTSTRAP_ADDRS='72.14.191.28'.split(' '),
-)
-
-nets=dict((net.NAME, net) for net in set([BitcoinMainnet, BitcoinTestnet, LitecoinMainnet, LitecoinTestnet]))
-realnets=dict((net.NAME, net) for net in nets.itervalues() if '_testnet' not in net.NAME)
))) == 0x000000000000003aaaf7638f9f9c0d0c60e8b0eb817dcdb55fd2b1964efc5175
def test_header_hash_litecoin(self):
- assert networks.LitecoinMainnet.POW_FUNC(data.block_header_type.pack(dict(
+ assert networks.nets['litecoin'].POW_FUNC(data.block_header_type.pack(dict(
version=1,
previous_block=0xd928d3066613d1c9dd424d5810cdd21bfeef3c698977e81ec1640e1084950073,
merkle_root=0x03f4b646b58a66594a182b02e425e7b3a93c8a52b600aa468f1bc5549f395f16,
))) == 0xb53802b2333e828d6532059f46ecf6b313a42d79f97925e457fbbfda45367e5c
def test_address_to_pubkey_hash(self):
- assert data.address_to_pubkey_hash('1KUCp7YP5FP8ViRxhfszSUJCTAajK6viGy', networks.BitcoinMainnet) == pack.IntType(160).unpack('ca975b00a8c203b8692f5a18d92dc5c2d2ebc57b'.decode('hex'))
+ assert data.address_to_pubkey_hash('1KUCp7YP5FP8ViRxhfszSUJCTAajK6viGy', networks.nets['bitcoin']) == pack.IntType(160).unpack('ca975b00a8c203b8692f5a18d92dc5c2d2ebc57b'.decode('hex'))
def test_merkle_hash(self):
assert data.merkle_hash([