Make chain-id, transferAmount and dailyLimit configurable

This commit is contained in:
Adw8 2024-07-17 12:41:39 +05:30
parent 133637e044
commit e19f83c726
4 changed files with 50 additions and 41 deletions

View File

@ -2,16 +2,24 @@ services:
start-faucet:
restart: unless-stopped
image: cerc/laconic-faucet:local
command: ["bash", "-c", "./start-faucet.sh"]
environment:
CERC_SCRIPT_DEBUG: ${CERC_SCRIPT_DEBUG}
CERC_LACONICD_RPC_ENDPOINT: ${CERC_LACONICD_RPC_ENDPOINT:-http://laconicd:26657}
CERC_FAUCET_KEY: ${CERC_FAUCET_KEY}
CERC_RPC_ENDPOINT: ${CERC_RPC_ENDPOINT}
entrypoint: "bash"
command: "./start-faucet.sh"
CERC_LACONICD_CHAIN_ID: ${CERC_LACONICD_CHAIN_ID:-laconic_9000-1}
CERC_TRANSFER_AMOUNT: ${CERC_TRANSFER_AMOUNT:-1000000}
CERC_DAILY_LIMIT: ${CERC_DAILY_LIMIT:-3000000}
volumes:
- ../config/laconic-faucet/start-faucet.sh:/app/start-faucet.sh
- ../config/laconic-faucet/config-template.toml:/app/environments/config-template.toml
ports:
- "3000:3000"
- 3000
extra_hosts:
- "host.docker.internal:host-gateway"
healthcheck:
test: ["CMD", "nc", "-vz", "127.0.0.1", "3000"]
interval: 10s
timeout: 5s
retries: 10
start_period: 5s

View File

@ -1,11 +1,12 @@
[upstream]
rpcEndpoint = "REPLACE_WITH_RPC_ENDPOINT"
rpcEndpoint = "REPLACE_WITH_CERC_LACONICD_RPC_ENDPOINT"
chainId = "laconic_9000-1"
denom = "photon"
prefix = "laconic"
faucetKey = "REPLACE_WITH_CERC_FAUCET_KEY"
[server]
transferAmount = 1000000
dailyLimit = 3000000
port=3000
transferAmount = "REPLACE_WITH_CERC_TRANSFER_AMOUNT"
dailyLimit = "REPLACE_WITH_CERC_DAILY_LIMIT"
dbDir = "db"

View File

@ -7,7 +7,7 @@ if [ -n "$CERC_SCRIPT_DEBUG" ]; then
fi
config_template=$(cat environments/config-template.toml)
local_config="./environments/local.toml"
target_config="./environments/local.toml"
# Check if faucet key is set
if [ -z "${CERC_FAUCET_KEY:-}" ]; then
@ -16,25 +16,20 @@ if [ -z "${CERC_FAUCET_KEY:-}" ]; then
fi
faucet_key=${CERC_FAUCET_KEY}
rpc_endpoint=${CERC_LACONICD_RPC_ENDPOINT}
transfer_amount=${CERC_TRANSFER_AMOUNT}
daily_limit=${CERC_DAILY_LIMIT}
# Check if RPC endpoint is set
if [-z "${CERC_RPC_ENDPOINT:-}" ]; then
echo "Error: CERC_RPC_ENDPOINT is not set. Exiting..."
exit 1
fi
rpc_endpoint=${CERC_RPC_ENDPOINT}
echo "The RPC endpoint is $rpc_endpoint"
echo "Using laconicd RPC endpoint: $rpc_endpoint"
echo "Transfer amount per request: $transfer_amount"
echo "Daily transfer amount limit for an address: $daily_limit"
FAUCET_CONFIG=$(echo "$config_template" | \
sed -E "s|REPLACE_WITH_CERC_FAUCET_KEY|${faucet_key}|; s|REPLACE_WITH_RPC_ENDPOINT|${rpc_endpoint}|")
sed -E "s|REPLACE_WITH_CERC_FAUCET_KEY|${faucet_key}|g; \
s|REPLACE_WITH_CERC_LACONICD_RPC_ENDPOINT|${rpc_endpoint}|g; \
s|REPLACE_WITH_CERC_TRANSFER_AMOUNT|${transfer_amount}|g; \
s|REPLACE_WITH_CERC_DAILY_LIMIT|${daily_limit}|; ")
echo "$FAUCET_CONFIG" > $local_config
echo "Updated config file"
echo "Config.toml:"
cat $local_config
# Start node-js server
echo "$FAUCET_CONFIG" > $target_config
echo "Starting faucet..."
yarn start-faucet

View File

@ -1,16 +1,6 @@
# laconic-faucet
Instructions for running the laconic faucet server
## Prerequisites
* Minimum hardware requirements:
```bash
RAM: 8-16GB
Disk space: 200GB
CPU: 2 cores
```
Instructions for running the laconic faucet
## Setup
@ -62,12 +52,25 @@ Instructions for running the laconic faucet server
* Inside the `laconic-faucet-deployment` deployment directory, open `config.env` file and set following env variables:
```bash
# Private key of faucet
CERC_FAUCET_KEY=
CERC_RPC_ENDPOINT=
# Optional
# laconicd RPC endpoint (default: http://laconicd:26657)
CERC_LACONICD_RPC_ENDPOINT=
# laconicd chain id (default: laconic_9000-1)
CERC_LACONICD_CHAIN_ID=
# Amount of tokens to transfer on a single request (default: 1000000)
CERC_TRANSFER_AMOUNT=
# Daily limit for transfer amount for an address (default: 3000000) (3 requests per day)
CERC_DAILY_LIMIT=
```
## Start the deployment
* To start the deployment:
```bash
laconic-so deployment --dir laconic-faucet-deployment start
@ -85,12 +88,14 @@ Instructions for running the laconic faucet server
docker logs -f <CONTAINER_ID>
```
* Request tokens from the testnet faucet for your account if required
## Run
* Request tokens from the faucet for an account:
```bash
curl -X POST http://localhost:3000/faucet \
-H "Content-Type: application/json" \
-d '{"address": "<laconicd_address>"}'
-H "Content-Type: application/json" \
-d '{"address": "<laconicd_address>"}'
```
## Clean up
@ -98,7 +103,7 @@ Instructions for running the laconic faucet server
* Stop the `laconic-faucet` service running in the background:
```bash
# Stop the docker containe
# Stop the docker container
laconic-so deployment --dir laconic-faucet-deployment stop
```