Skip to content

Commit 53f3eb2

Browse files
Make config overridable by env vars
1 parent 2856c2d commit 53f3eb2

File tree

10 files changed

+88
-16
lines changed

10 files changed

+88
-16
lines changed

.env

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
# URL of the Ethereum node
2+
URL=http://localhost:8545
3+
# Default to 24 hours
4+
TIMEOUT=86400000
5+
RETRY_INTERVAL=10000
6+
POLLING_INTERVAL=30000
7+
CONFIRMATIONS=1
8+
# Default to 10 minutes
9+
CONFIRMATION_TIMEOUT=600000
10+
GAS_LIMIT_MULTIPLIER=160
11+
GAS_PRICE_MULTIPLIER=160
12+
BALANCE_THRESHOLD=0.05
13+
# Gas price predictor strategy. One of < eth-provider | fast | fastest | safeLow | average >
14+
GAS_PRICE_PROVIDER=eth-provider
15+
16+
# ETH Gas Station API parameters
17+
GAS_STATION_API_CHAIN_ID=1
18+
GAS_STATION_API_URL=https://ethgasstation.info/json/ethgasAPI.json
19+
GAS_STATION_API_KEY=
20+
GAS_STATION_API_REQUEST_TIMEOUT_MS=10000
21+
22+
# When loading wallet from MNEMONIC
23+
MNEMONIC=
24+
MNEMONIC_PATH=
25+
26+
# When loading wallet from SEED
27+
SEED=

.mocharc.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
{
22
"extension": ["ts"],
33
"timeout": 10000,
4-
"require": "ts-node/register",
4+
"require": ["ts-node/register", "test/setup.ts"],
55
"spec": "test/**/*.spec.ts",
66
"watch-files": ["test/**/*.ts"]
77
}

Dockerfile

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -36,6 +36,8 @@ COPY package.json ./
3636
COPY yarn.lock ./
3737
RUN yarn install --frozen-lockfile
3838

39-
## We just need the build to execute the command
39+
# We just need the build to execute the command
4040
COPY --from=builder /usr/src/app/dist ./dist
41+
# And the default environment variables
42+
COPY .env ./
4143
ENTRYPOINT ["node", "/app/dist/index.js"]

package.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@
1313
"@cartesi/util": "^1.0.1",
1414
"axios": "^0.21.4",
1515
"chalk": "^4.1.2",
16+
"dotenv": "^10.0.0",
1617
"ethers": "^5.4.7",
1718
"humanize-duration": "^3.27.0",
1819
"loglevel": "^1.7.1",

src/commands/start.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,7 @@ export const builder = (yargs: Argv) => {
3636
return yargs
3737
.option("url", {
3838
describe: "URL of the Ethereum node",
39-
default: process.env.URL || "http://localhost:8545",
39+
default: process.env.URL,
4040
})
4141
.option("wallet", {
4242
describe: "Filename of JSON wallet file",
@@ -48,7 +48,7 @@ export const builder = (yargs: Argv) => {
4848
})
4949
.option("gasPrice", {
5050
describe: "Gas price predictor strategy",
51-
default: process.env.GAS_PRICE_PROVIDER || "eth-provider",
51+
default: process.env.GAS_PRICE_PROVIDER,
5252
demandOption: true,
5353
choices: gasPriceProviderTypes,
5454
})

src/config.ts

Lines changed: 23 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -11,15 +11,26 @@
1111

1212
import { parseEther } from "@ethersproject/units";
1313

14-
export const TIMEOUT = 24 * 60 * 60 * 1000;
15-
export const RETRY_INTERVAL = 10000;
16-
export const POLLING_INTERVAL = 30000;
17-
export const CONFIRMATIONS = 1;
18-
export const CONFIRMATION_TIMEOUT = 10 * 60 * 1000; // 10 minutes
19-
export const GAS_LIMIT_MULTIPLIER = 160;
20-
export const GAS_PRICE_MULTIPLIER = 160;
21-
export const BALANCE_THRESHOLD = parseEther("0.05");
22-
export const GAS_STATION_API_CHAIN_ID = 1;
23-
export const GAS_STATION_API_URL =
24-
"https://ethgasstation.info/json/ethgasAPI.json";
25-
export const GAS_STATION_API_REQUEST_TIMEOUT_MS = 10000;
14+
export const TIMEOUT = parseInt(<string>process.env.TIMEOUT);
15+
export const RETRY_INTERVAL = parseInt(<string>process.env.RETRY_INTERVAL);
16+
export const POLLING_INTERVAL = parseInt(<string>process.env.POLLING_INTERVAL);
17+
export const CONFIRMATIONS = parseInt(<string>process.env.CONFIRMATIONS);
18+
export const CONFIRMATION_TIMEOUT = parseInt(
19+
<string>process.env.CONFIRMATION_TIMEOUT
20+
);
21+
export const GAS_LIMIT_MULTIPLIER = parseInt(
22+
<string>process.env.GAS_LIMIT_MULTIPLIER
23+
);
24+
export const GAS_PRICE_MULTIPLIER = parseInt(
25+
<string>process.env.GAS_PRICE_MULTIPLIER
26+
);
27+
export const BALANCE_THRESHOLD = parseEther(
28+
<string>process.env.BALANCE_THRESHOLD
29+
);
30+
export const GAS_STATION_API_CHAIN_ID = parseInt(
31+
<string>process.env.GAS_STATION_API_CHAIN_ID
32+
);
33+
export const GAS_STATION_API_URL = process.env.GAS_STATION_API_URL;
34+
export const GAS_STATION_API_REQUEST_TIMEOUT_MS = parseInt(
35+
<string>process.env.GAS_STATION_API_REQUEST_TIMEOUT_MS
36+
);

src/env.ts

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
// Copyright 2020 Cartesi Pte. Ltd.
2+
3+
// Licensed under the Apache License, Version 2.0 (the "License"); you may not use
4+
// this file except in compliance with the License. You may obtain a copy of the
5+
// License at http://www.apache.org/licenses/LICENSE-2.0
6+
7+
// Unless required by applicable law or agreed to in writing, software distributed
8+
// under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR
9+
// CONDITIONS OF ANY KIND, either express or implied. See the License for the
10+
// specific language governing permissions and limitations under the License.
11+
12+
import { config } from "dotenv";
13+
config();

src/index.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@
1010
// CONDITIONS OF ANY KIND, either express or implied. See the License for the
1111
// specific language governing permissions and limitations under the License.
1212

13+
import "./env";
1314
import log from "loglevel";
1415
import chalk from "chalk";
1516
import prefix from "loglevel-plugin-prefix";

test/setup.ts

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
// Copyright 2020 Cartesi Pte. Ltd.
2+
3+
// Licensed under the Apache License, Version 2.0 (the "License"); you may not use
4+
// this file except in compliance with the License. You may obtain a copy of the
5+
// License at http://www.apache.org/licenses/LICENSE-2.0
6+
7+
// Unless required by applicable law or agreed to in writing, software distributed
8+
// under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR
9+
// CONDITIONS OF ANY KIND, either express or implied. See the License for the
10+
// specific language governing permissions and limitations under the License.
11+
12+
import "../src/env";

yarn.lock

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3540,6 +3540,11 @@ domutils@^2.5.2, domutils@^2.6.0, domutils@^2.7.0:
35403540
domelementtype "^2.2.0"
35413541
domhandler "^4.2.0"
35423542

3543+
dotenv@^10.0.0:
3544+
version "10.0.0"
3545+
resolved "https://registry.yarnpkg.com/dotenv/-/dotenv-10.0.0.tgz#3d4227b8fb95f81096cdd2b66653fb2c7085ba81"
3546+
integrity sha512-rlBi9d8jpv9Sf1klPjNfFAuWDjKLwTIJJ/VxtoTwIR6hnZxcEOQCZg2oIL3MWBYw5GpUDKOEnND7LXTbIpQ03Q==
3547+
35433548
dotignore@~0.1.2:
35443549
version "0.1.2"
35453550
resolved "https://registry.yarnpkg.com/dotignore/-/dotignore-0.1.2.tgz#f942f2200d28c3a76fbdd6f0ee9f3257c8a2e905"

0 commit comments

Comments
 (0)