-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathsqlite.js
58 lines (49 loc) · 1.61 KB
/
sqlite.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
const sqlite3 = require('sqlite3').verbose();
// Create a connection to the database (or create it if it doesn't exist)
const db = new sqlite3.Database('./Sqlite/TransactionInfo.sqlite', (err) => {
if (err) {
console.error('Error opening database', err.message);
} else {
console.log('Connected to the SQLite database.');
}
})
function createTransactionInfoTable(db) {
// Create the CRV transaction table
db.run(`CREATE TABLE IF NOT EXISTS Transactions (
id INTEGER PRIMARY KEY AUTOINCREMENT,
blockNumber INTEGER,
contractAddress TEXT,
cumulativeGasUsed TEXT,
fromAddress TEXT,
toAddress TEXT,
gasUsed TEXT,
gasPrice TEXT,
blobGasUsed TEXT,
blobGasPrice TEXT,
transactionHash TEXT UNIQUE,
transactionIndex INTEGER,
status INTEGER
);`)
db.run(`CREATE TABLE IF NOT EXISTS TransactionLogs (
id INTEGER PRIMARY KEY AUTOINCREMENT,
transactionHash TEXT,
logIndex INTEGER,
address TEXT,
blockHash TEXT,
blockNumber INTEGER,
data TEXT,
topics TEXT,
FOREIGN KEY (transactionHash) REFERENCES Transactions(transactionHash)
);`);
};
// Close the database connection
function closeDatabase(db) {
db.close((err) => {
if (err) {
console.error('Error closing database', err.message);
} else {
console.log('Database connection closed.');
}
});
}
module.exports = { db, createTransactionInfoTable, closeDatabase };