This repository has been archived on 2024-12-07. You can view files and clone it, but cannot push or open issues or pull requests.
PyBitmessage-2024-12-07/src/helper_sent.py

48 lines
1.5 KiB
Python
Raw Normal View History

2019-10-07 15:58:12 +02:00
"""
2019-10-09 15:27:51 +02:00
Insert values into sent table
2019-10-07 15:58:12 +02:00
"""
2020-11-05 21:32:13 +01:00
import time
import uuid
2020-11-05 21:32:13 +01:00
from addresses import decodeAddress
from bmconfigparser import BMConfigParser
2020-11-05 21:32:13 +01:00
from helper_ackPayload import genAckPayload
2019-12-23 10:49:03 +01:00
from helper_sql import sqlExecute
2019-10-09 15:27:51 +02:00
2020-11-05 21:32:13 +01:00
def insert(t, is_testcase=False):
2019-10-09 15:27:51 +02:00
"""Perform an insert into the `sent` table"""
# pylint: disable=unused-variable
if '' in t or 0 in t:
temp = list(t)
temp_dict = {
0: uuid.uuid4().bytes, # if msgid is empty the put uuid
7: int(time.time()), # sentTime
8: int(time.time()), # lastActionTime
9: 0, # sleeptill
10: 'msgqueued',
11: 0, # retryNumber
12: 'sent', # folder
13: 2, # encoding
14: BMConfigParser().getint('bitmessagesettings', 'ttl')
}
2020-11-05 21:32:13 +01:00
if not temp[2] or not temp[6]:
status, addressVersionNumber, streamNumber, ripe = decodeAddress(temp[1])
if not temp[2]:
temp_dict[2] = ripe
2020-11-05 21:32:13 +01:00
if not temp[6]:
stealthLevel = BMConfigParser().safeGetInt(
'bitmessagesettings', 'ackstealthlevel')
ackdata = genAckPayload(streamNumber, stealthLevel)
temp_dict[6] = ackdata
for i in dict(enumerate(temp)):
if not temp[i]:
temp[i] = temp_dict[i]
t = tuple(temp)
2015-03-09 07:35:32 +01:00
sqlExecute('''INSERT INTO sent VALUES (?,?,?,?,?,?,?,?,?,?,?,?,?,?,?)''', *t)
2020-11-05 21:32:13 +01:00
return t if is_testcase else None