Skip to content

Commit 6d40d55

Browse files
committed
Add networkId to options
1 parent 2a28e9d commit 6d40d55

File tree

3 files changed

+2557
-8
lines changed

3 files changed

+2557
-8
lines changed

cli.js

+5-1
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,10 @@ program
1616
.version(packageJson.version)
1717
.option("-w, --workdir <dir>", "Specify a working dir.", "ethnode-data");
1818

19+
program
20+
.version(packageJson.version)
21+
.option("-n, --networkId <number>", "Specify a network ID.");
22+
1923
program
2024
.command("parity")
2125
.description("Run a Parity development node.")
@@ -35,5 +39,5 @@ program
3539
program.parse(process.argv);
3640

3741
if (noAction) {
38-
run("geth", program.workdir);
42+
run("geth", program.workdir, program.networkId);
3943
}

main.js

+8-7
Original file line numberDiff line numberDiff line change
@@ -23,20 +23,21 @@ function getPaths(client, workdir) {
2323
};
2424
}
2525

26-
function generateGenesis(client, balances) {
26+
function generateGenesis(client, balances, networkId) {
2727
const genesis = JSON.parse(
2828
JSON.stringify(require(`./genesis.${client}.json`))
2929
);
30+
networkId = networkId || randomId();
3031
if (client === "geth") {
31-
genesis.chainId = randomId();
32+
genesis.config.chainId = parseInt(networkId, 10);
3233
genesis.extraData =
3334
"0x" +
3435
"0".repeat(64) +
3536
Object.keys(balances)[0].substr(2) +
3637
"0".repeat(130);
3738
genesis.alloc = { ...genesis.alloc, ...balances };
3839
} else if (client === "parity") {
39-
genesis.params.networkID = randomId();
40+
genesis.params.networkID = networkId;
4041
genesis.accounts = { ...genesis.accounts, ...balances };
4142
}
4243
return genesis;
@@ -67,10 +68,10 @@ function setup(client, workdir) {
6768
}
6869
}
6970

70-
function provide(client, workdir) {
71+
function provide(client, workdir, networkId) {
7172
const paths = getPaths(client, workdir);
7273
const keypairs = getKeypairs(KEYS_SOURCE, "password");
73-
const genesis = generateGenesis(client, generateBalances(keypairs));
74+
const genesis = generateGenesis(client, generateBalances(keypairs), networkId);
7475
let keysDest =
7576
client === "geth" ? paths.keys : path.join(paths.keys, genesis.name);
7677

@@ -100,11 +101,11 @@ function provide(client, workdir) {
100101
}
101102
}
102103

103-
function run(client, workdir) {
104+
function run(client, workdir, networkId) {
104105
const paths = getPaths(client, workdir);
105106
setup(client, workdir);
106107
if (!fs.existsSync(paths.genesis)) {
107-
provide(client, workdir);
108+
provide(client, workdir, networkId);
108109
}
109110

110111
const genesis = JSON.parse(fs.readFileSync(paths.genesis));

0 commit comments

Comments
 (0)