-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathbasic.ts
More file actions
36 lines (33 loc) · 884 Bytes
/
basic.ts
File metadata and controls
36 lines (33 loc) · 884 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
import 'dotenv/config';
import {
Config,
EthersEthClient,
Indexer,
PinoLogger,
SqliteDatabase,
} from '../src/index';
const config = new Config();
const logger = new PinoLogger(config.getLoggerOptions());
async function main() {
const idx = new Indexer(
config,
new EthersEthClient(config.getRpcUrl(), config.getLatestBlockStrategy()),
new SqliteDatabase(config.getDbPath()),
logger,
async (db) => {
const lastId = (db.getLastProcessedEvent() ?? -1) + 1;
const events = db.getEvents(lastId);
if (events?.length) {
logger.info({ events }, 'Unprocessed events');
db.setLastProcessedEvent(events[events.length - 1].id);
}
},
);
logger.info({ config }, 'Starting indexer');
await idx.init();
await idx.start();
}
main().catch((e) => {
logger.error({ err: e }, 'Fatal error');
process.exit(1);
});