From e60d12ddbff331bdd43febfcf1c99963f3fd27e4 Mon Sep 17 00:00:00 2001 From: navjot Date: Tue, 15 Sep 2020 16:48:24 +0530 Subject: [PATCH] Refactord the uuid creation code and placed it in helper_sent.insert method refactored on the bases of comments Fixed CQ of src.helper_sent module fixed CQ for helper_sent module --- src/bitmessagecurses/__init__.py | 13 +++++-------- src/bitmessageqt/__init__.py | 11 ++++------- src/helper_sent.py | 11 +++++++++++ 3 files changed, 20 insertions(+), 15 deletions(-) diff --git a/src/bitmessagecurses/__init__.py b/src/bitmessagecurses/__init__.py index cc9eac41..564a30a8 100644 --- a/src/bitmessagecurses/__init__.py +++ b/src/bitmessagecurses/__init__.py @@ -19,6 +19,7 @@ from textwrap import fill from threading import Timer from dialog import Dialog +import helper_sent import l10n import network.stats import queues @@ -32,8 +33,6 @@ from helper_ackPayload import genAckPayload from helper_sql import sqlExecute, sqlQuery from inventory import Inventory -import uuid -import helper_sent # pylint: disable=global-statement @@ -969,9 +968,8 @@ def sendMessage(sender="", recv="", broadcast=None, subject="", body="", reply=F scrollbox(d, unicode("Because you are not currently connected to the network, ")) stealthLevel = BMConfigParser().safeGetInt('bitmessagesettings', 'ackstealthlevel') ackdata = genAckPayload(decodeAddress(addr)[2], stealthLevel) - msgid = uuid.uuid4().bytes t = ( - msgid, + '', addr, ripe, sender, @@ -985,7 +983,7 @@ def sendMessage(sender="", recv="", broadcast=None, subject="", body="", reply=F 0, # retryNumber "sent", 2, # encodingType - BMConfigParser().getint('bitmessagesettings', 'ttl') + 0 ) helper_sent.insert(t) queues.workerQueue.put(("sendmessage", addr)) @@ -998,9 +996,8 @@ def sendMessage(sender="", recv="", broadcast=None, subject="", body="", reply=F ackdata = genAckPayload(decodeAddress(addr)[2], 0) recv = BROADCAST_STR ripe = "" - msgid = uuid.uuid4().bytes t = ( - msgid, + '', recv, ripe, sender, @@ -1014,7 +1011,7 @@ def sendMessage(sender="", recv="", broadcast=None, subject="", body="", reply=F 0, # retryNumber "sent", # folder 2, # encodingType - BMConfigParser().getint('bitmessagesettings', 'ttl') + 0 ) helper_sent.insert(t) queues.workerQueue.put(('sendbroadcast', '')) diff --git a/src/bitmessageqt/__init__.py b/src/bitmessageqt/__init__.py index fa69bbd9..fba76a0c 100644 --- a/src/bitmessageqt/__init__.py +++ b/src/bitmessageqt/__init__.py @@ -54,7 +54,6 @@ from statusbar import BMStatusBar import sound # This is needed for tray icon import bitmessage_icons_rc # noqa:F401 pylint: disable=unused-import -import uuid import helper_sent try: @@ -2167,9 +2166,8 @@ class MyForm(settingsmixin.SMainWindow): stealthLevel = BMConfigParser().safeGetInt( 'bitmessagesettings', 'ackstealthlevel') ackdata = genAckPayload(streamNumber, stealthLevel) - msgid = uuid.uuid4().bytes t = ( - msgid, + '', toAddress, ripe, fromAddress, @@ -2183,7 +2181,7 @@ class MyForm(settingsmixin.SMainWindow): 0, # retryNumber 'sent', # folder encoding, # encodingtype - BMConfigParser().getint('bitmessagesettings', 'ttl') + 0 ) helper_sent.insert(t) toLabel = '' @@ -2223,8 +2221,7 @@ class MyForm(settingsmixin.SMainWindow): ackdata = genAckPayload(streamNumber, 0) toAddress = str_broadcast_subscribers ripe = '' - msgid = uuid.uuid4().bytes - t = (msgid, # msgid. We don't know what this will be until the POW is done. + t = ('', # msgid. We don't know what this will be until the POW is done. toAddress, ripe, fromAddress, @@ -2238,7 +2235,7 @@ class MyForm(settingsmixin.SMainWindow): 0, # retryNumber 'sent', # folder encoding, # encoding type - BMConfigParser().getint('bitmessagesettings', 'ttl') + 0 ) helper_sent.insert(t) diff --git a/src/helper_sent.py b/src/helper_sent.py index bc3362e8..1cf48ece 100644 --- a/src/helper_sent.py +++ b/src/helper_sent.py @@ -2,9 +2,20 @@ Insert values into sent table """ +import uuid +from bmconfigparser import BMConfigParser from helper_sql import sqlExecute def insert(t): """Perform an insert into the `sent` table""" + if not t[0] or not t[-1]: + temp = list(t) + if not t[0]: + print('zero index is not available') + temp[0] = uuid.uuid4().bytes # if msgid is empty the put uuid + if not t[-1]: + print('Lasr index is not available') + temp[-1] = BMConfigParser().getint('bitmessagesettings', 'ttl') + t = tuple(temp) sqlExecute('''INSERT INTO sent VALUES (?,?,?,?,?,?,?,?,?,?,?,?,?,?,?)''', *t)