index.ts


Overview

This file is the Pulumi deployment entrypoint script for the **Bitcoin Cash (bitcoincash) coinstack** within the Unchained multi-blockchain infrastructure platform. It orchestrates the deployment of blockchain node services—specifically the daemon node and the indexer service—into a Kubernetes cluster using Pulumi infrastructure-as-code.

The script performs the following key functions:

This file is tailored specifically for the Bitcoin Cash coinstack, configuring its services with blockchain-appropriate ports, readiness probes, and indexer configuration data.


Detailed Explanation

Imports

import { readFileSync } from 'fs'
import { deployCoinstack } from '../../../../pulumi/src/coinstack'
import { Outputs, CoinServiceArgs, getConfig } from '../../../../pulumi/src'
import { defaultBlockbookServiceArgs } from '../../../packages/blockbook/src/constants'

Exported Async Deployment Function

export = async (): Promise<Outputs> => {
  ...
}

This is the main entrypoint function executed by Pulumi during deployment.


Internal Function Workflow

  1. Define Constants

const appName = 'unchained'
const coinstack = 'bitcoincash'
  1. Read Sample Environment File

const sampleEnv = readFileSync('../sample.env')
  1. Fetch Kubernetes Configuration

const { kubeconfig, config, namespace } = await getConfig()
  1. Map Stateful Services to Deployment Arguments

const coinServiceArgs = config.statefulService?.services?.map((service): CoinServiceArgs => {
  switch (service.name) {
    case 'daemon':
      return {
        ...service,
        ports: { 'daemon-rpc': { port: 8332 } },
        env: {
          NETWORK: config.network,
        },
        readinessProbe: { periodSeconds: 30, failureThreshold: 10 },
      }
    case 'indexer':
      return {
        ...service,
        ...defaultBlockbookServiceArgs,
        configMapData: { 'indexer-config.json': readFileSync('../indexer/config.json').toString() },
      }
    default:
      throw new Error(`no support for coin service: ${service.name}`)
  }
})
  1. Invoke Deployment

return deployCoinstack({
  appName,
  coinServiceArgs,
  coinstack,
  coinstackType: 'node',
  config,
  kubeconfig,
  namespace,
  sampleEnv,
})

Key Types


Important Implementation Details


Interaction with Other System Components


Usage Example

Assuming the deployment environment is set up, running Pulumi in this coinstack directory will invoke this script:

pulumi up

This triggers:


Mermaid Diagram: Flowchart of index.ts Deployment Workflow

flowchart TD
  A[Start Deployment] --> B[Read sample.env file]
  B --> C[Fetch Kubernetes config & namespace via getConfig()]
  C --> D[Map stateful services from config]
  D --> E{Service name?}
  E -->|daemon| F[Configure daemon service args: ports, env, readinessProbe]
  E -->|indexer| G[Configure indexer service args: defaultBlockbookServiceArgs, configMapData]
  E -->|other| H[Throw error for unsupported service]
  F --> I[Aggregate service args]
  G --> I
  I --> J[Call deployCoinstack() with all deployment args]
  J --> K[Pulumi provisions Kubernetes StatefulSets, Services, ConfigMaps]
  K --> L[Pods start and Kubernetes monitors health probes]
  L --> M[Deployment completes, return Outputs]

Summary

This `index.ts` file is the Pulumi deployment script for the Bitcoin Cash coinstack within the Unchained platform. It reads configuration files and Kubernetes context, maps blockchain services (daemon and indexer) to deployment parameters including ports and probes, and calls a shared deployment function to provision Kubernetes resources. It ensures the Bitcoin Cash node and its indexer are deployed consistently and reliably, using best practices such as readiness probes and ConfigMaps for configuration. This file exemplifies the modular, reusable design pattern used across multi-blockchain coinstacks in the Unchained ecosystem.