def hash256(self, obj):
return HashType().unpack(hashlib.sha256(hashlib.sha256(self.pack(obj)).digest()).digest())
-
- ltc_scrypt = None
+
def scrypt(self, obj):
- # dynamically import ltc_scrypt so you will only get an error on runtime
- if (not self.ltc_scrypt):
- self.ltc_scrypt = __import__('ltc_scrypt')
+ import ltc_scrypt
return HashType().unpack(self.ltc_scrypt.getPoWHash(self.pack(obj)))
class VarIntType(Type):
from twisted.internet import defer
+from . import data
+
class BitcoinMainnet(object):
BITCOIN_P2P_PREFIX = 'f9beb4d9'.decode('hex')
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'
class BitcoinTestnet(object):
(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'
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'
class NamecoinTestnet(object):
(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'
not (yield bitcoind.rpc_getinfo())['testnet']
)))
BITCOIN_SUBSIDY_FUNC = staticmethod(lambda height: 96*100000000 >> (height + 1)//210000)
+ BITCOIN_POW_FUNC = data.block_header_type.hash256
BITCOIN_SYMBOL = 'IXC'
class IxcoinTestnet(object):
(yield bitcoind.rpc_getinfo())['testnet']
)))
BITCOIN_SUBSIDY_FUNC = staticmethod(lambda height: 96*100000000 >> (height + 1)//210000)
+ BITCOIN_POW_FUNC = data.block_header_type.hash256
BITCOIN_SYMBOL = 'tIXC'
not (yield bitcoind.rpc_getinfo())['testnet']
)))
BITCOIN_SUBSIDY_FUNC = staticmethod(lambda height: 48*100000000 >> (height + 1)//218750)
+ BITCOIN_POW_FUNC = data.block_header_type.hash256
BITCOIN_SYMBOL = 'I0C'
class I0coinTestnet(object):
(yield bitcoind.rpc_getinfo())['testnet']
)))
BITCOIN_SUBSIDY_FUNC = staticmethod(lambda height: 48*100000000 >> (height + 1)//218750)
+ BITCOIN_POW_FUNC = data.block_header_type.hash256
BITCOIN_SYMBOL = 'tI0C'
not (yield bitcoind.rpc_getinfo())['testnet']
)))
BITCOIN_SUBSIDY_FUNC = staticmethod(lambda height: 32*100000000 >> (height + 1)//300000)
+ BITCOIN_POW_FUNC = data.block_header_type.hash256
BITCOIN_SYMBOL = 'SC'
not (yield bitcoind.rpc_getinfo())['testnet']
)))
BITCOIN_SUBSIDY_FUNC = staticmethod(lambda height: 50*100000000 >> (height + 1)//840000)
- BITCOIN_POW_SCRYPT = True;
+ BITCOIN_POW_FUNC = data.block_header_type.scrypt
BITCOIN_SYMBOL = 'LTC'
class LitecoinTestnet(object):
(yield bitcoind.rpc_getinfo())['testnet']
)))
BITCOIN_SUBSIDY_FUNC = staticmethod(lambda height: 50*100000000 >> (height + 1)//840000)
- BITCOIN_POW_SCRYPT = True;
+ BITCOIN_POW_FUNC = data.block_header_type.scrypt
BITCOIN_SYMBOL = 'tLTC'
if len(self.nonce) > 100:
raise ValueError('nonce too long!')
-
- # use scrypt for Litecoin
- if (getattr(net, 'BITCOIN_POW_SCRYPT', False)):
- self.bitcoin_hash = bitcoin_data.block_header_type.scrypt(header)
- self.hash = share1a_type.scrypt(self.as_share1a())
- else:
- self.bitcoin_hash = bitcoin_data.block_header_type.hash256(header)
- self.hash = share1a_type.hash256(self.as_share1a())
-
+
+ self.bitcoin_hash = net.BITCOIN_POW_FUNC(header)
+ self.hash = net.BITCOIN_POW_FUNC(header) # XXX was a bug in litecoin pull
+
if self.bitcoin_hash > self.target:
print 'hash %x' % self.bitcoin_hash
print 'targ %x' % self.target
return False
block = dict(header=header, txs=transactions)
hash_ = bitcoin.data.block_header_type.hash256(block['header'])
- pow = hash_;
-
- # use scrypt for Litecoin
- if (getattr(args.net, 'BITCOIN_POW_SCRYPT', False)):
- pow = bitcoin.data.block_header_type.scrypt(block['header']);
-# print 'LTC: hash256 %x' % hash_
-# print 'LTC: scrypt %x' % pow
-# print 'LTC: target %x' % block['header']['target']
-# print 'LTC: starget %x' % p2pool.coinbase_type.unpack(transactions[0]['tx_ins'][0]['script'])['share_data']['target']
-
- if pow <= block['header']['target'] or p2pool_init.DEBUG:
+ pow_hash = args.net.BITCOIN_POW_FUNC(block['header'])
+
+ if pow_hash <= block['header']['target'] or p2pool_init.DEBUG:
if factory.conn.value is not None:
factory.conn.value.send_block(block=block)
else:
print 'No bitcoind connection! Erp!'
- if pow <= block['header']['target']:
+ if pow_hash <= block['header']['target']:
print
print 'GOT BLOCK! Passing to bitcoind! bitcoin: %x' % (hash_,)
print
- if current_work.value['aux_work'] is not None and pow <= current_work.value['aux_work']['target']:
+ if current_work.value['aux_work'] is not None and pow_hash <= current_work.value['aux_work']['target']:
try:
aux_pow = dict(
merkle_tx=dict(
log.err(None, 'Error while processing merged mining POW:')
target = p2pool.coinbase_type.unpack(transactions[0]['tx_ins'][0]['script'])['share_data']['target']
- if pow > target:
- print 'Worker submitted share with hash > target:\nhash : %x\ntarget: %x' % (pow, target)
+ if pow_hash > target:
+ print 'Worker submitted share with hash > target:\nhash : %x\ntarget: %x' % (pow_hash, target)
return False
share = p2pool.Share.from_block(block, args.net)
my_shares.add(share.hash)
def handle_share1as(self, share1as):
shares = []
for share1a in share1as:
- # use scrypt for Litecoin
- if (getattr(self.node.net, 'BITCOIN_POW_SCRYPT', False)):
- hash_ = bitcoin_data.block_header_type.scrypt(share1a['header']);
- else:
- hash_ = bitcoin_data.block_header_type.hash256(share1a['header'])
- if hash_ <= share1a['header']['target']:
+ if self.node.net.BITCOIN_POW_FUNC(share1a['header']) <= share1a['header']['target']:
print 'Dropping peer %s:%i due to invalid share' % self.addr
self.transport.loseConnection()
return
def handle_share1bs(self, share1bs):
shares = []
for share1b in share1bs:
- # use scrypt for Litecoin
- if (getattr(self.node.net, 'BITCOIN_POW_SCRYPT', False)):
- hash_ = bitcoin_data.block_header_type.scrypt(share1b['header']);
- else:
- hash_ = bitcoin_data.block_header_type.hash256(share1b['header'])
- if not hash_ <= share1b['header']['target']:
+ if not self.node.net.BITCOIN_POW_FUNC(share1a['header']) <= share1b['header']['target']:
print 'Dropping peer %s:%i due to invalid share' % self.addr
self.transport.loseConnection()
return