refactoring core databases to not use core anymore

This commit is contained in:
Kevin Froman 2019-07-17 11:58:40 -05:00
parent 000538ddc8
commit bf8a9c4f27
9 changed files with 39 additions and 52 deletions

View file

@ -17,22 +17,21 @@
You should have received a copy of the GNU General Public License
along with this program. If not, see <https://www.gnu.org/licenses/>.
'''
import os, sqlite3
import os, sqlite3, secrets
from onionrutils import epoch, blockmetadata
def add_to_block_DB(core_inst, newHash, selfInsert=False, dataSaved=False):
from .. import dbfiles
def add_to_block_DB(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')
if blockmetadata.has_block(core_inst, newHash):
if blockmetadata.has_block(newHash):
return
conn = sqlite3.connect(core_inst.blockDB, timeout=30)
conn = sqlite3.connect(dbfiles.block_meta_db, timeout=30)
c = conn.cursor()
currentTime = epoch.get_epoch() + core_inst._crypto.secrets.randbelow(301)
currentTime = epoch.get_epoch() + secrets.randbelow(301)
if selfInsert or dataSaved:
selfInsert = 1
else:

View file

@ -19,9 +19,10 @@
'''
import sqlite3
from onionrutils import epoch
def get_expired_blocks(core_inst):
from .. import dbfiles
def get_expired_blocks():
'''Returns a list of expired blocks'''
conn = sqlite3.connect(core_inst.blockDB, timeout=30)
conn = sqlite3.connect(dbfiles.block_meta_db, timeout=30)
c = conn.cursor()
date = int(epoch.get_epoch())

View file

@ -17,13 +17,27 @@
You should have received a copy of the GNU General Public License
along with this program. If not, see <https://www.gnu.org/licenses/>.
'''
import sqlite3
def update_block_info(core_inst, hash, key, data):
from .. import dbfiles
def update_block_info(hash, key, data):
'''
sets info associated with a block
hash - the hash of a block
dateReceived - the date the block was recieved, not necessarily when it was created
decrypted - if we can successfully decrypt the block (does not describe its current state)
dataType - data type of the block
dataFound - if the data has been found for the block
dataSaved - if the data has been saved for the block
sig - optional signature by the author (not optional if author is specified)
author - multi-round partial sha3-256 hash of authors public key
dateClaimed - timestamp claimed inside the block, only as trustworthy as the block author is
expire - expire date for a block
'''
if key not in ('dateReceived', 'decrypted', 'dataType', 'dataFound', 'dataSaved', 'sig', 'author', 'dateClaimed', 'expire'):
return False
conn = sqlite3.connect(core_inst.blockDB, timeout=30)
conn = sqlite3.connect(dbfiles.block_meta_db, timeout=30)
c = conn.cursor()
args = (data, hash)
c.execute("UPDATE hashes SET " + key + " = ? where hash = ?;", args)