pubkey_type = FixedStrType(65)
def pubkey_hash_to_address(pubkey_hash, net):
- return human_address_type.pack_base58(dict(version=net.BITCOIN_ADDRESS_VERSION, pubkey_hash=pubkey_hash))
+ return human_address_type.pack_base58(dict(version=net.ADDRESS_VERSION, pubkey_hash=pubkey_hash))
def pubkey_to_address(pubkey, net):
return pubkey_hash_to_address(pubkey_type.hash160(pubkey), net)
def address_to_pubkey_hash(address, net):
x = human_address_type.unpack_base58(address)
- if x['version'] != net.BITCOIN_ADDRESS_VERSION:
+ if x['version'] != net.ADDRESS_VERSION:
raise ValueError('address not for this net!')
return x['pubkey_hash']
class BitcoinMainnet(object):
- BITCOIN_P2P_PREFIX = 'f9beb4d9'.decode('hex')
- BITCOIN_P2P_PORT = 8333
- BITCOIN_ADDRESS_VERSION = 0
- BITCOIN_RPC_PORT = 8332
- BITCOIN_RPC_CHECK = staticmethod(defer.inlineCallbacks(lambda bitcoind: defer.returnValue(
+ P2P_PREFIX = 'f9beb4d9'.decode('hex')
+ P2P_PORT = 8333
+ ADDRESS_VERSION = 0
+ RPC_PORT = 8332
+ RPC_CHECK = staticmethod(defer.inlineCallbacks(lambda bitcoind: defer.returnValue(
'bitcoinaddress' in (yield bitcoind.rpc_help()) and
not (yield bitcoind.rpc_getinfo())['testnet']
)))
- BITCOIN_SUBSIDY_FUNC = staticmethod(lambda height: 50*100000000 >> (height + 1)//210000)
- BITCOIN_POW_FUNC = data.block_header_type.hash256
- BITCOIN_SYMBOL = 'BTC'
+ SUBSIDY_FUNC = staticmethod(lambda height: 50*100000000 >> (height + 1)//210000)
+ POW_FUNC = data.block_header_type.hash256
+ SYMBOL = 'BTC'
class BitcoinTestnet(object):
- BITCOIN_P2P_PREFIX = 'fabfb5da'.decode('hex')
- BITCOIN_P2P_PORT = 18333
- BITCOIN_ADDRESS_VERSION = 111
- BITCOIN_RPC_PORT = 8332
- BITCOIN_RPC_CHECK = staticmethod(defer.inlineCallbacks(lambda bitcoind: defer.returnValue(
+ P2P_PREFIX = 'fabfb5da'.decode('hex')
+ P2P_PORT = 18333
+ ADDRESS_VERSION = 111
+ RPC_PORT = 8332
+ RPC_CHECK = staticmethod(defer.inlineCallbacks(lambda bitcoind: defer.returnValue(
'bitcoinaddress' in (yield bitcoind.rpc_help()) and
(yield bitcoind.rpc_getinfo())['testnet']
)))
- BITCOIN_SUBSIDY_FUNC = staticmethod(lambda height: 50*100000000 >> (height + 1)//210000)
- BITCOIN_POW_FUNC = data.block_header_type.hash256
- BITCOIN_SYMBOL = 'tBTC'
+ SUBSIDY_FUNC = staticmethod(lambda height: 50*100000000 >> (height + 1)//210000)
+ POW_FUNC = data.block_header_type.hash256
+ SYMBOL = 'tBTC'
class NamecoinMainnet(object):
- BITCOIN_P2P_PREFIX = 'f9beb4fe'.decode('hex')
- BITCOIN_P2P_PORT = 8334
- BITCOIN_ADDRESS_VERSION = 52
- BITCOIN_RPC_PORT = 8332
- BITCOIN_RPC_CHECK = staticmethod(defer.inlineCallbacks(lambda bitcoind: defer.returnValue(
+ P2P_PREFIX = 'f9beb4fe'.decode('hex')
+ P2P_PORT = 8334
+ ADDRESS_VERSION = 52
+ RPC_PORT = 8332
+ RPC_CHECK = staticmethod(defer.inlineCallbacks(lambda bitcoind: defer.returnValue(
'namecoinaddress' in (yield bitcoind.rpc_help()) and
not (yield bitcoind.rpc_getinfo())['testnet']
)))
- BITCOIN_SUBSIDY_FUNC = staticmethod(lambda height: 50*100000000 >> (height + 1)//210000)
- BITCOIN_POW_FUNC = data.block_header_type.hash256
- BITCOIN_SYMBOL = 'NMC'
+ SUBSIDY_FUNC = staticmethod(lambda height: 50*100000000 >> (height + 1)//210000)
+ POW_FUNC = data.block_header_type.hash256
+ SYMBOL = 'NMC'
class NamecoinTestnet(object):
- BITCOIN_P2P_PREFIX = 'fabfb5fe'.decode('hex')
- BITCOIN_P2P_PORT = 18334
- BITCOIN_ADDRESS_VERSION = 111
- BITCOIN_RPC_PORT = 8332
- BITCOIN_RPC_CHECK = staticmethod(defer.inlineCallbacks(lambda bitcoind: defer.returnValue(
+ P2P_PREFIX = 'fabfb5fe'.decode('hex')
+ P2P_PORT = 18334
+ ADDRESS_VERSION = 111
+ RPC_PORT = 8332
+ RPC_CHECK = staticmethod(defer.inlineCallbacks(lambda bitcoind: defer.returnValue(
'namecoinaddress' in (yield bitcoind.rpc_help()) and
(yield bitcoind.rpc_getinfo())['testnet']
)))
- BITCOIN_SUBSIDY_FUNC = staticmethod(lambda height: 50*100000000 >> (height + 1)//210000)
- BITCOIN_POW_FUNC = data.block_header_type.hash256
- BITCOIN_SYMBOL = 'tNMC'
+ SUBSIDY_FUNC = staticmethod(lambda height: 50*100000000 >> (height + 1)//210000)
+ POW_FUNC = data.block_header_type.hash256
+ SYMBOL = 'tNMC'
class LitecoinMainnet(object):
- BITCOIN_P2P_PREFIX = 'fbc0b6db'.decode('hex')
- BITCOIN_P2P_PORT = 9333
- BITCOIN_ADDRESS_VERSION = 48
- BITCOIN_RPC_PORT = 9332
- BITCOIN_RPC_CHECK = staticmethod(defer.inlineCallbacks(lambda bitcoind: defer.returnValue(
+ P2P_PREFIX = 'fbc0b6db'.decode('hex')
+ P2P_PORT = 9333
+ ADDRESS_VERSION = 48
+ RPC_PORT = 9332
+ RPC_CHECK = staticmethod(defer.inlineCallbacks(lambda bitcoind: defer.returnValue(
'litecoinaddress' in (yield bitcoind.rpc_help()) and
not (yield bitcoind.rpc_getinfo())['testnet']
)))
- BITCOIN_SUBSIDY_FUNC = staticmethod(lambda height: 50*100000000 >> (height + 1)//840000)
- BITCOIN_POW_FUNC = data.block_header_type.scrypt
- BITCOIN_SYMBOL = 'LTC'
+ SUBSIDY_FUNC = staticmethod(lambda height: 50*100000000 >> (height + 1)//840000)
+ POW_FUNC = data.block_header_type.scrypt
+ SYMBOL = 'LTC'
class LitecoinTestnet(object):
- BITCOIN_P2P_PREFIX = 'fcc1b7dc'.decode('hex')
- BITCOIN_P2P_PORT = 19333
- BITCOIN_ADDRESS_VERSION = 111
- BITCOIN_RPC_PORT = 19332
- BITCOIN_RPC_CHECK = staticmethod(defer.inlineCallbacks(lambda bitcoind: defer.returnValue(
+ P2P_PREFIX = 'fcc1b7dc'.decode('hex')
+ P2P_PORT = 19333
+ ADDRESS_VERSION = 111
+ RPC_PORT = 19332
+ RPC_CHECK = staticmethod(defer.inlineCallbacks(lambda bitcoind: defer.returnValue(
'litecoinaddress' in (yield bitcoind.rpc_help()) and
(yield bitcoind.rpc_getinfo())['testnet']
)))
- BITCOIN_SUBSIDY_FUNC = staticmethod(lambda height: 50*100000000 >> (height + 1)//840000)
- BITCOIN_POW_FUNC = data.block_header_type.scrypt
- BITCOIN_SYMBOL = 'tLTC'
+ SUBSIDY_FUNC = staticmethod(lambda height: 50*100000000 >> (height + 1)//840000)
+ POW_FUNC = data.block_header_type.scrypt
+ SYMBOL = 'tLTC'
class Protocol(BaseProtocol):
def __init__(self, net):
- self._prefix = net.BITCOIN_P2P_PREFIX
+ self._prefix = net.P2P_PREFIX
version = 0
if len(self.share_data['coinbase']) > 100:
raise ValueError('''coinbase too large! %i bytes''' % (len(self.share_data['coinbase']),))
- self.pow_hash = net.BITCOIN_POW_FUNC(header)
+ self.pow_hash = net.PARENT.POW_FUNC(header)
self.header_hash = bitcoin_data.block_header_type.hash256(header)
self.hash = share1a_type.hash256(self.as_share1a())
@deferral.retry('Error creating payout script:', 10)
@defer.inlineCallbacks
-def get_payout_script2(bitcoind, net):
+def get_payout_script2(bitcoind, net2):
address = yield bitcoind.rpc_getaccountaddress('p2pool')
validate_response = yield bitcoind.rpc_validateaddress(address)
if 'pubkey' not in validate_response:
print ' Pubkey request failed. Falling back to payout to address.'
- defer.returnValue(bitcoin_data.pubkey_hash_to_script2(bitcoin_data.address_to_pubkey_hash(address, net)))
+ defer.returnValue(bitcoin_data.pubkey_hash_to_script2(bitcoin_data.address_to_pubkey_hash(address, net2)))
pubkey = validate_response['pubkey'].decode('hex')
defer.returnValue(bitcoin_data.pubkey_to_script2(pubkey))
url = 'http://%s:%i/' % (args.bitcoind_address, args.bitcoind_rpc_port)
print '''Testing bitcoind RPC connection to '%s' with username '%s'...''' % (url, args.bitcoind_rpc_username)
bitcoind = jsonrpc.Proxy(url, (args.bitcoind_rpc_username, args.bitcoind_rpc_password))
- good = yield deferral.retry('Error while checking bitcoind identity:', 1)(net.BITCOIN_RPC_CHECK)(bitcoind)
+ good = yield deferral.retry('Error while checking bitcoind identity:', 1)(net.PARENT.RPC_CHECK)(bitcoind)
if not good:
print " Check failed! Make sure that you're connected to the right bitcoind with --bitcoind-rpc-port!"
return
# connect to bitcoind over bitcoin-p2p
print '''Testing bitcoind P2P connection to '%s:%s'...''' % (args.bitcoind_address, args.bitcoind_p2p_port)
- factory = bitcoin_p2p.ClientFactory(net)
+ factory = bitcoin_p2p.ClientFactory(net.PARENT)
reactor.connectTCP(args.bitcoind_address, args.bitcoind_p2p_port, factory)
yield factory.getProtocol() # waits until handshake is successful
print ' ...success!'
if args.pubkey_hash is None:
print 'Getting payout address from bitcoind...'
- my_script = yield get_payout_script2(bitcoind, net)
+ my_script = yield get_payout_script2(bitcoind, net.PARENT)
else:
print 'Computing payout script from provided address....'
my_script = bitcoin_data.pubkey_hash_to_script2(args.pubkey_hash)
print ' ...success!'
- print ' Payout script:', bitcoin_data.script2_to_human(my_script, net)
+ print ' Payout script:', bitcoin_data.script2_to_human(my_script, net.PARENT)
print
ht = bitcoin_p2p.HeightTracker(bitcoind, factory)
print 'New work for worker %s! Difficulty: %.06f Payout if block: %.6f %s Total block value: %.6f %s including %i transactions' % (
user,
bitcoin_data.target_to_difficulty(share_info['bits'].target),
- (sum(t['value'] for t in generate_tx['tx_outs'] if t['script'] == payout_script) - subsidy//200)*1e-8, net.BITCOIN_SYMBOL,
- subsidy*1e-8, net.BITCOIN_SYMBOL,
+ (sum(t['value'] for t in generate_tx['tx_outs'] if t['script'] == payout_script) - subsidy//200)*1e-8, net.PARENT.SYMBOL,
+ subsidy*1e-8, net.PARENT.SYMBOL,
len(current_work2.value['transactions']),
)
hash_ = bitcoin_data.block_header_type.hash256(header)
- pow_hash = net.BITCOIN_POW_FUNC(header)
+ pow_hash = net.PARENT.POW_FUNC(header)
if pow_hash <= header['bits'].target or p2pool.DEBUG:
if factory.conn.value is not None:
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)''' % ', '.join('%s:%i' % (n.NAME, n.BITCOIN_RPC_PORT) for _, n in sorted(networks.realnets.items())),
+ help='''connect to JSON-RPC interface at this port (default: %s)''' % ', '.join('%s:%i' % (n.NAME, n.PARENT.RPC_PORT) for _, n in sorted(networks.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)''' % ', '.join('%s:%i' % (n.NAME, n.BITCOIN_P2P_PORT) for _, n in sorted(networks.realnets.items())),
+ help='''connect to P2P interface at this port (default: %s)''' % ', '.join('%s:%i' % (n.NAME, n.PARENT.P2P_PORT) for _, n in sorted(networks.realnets.items())),
type=int, action='store', default=None, dest='bitcoind_p2p_port')
bitcoind_group.add_argument(metavar='BITCOIND_RPCUSER',
task.LoopingCall(logfile.reopen).start(5)
if args.bitcoind_rpc_port is None:
- args.bitcoind_rpc_port = net.BITCOIN_RPC_PORT
+ args.bitcoind_rpc_port = net.PARENT.RPC_PORT
if args.bitcoind_p2p_port is None:
- args.bitcoind_p2p_port = net.BITCOIN_P2P_PORT
+ args.bitcoind_p2p_port = net.PARENT.P2P_PORT
if args.p2pool_port is None:
args.p2pool_port = net.P2P_PORT
if args.address is not None:
try:
- args.pubkey_hash = bitcoin_data.address_to_pubkey_hash(args.address, net)
+ args.pubkey_hash = bitcoin_data.address_to_pubkey_hash(args.address, net.PARENT)
except Exception, e:
parser.error('error parsing address: ' + repr(e))
else:
# REAL_CHAIN_LENGTH must be changed in sync with all other clients
# changes can be done by changing one, then the other
-class BitcoinMainnet(networks.BitcoinMainnet):
+class BitcoinMainnet(object):
+ PARENT = networks.BitcoinMainnet
SHARE_PERIOD = 10 # seconds
CHAIN_LENGTH = 24*60*60//10 # shares
REAL_CHAIN_LENGTH_FUNC = staticmethod(lambda ts: 24*60*60//10 if ts >= 1325805105 else 24*60*60//10//2) # shares
PERSIST = True
WORKER_PORT = 9332
-class BitcoinTestnet(networks.BitcoinTestnet):
+class BitcoinTestnet(object):
+ PARENT = networks.BitcoinTestnet
SHARE_PERIOD = 10 # seconds
CHAIN_LENGTH = 24*60*60//10 # shares
REAL_CHAIN_LENGTH_FUNC = staticmethod(lambda ts: 24*60*60//10 if ts >= 1325805105 else 24*60*60//10//2) # shares
PERSIST = False
WORKER_PORT = 19332
-class NamecoinMainnet(networks.NamecoinMainnet):
+class NamecoinMainnet(object):
+ PARENT = networks.NamecoinMainnet
SHARE_PERIOD = 10 # seconds
CHAIN_LENGTH = 24*60*60//10 # shares
REAL_CHAIN_LENGTH = 24*60*60//10 # shares
PERSIST = True
WORKER_PORT = 9331
-class NamecoinTestnet(networks.NamecoinTestnet):
+class NamecoinTestnet(object):
+ PARENT = networks.NamecoinTestnet
SHARE_PERIOD = 10 # seconds
CHAIN_LENGTH = 24*60*60//10 # shares
REAL_CHAIN_LENGTH = 24*60*60//10 # shares
PERSIST = False
WORKER_PORT = 19331
-class LitecoinMainnet(networks.LitecoinMainnet):
+class LitecoinMainnet(object):
+ PARENT = networks.LitecoinMainnet
SHARE_PERIOD = 10 # seconds
CHAIN_LENGTH = 24*60*60//10 # shares
REAL_CHAIN_LENGTH_FUNC = staticmethod(lambda ts: 24*60*60//10 if ts >= 1325805105 else 24*60*60//10//2) # shares
PERSIST = True
WORKER_PORT = 9327
-class LitecoinTestnet(networks.LitecoinTestnet):
+class LitecoinTestnet(object):
+ PARENT = networks.LitecoinTestnet
SHARE_PERIOD = 10 # seconds
CHAIN_LENGTH = 24*60*60//10 # shares
REAL_CHAIN_LENGTH_FUNC = staticmethod(lambda ts: 24*60*60//10 if ts >= 1325805105 else 24*60*60//10//2) # shares