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
|
2020-09-15 13:18:24 +02:00
|
|
|
import uuid
|
2020-11-05 21:32:13 +01:00
|
|
|
from addresses import decodeAddress
|
2020-09-15 13:18:24 +02:00
|
|
|
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"""
|
2020-11-05 21:32:13 +01:00
|
|
|
all_fields_availabe = all([True if i else False for i in t])
|
|
|
|
if not all_fields_availabe:
|
2020-09-15 13:18:24 +02:00
|
|
|
temp = list(t)
|
2020-11-05 21:32:13 +01:00
|
|
|
if not temp[0]:
|
2020-09-15 13:18:24 +02:00
|
|
|
temp[0] = uuid.uuid4().bytes # if msgid is empty the put uuid
|
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[2] = ripe
|
|
|
|
if not temp[6]:
|
|
|
|
stealthLevel = BMConfigParser().safeGetInt(
|
|
|
|
'bitmessagesettings', 'ackstealthlevel')
|
|
|
|
ackdata = genAckPayload(streamNumber, stealthLevel)
|
|
|
|
temp[6] = ackdata
|
|
|
|
if not temp[7]: # sentTime
|
|
|
|
temp[7] = int(time.time())
|
|
|
|
if not temp[8]: # lastActionTime
|
|
|
|
temp[8] = int(time.time())
|
|
|
|
if not temp[9] and temp[9] != 0: # sleeptill
|
|
|
|
temp[9] = 0
|
|
|
|
if not temp[10]:
|
|
|
|
temp[10] = 'msgqueued'
|
|
|
|
if not temp[11] and temp[11] != 0:
|
|
|
|
temp[11] = 0
|
|
|
|
if not temp[12]:
|
|
|
|
temp[12] = 'sent'
|
|
|
|
if not temp[13]:
|
|
|
|
temp[13] = 2 # checking encoding
|
|
|
|
if not temp[14]:
|
|
|
|
temp[14] = BMConfigParser().getint('bitmessagesettings', 'ttl')
|
2020-09-15 13:18:24 +02:00
|
|
|
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
|