Skip to content

Commit 71a1705

Browse files
committed
Add --allocate option
1 parent b1f56f0 commit 71a1705

5 files changed

Lines changed: 46 additions & 13 deletions

File tree

README.md

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,22 @@ ethnode
1818

1919
By default `ethnode` runs `geth`. If you want to run `parity` type `ethnode parity`.
2020

21+
# Examples
22+
23+
## Start ethnode and store the data in a specific directory
24+
Every time you run `ethnode`, it creates a new temporary directory to store the data. If you want to persist the data across
25+
```
26+
ethnode --workdir=mydata
27+
```
28+
29+
## Start ethnode and allocate 100ETH to one or more target addresses
30+
Sometimes you want to allocate Ether to some specific addresses (maybe some other accounts you have on MetaMask). This is an alternative approach to import a private key to your MetaMask extension.
31+
```
32+
ethnode --allocate=0xad7b5e515e557b2dc4d0625d206394b502412003,0xecdd5b467e38731bfad4bd75faa45c7d58e41b49
33+
```
34+
35+
## Start
36+
2137
## FAQ
2238
### Why not just running `parity --config dev`?
2339
Parity has a nice feature to run it as a [private development chain][parity:devchain] (aka *test RPC*).

cli.js

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -13,17 +13,22 @@ function getOptions(program) {
1313
return {
1414
workdir: program.workdir || fs.mkdtempSync(`${os.tmpdir()}${sep}`),
1515
download: program.download,
16-
logging: program.logging
16+
logging: program.logging,
17+
allocate: program.allocate
1718
};
1819
}
1920

2021
program
2122
.version(packageJson.version)
2223
.option("-d, --download", "Download the Ethereum client and exit.")
2324
.option("-w, --workdir <dir>", "Specify a working dir.")
25+
.option("-l, --logging <level>", "Specify logging level (error, warn, info).")
26+
.option("-w, --workdir <dir>", "Specify a working dir.")
2427
.option(
25-
"-l, --logging <level>",
26-
"Specify logging level (error, warn, info)."
28+
"-a, --allocate <addresses>",
29+
"Comma separated list of addresses. Allocate 100 Ethers for each address.",
30+
val => val.split(","),
31+
[]
2732
);
2833

2934
program.version(packageJson.version);

main.js

Lines changed: 20 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -47,11 +47,11 @@ function generateGenesis(client, balances) {
4747
return genesis;
4848
}
4949

50-
function generateBalances(keypairs, balance) {
50+
function generateBalances(addresses, balance) {
5151
balance = balance || "100000000000000000000";
5252
const balances = {};
53-
for (var i = 0; i < keypairs.length; i++) {
54-
balances[keypairs[i].address] = {
53+
for (var i = 0; i < addresses.length; i++) {
54+
balances[addresses[i]] = {
5555
balance: balance
5656
};
5757
}
@@ -69,10 +69,13 @@ function downloadClient(client, workdir) {
6969
}
7070
}
7171

72-
function provide(client, workdir) {
72+
function provide(client, workdir, allocate) {
7373
const paths = getPaths(client, workdir);
7474
const keypairs = getKeypairs(KEYS_SOURCE, "password");
75-
const genesis = generateGenesis(client, generateBalances(keypairs));
75+
const balances = generateBalances(
76+
keypairs.map(x => x.address).concat(allocate)
77+
);
78+
const genesis = generateGenesis(client, balances);
7679
let keysDest =
7780
client === "geth" ? paths.keys : path.join(paths.keys, genesis.name);
7881

@@ -109,14 +112,14 @@ function provide(client, workdir) {
109112
}
110113
}
111114

112-
function run(client, { download, workdir, logging }) {
115+
function run(client, { download, workdir, logging, allocate }) {
113116
const paths = getPaths(client, workdir);
114117
downloadClient(client, workdir);
115118
if (download) {
116119
return;
117120
}
118121
if (!fs.existsSync(paths.genesis)) {
119-
provide(client, workdir);
122+
provide(client, workdir, allocate);
120123
}
121124

122125
const genesis = JSON.parse(fs.readFileSync(paths.genesis));
@@ -128,9 +131,18 @@ function run(client, { download, workdir, logging }) {
128131
console.log("Run development node using configuration in", workdir);
129132
console.log("Test accounts");
130133
console.log("# Address Private Key");
131-
for (var i = 0; i < keypairs.length; i++) {
134+
for (let i = 0; i < keypairs.length; i++) {
132135
console.log(`${i}: ${keypairs[i].address} ${keypairs[i].privateKey}`);
133136
}
137+
if (allocate.length > 0) {
138+
console.log();
139+
console.log("Extra account allocations");
140+
console.log("Address Private Key");
141+
for (let i = 0; i < allocate.length; i++) {
142+
console.log(`${allocate[i]} <no private key available>`);
143+
}
144+
}
145+
console.log();
134146

135147
let args;
136148
if (client === "geth") {

package-lock.json

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "ethnode",
3-
"version": "0.0.12",
3+
"version": "0.0.13",
44
"description": "Run an Ethereum node for development.",
55
"homepage": "https://github.com/vrde/ethnode",
66
"main": "main.js",

0 commit comments

Comments
 (0)