update db schema to eip712 signature instead of snapshot id

This commit is contained in:
boneyard93501
2021-11-06 18:50:27 -05:00
parent e23d66d2f8
commit dea3be5d4e
6 changed files with 27 additions and 29 deletions

View File

@ -14,9 +14,8 @@ data ValidationResult:
data DBRecord:
snapshot_id: u64
signature: u64
event_address: string
event_signature: string
eip712_doc: string
peer_id: string
timestamp: u64
@ -34,7 +33,7 @@ service EIPValidator("snapshot"):
service DataProvider("snapshot"):
get_records() -> DBResult
get_record(snapshot_id: u64) -> DBResult
get_record(signnature: string) -> DBResult
get_record_count() -> u64
delete_records(password: string) -> DBResult
@ -48,9 +47,9 @@ func validate_from_url(relay: string, peer:string, eip712_url: string) -> Valida
result <- EIPValidator.eip712_validation_url(eip712_url, peer)
<- result
func get_record(relay:string, peer:string, snapshot_id: u64) -> DBResult:
func get_record(relay:string, peer:string, signature: string) -> DBResult:
on peer via relay:
result <- DataProvider.get_record(snapshot_id)
result <- DataProvider.get_record(signature)
<- result
func get_records(relay:string, peer:string) -> DBResult:

Binary file not shown.

View File

@ -80,10 +80,10 @@ export function registerEIPValidator(...args: any) {
export interface DataProviderDef {
delete_records: (password: string, callParams: CallParams<'password'>) => { stderr: string; stdout: { eip712_doc: string; eip_validation: boolean; event_address: string; event_signature: string; peer_id: string; signed_response: string; snapshot_id: number; timestamp: number; ts_validation: boolean; }[]; } | Promise<{ stderr: string; stdout: { eip712_doc: string; eip_validation: boolean; event_address: string; event_signature: string; peer_id: string; signed_response: string; snapshot_id: number; timestamp: number; ts_validation: boolean; }[]; }>;
get_record: (snapshot_id: number, callParams: CallParams<'snapshot_id'>) => { stderr: string; stdout: { eip712_doc: string; eip_validation: boolean; event_address: string; event_signature: string; peer_id: string; signed_response: string; snapshot_id: number; timestamp: number; ts_validation: boolean; }[]; } | Promise<{ stderr: string; stdout: { eip712_doc: string; eip_validation: boolean; event_address: string; event_signature: string; peer_id: string; signed_response: string; snapshot_id: number; timestamp: number; ts_validation: boolean; }[]; }>;
delete_records: (password: string, callParams: CallParams<'password'>) => { stderr: string; stdout: { eip712_doc: string; eip_validation: boolean; event_address: string; peer_id: string; signature: number; signed_response: string; timestamp: number; ts_validation: boolean; }[]; } | Promise<{ stderr: string; stdout: { eip712_doc: string; eip_validation: boolean; event_address: string; peer_id: string; signature: number; signed_response: string; timestamp: number; ts_validation: boolean; }[]; }>;
get_record: (signnature: string, callParams: CallParams<'signnature'>) => { stderr: string; stdout: { eip712_doc: string; eip_validation: boolean; event_address: string; peer_id: string; signature: number; signed_response: string; timestamp: number; ts_validation: boolean; }[]; } | Promise<{ stderr: string; stdout: { eip712_doc: string; eip_validation: boolean; event_address: string; peer_id: string; signature: number; signed_response: string; timestamp: number; ts_validation: boolean; }[]; }>;
get_record_count: (callParams: CallParams<null>) => number | Promise<number>;
get_records: (callParams: CallParams<null>) => { stderr: string; stdout: { eip712_doc: string; eip_validation: boolean; event_address: string; event_signature: string; peer_id: string; signed_response: string; snapshot_id: number; timestamp: number; ts_validation: boolean; }[]; } | Promise<{ stderr: string; stdout: { eip712_doc: string; eip_validation: boolean; event_address: string; event_signature: string; peer_id: string; signed_response: string; snapshot_id: number; timestamp: number; ts_validation: boolean; }[]; }>;
get_records: (callParams: CallParams<null>) => { stderr: string; stdout: { eip712_doc: string; eip_validation: boolean; event_address: string; peer_id: string; signature: number; signed_response: string; timestamp: number; ts_validation: boolean; }[]; } | Promise<{ stderr: string; stdout: { eip712_doc: string; eip_validation: boolean; event_address: string; peer_id: string; signature: number; signed_response: string; timestamp: number; ts_validation: boolean; }[]; }>;
}
export function registerDataProvider(service: DataProviderDef): void;
export function registerDataProvider(serviceId: string, service: DataProviderDef): void;
@ -115,7 +115,7 @@ export function registerDataProvider(...args: any) {
"functionName" : "get_record",
"argDefs" : [
{
"name" : "snapshot_id",
"name" : "signnature",
"argType" : {
"tag" : "primitive"
}
@ -329,9 +329,9 @@ export function get_count(...args: any) {
}
export type Get_recordResult = { stderr: string; stdout: { eip712_doc: string; eip_validation: boolean; event_address: string; event_signature: string; peer_id: string; signed_response: string; snapshot_id: number; timestamp: number; ts_validation: boolean; }[]; }
export function get_record(relay: string, peer_: string, snapshot_id: number, config?: {ttl?: number}): Promise<Get_recordResult>;
export function get_record(peer: FluencePeer, relay: string, peer_: string, snapshot_id: number, config?: {ttl?: number}): Promise<Get_recordResult>;
export type Get_recordResult = { stderr: string; stdout: { eip712_doc: string; eip_validation: boolean; event_address: string; peer_id: string; signature: number; signed_response: string; timestamp: number; ts_validation: boolean; }[]; }
export function get_record(relay: string, peer_: string, signature: string, config?: {ttl?: number}): Promise<Get_recordResult>;
export function get_record(peer: FluencePeer, relay: string, peer_: string, signature: string, config?: {ttl?: number}): Promise<Get_recordResult>;
export function get_record(...args: any) {
let script = `
@ -350,14 +350,14 @@ export function get_record(...args: any) {
)
(call %init_peer_id% ("getDataSrv" "peer") [] peer)
)
(call %init_peer_id% ("getDataSrv" "snapshot_id") [] snapshot_id)
(call %init_peer_id% ("getDataSrv" "signature") [] signature)
)
(call -relay- ("op" "noop") [])
)
(call relay ("op" "noop") [])
)
(xor
(call peer ("snapshot" "get_record") [snapshot_id] result)
(call peer ("snapshot" "get_record") [signature] result)
(seq
(seq
(seq
@ -403,7 +403,7 @@ export function get_record(...args: any) {
}
},
{
"name" : "snapshot_id",
"name" : "signature",
"argType" : {
"tag" : "primitive"
}
@ -424,7 +424,7 @@ export function get_record(...args: any) {
}
export type Delete_recordsResult = { stderr: string; stdout: { eip712_doc: string; eip_validation: boolean; event_address: string; event_signature: string; peer_id: string; signed_response: string; snapshot_id: number; timestamp: number; ts_validation: boolean; }[]; }
export type Delete_recordsResult = { stderr: string; stdout: { eip712_doc: string; eip_validation: boolean; event_address: string; peer_id: string; signature: number; signed_response: string; timestamp: number; ts_validation: boolean; }[]; }
export function delete_records(passwd: string, peer_: string, relay: string, config?: {ttl?: number}): Promise<Delete_recordsResult>;
export function delete_records(peer: FluencePeer, passwd: string, peer_: string, relay: string, config?: {ttl?: number}): Promise<Delete_recordsResult>;
export function delete_records(...args: any) {
@ -614,7 +614,7 @@ export function validate(...args: any) {
}
export type Get_recordsResult = { stderr: string; stdout: { eip712_doc: string; eip_validation: boolean; event_address: string; event_signature: string; peer_id: string; signed_response: string; snapshot_id: number; timestamp: number; ts_validation: boolean; }[]; }
export type Get_recordsResult = { stderr: string; stdout: { eip712_doc: string; eip_validation: boolean; event_address: string; peer_id: string; signature: number; signed_response: string; timestamp: number; ts_validation: boolean; }[]; }
export function get_records(relay: string, peer_: string, config?: {ttl?: number}): Promise<Get_recordsResult>;
export function get_records(peer: FluencePeer, relay: string, peer_: string, config?: {ttl?: number}): Promise<Get_recordsResult>;
export function get_records(...args: any) {

View File

@ -78,9 +78,9 @@ class EIPValidator implements EIPValidatorDef {
}
// class exposed as service `DataProviderDef` in snapshot.aqua
class DataProvider implements DataProviderDef {
// record by snapshot_id
async get_record(snapshot_id: number): Promise<any> {
return select_event(snapshot_id);
// record by signature
async get_record(signature: string): Promise<any> {
return select_event(signature);
}
// get all records. currently limited to 100 rows max.

View File

@ -11,7 +11,7 @@ const DB_PATH = './data/snapshot.db';
const PWD_HASH = "bad really bad";
export interface DBRecord {
snapshot_id: number;
signature: string;
event_address: string;
event_signature: string;
eip712_doc: string;
@ -47,9 +47,8 @@ export function get_db(db_path: string): sqlite.Database {
export async function create_table(db: sqlite.Database) {
const stmt = `create table if not exists snapshot (
snapshot_id integer unique,
signature text unique,
event_address text,
event_signature text,
eip712_doc blob,
peer_id text,
timestamp integer,
@ -71,8 +70,8 @@ export async function create_table(db: sqlite.Database) {
}
export async function insert_event(db: sqlite.Database, eip_obj: any, response_obj: Response, signed_msg: string) {
const stmt = `insert into snapshot values (?, ?, ?, ?, ?, ?, ?, ?, ?)`;
var ins_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];
const stmt = `insert into snapshot values (?, ?, ?, ?, ?, ?, ?, ?)`;
var ins_vals = [eip_obj.sig, eip_obj.address, JSON.stringify(eip_obj.data), response_obj.peer_id, response_obj.timestamp, response_obj.eip_validation, response_obj.ts_validation, signed_msg];
let promise = new Promise<void>((resolve, reject) => db.run(stmt, ins_vals, (res: sqlite.RunResult, err: Error) => {
// console.dir(res);
if (err !== null) {
@ -85,12 +84,12 @@ export async function insert_event(db: sqlite.Database, eip_obj: any, response_o
return promise;
}
export async function select_event(snapshot_id: number): Promise<DBResult> {
export async function select_event(signature: string): Promise<DBResult> {
var db = get_db(DB_PATH);
let result: DBResult = {} as DBResult;
const stmt = 'select * from snapshot where snapshot_id=?';
const stmt = 'select * from snapshot where signature=?';
return new Promise((resolve) => {
db.get(stmt, [snapshot_id], (err, row) => {
db.get(stmt, [signature], (err, row) => {
db.close();
if (err) {
result.stderr = err.message;