added block database creation and insertion

This commit is contained in:
Kevin Froman 2018-01-20 23:49:16 -06:00
parent 4d33005d16
commit b62f799b02
No known key found for this signature in database
GPG Key ID: 0D414D0FE405B63B
1 changed files with 34 additions and 0 deletions

View File

@ -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):
'''