From 61f7f32dfc2b884c807fa0c74052522e4688254f Mon Sep 17 00:00:00 2001 From: navjot Date: Mon, 16 Nov 2020 18:50:28 +0530 Subject: [PATCH] removed unused code and return ackdata from inset method insted of msgid --- src/api.py | 4 ++-- src/bitmessagecurses/__init__.py | 6 +----- src/bitmessageqt/__init__.py | 2 +- src/class_objectProcessor.py | 4 ---- src/helper_sent.py | 12 ++++++------ src/tests/core.py | 10 ++++++---- 6 files changed, 16 insertions(+), 22 deletions(-) diff --git a/src/api.py b/src/api.py index c294937c..da8b0d51 100644 --- a/src/api.py +++ b/src/api.py @@ -1163,8 +1163,8 @@ class BMRPCDispatcher(object): toAddress = str_broadcast_subscribers helper_sent.insert( - toAddress=toAddress, fromAddress=fromAddress, - subject=subject, message=message, status='broadcastqueued', + fromAddress=fromAddress, subject=subject, + message=message, status='broadcastqueued', encoding=encodingType) toLabel = str_broadcast_subscribers diff --git a/src/bitmessagecurses/__init__.py b/src/bitmessagecurses/__init__.py index 7d694c96..3893cc7e 100644 --- a/src/bitmessagecurses/__init__.py +++ b/src/bitmessagecurses/__init__.py @@ -966,8 +966,6 @@ def sendMessage(sender="", recv="", broadcast=None, subject="", body="", reply=F if not network.stats.connectedHostsList(): set_background_title(d, "Not connected warning") scrollbox(d, unicode("Because you are not currently connected to the network, ")) - stealthLevel = BMConfigParser().safeGetInt('bitmessagesettings', 'ackstealthlevel') - ackdata = genAckPayload(decodeAddress(addr)[2], stealthLevel) helper_sent.insert( toAddress=addr, fromAddress=sender, subject=subject, message=body) queues.workerQueue.put(("sendmessage", addr)) @@ -977,10 +975,8 @@ def sendMessage(sender="", recv="", broadcast=None, subject="", body="", reply=F scrollbox(d, unicode("You must specify an address to send the message from.")) else: # dummy ackdata, no need for stealth - ackdata = genAckPayload(decodeAddress(addr)[2], 0) - recv = BROADCAST_STR helper_sent.insert( - toAddress=recv, fromAddress=sender, subject=subject, + fromAddress=sender, subject=subject, message=body, status='broadcastqueued') queues.workerQueue.put(('sendbroadcast', '')) diff --git a/src/bitmessageqt/__init__.py b/src/bitmessageqt/__init__.py index cafe8250..913b24a5 100644 --- a/src/bitmessageqt/__init__.py +++ b/src/bitmessageqt/__init__.py @@ -2208,7 +2208,7 @@ class MyForm(settingsmixin.SMainWindow): # msgid. We don't know what this will be until the POW is done. helper_sent.insert( - toAddress=toAddress, fromAddress=fromAddress, + fromAddress=fromAddress, subject=subject, message=message, status='broadcastqueued', encoding=encoding) diff --git a/src/class_objectProcessor.py b/src/class_objectProcessor.py index 01652aeb..35c2c29e 100644 --- a/src/class_objectProcessor.py +++ b/src/class_objectProcessor.py @@ -745,13 +745,9 @@ class objectProcessor(threading.Thread): # We don't actually need the ackdata for acknowledgement # since this is a broadcast message but we can use it to # update the user interface when the POW is done generating. - streamNumber = decodeAddress(fromAddress)[2] - - ackdata = genAckPayload(streamNumber, 0) toAddress = '[Broadcast subscribers]' helper_sent.insert( - toAddress=toAddress, fromAddress=fromAddress, status='broadcastqueued', subject=subject, diff --git a/src/helper_sent.py b/src/helper_sent.py index b779b4cd..635afc6b 100644 --- a/src/helper_sent.py +++ b/src/helper_sent.py @@ -11,9 +11,9 @@ from helper_sql import sqlExecute # pylint: disable=too-many-arguments -def insert(msgid=None, toAddress=None, fromAddress=None, subject=None, message=None, - status=None, ripe=None, ackdata=None, sentTime=None, lastActionTime=None, - sleeptill=0, retryNumber=0, encoding=2, ttl=None, folder='sent'): +def insert(msgid=None, toAddress='[Broadcast subscribers]', fromAddress=None, subject=None, + message=None, status='msgqueued', ripe=None, ackdata=None, sentTime=None, + lastActionTime=None, sleeptill=0, retryNumber=0, encoding=2, ttl=None, folder='sent'): """Perform an insert into the `sent` table""" # pylint: disable=unused-variable # pylint: disable-msg=too-many-locals @@ -21,7 +21,8 @@ def insert(msgid=None, toAddress=None, fromAddress=None, subject=None, message=N msgid = msgid if msgid else uuid.uuid4().bytes if not ripe or not ackdata: - new_status, addressVersionNumber, streamNumber, new_ripe = decodeAddress(toAddress) + addr = fromAddress if toAddress == '[Broadcast subscribers]' else toAddress + new_status, addressVersionNumber, streamNumber, new_ripe = decodeAddress(addr) if not ripe: ripe = new_ripe @@ -34,7 +35,6 @@ def insert(msgid=None, toAddress=None, fromAddress=None, subject=None, message=N sentTime = sentTime if sentTime else int(time.time()) # sentTime (this doesn't change) lastActionTime = lastActionTime if lastActionTime else int(time.time()) - status = status if status else 'msgqueued' ttl = ttl if ttl else BMConfigParser().getint('bitmessagesettings', 'ttl') t = (msgid, toAddress, ripe, fromAddress, subject, message, ackdata, @@ -42,4 +42,4 @@ def insert(msgid=None, toAddress=None, fromAddress=None, subject=None, message=N encoding, ttl) sqlExecute('''INSERT INTO sent VALUES (?,?,?,?,?,?,?,?,?,?,?,?,?,?,?)''', *t) - return msgid + return ackdata diff --git a/src/tests/core.py b/src/tests/core.py index bd252be8..42ebe83b 100644 --- a/src/tests/core.py +++ b/src/tests/core.py @@ -19,6 +19,7 @@ import helper_sent from bmconfigparser import BMConfigParser from helper_msgcoding import MsgEncode, MsgDecode from helper_startup import start_proxyconfig +from helper_sql import sqlQuery from network import asyncore_pollchoose as asyncore, knownnodes from network.bmproto import BMProto from network.connectionpool import BMConnectionPool @@ -246,12 +247,13 @@ class TestCore(unittest.TestCase): toAddress = 'BM-2cVWtdUzPwF7UNGDrZftWuHWgjdfkj89fdf' message = 'test message' subject = 'test subject' - status = 'msgqueued' result = helper_sent.insert( - toAddress=toAddress, fromAddress=fromAddress, subject=subject, - message=message, status=status, + toAddress=toAddress, fromAddress=fromAddress, + subject=subject, message=message, ) - self.assertNotEqual(result, '') + queryreturn = sqlQuery( + '''select msgid from sent where ackdata=?''', result) + self.assertNotEqual(queryreturn[0][0], '') def run():