mirror of
https://github.com/fluencelabs/eip712-validation-node
synced 2025-05-28 23:41:20 +00:00
update db schema to eip712 signature instead of snapshot id
This commit is contained in:
parent
e23d66d2f8
commit
dea3be5d4e
@ -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}}',
|
||||
|
@ -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.
@ -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) {
|
||||
|
@ -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.
|
||||
|
@ -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;
|
||||
|
Loading…
x
Reference in New Issue
Block a user