index.ts


Overview

This file serves as the **entry point** for deploying the Litecoin blockchain coinstack services using Pulumi, a modern infrastructure-as-code tool. It orchestrates the setup of Litecoin-specific node daemon and indexer services by:

The file abstracts the complexities of blockchain node deployment by specifying service parameters such as ports, readiness probes, and configuration maps, allowing seamless, repeatable deployments into Kubernetes clusters.


Detailed Explanation

Exported Async Function (Default Export)

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

This is the main exported asynchronous function executed by Pulumi during the deployment process.

Purpose

Parameters

Return Value


Internal Variables and Workflow

Variable

Description

`appName`

Fixed string `'unchained'` representing the application namespace or deployment grouping.

`coinstack`

Fixed string `'litecoin'` identifying the blockchain coinstack to deploy.

`sampleEnv`

Contents of the `sample.env` file loaded via `readFileSync` which contains environment variables to be injected as Kubernetes Secrets. The file path is relative: `'../sample.env'`.

`{ kubeconfig, config, namespace }`

Destructured result of the asynchronous `getConfig()` call that fetches Kubernetes cluster credentials, the deployment configuration object, and the Kubernetes namespace to deploy into.

`coinServiceArgs`

An array of `CoinServiceArgs` objects, built by mapping over the configured services in `config.statefulService?.services`. Each service is customized according to its type (`daemon` or `indexer`).


Service Mapping Logic

The function processes each service defined in the `statefulService.services` array of the config and maps it to a `CoinServiceArgs` object required by the deployment functions.

const coinServiceArgs = config.statefulService?.services?.map((service): CoinServiceArgs => {
  switch (service.name) {
    case 'daemon':
      return {
        ...service,
        ports: { 'daemon-rpc': { port: 8332 } },
        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}`)
  }
})

Final Deployment Call

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

Usage Example

This file is not typically imported manually but executed by Pulumi as the deployment entrypoint.

To deploy the Litecoin coinstack:

pulumi up -s <stack-name> --cwd node/coinstacks/litecoin/pulumi

Pulumi will run this script, which will:


Important Implementation Details


Interaction with Other Parts of the System


Mermaid Diagram: Flowchart of index.ts Workflow

flowchart TD
    A[Start Deployment Script]
    B[Read sample.env file]
    C[getConfig() → kubeconfig, config, namespace]
    D[Map config.statefulService.services to coinServiceArgs]
    E{Service Name?}
    E -->|daemon| F[Prepare daemon service args: ports, readinessProbe]
    E -->|indexer| G[Prepare indexer service args: defaultBlockbookServiceArgs + configMapData]
    E -->|unknown| H[Throw Error: Unsupported service]
    F & G --> I[Collect all CoinServiceArgs]
    I --> J[Call deployCoinstack() with all args]
    J --> K[Deploy Litecoin coinstack to Kubernetes]
    K --> L[Return deployment outputs]
    L --> M[End]
    
    A --> B --> C --> D --> E

Summary

The `index.ts` file is the Litecoin blockchain coinstack's Pulumi deployment entrypoint. It reads environment and configuration files, maps configured services (`daemon` and `indexer`) to deployment arguments with Litecoin-specific settings, and calls the shared `deployCoinstack` function to provision the blockchain node and indexer services as Kubernetes StatefulSets. The script ensures strict service validation, injects configuration via ConfigMaps and Secrets, and integrates with Kubernetes through Pulumi to deliver repeatable, consistent Litecoin infrastructure deployments.

This modular approach aligns with the project's design principles of scalable multi-blockchain support, configuration-as-code, and automated infrastructure management.