· 7 years ago · Dec 02, 2018, 01:40 PM
1import sqlite3
2
3connection = sqlite3.connect('tipBotDatabase.db')
4
5
6# Create table to store wallets if it does not exist
7def create_tx_table():
8 """Table to store all transactions for history:
9 Payment ID
10 Date
11 From
12 TO
13 Amount
14 Private vs Public
15 Community"""
16
17 cursor = connection.cursor()
18 cursor.execute('CREATE TABLE IF NOT EXISTS tx_history'
19 '(payment_id TEXT,'
20 ' tx_date TEXT,'
21 ' sender TEXT, '
22 ' recipient TEXT,'
23 ' amount REAL,'
24 ' type TEXT,'
25 ' community TEXT)')
26
27
28# Store transaction into DB
29def tx_entry(payment_id, tx_timestamp, tx_sender, tx_recipient, tx_amount, tx_type, tx_community):
30 create_tx_table()
31 cursor = connection.cursor()
32 cursor.execute('INSERT INTO tx_history VALUES(?, ?, ?, ?, ?, ?, ?)',
33 (payment_id, tx_timestamp, tx_sender, tx_recipient, tx_amount, tx_type, tx_community))
34 connection.commit()
35 cursor.close()
36
37
38# check if transaction exists
39def tx_check(tx_id):
40 create_tx_table()
41 cursor = connection.cursor()
42 cursor.execute('SELECT payment_id FROM tx_history WHERE payment_id = ?', (tx_id,))
43 data = cursor.fetchone()
44
45 # Check if transaction is in database
46 if data is None:
47 return False
48 else:
49 return True