From b6ceca5d52c8212553b1fbf59c5e24ccf06547e6 Mon Sep 17 00:00:00 2001 From: Chih Cheng Liang Date: Fri, 22 Jan 2021 17:07:13 +0800 Subject: [PATCH] deploy with parameters file and output path --- .gitignore | 1 + package.json | 3 ++- scripts/deploy.ts | 18 ++++++++++++++---- scripts/genParam.ts | 5 +++++ 4 files changed, 22 insertions(+), 5 deletions(-) create mode 100644 scripts/genParam.ts diff --git a/.gitignore b/.gitignore index 3bc05cc2..a6cd13dd 100644 --- a/.gitignore +++ b/.gitignore @@ -1,4 +1,5 @@ node_modules/ +parameters.json genesis.json types/ cache/ diff --git a/package.json b/package.json index 29ad87d8..cf822290 100644 --- a/package.json +++ b/package.json @@ -14,7 +14,8 @@ "deploy": "ts-node ./scripts/deploy.ts", "deposit": "ts-node ./scripts/deposit.ts", "bench": "hardhat run ./scripts/benchmark.ts", - "slither": "slither ." + "slither": "slither .", + "genParam": "ts-node ./scripts/genParam.ts" }, "repository": { "type": "git", diff --git a/scripts/deploy.ts b/scripts/deploy.ts index 83a5f3de..54ea1d88 100644 --- a/scripts/deploy.ts +++ b/scripts/deploy.ts @@ -8,7 +8,7 @@ import { StateTree } from "../ts/stateTree"; import { execSync } from "child_process"; const argv = require("minimist")(process.argv.slice(2), { - string: ["url", "root", "key"] + string: ["url", "root", "key", "input", "output"] }); /* Note separate pubkeys with commas @@ -17,6 +17,9 @@ const argv = require("minimist")(process.argv.slice(2), { You can also specify a private key > npm run deploy -- --key 0xYourPrivateKey + + You can use a custom parameters.json + > npm run deploy -- --input parameters.json --output ../hubbe-commander/genesis.json */ function getDefaultGenesisRoot(parameters: DeploymentParameters) { @@ -34,10 +37,17 @@ async function main() { ? new ethers.Wallet(argv.key).connect(provider) : provider.getSigner(); - const parameters = PRODUCTION_PARAMS; + const parameters = argv.input + ? JSON.parse(fs.readFileSync(argv.input).toString()) + : PRODUCTION_PARAMS; + parameters.GENESIS_STATE_ROOT = argv.root || getDefaultGenesisRoot(parameters); + const genesisPath = argv.output ?? "genesis.json"; + + console.log("Deploy with parameters", parameters); + const genesisEth1Block = await provider.getBlockNumber(); const contracts = await deployAll(signer, parameters, true); let addresses: { [key: string]: string } = {}; @@ -54,8 +64,8 @@ async function main() { version }; const configs = { parameters, addresses, auxiliary }; - console.log("Writing genesis.json"); - fs.writeFileSync("genesis.json", JSON.stringify(configs, null, 4)); + console.log("Writing genesis file to", genesisPath); + fs.writeFileSync(genesisPath, JSON.stringify(configs, null, 4)); console.log("Successsfully deployed", configs); } diff --git a/scripts/genParam.ts b/scripts/genParam.ts new file mode 100644 index 00000000..22a7bb74 --- /dev/null +++ b/scripts/genParam.ts @@ -0,0 +1,5 @@ +import { PRODUCTION_PARAMS } from "../ts/constants"; + +import fs from "fs"; + +fs.writeFileSync("parameters.json", JSON.stringify(PRODUCTION_PARAMS, null, 4));