diff --git a/.gitignore b/.gitignore index 91b1cde..e118e77 100644 --- a/.gitignore +++ b/.gitignore @@ -2,3 +2,4 @@ conf/config.py *.log LOG +*.bak diff --git a/lib/block_template.py b/lib/block_template.py index 3b8bb06..686baf0 100644 --- a/lib/block_template.py +++ b/lib/block_template.py @@ -68,7 +68,7 @@ class BlockTemplate(halfnode.CBlock): self.height = data['height'] self.nVersion = data['version'] self.hashPrevBlock = int(data['previousblockhash'], 16) - self.nBits = int(data['bits'], 16) + self.nBits = int(data['bits'], 8) self.hashMerkleRoot = 0 self.nTime = 0 self.nNonce = 0 diff --git a/lib/halfnode.py b/lib/halfnode.py index a3cfa13..51b1420 100644 --- a/lib/halfnode.py +++ b/lib/halfnode.py @@ -341,7 +341,7 @@ class CBlock(object): if settings.COINDAEMON_ALGO == 'riecoin': target = settings.POOL_TARGET - else + else: target = uint256_from_compact(self.nBits) if settings.COINDAEMON_ALGO == 'riecoin': diff --git a/lib/template_registry.py b/lib/template_registry.py index de3693c..5accf00 100644 --- a/lib/template_registry.py +++ b/lib/template_registry.py @@ -248,7 +248,7 @@ class TemplateRegistry(object): header_bin = job.serialize_header(merkle_root_int, ntime_bin, nonce_bin) # 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) ])) 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)) @@ -295,7 +295,7 @@ class TemplateRegistry(object): # 5. Compare hash with target of the network isBlockCandidate = False if settings.COINDAEMON_ALGO == 'riecoin': - if hash_int == 6 + if hash_int == 6: isBlockCandidate = True else: if hash_int <= job.target: diff --git a/lib/util.py b/lib/util.py index 0035d85..d1dc4c7 100644 --- a/lib/util.py +++ b/lib/util.py @@ -212,19 +212,19 @@ def ser_number(n): return bytes(s) -def isPrime( n ) +def isPrime( n ): if pow( 2, n-1, n ) == 1: return True return False -def riecoinPoW( hash_bin, diff, nNonce ) +def riecoinPoW( hash_bin, diff, nNonce ): base = 1 << 8 - for i in range(256) + for i in range(256): base = base << 1 base = base | (hash_bin & 1) hash_bin = hash_bin >> 1 trailingZeros = diff - 1 - 8 - 256 - if trailingZeros < 16 or trailingZeros > 20000 + if trailingZeros < 16 or trailingZeros > 20000: return 0 base = base << trailingZeros @@ -234,30 +234,29 @@ def riecoinPoW( hash_bin, diff, nNonce ) if (base % 210) != 97: return 0 - if !isPrime( base ): + if not isPrime( base ): return primes primes++ base += 4 - if !isPrime( base ): - return primes - primes++ + if isPrime( base ): + primes+=1 base += 2 if isPrime( base ): - primes++ + primes+=1 base += 4 - if !isPrime( base ): - primes++ + if isPrime( base ): + primes+=1 base += 2 - if !isPrime( base ): - primes++ + if isPrime( base ): + primes+=1 base += 4 - if !isPrime( base ): - primes++ + if isPrime( base ): + primes+=1 return primes