@@ -21,6 +21,7 @@ import {
2121 CommandUtils ,
2222 ConfigLoader ,
2323 CustomPreset ,
24+ DeepPartial ,
2425 FileSystemService ,
2526 Logger ,
2627 LoggerFactory ,
@@ -29,7 +30,8 @@ import {
2930 Preset ,
3031 YamlUtils ,
3132} from 'symbol-bootstrap' ;
32- import { Account , NetworkType } from 'symbol-sdk' ;
33+ import { CurrencyDistribution , MosaicPreset } from 'symbol-bootstrap/lib/model/ConfigPreset' ;
34+ import { Account , Address , NetworkType } from 'symbol-sdk' ;
3335import {
3436 Network ,
3537 NetworkConfigurationService ,
@@ -97,6 +99,7 @@ export class InitService {
9799 if ( ! nemesisPreset ) throw new Error ( 'Network nemesis must be found!' ) ;
98100 if ( ! nemesisPreset . mosaics ) throw new Error ( `Network nemesis's mosaics must be found!` ) ;
99101 let faucetBalances : number [ ] | undefined ;
102+ let additionalCurrencyDistributions : CurrencyDistribution [ ] [ ] | undefined ;
100103 let customNetworkPreset : CustomPreset | undefined = { } ;
101104 if ( isNewNetwork ) {
102105 customNetworkPreset = _ . merge ( { nemesis : { mosaics : [ ] } } , this . params . additionalNetworkPreset ) ;
@@ -126,17 +129,18 @@ export class InitService {
126129 'Enter the basename for the network aliases' ,
127130 networkPreset . baseNamespace ,
128131 ) ;
129-
132+ additionalCurrencyDistributions = [ ] ;
130133 for ( const [ index , mosaic ] of nemesisPreset . mosaics . entries ( ) ) {
131134 const currencyType = index == 0 ? 'Network' : index == 1 ? 'Harvest' : 'Custom' ;
132135 const name = await this . promptName (
133136 `${ currencyType } Currency Name` ,
134137 `Enter the alias for the ${ currencyType } Currency` ,
135138 mosaic . name ,
136139 ) ;
137- customNetworkPreset . nemesis ! . mosaics ! . push ( {
140+ const mosaicPreset : DeepPartial < MosaicPreset > = {
138141 name,
139- } ) ;
142+ } ;
143+ customNetworkPreset . nemesis ! . mosaics ! . push ( mosaicPreset ) ;
140144 }
141145
142146 const nemesisSignerAccount = await this . promptPrivateKey ( networkType , 'Nemesis Signer Account' ) ;
@@ -148,15 +152,20 @@ export class InitService {
148152 if ( await this . confirm ( 'Do you want to have a Faucet account?' ) ) {
149153 const faucetAccount = await this . promptPrivateKey ( networkType , 'Faucet Account' ) ;
150154 await keyStore . saveNetworkAccount ( networkType , 'faucet' , faucetAccount . privateKey ) ;
151- for ( const mosaic of nemesisPreset . mosaics ) {
155+ for ( const [ index , mosaic ] of nemesisPreset . mosaics . entries ( ) ) {
156+ const name = customNetworkPreset . nemesis ! . mosaics ! [ index ] ?. name || mosaic . name ;
152157 const balance = await this . promptNumber (
153158 'Balance' ,
154- `What's the initial ${ mosaic . name } balance for the Faucet Account ${ faucetAccount . address . plain ( ) } ?` ,
159+ `What's the initial ${ name } coin balance for the Faucet Account ${ faucetAccount . address . plain ( ) } ?` ,
155160 Math . floor ( mosaic . supply / 100 / Math . pow ( 10 , mosaic . divisibility ) ) * 5 ,
156161 ) ;
157162 faucetBalances . push ( balance ) ;
158163 }
159164 }
165+ for ( const [ index , mosaic ] of nemesisPreset . mosaics . entries ( ) ) {
166+ const name = customNetworkPreset . nemesis ! . mosaics ! [ index ] ?. name || mosaic . name ;
167+ additionalCurrencyDistributions . push ( await this . promptDistribution ( networkType , name ) ) ;
168+ }
160169
161170 const harvestNetworkFeeSinkAccount = await this . promptPrivateKey ( networkType , 'Harvest Network Fee Sink Account' ) ;
162171 await keyStore . saveNetworkAccount ( networkType , 'harvestNetworkFeeSink' , harvestNetworkFeeSinkAccount . privateKey ) ;
@@ -194,6 +203,7 @@ export class InitService {
194203 networkType : networkType ! ,
195204 isNewNetwork : isNewNetwork ,
196205 faucetBalances : faucetBalances ,
206+ additionalCurrencyDistributions : additionalCurrencyDistributions ,
197207 nemesisSeedFolder : nemesisSeedFolder ,
198208 nodeTypes : nodeTypes ,
199209 customNetworkPreset : customNetworkPreset ,
@@ -283,7 +293,7 @@ export class InitService {
283293 ] ) ;
284294 nemesisSeedFolder = nemesisSeedFolderResponse . value ;
285295 try {
286- await new FileSystemService ( this . logger ) . validateSeedFolder ( nemesisSeedFolder , '' ) ;
296+ new FileSystemService ( this . logger ) . validateSeedFolder ( nemesisSeedFolder , '' ) ;
287297 } catch ( e ) {
288298 console . log ( ) ;
289299 console . log (
@@ -452,6 +462,54 @@ export class InitService {
452462 ) ;
453463 }
454464
465+ public async promptAddress ( networkType : NetworkType , fieldName : string ) : Promise < Address > {
466+ return this . confirmedPrompt < Address > (
467+ fieldName ,
468+ async ( currentValue ) : Promise < Address > => {
469+ const { value } = await prompt ( [
470+ {
471+ name : 'value' ,
472+ message : `Enter a valid Symbol ${ fieldName } ` ,
473+ type : 'input' ,
474+ default : currentValue ?. plain ( ) ,
475+ validate : ( value ) => {
476+ try {
477+ const address = Address . createFromRawAddress ( value ) ;
478+ if ( address . networkType != networkType ) {
479+ return `it's not for the right network` ;
480+ }
481+ return true ;
482+ } catch ( e ) {
483+ return `it is not a valid address. ${ NetworkUtils . getMessage ( e ) } ` ;
484+ }
485+ } ,
486+ } ,
487+ ] ) ;
488+ return Address . createFromRawAddress ( value ) ;
489+ } ,
490+ undefined ,
491+ ( address ) => `address ${ address . plain ( ) } ` ,
492+ ) ;
493+ }
494+
495+ public async promptDistribution ( networkType : NetworkType , mosaicName : string ) : Promise < CurrencyDistribution [ ] > {
496+ const list : CurrencyDistribution [ ] = [ ] ;
497+ console . log ( ) ;
498+ console . log (
499+ `In additions to the node, faucet and founder accounts, you can include (opt-in) more accounts into the nemesis block by distributing ${ mosaicName } coins.` ,
500+ ) ;
501+ while ( await this . confirm ( `Do you want to distribute coin ${ mosaicName } to different accounts on the nemesis block?` , false ) ) {
502+ const address = await this . promptAddress ( networkType , 'distribution address' ) ;
503+ const amount = await this . promptNumber (
504+ 'distribution amount' ,
505+ `Enter how much ${ mosaicName } you want to give to address ${ address . plain ( ) } ` ,
506+ 100 ,
507+ ) ;
508+ list . push ( { address : address . plain ( ) , amount : amount } ) ;
509+ }
510+ return list ;
511+ }
512+
455513 public async generateRandomKey ( fieldName : string , message : string , networkType : NetworkType ) : Promise < string > {
456514 return this . promptText ( fieldName , message , Account . generateNewAccount ( networkType ) . privateKey , CommandUtils . isValidPrivateKey ) ;
457515 }
0 commit comments