@@ -16,7 +16,7 @@ Object.freeze(config);
1616console . log ( "config" , config ) ;
1717
1818let bootnode = "" ;
19- const keys = gen_other . genXdposKeys ( ) ;
19+ const keys = genXdposKeys ( ) ;
2020const num_per_machine = Array ( config . num_machines ) ;
2121// integer division
2222for ( let i = 0 ; i < config . num_machines ; i ++ ) {
@@ -212,6 +212,21 @@ function initConfig(config) {
212212 validatePK ( privatekey ) ;
213213 }
214214
215+ if ( config . xdpos . foundation_pk !== "" ) {
216+ try {
217+ [ config . xdpos . foundation_addr , config . keys . foundation_pk ] = validatePK (
218+ config . keys . foundation_pk
219+ ) ;
220+ } catch {
221+ console . log ( "Invalid FOUNDATION_PK" ) ;
222+ process . exit ( 1 ) ;
223+ }
224+ } else {
225+ const privatekey = crypto . randomBytes ( 32 ) . toString ( "hex" ) ;
226+ [ config . xdpos . foundation_addr , config . xdpos . foundation_pk ] =
227+ validatePK ( privatekey ) ;
228+ }
229+
215230 if ( config . keys . subnets_pk !== "" ) {
216231 try {
217232 let output_pk = [ ] ;
@@ -341,7 +356,7 @@ function genXdposCompose(machine_id, num, start_num = 1) {
341356 const rpcport = 8544 + i ;
342357 const wsport = 9554 + i ;
343358
344- imageName = `xinfinorg/xdposchain: ${ config . xdpos . xdposnode } ` ;
359+ imageName = `${ config . xdpos . xdposnode } ` ;
345360 config_path = "masternode" + i . toString ( ) + ".env" ;
346361
347362 nodes [ node_name ] = {
@@ -362,4 +377,34 @@ function genXdposCompose(machine_id, num, start_num = 1) {
362377 } ;
363378 }
364379 return nodes ;
365- }
380+ }
381+
382+ function genXdposKeys ( ) {
383+ const keys = { } ;
384+ console . log ( "genXdposKeys called" ) ;
385+ console . log ( config . keys )
386+ // const num = config.keys.subnets_addr.length
387+ for ( let i = 0 ; i < config . keys . subnets_addr . length ; i ++ ) {
388+ const key = `key${ i + 1 } ` ;
389+ const private_key = config . keys . subnets_pk [ i ] ;
390+ const address = config . keys . subnets_addr [ i ] ;
391+ keys [ key ] = {
392+ PrivateKey : private_key ,
393+ "0x" : address ,
394+ short : address . replace ( / ^ 0 x / i, "" ) ,
395+ } ;
396+ }
397+ keys [ "Owner" ] = {
398+ PrivateKey : config . keys . grandmaster_pk ,
399+ "0x" : config . keys . grandmaster_addr ,
400+ short : config . keys . grandmaster_addr . replace ( / ^ 0 x / i, "" ) ,
401+ } ;
402+ if ( Object . keys ( keys ) . length !== config . num_subnet + 1 ) {
403+ // sanity check
404+ console . log ( "bad case, key length not equal number of subnets" ) ;
405+ console . log ( Object . keys ( keys ) . length , config . num_subnet + 1 ) ;
406+ console . log ( keys ) ;
407+ process . exit ( ) ;
408+ }
409+ return keys ;
410+ }
0 commit comments