diff --git a/aqua/snapshot.aqua b/aqua/snapshot.aqua index 9998a16..528e68f 100644 --- a/aqua/snapshot.aqua +++ b/aqua/snapshot.aqua @@ -8,18 +8,17 @@ data DBResponse: snapshot_id: u64 service ProVoValidation("eip_validation"): - eip_validation(eip_str: string, peer_id: string) + eip712_validation(eip_str: string, peer_id: string) -> PVResponse service DataProvider(""): - get_records() - get_record(snapshot_id: u64) + get_records() -> []DBResponse + get_record(snapshot_id: u64) -> DBResponse -func validate(relay: string, peer:string, eip712_json: string) -> PVResponse { +func validate(relay: string, peer:string, eip712_json: string) -> PVResponse: on peer via relay: - result <- ProVoValidation.eip_validation(eip712_json, peer) + result <- ProVoValidation.eip712_validation(eip712_json, peer) <- result -} func get_record(relay:string, peer:string, snapshot_id: u64) -> DBResponse: diff --git a/src/eip_processor.ts b/src/eip_processor.ts index 3820d51..7724c0f 100644 --- a/src/eip_processor.ts +++ b/src/eip_processor.ts @@ -36,7 +36,8 @@ function check_signature(eip_obj: any): boolean { } -export async function eip_validation(eip_str: string, peer_id: string): Promise { +// export async function eip_validation(eip_str: string, peer_id: string): Promise { +export function eip_validation(eip_str: string, peer_id: string): Response { const eip_obj = JSON.parse(eip_str); diff --git a/src/index.ts b/src/index.ts index 61c89cd..9a39194 100644 --- a/src/index.ts +++ b/src/index.ts @@ -1,18 +1,11 @@ -// import { Fluence } from "@fluencelabs/fluence"; -// import { krasnodar } from "@fluencelabs/fluence-network-environment"; -// import { registerCalc, CalcDef } from "./_aqua/calc"; - +import { Fluence } from "@fluencelabs/fluence"; +import { krasnodar } from "@fluencelabs/fluence-network-environment"; +import { registerProVoValidation, ProVoValidationDef } from "./_aqua/snapshot"; 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, create_table, insert_event, DBRecord } from './local_db'; -var sqlite3 = require('sqlite3').verbose(); - - - - -const DB_PATH = './data/snapshot.db'; function create_wallet(): ethers.Wallet { return ethers.Wallet.createRandom(); @@ -22,43 +15,53 @@ function sign_response(wallet: ethers.Wallet, response: Response): Promise { + db.close(); + if (err) { + return console.error(err.message); + } + return row + ? console.log(row) + : console.log(`No record found for snapshot id: ${snapshot_id}`); + }); + // db.close(); +}; + +// export function select_events(): Array { +export function select_events(): any { + var db = get_db(DB_PATH); + // todo: add pagination + const stmt = 'select * from from snapshot limit ?'; + var response_arr: Array; + db.all(stmt, [100], (err, rows) => { + if (err) { + // todo: no good, change that. + return []; + } + for (var row of rows) { + const _row: DBRecord = row; + response_arr.push(_row); + }; + return response_arr; + }); + + db.close(); +} + + /* var db = new sqlite3.Database(DB_PATH);