fix: withdrawal idb store

This commit is contained in:
Danil Kovtonyuk 2022-06-14 18:56:36 +10:00
parent dce468cace
commit c7d1a5cb8e
4 changed files with 17 additions and 20 deletions

View File

@ -39,7 +39,7 @@ class IndexedDB {
return 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.onEventHandler()
this.dbExists = true this.dbExists = true
@ -224,12 +224,10 @@ class IndexedDB {
export default async (ctx, inject) => { export default async (ctx, inject) => {
const DEPOSIT_INDEXES = [ const DEPOSIT_INDEXES = [
{ name: 'instance', unique: false },
{ name: 'transactionHash', unique: false }, { name: 'transactionHash', unique: false },
{ name: 'commitment', unique: true } { name: 'commitment', unique: true }
] ]
const WITHDRAWAL_INDEXES = [ const WITHDRAWAL_INDEXES = [
{ name: 'instance', unique: false },
{ name: 'nullifierHash', unique: true } // keys on which the index is created { name: 'nullifierHash', unique: true } // keys on which the index is created
] ]
const LAST_EVENT_INDEXES = [{ name: 'name', unique: false }] const LAST_EVENT_INDEXES = [{ name: 'name', unique: false }]
@ -240,11 +238,6 @@ export default async (ctx, inject) => {
name: 'encrypted_events', name: 'encrypted_events',
keyPath: 'transactionHash' keyPath: 'transactionHash'
}, },
{
name: 'withdrawals',
keyPath: 'transactionHash',
indexes: WITHDRAWAL_INDEXES
},
{ {
name: 'lastEvents', name: 'lastEvents',
keyPath: 'name', keyPath: 'name',
@ -289,6 +282,12 @@ export default async (ctx, inject) => {
indexes: DEPOSIT_INDEXES indexes: DEPOSIT_INDEXES
}) })
stores.push({
name: `withdrawals_${token}_${amount}_${netId}`,
keyPath: 'transactionHash',
indexes: WITHDRAWAL_INDEXES
})
stores.push({ stores.push({
name: `stringify_tree_${token}_${amount}_${netId}`, name: `stringify_tree_${token}_${amount}_${netId}`,
keyPath: 'hashTree' keyPath: 'hashTree'

View File

@ -26,7 +26,7 @@ class EventService {
getStoreNames(type) { getStoreNames(type) {
const instanceName = `${type}s_${this.currency}_${this.amount}` 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 } return { instanceName, storeName }
} }
@ -338,9 +338,6 @@ class EventService {
await this.idb.createMultipleTransactions({ await this.idb.createMultipleTransactions({
data: events, data: events,
index: {
instance: instanceName
},
storeName storeName
}) })

View File

@ -147,9 +147,11 @@ async function getAllDeposits({ currency, amount, fromBlock, netId }) {
const lastSyncBlock = await getMeta({ netId }) const lastSyncBlock = await getMeta({ netId })
const data = deposits.map((e) => ({ const data = deposits.map((e) => ({
...e, timestamp: e.timestamp,
commitment: e.commitment,
leafIndex: Number(e.index), leafIndex: Number(e.index),
blockNumber: Number(e.blockNumber) blockNumber: Number(e.blockNumber),
transactionHash: e.transactionHash
})) }))
const [lastEvent] = data.slice(-1) const [lastEvent] = data.slice(-1)
@ -270,10 +272,12 @@ async function getAllWithdrawals({ currency, amount, fromBlock, netId }) {
const lastSyncBlock = await getMeta({ netId }) const lastSyncBlock = await getMeta({ netId })
const data = withdrawals.map((e) => ({ const data = withdrawals.map((e) => ({
...e, to: e.to,
fee: e.fee,
timestamp: e.timestamp,
nullifierHash: e.nullifier, nullifierHash: e.nullifier,
leafIndex: Number(e.index), blockNumber: Number(e.blockNumber),
blockNumber: Number(e.blockNumber) transactionHash: e.transactionHash
})) }))
const [lastEvent] = data.slice(-1) const [lastEvent] = data.slice(-1)

View File

@ -16,10 +16,8 @@ export const GET_WITHDRAWALS = `
amount: $amount, amount: $amount,
blockNumber_gte: $fromBlock blockNumber_gte: $fromBlock
}) { }) {
id
to to
fee fee
index
nullifier nullifier
timestamp timestamp
blockNumber blockNumber
@ -48,7 +46,6 @@ export const GET_DEPOSITS = `
currency: $currency, currency: $currency,
blockNumber_gte: $fromBlock blockNumber_gte: $fromBlock
}) { }) {
id
index index
timestamp timestamp
commitment commitment