Created
August 27, 2022 07:50
-
-
Save luchenqun/571fcfe3a5b84d950732c6ed10d2d23d to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
if (Array.isArray(genesisCfg)) { | |
const convert = (value) => { | |
if (value == "true" || value == "false") { | |
return value == "true"; | |
} else if (value.startsWith("'")) { | |
return value.replace(/'/g, ""); | |
} else return parseInt(value); | |
}; | |
for (const cfg of genesisCfg) { | |
console.log("genesis." + cfg); | |
// eval("genesis." + cfg); | |
const [keyStr, value] = cfg.split("="); | |
let keys = keyStr.split("."); | |
let obj = genesis; | |
for (let i = 0; i < keys.length; i++) { | |
const key = keys[i]; | |
if (key.endsWith("]")) { | |
let [curKey, index] = key.split("["); | |
index = index.replace("]", ""); | |
if (i == keys.length - 1) { | |
obj[curKey][index] = convert(value); | |
} else { | |
obj = obj[curKey][index]; | |
} | |
} else { | |
if (i == keys.length - 1) { | |
obj[key] = convert(value); | |
} else { | |
obj = obj[key]; | |
} | |
} | |
console.log(key, JSON.stringify(obj.app_state.bank.balances[0])); | |
console.log("======================================================================="); | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment