|
|
|
@ -20,152 +20,24 @@ from debug import logger
|
|
|
|
|
# pylint: disable=attribute-defined-outside-init,protected-access
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
def execute_setting_table(func):
|
|
|
|
|
"""this method is used as a decorator"""
|
|
|
|
|
def inner(*args, **kwars):
|
|
|
|
|
reference = args[0]
|
|
|
|
|
item = '''SELECT value FROM settings WHERE key='version';'''
|
|
|
|
|
parameters = ''
|
|
|
|
|
reference.cur.execute(item, parameters)
|
|
|
|
|
func(reference)
|
|
|
|
|
return inner
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
class sqlThread(threading.Thread):
|
|
|
|
|
"""A thread for all SQL operations"""
|
|
|
|
|
|
|
|
|
|
def __init__(self):
|
|
|
|
|
threading.Thread.__init__(self, name="SQL")
|
|
|
|
|
|
|
|
|
|
def run(self): # pylint: disable=too-many-locals, too-many-branches, too-many-statements
|
|
|
|
|
"""Process SQL queries from `.helper_sql.sqlSubmitQueue`"""
|
|
|
|
|
helper_sql.sql_available = True
|
|
|
|
|
self.conn = sqlite3.connect(state.appdata + 'messages.dat')
|
|
|
|
|
self.conn.text_factory = str
|
|
|
|
|
self.cur = self.conn.cursor()
|
|
|
|
|
|
|
|
|
|
self.cur.execute('PRAGMA secure_delete = true')
|
|
|
|
|
|
|
|
|
|
try:
|
|
|
|
|
self.cur.execute(
|
|
|
|
|
'''CREATE TABLE inbox (msgid blob, toaddress text, fromaddress text, subject text,'''
|
|
|
|
|
''' received text, message text, folder text, encodingtype int, read bool, sighash blob,'''
|
|
|
|
|
''' UNIQUE(msgid) ON CONFLICT REPLACE)''')
|
|
|
|
|
self.cur.execute(
|
|
|
|
|
'''CREATE TABLE sent (msgid blob, toaddress text, toripe blob, fromaddress text, subject text,'''
|
|
|
|
|
''' message text, ackdata blob, senttime integer, lastactiontime integer,'''
|
|
|
|
|
''' sleeptill integer, status text, retrynumber integer, folder text, encodingtype int, ttl int)''')
|
|
|
|
|
self.cur.execute(
|
|
|
|
|
'''CREATE TABLE subscriptions (label text, address text, enabled bool)''')
|
|
|
|
|
self.cur.execute(
|
|
|
|
|
'''CREATE TABLE addressbook (label text, address text, UNIQUE(address) ON CONFLICT IGNORE)''')
|
|
|
|
|
self.cur.execute(
|
|
|
|
|
'''CREATE TABLE blacklist (label text, address text, enabled bool)''')
|
|
|
|
|
self.cur.execute(
|
|
|
|
|
'''CREATE TABLE whitelist (label text, address text, enabled bool)''')
|
|
|
|
|
self.cur.execute(
|
|
|
|
|
'''CREATE TABLE pubkeys (address text, addressversion int, transmitdata blob, time int,'''
|
|
|
|
|
''' usedpersonally text, UNIQUE(address) ON CONFLICT REPLACE)''')
|
|
|
|
|
self.cur.execute(
|
|
|
|
|
'''CREATE TABLE inventory (hash blob, objecttype int, streamnumber int, payload blob,'''
|
|
|
|
|
''' expirestime integer, tag blob, UNIQUE(hash) ON CONFLICT REPLACE)''')
|
|
|
|
|
self.cur.execute(
|
|
|
|
|
'''INSERT INTO subscriptions VALUES'''
|
|
|
|
|
'''('Bitmessage new releases/announcements','BM-GtovgYdgs7qXPkoYaRgrLFuFKz1SFpsw',1)''')
|
|
|
|
|
self.cur.execute(
|
|
|
|
|
'''CREATE TABLE settings (key blob, value blob, UNIQUE(key) ON CONFLICT REPLACE)''')
|
|
|
|
|
self.cur.execute('''INSERT INTO settings VALUES('version','11')''')
|
|
|
|
|
self.cur.execute('''INSERT INTO settings VALUES('lastvacuumtime',?)''', (
|
|
|
|
|
int(time.time()),))
|
|
|
|
|
self.cur.execute(
|
|
|
|
|
'''CREATE TABLE objectprocessorqueue'''
|
|
|
|
|
''' (objecttype int, data blob, UNIQUE(objecttype, data) ON CONFLICT REPLACE)''')
|
|
|
|
|
self.conn.commit()
|
|
|
|
|
logger.info('Created messages database file')
|
|
|
|
|
except Exception as err:
|
|
|
|
|
if str(err) == 'table inbox already exists':
|
|
|
|
|
logger.debug('Database file already exists.')
|
|
|
|
|
|
|
|
|
|
else:
|
|
|
|
|
sys.stderr.write(
|
|
|
|
|
'ERROR trying to create database file (message.dat). Error message: %s\n' % str(err))
|
|
|
|
|
os._exit(0)
|
|
|
|
|
|
|
|
|
|
# If the settings version is equal to 2 or 3 then the
|
|
|
|
|
# sqlThread will modify the pubkeys table and change
|
|
|
|
|
# the settings version to 4.
|
|
|
|
|
settingsversion = BMConfigParser().getint(
|
|
|
|
|
'bitmessagesettings', 'settingsversion')
|
|
|
|
|
|
|
|
|
|
# People running earlier versions of PyBitmessage do not have the
|
|
|
|
|
# usedpersonally field in their pubkeys table. Let's add it.
|
|
|
|
|
if settingsversion == 2:
|
|
|
|
|
item = '''ALTER TABLE pubkeys ADD usedpersonally text DEFAULT 'no' '''
|
|
|
|
|
parameters = ''
|
|
|
|
|
self.cur.execute(item, parameters)
|
|
|
|
|
self.conn.commit()
|
|
|
|
|
|
|
|
|
|
settingsversion = 3
|
|
|
|
|
|
|
|
|
|
# People running earlier versions of PyBitmessage do not have the
|
|
|
|
|
# encodingtype field in their inbox and sent tables or the read field
|
|
|
|
|
# in the inbox table. Let's add them.
|
|
|
|
|
if settingsversion == 3:
|
|
|
|
|
item = '''ALTER TABLE inbox ADD encodingtype int DEFAULT '2' '''
|
|
|
|
|
parameters = ''
|
|
|
|
|
self.cur.execute(item, parameters)
|
|
|
|
|
|
|
|
|
|
item = '''ALTER TABLE inbox ADD read bool DEFAULT '1' '''
|
|
|
|
|
parameters = ''
|
|
|
|
|
self.cur.execute(item, parameters)
|
|
|
|
|
|
|
|
|
|
item = '''ALTER TABLE sent ADD encodingtype int DEFAULT '2' '''
|
|
|
|
|
parameters = ''
|
|
|
|
|
self.cur.execute(item, parameters)
|
|
|
|
|
self.conn.commit()
|
|
|
|
|
|
|
|
|
|
settingsversion = 4
|
|
|
|
|
|
|
|
|
|
BMConfigParser().set(
|
|
|
|
|
'bitmessagesettings', 'settingsversion', str(settingsversion))
|
|
|
|
|
BMConfigParser().save()
|
|
|
|
|
|
|
|
|
|
helper_startup.updateConfig()
|
|
|
|
|
|
|
|
|
|
# From now on, let us keep a 'version' embedded in the messages.dat
|
|
|
|
|
# file so that when we make changes to the database, the database
|
|
|
|
|
# version we are on can stay embedded in the messages.dat file. Let us
|
|
|
|
|
# check to see if the settings table exists yet.
|
|
|
|
|
item = '''SELECT name FROM sqlite_master WHERE type='table' AND name='settings';'''
|
|
|
|
|
parameters = ''
|
|
|
|
|
self.cur.execute(item, parameters)
|
|
|
|
|
if self.cur.fetchall() == []:
|
|
|
|
|
# The settings table doesn't exist. We need to make it.
|
|
|
|
|
logger.debug(
|
|
|
|
|
"In messages.dat database, creating new 'settings' table.")
|
|
|
|
|
self.cur.execute(
|
|
|
|
|
'''CREATE TABLE settings (key text, value blob, UNIQUE(key) ON CONFLICT REPLACE)''')
|
|
|
|
|
self.cur.execute('''INSERT INTO settings VALUES('version','1')''')
|
|
|
|
|
self.cur.execute('''INSERT INTO settings VALUES('lastvacuumtime',?)''', (
|
|
|
|
|
int(time.time()),))
|
|
|
|
|
logger.debug('In messages.dat database, removing an obsolete field from the pubkeys table.')
|
|
|
|
|
self.cur.execute(
|
|
|
|
|
'''CREATE TEMPORARY TABLE pubkeys_backup(hash blob, transmitdata blob, time int,'''
|
|
|
|
|
''' usedpersonally text, UNIQUE(hash) ON CONFLICT REPLACE);''')
|
|
|
|
|
self.cur.execute(
|
|
|
|
|
'''INSERT INTO pubkeys_backup SELECT hash, transmitdata, time, usedpersonally FROM pubkeys;''')
|
|
|
|
|
self.cur.execute('''DROP TABLE pubkeys''')
|
|
|
|
|
self.cur.execute(
|
|
|
|
|
'''CREATE TABLE pubkeys'''
|
|
|
|
|
''' (hash blob, transmitdata blob, time int, usedpersonally text, UNIQUE(hash) ON CONFLICT REPLACE)''')
|
|
|
|
|
self.cur.execute(
|
|
|
|
|
'''INSERT INTO pubkeys SELECT hash, transmitdata, time, usedpersonally FROM pubkeys_backup;''')
|
|
|
|
|
self.cur.execute('''DROP TABLE pubkeys_backup;''')
|
|
|
|
|
logger.debug(
|
|
|
|
|
'Deleting all pubkeys from inventory.'
|
|
|
|
|
' They will be redownloaded and then saved with the correct times.')
|
|
|
|
|
self.cur.execute(
|
|
|
|
|
'''delete from inventory where objecttype = 'pubkey';''')
|
|
|
|
|
logger.debug('replacing Bitmessage announcements mailing list with a new one.')
|
|
|
|
|
self.cur.execute(
|
|
|
|
|
'''delete from subscriptions where address='BM-BbkPSZbzPwpVcYZpU4yHwf9ZPEapN5Zx' ''')
|
|
|
|
|
self.cur.execute(
|
|
|
|
|
'''INSERT INTO subscriptions VALUES'''
|
|
|
|
|
'''('Bitmessage new releases/announcements','BM-GtovgYdgs7qXPkoYaRgrLFuFKz1SFpsw',1)''')
|
|
|
|
|
logger.debug('Commiting.')
|
|
|
|
|
self.conn.commit()
|
|
|
|
|
logger.debug('Vacuuming message.dat. You might notice that the file size gets much smaller.')
|
|
|
|
|
self.cur.execute(''' VACUUM ''')
|
|
|
|
|
|
|
|
|
|
def update_sent(self):
|
|
|
|
|
# After code refactoring, the possible status values for sent messages
|
|
|
|
|
# have changed.
|
|
|
|
|
self.cur.execute(
|
|
|
|
@ -178,11 +50,10 @@ class sqlThread(threading.Thread):
|
|
|
|
|
'''update sent set status='broadcastqueued' where status='broadcastpending' ''')
|
|
|
|
|
self.conn.commit()
|
|
|
|
|
|
|
|
|
|
@execute_setting_table
|
|
|
|
|
def versionTwo(self):
|
|
|
|
|
# Let's get rid of the first20bytesofencryptedmessage field in
|
|
|
|
|
# the inventory table.
|
|
|
|
|
item = '''SELECT value FROM settings WHERE key='version';'''
|
|
|
|
|
parameters = ''
|
|
|
|
|
self.cur.execute(item, parameters)
|
|
|
|
|
if int(self.cur.fetchall()[0][0]) == 2:
|
|
|
|
|
logger.debug(
|
|
|
|
|
'In messages.dat database, removing an obsolete field from'
|
|
|
|
@ -207,10 +78,9 @@ class sqlThread(threading.Thread):
|
|
|
|
|
parameters = (3,)
|
|
|
|
|
self.cur.execute(item, parameters)
|
|
|
|
|
|
|
|
|
|
@execute_setting_table
|
|
|
|
|
def versionThree(self):
|
|
|
|
|
# Add a new column to the inventory table to store tags.
|
|
|
|
|
item = '''SELECT value FROM settings WHERE key='version';'''
|
|
|
|
|
parameters = ''
|
|
|
|
|
self.cur.execute(item, parameters)
|
|
|
|
|
currentVersion = int(self.cur.fetchall()[0][0])
|
|
|
|
|
if currentVersion == 1 or currentVersion == 3:
|
|
|
|
|
logger.debug(
|
|
|
|
@ -223,11 +93,10 @@ class sqlThread(threading.Thread):
|
|
|
|
|
parameters = (4,)
|
|
|
|
|
self.cur.execute(item, parameters)
|
|
|
|
|
|
|
|
|
|
@execute_setting_table
|
|
|
|
|
def versionFour(self):
|
|
|
|
|
# Add a new column to the pubkeys table to store the address version.
|
|
|
|
|
# We're going to trash all of our pubkeys and let them be redownloaded.
|
|
|
|
|
item = '''SELECT value FROM settings WHERE key='version';'''
|
|
|
|
|
parameters = ''
|
|
|
|
|
self.cur.execute(item, parameters)
|
|
|
|
|
currentVersion = int(self.cur.fetchall()[0][0])
|
|
|
|
|
if currentVersion == 4:
|
|
|
|
|
self.cur.execute('''DROP TABLE pubkeys''')
|
|
|
|
@ -240,11 +109,10 @@ class sqlThread(threading.Thread):
|
|
|
|
|
parameters = (5,)
|
|
|
|
|
self.cur.execute(item, parameters)
|
|
|
|
|
|
|
|
|
|
@execute_setting_table
|
|
|
|
|
def versionFive(self):
|
|
|
|
|
# Add a new table: objectprocessorqueue with which to hold objects
|
|
|
|
|
# that have yet to be processed if the user shuts down Bitmessage.
|
|
|
|
|
item = '''SELECT value FROM settings WHERE key='version';'''
|
|
|
|
|
parameters = ''
|
|
|
|
|
self.cur.execute(item, parameters)
|
|
|
|
|
currentVersion = int(self.cur.fetchall()[0][0])
|
|
|
|
|
if currentVersion == 5:
|
|
|
|
|
self.cur.execute('''DROP TABLE knownnodes''')
|
|
|
|
@ -255,12 +123,11 @@ class sqlThread(threading.Thread):
|
|
|
|
|
parameters = (6,)
|
|
|
|
|
self.cur.execute(item, parameters)
|
|
|
|
|
|
|
|
|
|
@execute_setting_table
|
|
|
|
|
def versionSix(self):
|
|
|
|
|
# changes related to protocol v3
|
|
|
|
|
# In table inventory and objectprocessorqueue, objecttype is now
|
|
|
|
|
# an integer (it was a human-friendly string previously)
|
|
|
|
|
item = '''SELECT value FROM settings WHERE key='version';'''
|
|
|
|
|
parameters = ''
|
|
|
|
|
self.cur.execute(item, parameters)
|
|
|
|
|
currentVersion = int(self.cur.fetchall()[0][0])
|
|
|
|
|
if currentVersion == 6:
|
|
|
|
|
logger.debug(
|
|
|
|
@ -281,12 +148,11 @@ class sqlThread(threading.Thread):
|
|
|
|
|
logger.debug(
|
|
|
|
|
'Finished dropping and recreating the inventory table.')
|
|
|
|
|
|
|
|
|
|
@execute_setting_table
|
|
|
|
|
def versionSeven(self):
|
|
|
|
|
# The format of data stored in the pubkeys table has changed. Let's
|
|
|
|
|
# clear it, and the pubkeys from inventory, so that they'll
|
|
|
|
|
# be re-downloaded.
|
|
|
|
|
item = '''SELECT value FROM settings WHERE key='version';'''
|
|
|
|
|
parameters = ''
|
|
|
|
|
self.cur.execute(item, parameters)
|
|
|
|
|
currentVersion = int(self.cur.fetchall()[0][0])
|
|
|
|
|
if currentVersion == 7:
|
|
|
|
|
logger.debug(
|
|
|
|
@ -305,12 +171,11 @@ class sqlThread(threading.Thread):
|
|
|
|
|
self.cur.execute(query, parameters)
|
|
|
|
|
logger.debug('Finished clearing currently held pubkeys.')
|
|
|
|
|
|
|
|
|
|
@execute_setting_table
|
|
|
|
|
def versionEight(self):
|
|
|
|
|
# Add a new column to the inbox table to store the hash of
|
|
|
|
|
# the message signature. We'll use this as temporary message UUID
|
|
|
|
|
# in order to detect duplicates.
|
|
|
|
|
item = '''SELECT value FROM settings WHERE key='version';'''
|
|
|
|
|
parameters = ''
|
|
|
|
|
self.cur.execute(item, parameters)
|
|
|
|
|
currentVersion = int(self.cur.fetchall()[0][0])
|
|
|
|
|
if currentVersion == 8:
|
|
|
|
|
logger.debug(
|
|
|
|
@ -323,11 +188,10 @@ class sqlThread(threading.Thread):
|
|
|
|
|
parameters = (9,)
|
|
|
|
|
self.cur.execute(item, parameters)
|
|
|
|
|
|
|
|
|
|
@execute_setting_table
|
|
|
|
|
def versionNine(self):
|
|
|
|
|
# We'll also need a `sleeptill` field and a `ttl` field. Also we
|
|
|
|
|
# can combine the pubkeyretrynumber and msgretrynumber into one.
|
|
|
|
|
item = '''SELECT value FROM settings WHERE key='version';'''
|
|
|
|
|
parameters = ''
|
|
|
|
|
self.cur.execute(item, parameters)
|
|
|
|
|
currentVersion = int(self.cur.fetchall()[0][0])
|
|
|
|
|
if currentVersion == 9:
|
|
|
|
|
logger.info(
|
|
|
|
@ -390,24 +254,163 @@ class sqlThread(threading.Thread):
|
|
|
|
|
' and removing the hash field.')
|
|
|
|
|
self.cur.execute('''update settings set value=10 WHERE key='version';''')
|
|
|
|
|
|
|
|
|
|
# Update the address colunm to unique in addressbook table
|
|
|
|
|
item = '''SELECT value FROM settings WHERE key='version';'''
|
|
|
|
|
def run(self): # pylint: disable=too-many-locals, too-many-branches, too-many-statements
|
|
|
|
|
"""Process SQL queries from `.helper_sql.sqlSubmitQueue`"""
|
|
|
|
|
helper_sql.sql_available = True
|
|
|
|
|
self.conn = sqlite3.connect(state.appdata + 'messages.dat')
|
|
|
|
|
self.conn.text_factory = str
|
|
|
|
|
self.cur = self.conn.cursor()
|
|
|
|
|
|
|
|
|
|
self.cur.execute('PRAGMA secure_delete = true')
|
|
|
|
|
|
|
|
|
|
try:
|
|
|
|
|
self.cur.execute(
|
|
|
|
|
'''CREATE TABLE inbox (msgid blob, toaddress text, fromaddress text, subject text,'''
|
|
|
|
|
''' received text, message text, folder text, encodingtype int, read bool, sighash blob,'''
|
|
|
|
|
''' UNIQUE(msgid) ON CONFLICT REPLACE)''')
|
|
|
|
|
self.cur.execute(
|
|
|
|
|
'''CREATE TABLE sent (msgid blob, toaddress text, toripe blob, fromaddress text, subject text,'''
|
|
|
|
|
''' message text, ackdata blob, senttime integer, lastactiontime integer,'''
|
|
|
|
|
''' sleeptill integer, status text, retrynumber integer, folder text, encodingtype int, ttl int)''')
|
|
|
|
|
self.cur.execute(
|
|
|
|
|
'''CREATE TABLE subscriptions (label text, address text, enabled bool)''')
|
|
|
|
|
self.cur.execute(
|
|
|
|
|
'''CREATE TABLE addressbook (label text, address text)''')
|
|
|
|
|
self.cur.execute(
|
|
|
|
|
'''CREATE TABLE blacklist (label text, address text, enabled bool)''')
|
|
|
|
|
self.cur.execute(
|
|
|
|
|
'''CREATE TABLE whitelist (label text, address text, enabled bool)''')
|
|
|
|
|
self.cur.execute(
|
|
|
|
|
'''CREATE TABLE pubkeys (address text, addressversion int, transmitdata blob, time int,'''
|
|
|
|
|
''' usedpersonally text, UNIQUE(address) ON CONFLICT REPLACE)''')
|
|
|
|
|
self.cur.execute(
|
|
|
|
|
'''CREATE TABLE inventory (hash blob, objecttype int, streamnumber int, payload blob,'''
|
|
|
|
|
''' expirestime integer, tag blob, UNIQUE(hash) ON CONFLICT REPLACE)''')
|
|
|
|
|
self.cur.execute(
|
|
|
|
|
'''INSERT INTO subscriptions VALUES'''
|
|
|
|
|
'''('Bitmessage new releases/announcements','BM-GtovgYdgs7qXPkoYaRgrLFuFKz1SFpsw',1)''')
|
|
|
|
|
self.cur.execute(
|
|
|
|
|
'''CREATE TABLE settings (key blob, value blob, UNIQUE(key) ON CONFLICT REPLACE)''')
|
|
|
|
|
self.cur.execute('''INSERT INTO settings VALUES('version','10')''')
|
|
|
|
|
self.cur.execute('''INSERT INTO settings VALUES('lastvacuumtime',?)''', (
|
|
|
|
|
int(time.time()),))
|
|
|
|
|
self.cur.execute(
|
|
|
|
|
'''CREATE TABLE objectprocessorqueue'''
|
|
|
|
|
''' (objecttype int, data blob, UNIQUE(objecttype, data) ON CONFLICT REPLACE)''')
|
|
|
|
|
self.conn.commit()
|
|
|
|
|
logger.info('Created messages database file')
|
|
|
|
|
except Exception as err:
|
|
|
|
|
if str(err) == 'table inbox already exists':
|
|
|
|
|
logger.debug('Database file already exists.')
|
|
|
|
|
|
|
|
|
|
else:
|
|
|
|
|
sys.stderr.write(
|
|
|
|
|
'ERROR trying to create database file (message.dat). Error message: %s\n' % str(err))
|
|
|
|
|
os._exit(0)
|
|
|
|
|
|
|
|
|
|
# If the settings version is equal to 2 or 3 then the
|
|
|
|
|
# sqlThread will modify the pubkeys table and change
|
|
|
|
|
# the settings version to 4.
|
|
|
|
|
settingsversion = BMConfigParser().getint(
|
|
|
|
|
'bitmessagesettings', 'settingsversion')
|
|
|
|
|
|
|
|
|
|
# People running earlier versions of PyBitmessage do not have the
|
|
|
|
|
# usedpersonally field in their pubkeys table. Let's add it.
|
|
|
|
|
if settingsversion == 2:
|
|
|
|
|
item = '''ALTER TABLE pubkeys ADD usedpersonally text DEFAULT 'no' '''
|
|
|
|
|
parameters = ''
|
|
|
|
|
self.cur.execute(item, parameters)
|
|
|
|
|
self.conn.commit()
|
|
|
|
|
|
|
|
|
|
settingsversion = 3
|
|
|
|
|
|
|
|
|
|
# People running earlier versions of PyBitmessage do not have the
|
|
|
|
|
# encodingtype field in their inbox and sent tables or the read field
|
|
|
|
|
# in the inbox table. Let's add them.
|
|
|
|
|
if settingsversion == 3:
|
|
|
|
|
item = '''ALTER TABLE inbox ADD encodingtype int DEFAULT '2' '''
|
|
|
|
|
parameters = ''
|
|
|
|
|
self.cur.execute(item, parameters)
|
|
|
|
|
|
|
|
|
|
item = '''ALTER TABLE inbox ADD read bool DEFAULT '1' '''
|
|
|
|
|
parameters = ''
|
|
|
|
|
self.cur.execute(item, parameters)
|
|
|
|
|
|
|
|
|
|
item = '''ALTER TABLE sent ADD encodingtype int DEFAULT '2' '''
|
|
|
|
|
parameters = ''
|
|
|
|
|
self.cur.execute(item, parameters)
|
|
|
|
|
self.conn.commit()
|
|
|
|
|
|
|
|
|
|
settingsversion = 4
|
|
|
|
|
|
|
|
|
|
BMConfigParser().set(
|
|
|
|
|
'bitmessagesettings', 'settingsversion', str(settingsversion))
|
|
|
|
|
BMConfigParser().save()
|
|
|
|
|
|
|
|
|
|
helper_startup.updateConfig()
|
|
|
|
|
|
|
|
|
|
# From now on, let us keep a 'version' embedded in the messages.dat
|
|
|
|
|
# file so that when we make changes to the database, the database
|
|
|
|
|
# version we are on can stay embedded in the messages.dat file. Let us
|
|
|
|
|
# check to see if the settings table exists yet.
|
|
|
|
|
item = '''SELECT name FROM sqlite_master WHERE type='table' AND name='settings';'''
|
|
|
|
|
parameters = ''
|
|
|
|
|
self.cur.execute(item, parameters)
|
|
|
|
|
currentVersion = int(self.cur.fetchall()[0][0])
|
|
|
|
|
if currentVersion == 10:
|
|
|
|
|
if self.cur.fetchall() == []:
|
|
|
|
|
# The settings table doesn't exist. We need to make it.
|
|
|
|
|
logger.debug(
|
|
|
|
|
'In messages.dat database, updating address column to UNIQUE'
|
|
|
|
|
' in the addressbook table.')
|
|
|
|
|
"In messages.dat database, creating new 'settings' table.")
|
|
|
|
|
self.cur.execute(
|
|
|
|
|
'''ALTER TABLE addressbook RENAME TO old_addressbook''')
|
|
|
|
|
'''CREATE TABLE settings (key text, value blob, UNIQUE(key) ON CONFLICT REPLACE)''')
|
|
|
|
|
self.cur.execute('''INSERT INTO settings VALUES('version','1')''')
|
|
|
|
|
self.cur.execute('''INSERT INTO settings VALUES('lastvacuumtime',?)''', (
|
|
|
|
|
int(time.time()),))
|
|
|
|
|
logger.debug('In messages.dat database, removing an obsolete field from the pubkeys table.')
|
|
|
|
|
self.cur.execute(
|
|
|
|
|
'''CREATE TEMPORARY TABLE pubkeys_backup(hash blob, transmitdata blob, time int,'''
|
|
|
|
|
''' usedpersonally text, UNIQUE(hash) ON CONFLICT REPLACE);''')
|
|
|
|
|
self.cur.execute(
|
|
|
|
|
'''INSERT INTO pubkeys_backup SELECT hash, transmitdata, time, usedpersonally FROM pubkeys;''')
|
|
|
|
|
self.cur.execute('''DROP TABLE pubkeys''')
|
|
|
|
|
self.cur.execute(
|
|
|
|
|
'''CREATE TABLE pubkeys'''
|
|
|
|
|
''' (hash blob, transmitdata blob, time int, usedpersonally text, UNIQUE(hash) ON CONFLICT REPLACE)''')
|
|
|
|
|
self.cur.execute(
|
|
|
|
|
'''INSERT INTO pubkeys SELECT hash, transmitdata, time, usedpersonally FROM pubkeys_backup;''')
|
|
|
|
|
self.cur.execute('''DROP TABLE pubkeys_backup;''')
|
|
|
|
|
logger.debug(
|
|
|
|
|
'Deleting all pubkeys from inventory.'
|
|
|
|
|
' They will be redownloaded and then saved with the correct times.')
|
|
|
|
|
self.cur.execute(
|
|
|
|
|
'''CREATE TABLE addressbook'''
|
|
|
|
|
''' (label text, address text, UNIQUE(address) ON CONFLICT IGNORE)''')
|
|
|
|
|
'''delete from inventory where objecttype = 'pubkey';''')
|
|
|
|
|
logger.debug('replacing Bitmessage announcements mailing list with a new one.')
|
|
|
|
|
self.cur.execute(
|
|
|
|
|
'''INSERT INTO addressbook SELECT label, address FROM old_addressbook;''')
|
|
|
|
|
self.cur.execute('''DROP TABLE old_addressbook''')
|
|
|
|
|
self.cur.execute('''update settings set value=11 WHERE key='version';''')
|
|
|
|
|
'''delete from subscriptions where address='BM-BbkPSZbzPwpVcYZpU4yHwf9ZPEapN5Zx' ''')
|
|
|
|
|
self.cur.execute(
|
|
|
|
|
'''INSERT INTO subscriptions VALUES'''
|
|
|
|
|
'''('Bitmessage new releases/announcements','BM-GtovgYdgs7qXPkoYaRgrLFuFKz1SFpsw',1)''')
|
|
|
|
|
logger.debug('Commiting.')
|
|
|
|
|
self.conn.commit()
|
|
|
|
|
logger.debug('Vacuuming message.dat. You might notice that the file size gets much smaller.')
|
|
|
|
|
self.cur.execute(''' VACUUM ''')
|
|
|
|
|
|
|
|
|
|
self.update_sent()
|
|
|
|
|
|
|
|
|
|
self.versionTwo()
|
|
|
|
|
|
|
|
|
|
self.versionThree()
|
|
|
|
|
|
|
|
|
|
self.versionFour()
|
|
|
|
|
|
|
|
|
|
self.versionFive()
|
|
|
|
|
|
|
|
|
|
self.versionSix()
|
|
|
|
|
|
|
|
|
|
self.versionSeven()
|
|
|
|
|
|
|
|
|
|
self.versionEight()
|
|
|
|
|
|
|
|
|
|
self.versionNine()
|
|
|
|
|
|
|
|
|
|
# Are you hoping to add a new option to the keys.dat file of existing
|
|
|
|
|
# Bitmessage users or modify the SQLite database? Add it right
|
|
|
|
|