@@ -30,8 +30,9 @@ import * as helpers from './helpers.js';
30
30
import { getNodeAccountMap } from './helpers.js' ;
31
31
import type { SemVer } from 'semver' ;
32
32
import type { SoloLogger } from './logging.js' ;
33
- import type { AnyObject , NodeAlias , NodeAliases , Path } from '../types/aliases.js' ;
33
+ import type { AnyObject , DirPath , NodeAlias , NodeAliases , Path } from '../types/aliases.js' ;
34
34
import type { GenesisNetworkDataConstructor } from './models/genesisNetworkDataConstructor.js' ;
35
+ import type { Optional } from '../types/index.js' ;
35
36
36
37
const consensusSidecars = [
37
38
'recordStreamUploader' ,
@@ -44,12 +45,12 @@ const consensusSidecars = [
44
45
export class ProfileManager {
45
46
private readonly logger : SoloLogger ;
46
47
private readonly configManager : ConfigManager ;
47
- private readonly cacheDir : string ;
48
+ private readonly cacheDir : DirPath ;
48
49
49
50
private profiles : Map < string , AnyObject > ;
50
- private profileFile : string | undefined ;
51
+ private profileFile : Optional < string > ;
51
52
52
- constructor ( logger : SoloLogger , configManager : ConfigManager , cacheDir = constants . SOLO_VALUES_DIR ) {
53
+ constructor ( logger : SoloLogger , configManager : ConfigManager , cacheDir : DirPath = constants . SOLO_VALUES_DIR ) {
53
54
if ( ! logger ) throw new MissingArgumentError ( 'An instance of core/SoloLogger is required' ) ;
54
55
if ( ! configManager ) throw new MissingArgumentError ( 'An instance of core/ConfigManager is required' ) ;
55
56
@@ -176,7 +177,7 @@ export class ProfileManager {
176
177
for ( const key in dotItems ) {
177
178
let itemKey = key ;
178
179
179
- // if it is an array key like extraEnv[0].JAVA_OPTS, convert it into dot separated key as extraEnv.0.JAVA_OPTS
180
+ // if it is an array key like extraEnv[0].JAVA_OPTS, convert it into a dot separated key as extraEnv.0.JAVA_OPTS
180
181
if ( key . indexOf ( '[' ) !== - 1 ) {
181
182
itemKey = key . replace ( '[' , '.' ) . replace ( ']' , '' ) ;
182
183
}
@@ -370,10 +371,13 @@ export class ProfileManager {
370
371
return this . writeToYaml ( cachedValuesFile , yamlRoot ) ;
371
372
}
372
373
373
- public setValueForGenesisNetwork ( path : string ) {
374
+ public prepareValuesForGenesisNetwork ( genesisNetworkData : GenesisNetworkDataConstructor ) : Promise < string > {
374
375
const yamlRoot = { } ;
375
376
376
- this . _setFileContentsAsValue ( 'hedera.configMaps.genesisNetworkJson' , path , yamlRoot ) ;
377
+ this . _setValue ( 'hedera.configMaps.genesisNetworkJson' , genesisNetworkData . toJSON ( ) , yamlRoot ) ;
378
+
379
+ const cachedValuesFile = path . join ( this . cacheDir , 'genesis-network.yaml' ) ;
380
+ return this . writeToYaml ( cachedValuesFile , yamlRoot ) ;
377
381
}
378
382
379
383
/**
@@ -484,12 +488,15 @@ export class ProfileManager {
484
488
chainId = constants . HEDERA_CHAIN_ID ,
485
489
genesisNetworkData ?: GenesisNetworkDataConstructor ,
486
490
) {
487
- if ( ! nodeAccountMap || nodeAccountMap . size === 0 )
491
+ if ( ! nodeAccountMap || nodeAccountMap . size === 0 ) {
488
492
throw new MissingArgumentError ( 'nodeAccountMap the map of node IDs to account IDs is required' ) ;
493
+ }
494
+
489
495
if ( ! releaseTag ) throw new MissingArgumentError ( 'release tag is required' ) ;
490
496
491
- if ( ! fs . existsSync ( destPath ) )
497
+ if ( ! fs . existsSync ( destPath ) ) {
492
498
throw new IllegalArgumentError ( `config destPath does not exist: ${ destPath } ` , destPath ) ;
499
+ }
493
500
494
501
// init variables
495
502
const internalPort = + constants . HEDERA_NODE_INTERNAL_GOSSIP_PORT ;
@@ -516,11 +523,11 @@ export class ProfileManager {
516
523
nodeDataWrapper . weight = nodeStakeAmount ;
517
524
nodeDataWrapper . accountId = account ;
518
525
519
- // Add gossip endpoints
526
+ //? Add gossip endpoints
520
527
nodeDataWrapper . addGossipEndpoint ( externalIP , externalPort ) ;
521
528
nodeDataWrapper . addGossipEndpoint ( internalIP , internalPort ) ;
522
529
523
- // Add service endpoints
530
+ //? Add service endpoints
524
531
nodeDataWrapper . addServiceEndpoint ( internalIP , internalPort ) ;
525
532
}
526
533
0 commit comments