|
|
@ -36,6 +36,7 @@ from threading import RLock
|
|
|
|
from threading import Thread
|
|
|
|
from threading import Thread
|
|
|
|
import logging
|
|
|
|
import logging
|
|
|
|
import copy
|
|
|
|
import copy
|
|
|
|
|
|
|
|
import litecoin_scrypt
|
|
|
|
from test_framework.siphash import siphash256
|
|
|
|
from test_framework.siphash import siphash256
|
|
|
|
|
|
|
|
|
|
|
|
BIP0031_VERSION = 60000
|
|
|
|
BIP0031_VERSION = 60000
|
|
|
@ -535,6 +536,7 @@ class CBlockHeader(object):
|
|
|
|
self.nNonce = header.nNonce
|
|
|
|
self.nNonce = header.nNonce
|
|
|
|
self.sha256 = header.sha256
|
|
|
|
self.sha256 = header.sha256
|
|
|
|
self.hash = header.hash
|
|
|
|
self.hash = header.hash
|
|
|
|
|
|
|
|
self.scrypt256 = header.scrypt256
|
|
|
|
self.calc_sha256()
|
|
|
|
self.calc_sha256()
|
|
|
|
|
|
|
|
|
|
|
|
def set_null(self):
|
|
|
|
def set_null(self):
|
|
|
@ -546,6 +548,7 @@ class CBlockHeader(object):
|
|
|
|
self.nNonce = 0
|
|
|
|
self.nNonce = 0
|
|
|
|
self.sha256 = None
|
|
|
|
self.sha256 = None
|
|
|
|
self.hash = None
|
|
|
|
self.hash = None
|
|
|
|
|
|
|
|
self.scrypt256 = None
|
|
|
|
|
|
|
|
|
|
|
|
def deserialize(self, f):
|
|
|
|
def deserialize(self, f):
|
|
|
|
self.nVersion = struct.unpack("<i", f.read(4))[0]
|
|
|
|
self.nVersion = struct.unpack("<i", f.read(4))[0]
|
|
|
@ -556,6 +559,7 @@ class CBlockHeader(object):
|
|
|
|
self.nNonce = struct.unpack("<I", f.read(4))[0]
|
|
|
|
self.nNonce = struct.unpack("<I", f.read(4))[0]
|
|
|
|
self.sha256 = None
|
|
|
|
self.sha256 = None
|
|
|
|
self.hash = None
|
|
|
|
self.hash = None
|
|
|
|
|
|
|
|
self.scrypt256 = None
|
|
|
|
|
|
|
|
|
|
|
|
def serialize(self):
|
|
|
|
def serialize(self):
|
|
|
|
r = b""
|
|
|
|
r = b""
|
|
|
@ -578,9 +582,11 @@ class CBlockHeader(object):
|
|
|
|
r += struct.pack("<I", self.nNonce)
|
|
|
|
r += struct.pack("<I", self.nNonce)
|
|
|
|
self.sha256 = uint256_from_str(hash256(r))
|
|
|
|
self.sha256 = uint256_from_str(hash256(r))
|
|
|
|
self.hash = encode(hash256(r)[::-1], 'hex_codec').decode('ascii')
|
|
|
|
self.hash = encode(hash256(r)[::-1], 'hex_codec').decode('ascii')
|
|
|
|
|
|
|
|
self.scrypt256 = uint256_from_str(litecoin_scrypt.getPoWHash(r))
|
|
|
|
|
|
|
|
|
|
|
|
def rehash(self):
|
|
|
|
def rehash(self):
|
|
|
|
self.sha256 = None
|
|
|
|
self.sha256 = None
|
|
|
|
|
|
|
|
self.scrypt256 = None
|
|
|
|
self.calc_sha256()
|
|
|
|
self.calc_sha256()
|
|
|
|
return self.sha256
|
|
|
|
return self.sha256
|
|
|
|
|
|
|
|
|
|
|
@ -639,7 +645,7 @@ class CBlock(CBlockHeader):
|
|
|
|
def is_valid(self):
|
|
|
|
def is_valid(self):
|
|
|
|
self.calc_sha256()
|
|
|
|
self.calc_sha256()
|
|
|
|
target = uint256_from_compact(self.nBits)
|
|
|
|
target = uint256_from_compact(self.nBits)
|
|
|
|
if self.sha256 > target:
|
|
|
|
if self.scrypt256 > target:
|
|
|
|
return False
|
|
|
|
return False
|
|
|
|
for tx in self.vtx:
|
|
|
|
for tx in self.vtx:
|
|
|
|
if not tx.is_valid():
|
|
|
|
if not tx.is_valid():
|
|
|
@ -651,7 +657,7 @@ class CBlock(CBlockHeader):
|
|
|
|
def solve(self):
|
|
|
|
def solve(self):
|
|
|
|
self.rehash()
|
|
|
|
self.rehash()
|
|
|
|
target = uint256_from_compact(self.nBits)
|
|
|
|
target = uint256_from_compact(self.nBits)
|
|
|
|
while self.sha256 > target:
|
|
|
|
while self.scrypt256 > target:
|
|
|
|
self.nNonce += 1
|
|
|
|
self.nNonce += 1
|
|
|
|
self.rehash()
|
|
|
|
self.rehash()
|
|
|
|
|
|
|
|
|
|
|
|