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

48 lines
1.7 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"""
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:
temp = list(t)
2020-11-05 21:32:13 +01:00
if not temp[0]:
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')
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