Skip to content

Commit

Permalink
add session
Browse files Browse the repository at this point in the history
fixes: #4
  • Loading branch information
DenisCarriere committed Oct 2, 2023
1 parent 13eb8e3 commit e70a5cf
Showing 1 changed file with 9 additions and 4 deletions.
13 changes: 9 additions & 4 deletions index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,12 +7,9 @@ import type { WebhookRunOptions } from "./bin/cli.js";
import { ping } from "./src/ping.js";
import { banner } from './src/banner.js';
import { toText } from './src/http.js';
import type { SessionInit } from "@substreams/core/proto";

export async function action(options: WebhookRunOptions) {
// TEMP FIX FOR
// https://github.com/pinax-network/substreams-sink/issues/15
options.headers = new Headers();

// Block Emitter
const { emitter, moduleHash } = await setup(options);

Expand All @@ -26,12 +23,20 @@ export async function action(options: WebhookRunOptions) {
process.exit(1);
}
}
let session: SessionInit;
emitter.on("session", data => {
session = data
});

// Stream Blocks
emitter.on("anyMessage", async (data, cursor, clock) => {
if (!clock.timestamp) return;
const metadata = {
cursor,
session: {
traceId: session.traceId,
resolvedStartBlock: Number(session.resolvedStartBlock),
},
clock: {
timestamp: clock.timestamp.toDate().toISOString(),
number: Number(clock.number),
Expand Down

0 comments on commit e70a5cf

Please sign in to comment.