mirror of
https://github.com/fluencelabs/eip712-validation-node
synced 2025-05-10 07:17:11 +00:00
update db
This commit is contained in:
parent
68869a5eca
commit
8aad787da9
BIN
data/snapshot.db
BIN
data/snapshot.db
Binary file not shown.
13
src/index.ts
13
src/index.ts
@ -5,7 +5,10 @@
|
||||
import { ethers } from "ethers";
|
||||
import { TypedDataUtils } from 'ethers-eip712'; // https://github.com/0xsequence/ethers-eip712
|
||||
import { eip_validation, Response } from "./eip_processor";
|
||||
import { get_db, crate_table, insert_event } from './local_db';
|
||||
import { get_db, create_table, insert_event } from './local_db';
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
const DB_PATH = './data/snapshot.db';
|
||||
@ -47,8 +50,12 @@ async function main() {
|
||||
|
||||
// return (resp_str, signed_response);
|
||||
|
||||
var db = get_db('./data/snapshot.db');
|
||||
// crate_table(db);
|
||||
var db = await get_db(DB_PATH);
|
||||
await create_table(db);
|
||||
await insert_event(db, JSON.parse(eip712_doc), response, signed_response);
|
||||
|
||||
|
||||
db.close();
|
||||
}
|
||||
|
||||
main();
|
||||
|
@ -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);
|
||||
});
|
||||
});
|
||||
|
||||
*/
|
Loading…
x
Reference in New Issue
Block a user