added hasBlock function
parent
b4d61d3598
commit
1c3e886ba0
|
@ -108,6 +108,8 @@ class OnionrCommunicate:
|
||||||
logger.debug('BLOCKS: \n' + blocks)
|
logger.debug('BLOCKS: \n' + blocks)
|
||||||
blockList = blocks.split('\n')
|
blockList = blocks.split('\n')
|
||||||
for i in blockList:
|
for i in blockList:
|
||||||
|
if self._utils.hasBlock(i):
|
||||||
|
continue
|
||||||
logger.debug('Exchanged block (blockList): ' + i)
|
logger.debug('Exchanged block (blockList): ' + i)
|
||||||
if not self._utils.validateHash(i):
|
if not self._utils.validateHash(i):
|
||||||
# skip hash if it isn't valid
|
# skip hash if it isn't valid
|
||||||
|
|
|
@ -18,7 +18,7 @@
|
||||||
along with this program. If not, see <https://www.gnu.org/licenses/>.
|
along with this program. If not, see <https://www.gnu.org/licenses/>.
|
||||||
'''
|
'''
|
||||||
# Misc functions that do not fit in the main api, but are useful
|
# Misc functions that do not fit in the main api, but are useful
|
||||||
import getpass, sys, requests, configparser, os, socket, gnupg, hashlib, logger
|
import getpass, sys, requests, configparser, os, socket, gnupg, hashlib, logger, sqlite3
|
||||||
if sys.version_info < (3, 6):
|
if sys.version_info < (3, 6):
|
||||||
try:
|
try:
|
||||||
import sha3
|
import sha3
|
||||||
|
@ -96,6 +96,22 @@ class OnionrUtils:
|
||||||
dataHash = hasher.hexdigest()
|
dataHash = hasher.hexdigest()
|
||||||
return dataHash
|
return dataHash
|
||||||
|
|
||||||
|
def hasBlock(self, hash):
|
||||||
|
'''detect if we have a block in the list or not'''
|
||||||
|
conn = sqlite3.connect(self._core.blockDB)
|
||||||
|
c = conn.cursor()
|
||||||
|
if not self.validateHash(hash):
|
||||||
|
raise Exception("Invalid hash")
|
||||||
|
for result in c.execute("SELECT COUNT() FROM hashes where hash='" + hash + "'"):
|
||||||
|
if result[0] >= 1:
|
||||||
|
conn.commit()
|
||||||
|
conn.close()
|
||||||
|
return True
|
||||||
|
else:
|
||||||
|
conn.commit()
|
||||||
|
conn.close()
|
||||||
|
return False
|
||||||
|
|
||||||
def validateHash(self, data, length=64):
|
def validateHash(self, data, length=64):
|
||||||
'''Validate if a string is a valid hex formatted hash'''
|
'''Validate if a string is a valid hex formatted hash'''
|
||||||
retVal = True
|
retVal = True
|
||||||
|
|
Loading…
Reference in New Issue