Skip to content

Commit

Permalink
Merge pull request #23 from pinax-network/feature/auth
Browse files Browse the repository at this point in the history
Update auth header with Substreams API key
  • Loading branch information
DenisCarriere authored Feb 12, 2024
2 parents b9444ff + ebf4f0c commit 067a058
Show file tree
Hide file tree
Showing 13 changed files with 129 additions and 304 deletions.
19 changes: 9 additions & 10 deletions .env-example
Original file line number Diff line number Diff line change
@@ -1,11 +1,10 @@
# Substreams endpoint
SUBSTREAMS_API_TOKEN=...
SUBSTREAMS_ENDPOINT=https://eth.firehose.pinax.network:9000
# Get Substreams API Key
# https://app.pinax.network
# https://app.streamingfast.io/
SUBSTREAMS_API_KEY=...
SUBSTREAMS_ENDPOINT=https://eth.substreams.pinax.network:443

# Substreams package
MANIFEST=https://github.com/pinax-network/subtivity-substreams/releases/download/v0.2.3/subtivity-ethereum-v0.2.3.spkg
MODULE_NAME=map_block_stats
START_BLOCK=100000
STOP_BLOCK=100010
VERBOSE=true
FINAL_BLOCKS_ONLY=false
# SPKG
MANIFEST=https://github.com/pinax-network/substreams/releases/download/blocks-v0.1.0/blocks-v0.1.0.spkg
MODULE_NAME=map_blocks
START_BLOCK=-10
2 changes: 1 addition & 1 deletion LICENSE-MIT → LICENSE
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
Copyright (c) 2023 Pinax
Copyright (c) 2024 Pinax

Permission is hereby granted, free of charge, to any
person obtaining a copy of this software and associated
Expand Down
201 changes: 0 additions & 201 deletions LICENSE-APACHE

This file was deleted.

40 changes: 36 additions & 4 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,10 @@
- [**Substreams** documentation](https://substreams.streamingfast.io)
- [Subtreams sink project template Github repo](https://github.com/pinax-network/substreams-sink-template)

## Get Substreams API Key
- https://app.pinax.network
- https://app.streamingfast.io/

## 🚀 Quick start

### Installation
Expand Down Expand Up @@ -64,9 +68,25 @@ Options:
### Example
**.env**
```env
# Get Substreams API Key
# https://app.pinax.network
# https://app.streamingfast.io/
SUBSTREAMS_API_KEY=...
SUBSTREAMS_ENDPOINT=https://eth.substreams.pinax.network:443

# SPKG
MANIFEST=https://github.com/pinax-network/substreams/releases/download/blocks-v0.1.0/blocks-v0.1.0.spkg
MODULE_NAME=map_blocks
START_BLOCK=-10
```
**example.js**
```js
import pkg from "./package.json" assert { type: "json" };
import { commander, setup, prometheus, http, logger } from "./dist/index.js";
import { commander, setup, prometheus, http, logger } from "substreams-sink";

// Setup CLI using Commander
const program = commander.program(pkg);
Expand All @@ -80,6 +100,14 @@ command.action(async options => {
// Setup sink for Block Emitter
const { emitter } = await setup(options);

emitter.on("session", (session) => {
console.log(session);
});

emitter.on("progress", (progress) => {
console.log(progress);
});

// Stream Blocks
emitter.on("anyMessage", (message, cursor, clock) => {
customCounter?.inc(1);
Expand All @@ -91,9 +119,13 @@ command.action(async options => {
// Setup HTTP server & Prometheus metrics
http.listen(options);

// Start streaming
await emitter.start();
http.server.close();
// Start the stream
emitter.start();

emitter.on("close", () => {
http.server.close();
console.log("✅ finished");
})
})
program.parse();
```
3 changes: 0 additions & 3 deletions example.env

This file was deleted.

18 changes: 14 additions & 4 deletions example.js
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,14 @@ const customCounter = prometheus.registerCounter("custom_counter");
command.action(async options => {
// Setup sink for Block Emitter
const { emitter } = await setup(options);
console.log("setup")

emitter.on("session", (session) => {
console.log(session);
});

emitter.on("progress", (progress) => {
console.log(progress);
});

// Stream Blocks
emitter.on("anyMessage", (message, cursor, clock) => {
Expand All @@ -25,9 +32,12 @@ command.action(async options => {
// Setup HTTP server & Prometheus metrics
http.listen(options);

// Start streaming
// Start the stream
emitter.start();
http.server.close();
console.log("✅ finished");

emitter.on("close", () => {
http.server.close();
console.log("✅ finished");
})
})
program.parse();
Loading

0 comments on commit 067a058

Please sign in to comment.