added forcedifficulty

This commit is contained in:
Kevin Froman 2018-07-21 19:20:28 -05:00
parent 16f5b69e74
commit 8e1b6e1e7e
No known key found for this signature in database
GPG Key ID: 0D414D0FE405B63B
2 changed files with 10 additions and 5 deletions

View File

@ -198,6 +198,8 @@ class API:
resp = Response('\n'.join(self._core.getBlockList()))
elif action == 'directMessage':
resp = Response(self._core.handle_direct_connection(data))
#elif action == 'nodeProof':
elif action == 'announce':
if data != '':
# TODO: require POW for this

View File

@ -22,16 +22,19 @@ import nacl.encoding, nacl.hash, nacl.utils, time, math, threading, binascii, lo
import core
class DataPOW:
def __init__(self, data, threadCount = 5):
def __init__(self, data, forceDifficulty=0, threadCount = 5):
self.foundHash = False
self.difficulty = 0
self.data = data
self.threadCount = threadCount
dataLen = sys.getsizeof(data)
self.difficulty = math.floor(dataLen / 1000000)
if self.difficulty <= 2:
self.difficulty = 4
if forceDifficulty == 0:
dataLen = sys.getsizeof(data)
self.difficulty = math.floor(dataLen / 1000000)
if self.difficulty <= 2:
self.difficulty = 4
else:
self.difficulty = forceDifficulty
try:
self.data = self.data.encode()