Skip to content

Commit bbfb922

Browse files
committed
move mnemonic from chains.json -> .env
1 parent fb7b110 commit bbfb922

File tree

6 files changed

+23
-25
lines changed

6 files changed

+23
-25
lines changed

.gitignore

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,3 @@
11
.env
2-
chains.json
32
node_modules/
4-
.vscode/
3+
.vscode/

chains.json

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
{
2+
"ditto": {
3+
"rpc_url": "https://rpc.ditto-val-stage-0.ojo.network",
4+
"prefix": "ojo",
5+
"denom": "uojo",
6+
"amount_to_send": 10000000,
7+
"gas_price": "0.025",
8+
"gas_amount": 200000,
9+
"cooldown_seconds": 21600
10+
}
11+
}

configs/.env.example

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1,2 @@
1-
API_PORT=3000
1+
API_PORT=3000
2+
FAUCET_MNEMONIC="decorate bus bright decorate gallery bus bus decorate bus way bus decorate"

configs/chains.json.example

Lines changed: 0 additions & 12 deletions
This file was deleted.

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
{
2-
"name": "cosmos-faucet",
2+
"name": "ojo-faucet",
33
"version": "1.0.0",
44
"description": "A REST API for GETting tokens",
55
"main": "src/index.ts",

src/index.ts

Lines changed: 8 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@ import fs from 'fs';
1212

1313
import { config } from 'dotenv';
1414
config();
15-
const { API_PORT } = process.env;
15+
const { API_PORT, FAUCET_MNEMONIC } = process.env;
1616

1717

1818
const app = express();
@@ -26,7 +26,6 @@ let cooldown_map = new Map();
2626
interface ChainInfo {
2727
rpc_url: string;
2828
prefix: string;
29-
faucet_mnemonic: string;
3029
denom: string;
3130
amount_to_send: number;
3231
gas_price: number;
@@ -71,7 +70,7 @@ app.get('/', (req, res) => {
7170
})
7271

7372

74-
app.get('/:chain_id', async (req, res) => {
73+
app.get('/:chain_id', async (req, res) => {
7574
const { chain_id } = req.params;
7675

7776
let chain = get_chain(chain_id);
@@ -83,8 +82,8 @@ app.get('/:chain_id', async (req, res) => {
8382
chain = chain as ChainInfo;
8483

8584
try {
86-
const payment_account = await getAccountFromMnemonic(chain.faucet_mnemonic, chain.prefix);
87-
85+
const payment_account = await getAccountFromMnemonic(FAUCET_MNEMONIC, chain.prefix);
86+
8887
const client = await CosmWasmClient.connect(chain.rpc_url);
8988
const balance = await client.getBalance(payment_account.account.address, chain.denom);
9089

@@ -129,20 +128,20 @@ app.get('/:chain_id/:address', async (req, res) => {
129128
error: 'Address is not valid'
130129
})
131130
}
132-
131+
133132
const map_key = `${chain_id}-${address}`;
134133
if (cooldown_map.has(map_key)) {
135134
let cooldown = cooldown_map.get(map_key);
136135
let seconds_until_then = (cooldown - Date.now()) / 1000;
137136
if (cooldown > Date.now()) {
138-
res.status(400).json({
137+
res.status(400).json({
139138
error: `Address is in cooldown for ${seconds_until_then} seconds`
140139
})
141140
return;
142141
}
143142
}
144143

145-
const payment_account = await getAccountFromMnemonic(chain.faucet_mnemonic, chain.prefix);
144+
const payment_account = await getAccountFromMnemonic(FAUCET_MNEMONIC, chain.prefix);
146145
if (address === payment_account.account.address) {
147146
res.status(400).json({
148147
error: 'Address is the same as the faucet address'
@@ -168,7 +167,7 @@ app.get('/:chain_id/:address', async (req, res) => {
168167

169168
res.json({
170169
message: `Payment of amount: ${amt.amount} ${amt.denom}`,
171-
faucet_account: payment_account.account.address,
170+
faucet_account: payment_account.account.address,
172171
result: result
173172
})
174173

0 commit comments

Comments
 (0)