Skip to content

Commit

Permalink
refactor(fuel-core-nats): improve fuel core nats dev script
Browse files Browse the repository at this point in the history
This change allows creating a .env file matching the templated environment variables from
.env.sample to start the fuel-core-nats service locally.
  • Loading branch information
Jurshsmith committed Jun 17, 2024
1 parent ab5091b commit 161d4ba
Show file tree
Hide file tree
Showing 4 changed files with 58 additions and 45 deletions.
8 changes: 6 additions & 2 deletions .env.sample
Original file line number Diff line number Diff line change
@@ -1,2 +1,6 @@
INFURA_API_KEY=2d0fcc5e22...
GENERATED_P2P_SECRET=930ge1d26cdd143e401923e69ca5d...
KEYPAIR=generated-p2p-secret
RELAYER=https://sepolia.infura.io/v3/infura-api-key
RELAYER_V2_LISTENING_CONTRACTS=0x768f9459E3339A1F7d59CcF24C80Eb4A711a01FB
RELAYER_DA_DEPLOY_HEIGHT=5791365
RELAYER_LOG_PAGE_SIZE=2000
SYNC_HEADER_BATCH_SIZE=100
6 changes: 3 additions & 3 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -27,9 +27,9 @@ setup: check-commands
# ------------------------------------------------------------
# Development
# ------------------------------------------------------------

dev/run-node:
./scripts/run-node.sh
# Starts fuel-core-nats service
start.fuel-core-nats:
./scripts/start-fuel-core-nats.sh

dev-watch:
cargo watch -- cargo run
Expand Down
40 changes: 0 additions & 40 deletions scripts/run-node.sh

This file was deleted.

49 changes: 49 additions & 0 deletions scripts/start-fuel-core-nats.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,49 @@
#!/bin/bash

# Load environment variables from .env file
if [ -f .env ]; then
export $(grep -v '^#' .env | xargs)
else
echo ".env file not found. Please create a .env file using the '.env.sample' template and try again."
exit 1
fi

# Function to check if environment variables are set
check_env_vars() {
local missing_vars=0

while IFS= read -r line; do
# Skip empty lines and comments
[[ -z "$line" || "$line" == \#* ]] && continue

# Extract the key
key=$(echo "$line" | cut -d '=' -f 1)

# Check if the key is set in the environment
if [ -z "${!key}" ]; then
echo "Environment variable $key is not set."
missing_vars=$((missing_vars + 1))
fi
done < ".env.sample"

return $missing_vars
}

check_env_vars

cargo run -p fuel-core-nats -- \
--service-name "NATS Publisher Node" \
--ip 0.0.0.0 \
--port 4000 \
--peering-port 30333 \
--db-path tmp/fuel-core-db \
--utxo-validation \
--poa-instant false \
--enable-p2p \
--keypair $KEYPAIR \
--sync-header-batch-size $SYNC_HEADER_BATCH_SIZE \
--enable-relayer \
--relayer $RELAYER \
--relayer-v2-listening-contracts $RELAYER_V2_LISTENING_CONTRACTS \
--relayer-da-deploy-height $RELAYER_DA_DEPLOY_HEIGHT \
--relayer-log-page-size $RELAYER_LOG_PAGE_SIZE \

0 comments on commit 161d4ba

Please sign in to comment.