forked from pinax-network/substreams-sink
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathexample.js
33 lines (27 loc) · 880 Bytes
/
example.js
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
import pkg from "./package.json" assert { type: "json" };
import { commander, setup, prometheus, http, logger } from "./dist/index.js";
// Setup CLI using Commander
const program = commander.program(pkg);
const command = commander.run(program, pkg);
logger.setName(pkg.name);
// Custom Prometheus Counters
const customCounter = prometheus.registerCounter("custom_counter");
command.action(async options => {
// Setup sink for Block Emitter
const { emitter } = await setup(options);
console.log("setup")
// Stream Blocks
emitter.on("anyMessage", (message, cursor, clock) => {
customCounter?.inc(1);
console.log(message);
console.log(cursor);
console.log(clock);
});
// Setup HTTP server & Prometheus metrics
http.listen(options);
// Start streaming
emitter.start();
http.server.close();
console.log("✅ finished");
})
program.parse();