2019-06-22 22:54:41 +00:00
|
|
|
import os, sqlite3
|
2019-06-25 23:07:35 +00:00
|
|
|
from onionrutils import epoch, blockmetadata
|
2019-06-22 22:54:41 +00:00
|
|
|
def add_to_block_DB(core_inst, newHash, selfInsert=False, dataSaved=False):
|
|
|
|
'''
|
|
|
|
Add a hash value to the block db
|
|
|
|
|
|
|
|
Should be in hex format!
|
|
|
|
'''
|
|
|
|
|
|
|
|
if not os.path.exists(core_inst.blockDB):
|
|
|
|
raise Exception('Block db does not exist')
|
2019-06-25 23:07:35 +00:00
|
|
|
if blockmetadata.has_block(core_inst, newHash):
|
2019-06-22 22:54:41 +00:00
|
|
|
return
|
|
|
|
conn = sqlite3.connect(core_inst.blockDB, timeout=30)
|
|
|
|
c = conn.cursor()
|
2019-06-25 23:07:35 +00:00
|
|
|
currentTime = epoch.get_epoch() + core_inst._crypto.secrets.randbelow(301)
|
2019-06-22 22:54:41 +00:00
|
|
|
if selfInsert or dataSaved:
|
|
|
|
selfInsert = 1
|
|
|
|
else:
|
|
|
|
selfInsert = 0
|
|
|
|
data = (newHash, currentTime, '', selfInsert)
|
|
|
|
c.execute('INSERT INTO hashes (hash, dateReceived, dataType, dataSaved) VALUES(?, ?, ?, ?);', data)
|
|
|
|
conn.commit()
|
|
|
|
conn.close()
|