riecoin support fixes

This commit is contained in:
gatra 2014-03-06 00:14:53 -03:00
parent 05d3f1789a
commit 94276a8132
5 changed files with 19 additions and 19 deletions

1
.gitignore vendored
View File

@ -2,3 +2,4 @@
conf/config.py conf/config.py
*.log *.log
LOG LOG
*.bak

View File

@ -68,7 +68,7 @@ class BlockTemplate(halfnode.CBlock):
self.height = data['height'] self.height = data['height']
self.nVersion = data['version'] self.nVersion = data['version']
self.hashPrevBlock = int(data['previousblockhash'], 16) self.hashPrevBlock = int(data['previousblockhash'], 16)
self.nBits = int(data['bits'], 16) self.nBits = int(data['bits'], 8)
self.hashMerkleRoot = 0 self.hashMerkleRoot = 0
self.nTime = 0 self.nTime = 0
self.nNonce = 0 self.nNonce = 0

View File

@ -341,7 +341,7 @@ class CBlock(object):
if settings.COINDAEMON_ALGO == 'riecoin': if settings.COINDAEMON_ALGO == 'riecoin':
target = settings.POOL_TARGET target = settings.POOL_TARGET
else else:
target = uint256_from_compact(self.nBits) target = uint256_from_compact(self.nBits)
if settings.COINDAEMON_ALGO == 'riecoin': if settings.COINDAEMON_ALGO == 'riecoin':

View File

@ -248,7 +248,7 @@ class TemplateRegistry(object):
header_bin = job.serialize_header(merkle_root_int, ntime_bin, nonce_bin) header_bin = job.serialize_header(merkle_root_int, ntime_bin, nonce_bin)
# 4. Reverse header and compare it with target of the user # 4. Reverse header and compare it with target of the user
elif settings.COINDAEMON_ALGO == 'scrypt': if settings.COINDAEMON_ALGO == 'scrypt':
hash_bin = ltc_scrypt.getPoWHash(''.join([ header_bin[i*4:i*4+4][::-1] for i in range(0, 20) ])) hash_bin = ltc_scrypt.getPoWHash(''.join([ header_bin[i*4:i*4+4][::-1] for i in range(0, 20) ]))
elif settings.COINDAEMON_ALGO == 'scrypt-jane': elif settings.COINDAEMON_ALGO == 'scrypt-jane':
hash_bin = yac_scrypt.getPoWHash(''.join([ header_bin[i*4:i*4+4][::-1] for i in range(0, 20) ]), int(ntime, 16)) hash_bin = yac_scrypt.getPoWHash(''.join([ header_bin[i*4:i*4+4][::-1] for i in range(0, 20) ]), int(ntime, 16))
@ -295,7 +295,7 @@ class TemplateRegistry(object):
# 5. Compare hash with target of the network # 5. Compare hash with target of the network
isBlockCandidate = False isBlockCandidate = False
if settings.COINDAEMON_ALGO == 'riecoin': if settings.COINDAEMON_ALGO == 'riecoin':
if hash_int == 6 if hash_int == 6:
isBlockCandidate = True isBlockCandidate = True
else: else:
if hash_int <= job.target: if hash_int <= job.target:

View File

@ -212,19 +212,19 @@ def ser_number(n):
return bytes(s) return bytes(s)
def isPrime( n ) def isPrime( n ):
if pow( 2, n-1, n ) == 1: if pow( 2, n-1, n ) == 1:
return True return True
return False return False
def riecoinPoW( hash_bin, diff, nNonce ) def riecoinPoW( hash_bin, diff, nNonce ):
base = 1 << 8 base = 1 << 8
for i in range(256) for i in range(256):
base = base << 1 base = base << 1
base = base | (hash_bin & 1) base = base | (hash_bin & 1)
hash_bin = hash_bin >> 1 hash_bin = hash_bin >> 1
trailingZeros = diff - 1 - 8 - 256 trailingZeros = diff - 1 - 8 - 256
if trailingZeros < 16 or trailingZeros > 20000 if trailingZeros < 16 or trailingZeros > 20000:
return 0 return 0
base = base << trailingZeros base = base << trailingZeros
@ -234,30 +234,29 @@ def riecoinPoW( hash_bin, diff, nNonce )
if (base % 210) != 97: if (base % 210) != 97:
return 0 return 0
if !isPrime( base ): if not isPrime( base ):
return primes return primes
primes++ primes++
base += 4 base += 4
if !isPrime( base ): if isPrime( base ):
return primes primes+=1
primes++
base += 2 base += 2
if isPrime( base ): if isPrime( base ):
primes++ primes+=1
base += 4 base += 4
if !isPrime( base ): if isPrime( base ):
primes++ primes+=1
base += 2 base += 2
if !isPrime( base ): if isPrime( base ):
primes++ primes+=1
base += 4 base += 4
if !isPrime( base ): if isPrime( base ):
primes++ primes+=1
return primes return primes