mirror of
https://github.com/fluencelabs/eip712-validation-node
synced 2025-06-14 15:31:41 +00:00
update db
This commit is contained in:
@ -12,7 +12,7 @@ export async function get_db(db_path: any) {
|
||||
db_path = ':memory';
|
||||
}
|
||||
|
||||
let db = new sqlite3.Database(db_path, (err: any) => {
|
||||
var db = new sqlite3.Database(db_path, (err: any) => {
|
||||
if (err) {
|
||||
return console.error("failure to get sqlite: ", err.message);
|
||||
}
|
||||
@ -21,16 +21,16 @@ export async function get_db(db_path: any) {
|
||||
|
||||
}
|
||||
|
||||
export async function crate_table(db: any) {
|
||||
const stmt = `create table if not exists snapshot.db (
|
||||
snapshot_id: integer primary key,
|
||||
event_address: text,
|
||||
event_signature: text,
|
||||
export async function create_table(db: any) {
|
||||
const stmt = `create table if not exists snapshot (
|
||||
snapshot_id integer primary key,
|
||||
event_address text,
|
||||
event_signature text,
|
||||
eip712_doc text,
|
||||
peer_id: text,
|
||||
timestamp: integer;
|
||||
eip_validation: boolean;
|
||||
ts_validation: boolean;
|
||||
peer_id text,
|
||||
timestamp integer,
|
||||
eip_validation boolean,
|
||||
ts_validation boolean,
|
||||
signed_response text
|
||||
)`;
|
||||
|
||||
@ -38,15 +38,42 @@ export async function crate_table(db: any) {
|
||||
}
|
||||
|
||||
export async function insert_event(db: any, eip_obj: any, response_obj: Response, signed_msg: string) {
|
||||
const stmt = `insert into snapshot.db (
|
||||
values (?,?,?,?,?,?,?,?,?)
|
||||
)`;
|
||||
const values = [eip_obj.data.message.snapshot, eip_obj.address, eip_obj.sig, JSON.stringify(eip_obj.data), response_obj.peer_id, response_obj.timestamp, response_obj.eip_validation, response_obj.ts_validation, signed_msg];
|
||||
db.run(stmt, values, function (err: any) {
|
||||
const stmt = `insert into snapshot values (?,?,?,?,?,?,?,?,?)`;
|
||||
var cursor = db.prepare(stmt);
|
||||
|
||||
const vals = [eip_obj.data.message.snapshot, eip_obj.address, eip_obj.sig, JSON.stringify(eip_obj.data), response_obj.peer_id, response_obj.timestamp, response_obj.eip_validation, response_obj.ts_validation, signed_msg];
|
||||
for (let v of vals) {
|
||||
console.log(typeof (v));
|
||||
}
|
||||
|
||||
cursor.run(stmt, vals, function (err: any) {
|
||||
if (err) {
|
||||
return console.log(err.message);
|
||||
return console.log("insert error: ", err.message);
|
||||
}
|
||||
// console.log(`A row has been inserted with row id: ${this.lastID}`);
|
||||
// console.log(`A row has been inserted with row id: ${db.}`);
|
||||
});
|
||||
cursor.finalize();
|
||||
}
|
||||
|
||||
|
||||
/*
|
||||
|
||||
var db = new sqlite3.Database(DB_PATH);
|
||||
db.serialize(function () {
|
||||
const create_stmt = "CREATE TABLE lorem (info TEXT)";
|
||||
db.run(create_stmt);
|
||||
|
||||
const ins_stmt = "INSERT INTO lorem VALUES (?)";
|
||||
var stmt = db.prepare("INSERT INTO lorem VALUES (?)");
|
||||
for (var i = 0; i < 10; i++) {
|
||||
stmt.run("Ipsum " + i);
|
||||
}
|
||||
stmt.finalize();
|
||||
|
||||
db.each("SELECT rowid AS id, info FROM lorem", function (err: any, row: any) {
|
||||
console.log(row.id + ": " + row.info);
|
||||
});
|
||||
});
|
||||
|
||||
*/
|
Reference in New Issue
Block a user