Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
23 changes: 9 additions & 14 deletions indexer/.env.example
Original file line number Diff line number Diff line change
@@ -1,20 +1,15 @@
NODE_API_URL=
SYNC_BASE_URL=

SYNC_MIN_HEIGHT=0
SYNC_FETCH_INTERVAL_IN_BLOCKS=100
NODE_API_URL=https://api.chainweb.com
SYNC_BASE_URL=https://api.chainweb.com/chainweb/0.0/mainnet01/cut
SYNC_NETWORK=mainnet01
KADENA_GRAPHQL_API_URL=http://localhost
KADENA_GRAPHQL_API_PORT=3001

API_GATEWAY_URL=https://api.mainnet.kadindexer.io
API_KADENA_URL=https://kadena.io

DB_USERNAME=postgres
DB_PASSWORD=postgres
DB_PASSWORD=my_secret_value
DB_NAME=indexer
DB_SSL_ENABLED=false
DB_SSL_ENABLED=true
DB_HOST=localhost
DB_SSL_ENABLED=false
DB_SSL_REJECT_UNAUTHORIZED=false

SENTRY_DSN=
KADENA_GRAPHQL_API_PORT=3001 #optional
SENTRY_DSN="http://sentryurl" #optional
ALLOWED_ORIGINS=http://localhost:3001,http://localhost:3002,http://localhost:3003 #optional
PRICE_CACHE_TTL=300 #optional
29 changes: 14 additions & 15 deletions indexer/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -45,21 +45,20 @@ cp indexer/.env.template indexer/.env

### 3.2. Environment Variables Reference

| Variable | Description | Example |
| ------------------------------- | --------------------------------------- | --------------------------------------- |
| `NODE_API_URL` | Base URL for the Kadena node API | `https://api.chainweb.com` |
| `SYNC_BASE_URL` | Base URL for the Chainweb API | `https://api.chainweb.com/chainweb/0.0` |
| `SYNC_MIN_HEIGHT` | Minimum height to start syncing from | `0` |
| `SYNC_FETCH_INTERVAL_IN_BLOCKS` | Interval in blocks to fetch | `100` |
| `SYNC_NETWORK` | Network to sync | `mainnet01`, `testnet04`, `devnet` |
| `KADENA_GRAPHQL_API_URL` | GraphQL API host | `localhost` |
| `KADENA_GRAPHQL_API_PORT` | GraphQL API port | `3000` |
| `DB_USERNAME` | PostgreSQL database username | `postgres` |
| `DB_PASSWORD` | PostgreSQL database password | `your_password` |
| `DB_NAME` | PostgreSQL database name | `indexer` |
| `DB_HOST` | PostgreSQL database host | `localhost` |
| `DB_SSL_ENABLED` | Enable/disable SSL for database | `true` or `false` |
| `PRICE_CACHE_TTL` | Time-to-live for price cache in seconds | `300` |
| Variable | Description | Example |
| ------------------------- | --------------------------------------- | --------------------------------------- |
| `NODE_API_URL` | Base URL for the Kadena node API | `https://api.chainweb.com` |
| `SYNC_BASE_URL` | Base URL for the Chainweb API | `https://api.chainweb.com/chainweb/0.0` |
| `SYNC_NETWORK` | Network to sync | `mainnet01`, `testnet04`, `devnet` |
| `DB_USERNAME` | PostgreSQL database username | `postgres` |
| `DB_PASSWORD` | PostgreSQL database password | `your_password` |
| `DB_NAME` | PostgreSQL database name | `indexer` |
| `DB_HOST` | PostgreSQL database host | `localhost` |
| `DB_SSL_ENABLED` | Enable/disable SSL for database | `true` or `false` |
| `KADENA_GRAPHQL_API_PORT` | GraphQL API port | `3000` |
| `SENTRY_DSN` | Sentry url to monitor indexer usage | `https://123.ingest.us.sentry.io/123` |
| `ALLOWED_ORIGINS` | Allowed origins for CORS | `http://abcde:3001,http://abcde:3002` |
| `PRICE_CACHE_TTL` | Time-to-live for price cache in seconds | `300` |

**NOTE:** The example Kadena node API from chainweb will not work for the indexer purpose. You will need to run your own Kadena node and set the `NODE_API_URL` to your node's API URL.

Expand Down
7 changes: 4 additions & 3 deletions indexer/src/kadena-server/server.ts
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@ import {
} from 'graphql';

import initCache from '../cache/init';
import { getRequiredEnvString, getRequiredArrayEnvString } from '../utils/helpers';
import { getArrayEnvString } from '../utils/helpers';
import {
directiveEstimator,
fieldExtensionsEstimator,
Expand Down Expand Up @@ -82,12 +82,13 @@ const typeDefs = readFileSync(join(__dirname, './config/schema.graphql'), 'utf-8
/**
* The port on which the GraphQL API will listen
*/
const KADENA_GRAPHQL_API_PORT = getRequiredEnvString('KADENA_GRAPHQL_API_PORT');
const KADENA_GRAPHQL_API_PORT = process.env.KADENA_GRAPHQL_API_PORT ?? '3001';

/**
* Array of domains allowed to access the GraphQL API
*/
const ALLOWED_ORIGINS = getRequiredArrayEnvString('ALLOWED_ORIGINS');

const ALLOWED_ORIGINS = getArrayEnvString('ALLOWED_ORIGINS');

/**
* Apollo Server plugin that validates pagination parameters in GraphQL requests
Expand Down
13 changes: 4 additions & 9 deletions indexer/src/utils/helpers.ts
Original file line number Diff line number Diff line change
Expand Up @@ -41,18 +41,13 @@ export function getRequiredEnvString(key: string): string {
}

/**
* Retrieves a required environment variable as a string array.
* Retrieves an optional environment variable as a string array.
* The environment variable is expected to be a comma-separated string.
* Throws an error if the variable is not found.
*
* @param key - The name of the environment variable to retrieve.
* @returns The value of the environment variable as a string array.
* @throws {Error} If the environment variable is not set.
* @returns The value of the environment variable as a string array, or an empty array if the variable is not set.
*/
export function getRequiredArrayEnvString(key: string): string[] {
const value = process.env[key];
if (!value) {
throw new Error(`[ERROR][ENV][MISSING] Environment variable ${key} is required`);
}
export function getArrayEnvString(key: string): string[] {
const value = process.env[key] ?? '';
return value.split(',').filter(item => item.trim() !== '');
}