Skip to content

Commit

Permalink
fix review
Browse files Browse the repository at this point in the history
  • Loading branch information
wanwiset25 committed Dec 15, 2023
1 parent 6f7d7fa commit 4b8425c
Show file tree
Hide file tree
Showing 5 changed files with 22 additions and 48 deletions.
27 changes: 17 additions & 10 deletions subnet/deployment-generator/script/config_gen.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ const crypto = require('crypto');
const net = require('net');
const dotenv = require('dotenv');
const ethers = require('ethers');
const { off } = require('process');
dotenv.config({ path: `${__dirname}/gen.env` });
// console.log(__dirname)

Expand All @@ -28,7 +29,7 @@ var config = {
},
parentnet:{
network: (process.env.PARENTNET || 'devnet'),
// url: '',
url: '',
pubkey: '' ,
privatekey: (process.env.PARENTNET_WALLET_PK || '') ,
},
Expand All @@ -43,7 +44,7 @@ var config = {
}
};

if (configSanityCheck(config) == true){
if (configSanityCheck(config) === true){
module.exports = config
} else {
console.log('bad config init file, please check again')
Expand All @@ -61,7 +62,7 @@ function configSanityCheck(config){
process.exit(1)
}

if (config.num_machines==0 || config.num_subnet ==0){
if (config.num_machines===0 || config.num_subnet ===0){
console.log('NUM_MACHINE and NUM_SUBNET cannot be 0')
process.exit(1)
}
Expand All @@ -71,7 +72,7 @@ function configSanityCheck(config){
process.exit(1)
}

if (!config.network_name || config.network_name==''){
if (!config.network_name || config.network_name===''){
console.log('NETWORK_NAME cannot be empty')
process.exit(1)
}
Expand All @@ -81,19 +82,25 @@ function configSanityCheck(config){
process.exit(1)
}

if (config.secret_string=='') {
if (config.secret_string==='') {
console.log('SERVICES_SECRET cannot be empty string')
process.exit(1)
}

if (!(config.relayer_mode == 'full' || config.relayer_mode == 'lite')) {
if (!(config.relayer_mode === 'full' || config.relayer_mode === 'lite')) {
console.log('RELAYER_MODE only accepts \'full\' or \'lite\' (default full)')
process.exit(1)
}

if (!(config.parentnet.network == 'devnet' ||
config.parentnet.network == 'testnet' ||
config.parentnet.network == 'mainnet' )){
if (!(config.parentnet.network === 'devnet' ||
config.parentnet.network === 'testnet' ||
config.parentnet.network === 'mainnet' )){
var official_urls = {
'devnet':'https://devnetstats.apothem.network/devnet' ,
'testnet':'https://erpc.apothem.network/' ,
'mainnet': 'https://devnetstats.apothem.network/mainnet' //confirm url
}
config.parentnet.url = official_urls[config.parentnet.network]
console.log('PARENTNET must be devnet, testnet, or mainnet ')
process.exit(1)
}
Expand Down Expand Up @@ -163,7 +170,7 @@ function configSanityCheck(config){

}

if (config.operating_system == 'mac') {
if (config.operating_system === 'mac') {
if (config.num_machines != 1){
console.log(`OS=mac requires NUM_MACHINE=1. Due to Docker network limitation, Subnets on MacOS can only communicate within its own machine. This option is intended for single machine testing environment only`)
process.exit()
Expand Down
4 changes: 2 additions & 2 deletions subnet/deployment-generator/script/gen.js
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,7 @@ Object.entries(subnet_services).forEach(entry => {
doc['services'][key]=value
});

if (config.operating_system == 'mac'){
if (config.operating_system === 'mac'){
doc, ip_record = gen_compose.injectMacConfig(doc)
commonconf = gen_env.genServicesConfigMac(ip_record)
subnetconf=[]
Expand All @@ -66,7 +66,7 @@ if (config.operating_system == 'mac'){
//checkpoint smartcontract deployment config
deployment_json = gen_other.genDeploymentJsonMac(keys, ip_record)

} else if(config.operating_system == 'linux'){
} else if(config.operating_system === 'linux'){
commonconf = gen_env.genServicesConfig()
subnetconf=[]
for (let i=1; i<=config.num_subnet; i++){
Expand Down
35 changes: 2 additions & 33 deletions subnet/deployment-generator/script/gen_env.js
Original file line number Diff line number Diff line change
Expand Up @@ -66,22 +66,7 @@ return config_env
}

function genServicesConfig(){
var url = ''
switch (config.parentnet.network){
case 'devnet':
url='https://devnetstats.apothem.network/devnet'
break
case 'testnet':
url='https://erpc.apothem.network/'
break
case 'mainnet':
url='https://devnetstats.apothem.network/mainnet' //confirm url
break
default:
console.error('PARENTNET invalid, should be devnet, testnet, or mainnet') //should not reach this case
exit()
}

var url = config.parentnet.url
var config_env=`
# Bootnode
EXTIP=${config.ip_1}
Expand All @@ -107,27 +92,11 @@ STATS_SECRET=${config.secret_string}
// # Parent Chain Observe Node
// PARENTNET_NODE_NAME=mainnet_observer
// PRIVATE_KEYS=11111111111111111111111111111111111111111111111111111111111111

return config_env
}

function genServicesConfigMac(ip_record){
var url = ''
switch (config.parentnet.network){
case 'devnet':
url='https://devnetstats.apothem.network/devnet'
break
case 'testnet':
url='https://erpc.apothem.network/'
break
case 'mainnet':
url='https://devnetstats.apothem.network/mainnet' //confirm url
break
default:
console.error('PARENTNET invalid, should be devnet, testnet, or mainnet') //should not reach this case
exit()
}

var url = config.parentnet.url
var config_env=`
# Bootnode
EXTIP=${ip_record["bootnode"]}
Expand Down
2 changes: 1 addition & 1 deletion subnet/deployment-generator/script/gen_other.js
Original file line number Diff line number Diff line change
Expand Up @@ -126,7 +126,7 @@ function genGenesisInputFile(network_name, network_id, num_subnet, keys ){
var grandmasters = []
Object.keys(keys).forEach(function(k) {
var v = keys[k];
if (k == 'Grandmaster'){
if (k === 'Grandmaster'){
grandmasters.push(v['0x'])
} else {
masternodes.push(v['0x'])
Expand Down
2 changes: 0 additions & 2 deletions subnet/scripts/faucet/coin.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,3 @@


const dotenv = require('dotenv');
dotenv.config({ path: `${__dirname}/coin.env` });
const { Web3 } = require('web3');
Expand Down

0 comments on commit 4b8425c

Please sign in to comment.