diff --git a/README.md b/README.md index b6ca9ae..490b44e 100644 --- a/README.md +++ b/README.md @@ -143,7 +143,7 @@ result for call with 9278489: { stderr: '', stdout: [ { - snapshot_id: 9278489, + signature: 0xdd91572e2e721a59ca62abd4ec07c55b9496bf10969112e6c1dbb9936394bd5a602b2f697b1bb0910edb72a726bc1f05a0f13d9cbf5bc715f87211f40c75348e1c, event_address: '0xeF8305E140ac520225DAf050e2f71d5fBcC543e7', event_signature: '0xc0a90a0bf43c0b774570608bf0279143b366b7880798112b678b416a7500576b41e19f7b4eb457d58de29be3a201f700fafab1f02179da0faae653b7e8ecf82b1c', eip712_doc: '{"domain":{"name":"snapshot","version":"0.1.4"},"types":{"Proposal":[{"name":"from","type":"address"},{"name":"space","type":"string"},{"name":"timestamp","type":"uint64"},{"name":"type","type":"string"},{"name":"title","type":"string"},{"name":"body","type":"string"},{"name":"choices","type":"string[]"},{"name":"start","type":"uint64"},{"name":"end","type":"uint64"},{"name":"snapshot","type":"uint64"},{"name":"network","type":"string"},{"name":"strategies","type":"string"},{"name":"plugins","type":"string"},{"name":"metadata","type":"string"}]},"message":{"space":"fabien.eth","type":"single-choice","title":"This is a long title this is a long title this is a long title this is a long title this is a long title this is a long","body":"This is a long title this is a long title this is a long title title this is a long title this is a long title title this is a long title this is a long title title this is a long title this is a long title title this is a long title this is a long title title this is a long title this is a long title title this is a long title this is a long title title this is a long title this is a long title title this is a long title this is a long title title this is a long title this is a long title title this is a long title this is a long title title this is a long title this is a long title title this is a long title this is a long title title this is a long title this is a long title title this is a long title this is a long title.","choices":["Approve","Reject"],"start":1630472400,"end":1640926800,"snapshot":9278489,"network":"4","strategies":"[{\\"name\\":\\"ticket\\",\\"params\\":{\\"value\\":100,\\"symbol\\":\\"$\\"}}]","plugins":"{}","metadata":"{}","from":"0xeF8305E140ac520225DAf050e2f71d5fBcC543e7","timestamp":1631432106}}', diff --git a/peer-node/aqua/snapshot.aqua b/peer-node/aqua/snapshot.aqua index 55b1cac..033698e 100644 --- a/peer-node/aqua/snapshot.aqua +++ b/peer-node/aqua/snapshot.aqua @@ -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: diff --git a/peer-node/data/snapshot.db b/peer-node/data/snapshot.db index 9c3a90a..80be5cc 100644 Binary files a/peer-node/data/snapshot.db and b/peer-node/data/snapshot.db differ diff --git a/peer-node/src/_aqua/snapshot.ts b/peer-node/src/_aqua/snapshot.ts index 3a93c8e..4450246 100644 --- a/peer-node/src/_aqua/snapshot.ts +++ b/peer-node/src/_aqua/snapshot.ts @@ -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) => number | Promise; -get_records: (callParams: CallParams) => { 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) => { 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; -export function get_record(peer: FluencePeer, relay: string, peer_: string, snapshot_id: number, config?: {ttl?: number}): Promise; +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; +export function get_record(peer: FluencePeer, relay: string, peer_: string, signature: string, config?: {ttl?: number}): Promise; 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; export function delete_records(peer: FluencePeer, passwd: string, peer_: string, relay: string, config?: {ttl?: number}): Promise; 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; export function get_records(peer: FluencePeer, relay: string, peer_: string, config?: {ttl?: number}): Promise; export function get_records(...args: any) { diff --git a/peer-node/src/index.ts b/peer-node/src/index.ts index 1f728f0..0ab73e5 100644 --- a/peer-node/src/index.ts +++ b/peer-node/src/index.ts @@ -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 { - return select_event(snapshot_id); + // record by signature + async get_record(signature: string): Promise { + return select_event(signature); } // get all records. currently limited to 100 rows max. diff --git a/peer-node/src/local_db.ts b/peer-node/src/local_db.ts index b5cc581..11c9c43 100644 --- a/peer-node/src/local_db.ts +++ b/peer-node/src/local_db.ts @@ -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((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 { +export async function select_event(signature: string): Promise { 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;