# The hash is the RIPEMD160 hash that is encoded in the Bitmessage address.
# transmitdata is literally the data that was included in the Bitmessage pubkey message when it arrived, except for the 24 byte protocol header- ie, it starts with the POW nonce.
# time is the time that the pubkey was broadcast on the network same as with every other type of Bitmessage object.
# usedpersonally is set to "yes" if we have used the key
# personally. This keeps us from deleting it because we may want to
# reply to a message in the future. This field is not a bool
# because we may need more flexability in the future and it doesn't
# take up much more space anyway.
self.cur.execute(
'''CREATE TABLE pubkeys (hash blob, transmitdata blob, time int, usedpersonally text, UNIQUE(hash) ON CONFLICT REPLACE)''')
'''update sent set status='doingmsgpow' where status='doingpow'''')
self.cur.execute(
'''update sent set status='msgsent' where status='sentmessage'''')
self.cur.execute(
'''update sent set status='doingpubkeypow' where status='findingpubkey'''')
self.cur.execute(
'''update sent set status='broadcastqueued' where status='broadcastpending'''')
self.conn.commit()
try:
testpayload='\x00\x00'
t=('1234',testpayload,'12345678','no')
self.cur.execute('''INSERT INTO pubkeys VALUES(?,?,?,?)''',t)
self.conn.commit()
self.cur.execute(
'''SELECT transmitdata FROM pubkeys WHERE hash='1234'''')
queryreturn=self.cur.fetchall()
forrowinqueryreturn:
transmitdata,=row
self.cur.execute('''DELETE FROM pubkeys WHERE hash='1234'''')
self.conn.commit()
iftransmitdata=='':
sys.stderr.write('Problem: The version of SQLite you have cannot store Null values. Please download and install the latest revision of your version of Python (for example, the latest Python 2.7 revision) and try again.\n')
sys.stderr.write('PyBitmessage will now exit very abruptly. You may now see threading errors related to this abrupt exit but the problem you need to solve is related to SQLite.\n\n')
os._exit(0)
exceptExceptionaserr:
printerr
# Let us check to see the last time we vaccumed the messages.dat file.
# If it has been more than a month let's do it now.
item='''SELECT value FROM settings WHERE key='lastvacuumtime';'''
parameters=''
self.cur.execute(item,parameters)
queryreturn=self.cur.fetchall()
forrowinqueryreturn:
value,=row
ifint(value)<int(time.time())-2592000:
print'It has been a long time since the messages.dat file has been vacuumed. Vacuuming now...'
self.cur.execute(''' VACUUM ''')
item='''update settings set value=? WHERE key='lastvacuumtime';'''
parameters=(int(time.time()),)
self.cur.execute(item,parameters)
whileTrue:
item=shared.sqlSubmitQueue.get()
ifitem=='commit':
self.conn.commit()
elifitem=='exit':
self.conn.close()
shared.printLock.acquire()
print'sqlThread exiting gracefully.'
shared.printLock.release()
return
elifitem=='movemessagstoprog':
shared.printLock.acquire()
print'the sqlThread is moving the messages.dat file to the local program directory.'
self.cur.execute('''delete from inbox where folder='trash'''')
self.cur.execute('''delete from sent where folder='trash'''')
self.conn.commit()
self.cur.execute(''' VACUUM ''')
else:
parameters=shared.sqlSubmitQueue.get()
# print 'item', item
# print 'parameters', parameters
try:
self.cur.execute(item,parameters)
exceptExceptionaserr:
shared.printLock.acquire()
sys.stderr.write('\nMajor error occurred when trying to execute a SQL statement within the sqlThread. Please tell Atheros about this error message or post it in the forum! Error occurred while trying to execute statement: "'+str(
item)+'" Here are the parameters; you might want to censor this data with asterisks (***) as it can contain private information: '+str(repr(parameters))+'\nHere is the actual error message thrown by the sqlThread: '+str(err)+'\n')
sys.stderr.write('This program shall now abruptly exit!\n')