Skip to content

HbarSuite/smart-config

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

1 Commit
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

@hsuite/smart-config

A powerful and flexible configuration management module for Hashgraph network applications, built on top of NestJS.

npm version License: MIT

Overview

The Smart Config module provides a centralized configuration management system for Hashgraph network operations. It handles various aspects of configuration including network environments, node management, service discovery, and fee structures.

Features

  • Network Environment Management

    • Support for testnet and mainnet environments
    • Public and private network configurations
    • Custom network settings
    • Local development environment support
  • Node Configuration

    • Dynamic node discovery and management
    • Consensus threshold calculation
    • Network entity configuration
    • Node health monitoring
  • Service Integration

    • Mirror node configuration
    • HTTP service integration
    • Utility service discovery
    • Fee structure management
  • Operator Management

    • Operator credentials handling
    • Access permission management
    • Operation parameter configuration

Installation

npm install @hsuite/smart-config

Peer Dependencies

{
  "@nestjs/common": "^10.4.2",
  "@nestjs/core": "^10.4.2"
}

Dependencies

{
  "@hsuite/hashgraph-types": "^2.0.0",
  "@hsuite/smart-network-types": "^2.0.0",
  "@hashgraph/sdk": "^2.51.0"
}

Usage

Module Registration

The Smart Config module can be registered asynchronously in your NestJS application:

import { Module } from '@nestjs/common';
import { SmartConfigModule } from '@hsuite/smart-config';

@Module({
  imports: [
    SmartConfigModule.forRootAsync({
      useFactory: () => ({
        environment: 'testnet',
        network: 'public',
        client_environment: 'testnet',
        // Additional configuration options
      }),
    }),
  ],
})
export class AppModule {}

Using the Service

Inject and use the SmartConfigService in your application:

import { Injectable } from '@nestjs/common';
import { SmartConfigService } from '@hsuite/smart-config';

@Injectable()
export class YourService {
  constructor(private readonly configService: SmartConfigService) {}

  async getNetworkNodes() {
    const nodes = await this.configService.getNodes();
    return nodes;
  }

  async getNetworkFees() {
    const fees = await this.configService.getFees();
    return fees;
  }
}

Configuration Options

Network Configuration

The module supports various network configurations through the SmartConfigOptionsFactory interface:

interface SmartConfigOptionsFactory {
  createSmartConfigOptions(): Promise<ISmartNetwork.INetwork.IConfig.IOptions> | ISmartNetwork.INetwork.IConfig.IOptions;
}

Async Configuration

Multiple configuration strategies are available:

  1. Factory Function
SmartConfigModule.forRootAsync({
  useFactory: (configService: ConfigService) => ({
    environment: configService.get('NETWORK_ENVIRONMENT'),
    network: configService.get('NETWORK_TYPE'),
    client_environment: configService.get('CLIENT_ENVIRONMENT'),
  }),
  inject: [ConfigService],
})
  1. Existing Factory
SmartConfigModule.forRootAsync({
  useExisting: [YourExistingConfigFactory],
})
  1. Class Factory
SmartConfigModule.forRootAsync({
  useClass: YourConfigFactory,
})

API Reference

SmartConfigService

Network Operations

  • getEnvironment(): Get current network environment
  • getClientEnvironment(): Get client environment as LedgerId
  • getNodes(): Retrieve network node configurations
  • getUtilities(): Get network utility services
  • getFees(): Retrieve network fee structure

Configuration Management

  • getIssuer(): Get Hashgraph network issuer configuration
  • getOperator(): Get client operator configuration
  • getMirrorNode(): Get mirror node settings
  • getThreshold(): Calculate network consensus threshold

Development

Documentation

Generate documentation using Compodoc:

npm run compodoc

Check documentation coverage:

npm run compodoc:coverage

Built with ❤️ by the HbarSuite Team
Copyright © 2024 HbarSuite. All rights reserved.

About

Public repository for smart-config

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published