@hsuite/smart-config v2.1.3
@hsuite/smart-config
A powerful and flexible configuration management module for Hashgraph network applications, built on top of NestJS.
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-configPeer 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.62.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:
- 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],
})- Existing Factory
SmartConfigModule.forRootAsync({
useExisting: [YourExistingConfigFactory],
})- Class Factory
SmartConfigModule.forRootAsync({
useClass: YourConfigFactory,
})API Reference
SmartConfigService
Network Operations
getEnvironment(): Get current network environmentgetClientEnvironment(): Get client environment as LedgerIdgetNodes(): Retrieve network node configurationsgetUtilities(): Get network utility servicesgetFees(): Retrieve network fee structure
Configuration Management
getIssuer(): Get Hashgraph network issuer configurationgetOperator(): Get client operator configurationgetMirrorNode(): Get mirror node settingsgetThreshold(): Calculate network consensus threshold
Development
Documentation
Generate documentation using Compodoc:
npm run compodocCheck documentation coverage:
npm run compodoc:coverage