|
2 | 2 | import fs from 'fs'; |
3 | 3 | import path from 'path'; |
4 | 4 | import rimraf from 'rimraf'; |
5 | | -import BigNumber from 'bignumber.js'; |
6 | | - |
7 | | -const serialize = (event) => { |
8 | | - const doc = Object.assign({}, event); |
9 | | - for (const key in event.args) { |
10 | | - if (event.args[key] instanceof BigNumber) { |
11 | | - doc.args[key] = { |
12 | | - type: 'BigNumber', |
13 | | - value: event.args[key].toString(), |
14 | | - }; |
15 | | - } |
16 | | - } |
17 | | - return doc; |
18 | | -}; |
19 | | - |
20 | | -const unserialize = (doc) => { |
21 | | - const event = Object.assign({}, doc); |
22 | | - for (const key in doc.args) { |
23 | | - if (doc.args[key] && doc.args[key].type === 'BigNumber') { |
24 | | - event.args[key] = new BigNumber(doc.args[key].value); |
25 | | - } |
26 | | - } |
27 | | - return event; |
28 | | -}; |
| 5 | +import { serialize, unserialize } from '../utils'; |
29 | 6 |
|
30 | 7 | export default class FileStore { |
31 | 8 | constructor(indexing, dbPath) { |
@@ -69,6 +46,9 @@ export default class FileStore { |
69 | 46 | get(eventType, indexId, value) { |
70 | 47 | const indexKey = `${eventType}-${indexId}-${value}`; |
71 | 48 | const filePath = `${this.dbPath}/${indexKey}.jsons`; |
| 49 | + if (!fs.existsSync(filePath)) { |
| 50 | + return []; |
| 51 | + } |
72 | 52 | return fs.readFileSync(filePath) |
73 | 53 | .toString().split('\n') |
74 | 54 | .filter(line => line.length > 0) |
|
0 commit comments