From c7d1a5cb8e00d7499ff8edbdc7ce2c2746d1d1d5 Mon Sep 17 00:00:00 2001 From: Danil Kovtonyuk Date: Tue, 14 Jun 2022 18:56:36 +1000 Subject: [PATCH] fix: withdrawal idb store --- plugins/idb.js | 15 +++++++-------- services/events.js | 5 +---- services/graph.js | 14 +++++++++----- services/queries.js | 3 --- 4 files changed, 17 insertions(+), 20 deletions(-) diff --git a/plugins/idb.js b/plugins/idb.js index aa6a1a5..5850e8b 100644 --- a/plugins/idb.js +++ b/plugins/idb.js @@ -39,7 +39,7 @@ class IndexedDB { return } - this.db = await openDB(this.dbName, 33, this.options) // version (optional): Schema version, or undefined to open the current version. + this.db = await openDB(this.dbName, 34, this.options) // version (optional): Schema version, or undefined to open the current version. this.onEventHandler() this.dbExists = true @@ -224,12 +224,10 @@ class IndexedDB { export default async (ctx, inject) => { const DEPOSIT_INDEXES = [ - { name: 'instance', unique: false }, { name: 'transactionHash', unique: false }, { name: 'commitment', unique: true } ] const WITHDRAWAL_INDEXES = [ - { name: 'instance', unique: false }, { name: 'nullifierHash', unique: true } // keys on which the index is created ] const LAST_EVENT_INDEXES = [{ name: 'name', unique: false }] @@ -240,11 +238,6 @@ export default async (ctx, inject) => { name: 'encrypted_events', keyPath: 'transactionHash' }, - { - name: 'withdrawals', - keyPath: 'transactionHash', - indexes: WITHDRAWAL_INDEXES - }, { name: 'lastEvents', keyPath: 'name', @@ -289,6 +282,12 @@ export default async (ctx, inject) => { indexes: DEPOSIT_INDEXES }) + stores.push({ + name: `withdrawals_${token}_${amount}_${netId}`, + keyPath: 'transactionHash', + indexes: WITHDRAWAL_INDEXES + }) + stores.push({ name: `stringify_tree_${token}_${amount}_${netId}`, keyPath: 'hashTree' diff --git a/services/events.js b/services/events.js index 39a536d..7be31ae 100644 --- a/services/events.js +++ b/services/events.js @@ -26,7 +26,7 @@ class EventService { getStoreNames(type) { const instanceName = `${type}s_${this.currency}_${this.amount}` - const storeName = type === eventsType.DEPOSIT ? `${instanceName}_${this.netId}` : `${type}s_${this.netId}` + const storeName = `${instanceName}_${this.netId}` return { instanceName, storeName } } @@ -338,9 +338,6 @@ class EventService { await this.idb.createMultipleTransactions({ data: events, - index: { - instance: instanceName - }, storeName }) diff --git a/services/graph.js b/services/graph.js index dc239d9..fb306df 100644 --- a/services/graph.js +++ b/services/graph.js @@ -147,9 +147,11 @@ async function getAllDeposits({ currency, amount, fromBlock, netId }) { const lastSyncBlock = await getMeta({ netId }) const data = deposits.map((e) => ({ - ...e, + timestamp: e.timestamp, + commitment: e.commitment, leafIndex: Number(e.index), - blockNumber: Number(e.blockNumber) + blockNumber: Number(e.blockNumber), + transactionHash: e.transactionHash })) const [lastEvent] = data.slice(-1) @@ -270,10 +272,12 @@ async function getAllWithdrawals({ currency, amount, fromBlock, netId }) { const lastSyncBlock = await getMeta({ netId }) const data = withdrawals.map((e) => ({ - ...e, + to: e.to, + fee: e.fee, + timestamp: e.timestamp, nullifierHash: e.nullifier, - leafIndex: Number(e.index), - blockNumber: Number(e.blockNumber) + blockNumber: Number(e.blockNumber), + transactionHash: e.transactionHash })) const [lastEvent] = data.slice(-1) diff --git a/services/queries.js b/services/queries.js index 2a58490..0cc7f97 100644 --- a/services/queries.js +++ b/services/queries.js @@ -16,10 +16,8 @@ export const GET_WITHDRAWALS = ` amount: $amount, blockNumber_gte: $fromBlock }) { - id to fee - index nullifier timestamp blockNumber @@ -48,7 +46,6 @@ export const GET_DEPOSITS = ` currency: $currency, blockNumber_gte: $fromBlock }) { - id index timestamp commitment