Added missing DB indexes
This commit is contained in:
parent
dfb20aa617
commit
3d3b987635
113
dist/index.js
vendored
113
dist/index.js
vendored
@ -3691,8 +3691,14 @@ async function saveDBEvents({
|
||||
lastBlock
|
||||
}) {
|
||||
try {
|
||||
const formattedEvents = events.map((e) => {
|
||||
return {
|
||||
eid: `${e.transactionHash}_${e.logIndex}`,
|
||||
...e
|
||||
};
|
||||
});
|
||||
await idb.createMultipleTransactions({
|
||||
data: events,
|
||||
data: formattedEvents,
|
||||
storeName: instanceName
|
||||
});
|
||||
await idb.putItem({
|
||||
@ -3722,8 +3728,12 @@ async function loadDBEvents({
|
||||
lastBlock: 0
|
||||
};
|
||||
}
|
||||
const events = (await idb.getAll({ storeName: instanceName })).map((e) => {
|
||||
delete e.eid;
|
||||
return e;
|
||||
});
|
||||
return {
|
||||
events: await idb.getAll({ storeName: instanceName }),
|
||||
events,
|
||||
lastBlock: lastBlockStore.blockNumber
|
||||
};
|
||||
} catch (err) {
|
||||
@ -9779,7 +9789,7 @@ class IndexedDB {
|
||||
}
|
||||
};
|
||||
this.dbName = dbName;
|
||||
this.dbVersion = 34;
|
||||
this.dbVersion = 35;
|
||||
}
|
||||
async initDB() {
|
||||
try {
|
||||
@ -9973,24 +9983,42 @@ async function getIndexedDB(netId) {
|
||||
await idb2.initDB();
|
||||
return idb2;
|
||||
}
|
||||
const DEPOSIT_INDEXES = [
|
||||
{ name: "transactionHash", unique: false },
|
||||
{ name: "commitment", unique: true }
|
||||
const minimalIndexes = [
|
||||
{
|
||||
name: "blockNumber",
|
||||
unique: false
|
||||
},
|
||||
{
|
||||
name: "transactionHash",
|
||||
unique: false
|
||||
}
|
||||
];
|
||||
const WITHDRAWAL_INDEXES = [
|
||||
{ name: "nullifierHash", unique: true }
|
||||
// keys on which the index is created
|
||||
];
|
||||
const LAST_EVENT_INDEXES = [{ name: "name", unique: false }];
|
||||
const defaultState = [
|
||||
{
|
||||
name: "encrypted_events",
|
||||
keyPath: "transactionHash"
|
||||
name: `echo_${netId}`,
|
||||
keyPath: "eid",
|
||||
indexes: [
|
||||
...minimalIndexes,
|
||||
{
|
||||
name: "address",
|
||||
unique: false
|
||||
}
|
||||
]
|
||||
},
|
||||
{
|
||||
name: `encrypted_notes_${netId}`,
|
||||
keyPath: "eid",
|
||||
indexes: minimalIndexes
|
||||
},
|
||||
{
|
||||
name: "lastEvents",
|
||||
keyPath: "name",
|
||||
indexes: LAST_EVENT_INDEXES
|
||||
indexes: [
|
||||
{
|
||||
name: "name",
|
||||
unique: false
|
||||
}
|
||||
]
|
||||
}
|
||||
];
|
||||
const config = getConfig(netId);
|
||||
@ -9998,33 +10026,68 @@ async function getIndexedDB(netId) {
|
||||
const stores = [...defaultState];
|
||||
if (netId === NetId.MAINNET) {
|
||||
stores.push({
|
||||
name: "register_events",
|
||||
keyPath: "ensName"
|
||||
name: `registered_${netId}`,
|
||||
keyPath: "ensName",
|
||||
indexes: [
|
||||
...minimalIndexes,
|
||||
{
|
||||
name: "relayerAddress",
|
||||
unique: false
|
||||
}
|
||||
]
|
||||
});
|
||||
stores.push({
|
||||
name: `governance_${netId}`,
|
||||
keyPath: "eid",
|
||||
indexes: [
|
||||
...minimalIndexes,
|
||||
{
|
||||
name: "event",
|
||||
unique: false
|
||||
}
|
||||
]
|
||||
});
|
||||
}
|
||||
Object.entries(tokens).forEach(([token, { instanceAddress }]) => {
|
||||
Object.keys(instanceAddress).forEach((amount) => {
|
||||
if (nativeCurrency === token) {
|
||||
stores.push({
|
||||
stores.push(
|
||||
{
|
||||
name: `stringify_bloom_${netId}_${token}_${amount}`,
|
||||
keyPath: "hashBloom"
|
||||
});
|
||||
keyPath: "hashBloom",
|
||||
indexes: []
|
||||
},
|
||||
{
|
||||
name: `stringify_tree_${netId}_${token}_${amount}`,
|
||||
keyPath: "hashTree",
|
||||
indexes: []
|
||||
}
|
||||
);
|
||||
}
|
||||
stores.push(
|
||||
{
|
||||
name: `deposits_${netId}_${token}_${amount}`,
|
||||
keyPath: "leafIndex",
|
||||
// the key by which it refers to the object must be in all instances of the storage
|
||||
indexes: DEPOSIT_INDEXES
|
||||
indexes: [
|
||||
...minimalIndexes,
|
||||
{
|
||||
name: "commitment",
|
||||
unique: true
|
||||
}
|
||||
]
|
||||
},
|
||||
{
|
||||
name: `withdrawals_${netId}_${token}_${amount}`,
|
||||
keyPath: "blockNumber",
|
||||
indexes: WITHDRAWAL_INDEXES
|
||||
},
|
||||
keyPath: "eid",
|
||||
indexes: [
|
||||
...minimalIndexes,
|
||||
{
|
||||
name: `stringify_tree_${netId}_${token}_${amount}`,
|
||||
keyPath: "hashTree"
|
||||
name: "nullifierHash",
|
||||
unique: true
|
||||
}
|
||||
// keys on which the index is created
|
||||
]
|
||||
}
|
||||
);
|
||||
});
|
||||
|
113
dist/index.mjs
vendored
113
dist/index.mjs
vendored
@ -3670,8 +3670,14 @@ async function saveDBEvents({
|
||||
lastBlock
|
||||
}) {
|
||||
try {
|
||||
const formattedEvents = events.map((e) => {
|
||||
return {
|
||||
eid: `${e.transactionHash}_${e.logIndex}`,
|
||||
...e
|
||||
};
|
||||
});
|
||||
await idb.createMultipleTransactions({
|
||||
data: events,
|
||||
data: formattedEvents,
|
||||
storeName: instanceName
|
||||
});
|
||||
await idb.putItem({
|
||||
@ -3701,8 +3707,12 @@ async function loadDBEvents({
|
||||
lastBlock: 0
|
||||
};
|
||||
}
|
||||
const events = (await idb.getAll({ storeName: instanceName })).map((e) => {
|
||||
delete e.eid;
|
||||
return e;
|
||||
});
|
||||
return {
|
||||
events: await idb.getAll({ storeName: instanceName }),
|
||||
events,
|
||||
lastBlock: lastBlockStore.blockNumber
|
||||
};
|
||||
} catch (err) {
|
||||
@ -9758,7 +9768,7 @@ class IndexedDB {
|
||||
}
|
||||
};
|
||||
this.dbName = dbName;
|
||||
this.dbVersion = 34;
|
||||
this.dbVersion = 35;
|
||||
}
|
||||
async initDB() {
|
||||
try {
|
||||
@ -9952,24 +9962,42 @@ async function getIndexedDB(netId) {
|
||||
await idb2.initDB();
|
||||
return idb2;
|
||||
}
|
||||
const DEPOSIT_INDEXES = [
|
||||
{ name: "transactionHash", unique: false },
|
||||
{ name: "commitment", unique: true }
|
||||
const minimalIndexes = [
|
||||
{
|
||||
name: "blockNumber",
|
||||
unique: false
|
||||
},
|
||||
{
|
||||
name: "transactionHash",
|
||||
unique: false
|
||||
}
|
||||
];
|
||||
const WITHDRAWAL_INDEXES = [
|
||||
{ name: "nullifierHash", unique: true }
|
||||
// keys on which the index is created
|
||||
];
|
||||
const LAST_EVENT_INDEXES = [{ name: "name", unique: false }];
|
||||
const defaultState = [
|
||||
{
|
||||
name: "encrypted_events",
|
||||
keyPath: "transactionHash"
|
||||
name: `echo_${netId}`,
|
||||
keyPath: "eid",
|
||||
indexes: [
|
||||
...minimalIndexes,
|
||||
{
|
||||
name: "address",
|
||||
unique: false
|
||||
}
|
||||
]
|
||||
},
|
||||
{
|
||||
name: `encrypted_notes_${netId}`,
|
||||
keyPath: "eid",
|
||||
indexes: minimalIndexes
|
||||
},
|
||||
{
|
||||
name: "lastEvents",
|
||||
keyPath: "name",
|
||||
indexes: LAST_EVENT_INDEXES
|
||||
indexes: [
|
||||
{
|
||||
name: "name",
|
||||
unique: false
|
||||
}
|
||||
]
|
||||
}
|
||||
];
|
||||
const config = getConfig(netId);
|
||||
@ -9977,33 +10005,68 @@ async function getIndexedDB(netId) {
|
||||
const stores = [...defaultState];
|
||||
if (netId === NetId.MAINNET) {
|
||||
stores.push({
|
||||
name: "register_events",
|
||||
keyPath: "ensName"
|
||||
name: `registered_${netId}`,
|
||||
keyPath: "ensName",
|
||||
indexes: [
|
||||
...minimalIndexes,
|
||||
{
|
||||
name: "relayerAddress",
|
||||
unique: false
|
||||
}
|
||||
]
|
||||
});
|
||||
stores.push({
|
||||
name: `governance_${netId}`,
|
||||
keyPath: "eid",
|
||||
indexes: [
|
||||
...minimalIndexes,
|
||||
{
|
||||
name: "event",
|
||||
unique: false
|
||||
}
|
||||
]
|
||||
});
|
||||
}
|
||||
Object.entries(tokens).forEach(([token, { instanceAddress }]) => {
|
||||
Object.keys(instanceAddress).forEach((amount) => {
|
||||
if (nativeCurrency === token) {
|
||||
stores.push({
|
||||
stores.push(
|
||||
{
|
||||
name: `stringify_bloom_${netId}_${token}_${amount}`,
|
||||
keyPath: "hashBloom"
|
||||
});
|
||||
keyPath: "hashBloom",
|
||||
indexes: []
|
||||
},
|
||||
{
|
||||
name: `stringify_tree_${netId}_${token}_${amount}`,
|
||||
keyPath: "hashTree",
|
||||
indexes: []
|
||||
}
|
||||
);
|
||||
}
|
||||
stores.push(
|
||||
{
|
||||
name: `deposits_${netId}_${token}_${amount}`,
|
||||
keyPath: "leafIndex",
|
||||
// the key by which it refers to the object must be in all instances of the storage
|
||||
indexes: DEPOSIT_INDEXES
|
||||
indexes: [
|
||||
...minimalIndexes,
|
||||
{
|
||||
name: "commitment",
|
||||
unique: true
|
||||
}
|
||||
]
|
||||
},
|
||||
{
|
||||
name: `withdrawals_${netId}_${token}_${amount}`,
|
||||
keyPath: "blockNumber",
|
||||
indexes: WITHDRAWAL_INDEXES
|
||||
},
|
||||
keyPath: "eid",
|
||||
indexes: [
|
||||
...minimalIndexes,
|
||||
{
|
||||
name: `stringify_tree_${netId}_${token}_${amount}`,
|
||||
keyPath: "hashTree"
|
||||
name: "nullifierHash",
|
||||
unique: true
|
||||
}
|
||||
// keys on which the index is created
|
||||
]
|
||||
}
|
||||
);
|
||||
});
|
||||
|
113
dist/tornado.umd.js
vendored
113
dist/tornado.umd.js
vendored
@ -60083,8 +60083,14 @@ async function saveDBEvents({
|
||||
lastBlock
|
||||
}) {
|
||||
try {
|
||||
const formattedEvents = events.map((e) => {
|
||||
return {
|
||||
eid: `${e.transactionHash}_${e.logIndex}`,
|
||||
...e
|
||||
};
|
||||
});
|
||||
await idb.createMultipleTransactions({
|
||||
data: events,
|
||||
data: formattedEvents,
|
||||
storeName: instanceName
|
||||
});
|
||||
await idb.putItem({
|
||||
@ -60114,8 +60120,12 @@ async function loadDBEvents({
|
||||
lastBlock: 0
|
||||
};
|
||||
}
|
||||
const events = (await idb.getAll({ storeName: instanceName })).map((e) => {
|
||||
delete e.eid;
|
||||
return e;
|
||||
});
|
||||
return {
|
||||
events: await idb.getAll({ storeName: instanceName }),
|
||||
events,
|
||||
lastBlock: lastBlockStore.blockNumber
|
||||
};
|
||||
} catch (err) {
|
||||
@ -61872,7 +61882,7 @@ class IndexedDB {
|
||||
}
|
||||
};
|
||||
this.dbName = dbName;
|
||||
this.dbVersion = 34;
|
||||
this.dbVersion = 35;
|
||||
}
|
||||
async initDB() {
|
||||
try {
|
||||
@ -62066,24 +62076,42 @@ async function getIndexedDB(netId) {
|
||||
await idb2.initDB();
|
||||
return idb2;
|
||||
}
|
||||
const DEPOSIT_INDEXES = [
|
||||
{ name: "transactionHash", unique: false },
|
||||
{ name: "commitment", unique: true }
|
||||
const minimalIndexes = [
|
||||
{
|
||||
name: "blockNumber",
|
||||
unique: false
|
||||
},
|
||||
{
|
||||
name: "transactionHash",
|
||||
unique: false
|
||||
}
|
||||
];
|
||||
const WITHDRAWAL_INDEXES = [
|
||||
{ name: "nullifierHash", unique: true }
|
||||
// keys on which the index is created
|
||||
];
|
||||
const LAST_EVENT_INDEXES = [{ name: "name", unique: false }];
|
||||
const defaultState = [
|
||||
{
|
||||
name: "encrypted_events",
|
||||
keyPath: "transactionHash"
|
||||
name: `echo_${netId}`,
|
||||
keyPath: "eid",
|
||||
indexes: [
|
||||
...minimalIndexes,
|
||||
{
|
||||
name: "address",
|
||||
unique: false
|
||||
}
|
||||
]
|
||||
},
|
||||
{
|
||||
name: `encrypted_notes_${netId}`,
|
||||
keyPath: "eid",
|
||||
indexes: minimalIndexes
|
||||
},
|
||||
{
|
||||
name: "lastEvents",
|
||||
keyPath: "name",
|
||||
indexes: LAST_EVENT_INDEXES
|
||||
indexes: [
|
||||
{
|
||||
name: "name",
|
||||
unique: false
|
||||
}
|
||||
]
|
||||
}
|
||||
];
|
||||
const config = (0,networkConfig/* getConfig */.zj)(netId);
|
||||
@ -62091,33 +62119,68 @@ async function getIndexedDB(netId) {
|
||||
const stores = [...defaultState];
|
||||
if (netId === networkConfig/* NetId */.zr.MAINNET) {
|
||||
stores.push({
|
||||
name: "register_events",
|
||||
keyPath: "ensName"
|
||||
name: `registered_${netId}`,
|
||||
keyPath: "ensName",
|
||||
indexes: [
|
||||
...minimalIndexes,
|
||||
{
|
||||
name: "relayerAddress",
|
||||
unique: false
|
||||
}
|
||||
]
|
||||
});
|
||||
stores.push({
|
||||
name: `governance_${netId}`,
|
||||
keyPath: "eid",
|
||||
indexes: [
|
||||
...minimalIndexes,
|
||||
{
|
||||
name: "event",
|
||||
unique: false
|
||||
}
|
||||
]
|
||||
});
|
||||
}
|
||||
Object.entries(tokens).forEach(([token, { instanceAddress }]) => {
|
||||
Object.keys(instanceAddress).forEach((amount) => {
|
||||
if (nativeCurrency === token) {
|
||||
stores.push({
|
||||
stores.push(
|
||||
{
|
||||
name: `stringify_bloom_${netId}_${token}_${amount}`,
|
||||
keyPath: "hashBloom"
|
||||
});
|
||||
keyPath: "hashBloom",
|
||||
indexes: []
|
||||
},
|
||||
{
|
||||
name: `stringify_tree_${netId}_${token}_${amount}`,
|
||||
keyPath: "hashTree",
|
||||
indexes: []
|
||||
}
|
||||
);
|
||||
}
|
||||
stores.push(
|
||||
{
|
||||
name: `deposits_${netId}_${token}_${amount}`,
|
||||
keyPath: "leafIndex",
|
||||
// the key by which it refers to the object must be in all instances of the storage
|
||||
indexes: DEPOSIT_INDEXES
|
||||
indexes: [
|
||||
...minimalIndexes,
|
||||
{
|
||||
name: "commitment",
|
||||
unique: true
|
||||
}
|
||||
]
|
||||
},
|
||||
{
|
||||
name: `withdrawals_${netId}_${token}_${amount}`,
|
||||
keyPath: "blockNumber",
|
||||
indexes: WITHDRAWAL_INDEXES
|
||||
},
|
||||
keyPath: "eid",
|
||||
indexes: [
|
||||
...minimalIndexes,
|
||||
{
|
||||
name: `stringify_tree_${netId}_${token}_${amount}`,
|
||||
keyPath: "hashTree"
|
||||
name: "nullifierHash",
|
||||
unique: true
|
||||
}
|
||||
// keys on which the index is created
|
||||
]
|
||||
}
|
||||
);
|
||||
});
|
||||
|
2
dist/tornado.umd.min.js
vendored
2
dist/tornado.umd.min.js
vendored
File diff suppressed because one or more lines are too long
@ -38,8 +38,15 @@ export async function saveDBEvents<T extends MinimalEvents>({
|
||||
lastBlock: number;
|
||||
}) {
|
||||
try {
|
||||
const formattedEvents = events.map((e) => {
|
||||
return {
|
||||
eid: `${e.transactionHash}_${e.logIndex}`,
|
||||
...e,
|
||||
};
|
||||
});
|
||||
|
||||
await idb.createMultipleTransactions({
|
||||
data: events,
|
||||
data: formattedEvents,
|
||||
storeName: instanceName,
|
||||
});
|
||||
|
||||
@ -76,8 +83,13 @@ export async function loadDBEvents<T extends MinimalEvents>({
|
||||
};
|
||||
}
|
||||
|
||||
const events = (await idb.getAll<(T & { eid?: string })[]>({ storeName: instanceName })).map((e) => {
|
||||
delete e.eid;
|
||||
return e;
|
||||
});
|
||||
|
||||
return {
|
||||
events: await idb.getAll<T[]>({ storeName: instanceName }),
|
||||
events,
|
||||
lastBlock: lastBlockStore.blockNumber,
|
||||
};
|
||||
} catch (err) {
|
||||
|
94
src/idb.ts
94
src/idb.ts
@ -55,7 +55,7 @@ export class IndexedDB {
|
||||
};
|
||||
|
||||
this.dbName = dbName;
|
||||
this.dbVersion = 34;
|
||||
this.dbVersion = 35;
|
||||
}
|
||||
|
||||
async initDB() {
|
||||
@ -322,24 +322,43 @@ export async function getIndexedDB(netId?: NetIdType) {
|
||||
return idb;
|
||||
}
|
||||
|
||||
const DEPOSIT_INDEXES = [
|
||||
{ name: 'transactionHash', unique: false },
|
||||
{ name: 'commitment', unique: true },
|
||||
const minimalIndexes = [
|
||||
{
|
||||
name: 'blockNumber',
|
||||
unique: false,
|
||||
},
|
||||
{
|
||||
name: 'transactionHash',
|
||||
unique: false,
|
||||
},
|
||||
];
|
||||
const WITHDRAWAL_INDEXES = [
|
||||
{ name: 'nullifierHash', unique: true }, // keys on which the index is created
|
||||
];
|
||||
const LAST_EVENT_INDEXES = [{ name: 'name', unique: false }];
|
||||
|
||||
const defaultState = [
|
||||
{
|
||||
name: 'encrypted_events',
|
||||
keyPath: 'transactionHash',
|
||||
name: `echo_${netId}`,
|
||||
keyPath: 'eid',
|
||||
indexes: [
|
||||
...minimalIndexes,
|
||||
{
|
||||
name: 'address',
|
||||
unique: false,
|
||||
},
|
||||
],
|
||||
},
|
||||
{
|
||||
name: `encrypted_notes_${netId}`,
|
||||
keyPath: 'eid',
|
||||
indexes: minimalIndexes,
|
||||
},
|
||||
{
|
||||
name: 'lastEvents',
|
||||
keyPath: 'name',
|
||||
indexes: LAST_EVENT_INDEXES,
|
||||
indexes: [
|
||||
{
|
||||
name: 'name',
|
||||
unique: false,
|
||||
},
|
||||
],
|
||||
},
|
||||
];
|
||||
|
||||
@ -351,34 +370,69 @@ export async function getIndexedDB(netId?: NetIdType) {
|
||||
|
||||
if (netId === NetId.MAINNET) {
|
||||
stores.push({
|
||||
name: 'register_events',
|
||||
name: `registered_${netId}`,
|
||||
keyPath: 'ensName',
|
||||
indexes: [
|
||||
...minimalIndexes,
|
||||
{
|
||||
name: 'relayerAddress',
|
||||
unique: false,
|
||||
},
|
||||
],
|
||||
});
|
||||
|
||||
stores.push({
|
||||
name: `governance_${netId}`,
|
||||
keyPath: 'eid',
|
||||
indexes: [
|
||||
...minimalIndexes,
|
||||
{
|
||||
name: 'event',
|
||||
unique: false,
|
||||
},
|
||||
],
|
||||
});
|
||||
}
|
||||
|
||||
Object.entries(tokens).forEach(([token, { instanceAddress }]) => {
|
||||
Object.keys(instanceAddress).forEach((amount) => {
|
||||
if (nativeCurrency === token) {
|
||||
stores.push({
|
||||
stores.push(
|
||||
{
|
||||
name: `stringify_bloom_${netId}_${token}_${amount}`,
|
||||
keyPath: 'hashBloom',
|
||||
});
|
||||
indexes: [],
|
||||
},
|
||||
{
|
||||
name: `stringify_tree_${netId}_${token}_${amount}`,
|
||||
keyPath: 'hashTree',
|
||||
indexes: [],
|
||||
},
|
||||
);
|
||||
}
|
||||
|
||||
stores.push(
|
||||
{
|
||||
name: `deposits_${netId}_${token}_${amount}`,
|
||||
keyPath: 'leafIndex', // the key by which it refers to the object must be in all instances of the storage
|
||||
indexes: DEPOSIT_INDEXES,
|
||||
indexes: [
|
||||
...minimalIndexes,
|
||||
{
|
||||
name: 'commitment',
|
||||
unique: true,
|
||||
},
|
||||
],
|
||||
},
|
||||
{
|
||||
name: `withdrawals_${netId}_${token}_${amount}`,
|
||||
keyPath: 'blockNumber',
|
||||
indexes: WITHDRAWAL_INDEXES,
|
||||
},
|
||||
keyPath: 'eid',
|
||||
indexes: [
|
||||
...minimalIndexes,
|
||||
{
|
||||
name: `stringify_tree_${netId}_${token}_${amount}`,
|
||||
keyPath: 'hashTree',
|
||||
name: 'nullifierHash',
|
||||
unique: true,
|
||||
}, // keys on which the index is created
|
||||
],
|
||||
},
|
||||
);
|
||||
});
|
||||
|
Loading…
Reference in New Issue
Block a user