From b62f799b02b8c66b70968894a7b089a3c5aeb740 Mon Sep 17 00:00:00 2001 From: Kevin Froman Date: Sat, 20 Jan 2018 23:49:16 -0600 Subject: [PATCH] added block database creation and insertion --- onionr/core.py | 34 ++++++++++++++++++++++++++++++++++ 1 file changed, 34 insertions(+) diff --git a/onionr/core.py b/onionr/core.py index fb6c5eea..b3398738 100644 --- a/onionr/core.py +++ b/onionr/core.py @@ -30,6 +30,7 @@ class Core: self.queueDB = 'data/queue.db' self.peerDB = 'data/peers.db' self.ownPGPID = '' + self.blockDB = 'data/blocks.db' #self.daemonQueue() # Call to create the DB if it doesn't exist return @@ -83,6 +84,39 @@ class Core: ''') conn.commit() conn.close() + def createBlockDB(self): + ''' + Create a database for blocks + + 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) + dataObtained - if the data has been obtained for the block + ''' + if os.path.exists(self.blockDB): + raise Exception("Block database already exists") + conn = sqlite3.connect(self.blockDB) + c = conn.cursor() + c.execute('''create table hashes( + hash text not null, + dateReceived int, + decrypted int, + dataFound int + ); + ''') + conn.commit() + conn.close() + def addToBlockDB(self, newHash): + '''add a hash value to the block db (should be in hex format)''' + if not os.path.exists(self.blockDB): + raise Exception('Block db does not exist') + conn = sqlite3.connect(self.blockDB) + c = conn.cursor() + currentTime = math.floor(time.time()) + data = (newHash, currentTime, 0, 0) + c.execute('INSERT into hashes values(?, ?, ?, ?);', data) + conn.commit() + conn.close() def dataDirEncrypt(self, password): '''