Files
dex/scripts/run-lux-testnet.sh
T
zeekayandHanzo Dev 95693668b0 rpc: /ext/ -> /v1/ — the dchain doc comments described a route luxd does not serve
luxd serves exactly one HTTP prefix. server/http/server.go:33 sets
baseURL = "/v1"; addRoute and AddAliases derive every path from it and
router.go mounts chains at baseURL+"/bc/C/rpc". /ext/* 404s everywhere.

The pkg/dchain package comments were the load-bearing part: ingest.go,
read.go, vm.go, read_test.go, ingest_test.go and zapingest.go all told
the reader that luxd mounts the DEX handlers at /ext/bc/<chainID>/dex/<m>.
That is the URL an integrator would build, and it 404s. The handlers are
at /v1/bc/<chainID>/dex/<m>.

zapingest.go said "/ext/bc route" with no trailing slash, so it does not
match an /ext/bc/ search -- searching for the whole prefix found it.

Also covers /ext/info, /ext/health and /ext/admin in the two local-network
scripts and in docs/source/node.mdx: baseURL applies to those routes too,
so swapping only the /bc/ ones would leave the scripts half broken.

Measured, positive and negative control on one host:
  api.lux.network/v1/bc/C/rpc -> 200 {"result":"0x17871"}   /ext -> 404
  api.lux.network/v1/info     -> 200 {"networkID":"1"}      /ext -> 404
  api.lux.network/v1/health   -> 405 (exists, GET-only)     /ext -> 404

go build + go vet clean on pkg/dchain, pkg/price, internal/standalone.
go test ./pkg/dchain/... ok 5.855s; go test ./pkg/price -run QChain ok 1.950s.
bash -n clean on both scripts. The repo-wide `go build ./...` was already
failing before this change on cgo packages that need luxcpp and libresolv.

Co-authored-by: Hanzo Dev <[email protected]>
2026-08-06 18:34:12 -07:00

252 lines
6.8 KiB
Bash
Executable File

#!/bin/bash
# Run Local Lux X-Chain Network for DEX
set -e
echo "🚀 Starting Local Lux X-Chain Network"
echo "======================================"
# Configuration
LUXD_PATH="${HOME}/work/lux/node/luxd"
DATA_DIR="/tmp/lux-dex-testnet"
NETWORK_ID=12345 # Local test network ID
# Colors
GREEN='\033[0;32m'
YELLOW='\033[1;33m'
RED='\033[0;31m'
NC='\033[0m'
# Clean previous data
echo "Cleaning previous test network data..."
rm -rf $DATA_DIR
mkdir -p $DATA_DIR/staking
# Generate staking keys
echo "Generating staking keys..."
cd $DATA_DIR/staking
openssl genrsa -out staker.key 4096 2>/dev/null
openssl req -new -x509 -key staker.key -out staker.crt -days 365 \
-subj '/C=US/ST=NY/O=LuxDEX/CN=lux' 2>/dev/null
cd - > /dev/null
echo -e "${GREEN}✅ Staking keys generated${NC}"
# Create chain configs
mkdir -p $DATA_DIR/configs/chains/C
cat > $DATA_DIR/configs/chains/C/config.json << 'EOF'
{
"coreth-admin-api-enabled": false,
"eth-apis": ["public-eth","public-eth-filter","net","web3","internal-public-eth","internal-public-blockchain","internal-public-transaction-pool"],
"rpc-gas-cap": 50000000,
"rpc-tx-fee-cap": 100,
"pruning-enabled": true,
"local-txs-enabled": true,
"api-max-duration": 30000000000,
"ws-cpu-refill-rate": 0,
"ws-cpu-max-stored": 0,
"api-max-blocks-per-request": 30,
"allow-unfinalized-queries": false,
"allow-unprotected-txs": false,
"remote-tx-gossip-only-enabled": false,
"log-level": "info"
}
EOF
# Start the node with minimal configuration for fast local testing
echo ""
echo -e "${YELLOW}Starting Lux Node...${NC}"
echo "Network ID: $NETWORK_ID"
echo "Data Directory: $DATA_DIR"
echo ""
# Kill any existing luxd processes
pkill -f luxd 2>/dev/null || true
sleep 2
# Run luxd with local testnet configuration
$LUXD_PATH \
--network-id=local \
--data-dir=$DATA_DIR \
--api-admin-enabled=true \
--api-ipcs-enabled=true \
--api-keystore-enabled=true \
--api-metrics-enabled=true \
--http-host=0.0.0.0 \
--http-port=9650 \
--staking-port=9651 \
--log-level=info \
--staking-enabled=false \
--public-ip=127.0.0.1 \
--health-check-frequency=2s \
--snow-sample-size=1 \
--snow-quorum-size=1 \
--index-enabled=true \
--db-dir=$DATA_DIR/db \
--chain-config-dir=$DATA_DIR/configs/chains \
--staking-tls-cert-file=$DATA_DIR/staking/staker.crt \
--staking-tls-key-file=$DATA_DIR/staking/staker.key \
> $DATA_DIR/node.log 2>&1 &
NODE_PID=$!
echo "Node PID: $NODE_PID"
echo "Log file: $DATA_DIR/node.log"
# Function to test endpoint
test_endpoint() {
local name=$1
local url=$2
local data=$3
echo -n "$name: "
if curl -s -X POST --data "$data" -H 'content-type:application/json;' "$url" 2>/dev/null | grep -q "result\|error"; then
echo -e "${GREEN}✅ Working${NC}"
return 0
else
echo -e "${RED}❌ Not ready${NC}"
return 1
fi
}
# Wait for node to start
echo ""
echo "Waiting for node to initialize..."
for i in {1..60}; do
if test_endpoint "Health Check" "http://127.0.0.1:9650/v1/health" '{}' 2>/dev/null; then
break
fi
echo -n "."
sleep 2
done
echo ""
echo ""
echo "Testing Lux RPC Endpoints..."
echo "============================="
# Test info endpoint
test_endpoint "1. Info API" \
"http://127.0.0.1:9650/v1/info" \
'{"jsonrpc":"2.0","id":1,"method":"info.getNodeID"}'
# Test keystore
test_endpoint "2. Keystore API" \
"http://127.0.0.1:9650/v1/keystore" \
'{"jsonrpc":"2.0","id":1,"method":"keystore.listUsers"}'
# Test X-Chain (AVM - Asset Virtual Machine)
test_endpoint "3. X-Chain API" \
"http://127.0.0.1:9650/v1/bc/X" \
'{"jsonrpc":"2.0","id":1,"method":"avm.getAssetDescription","params":{"assetID":"LUX"}}'
# Test P-Chain (Platform Chain)
test_endpoint "4. P-Chain API" \
"http://127.0.0.1:9650/v1/bc/P" \
'{"jsonrpc":"2.0","id":1,"method":"platform.getHeight"}'
# Test C-Chain (Contract Chain - EVM)
test_endpoint "5. C-Chain API" \
"http://127.0.0.1:9650/v1/bc/C/rpc" \
'{"jsonrpc":"2.0","method":"eth_chainId","params":[],"id":1}'
# Get blockchain info
echo ""
echo "Blockchain Status:"
echo "=================="
# Get node info
NODE_INFO=$(curl -s -X POST --data '{
"jsonrpc":"2.0",
"id":1,
"method":"info.getNodeVersion"
}' -H 'content-type:application/json;' http://127.0.0.1:9650/v1/info 2>/dev/null)
if [ ! -z "$NODE_INFO" ]; then
echo "Node Version: $(echo $NODE_INFO | grep -o '"version":"[^"]*"' | cut -d'"' -f4)"
fi
# Get X-Chain status
echo ""
echo "X-Chain (DEX Chain) Status:"
curl -s -X POST --data '{
"jsonrpc":"2.0",
"id":1,
"method":"avm.getHeight"
}' -H 'content-type:application/json;' http://127.0.0.1:9650/v1/bc/X 2>/dev/null | grep -o '"height":[0-9]*' || echo "Height: 0"
# Create test wallet
echo ""
echo "Creating Test Wallet..."
echo "======================="
# Create user
curl -s -X POST --data '{
"jsonrpc":"2.0",
"id":1,
"method":"keystore.createUser",
"params":{
"username":"dexuser",
"password":"dexpass123"
}
}' -H 'content-type:application/json;' http://127.0.0.1:9650/v1/keystore > /dev/null 2>&1
# Create X-Chain address
X_ADDR=$(curl -s -X POST --data '{
"jsonrpc":"2.0",
"id":1,
"method":"avm.createAddress",
"params":{
"username":"dexuser",
"password":"dexpass123"
}
}' -H 'content-type:application/json;' http://127.0.0.1:9650/v1/bc/X 2>/dev/null | grep -o '"address":"[^"]*"' | cut -d'"' -f4)
if [ ! -z "$X_ADDR" ]; then
echo -e "${GREEN}✅ X-Chain Address: $X_ADDR${NC}"
fi
echo ""
echo "======================================"
echo -e "${GREEN}✅ Local Lux Network is running!${NC}"
echo ""
echo "RPC Endpoints:"
echo " Info API: http://localhost:9650/v1/info"
echo " Health: http://localhost:9650/v1/health"
echo " X-Chain: http://localhost:9650/v1/bc/X"
echo " P-Chain: http://localhost:9650/v1/bc/P"
echo " C-Chain: http://localhost:9650/v1/bc/C/rpc"
echo ""
echo "Node PID: $NODE_PID"
echo "Logs: tail -f $DATA_DIR/node.log"
echo "To stop: kill $NODE_PID"
echo ""
# Monitor X-Chain
echo "Monitoring X-Chain blocks..."
echo "Press Ctrl+C to stop"
echo ""
while true; do
HEIGHT=$(curl -s -X POST --data '{
"jsonrpc":"2.0",
"id":1,
"method":"avm.getHeight"
}' -H 'content-type:application/json;' http://127.0.0.1:9650/v1/bc/X 2>/dev/null | grep -o '"height":[0-9]*' | cut -d':' -f2)
if [ ! -z "$HEIGHT" ]; then
echo "X-Chain Height: $HEIGHT at $(date '+%H:%M:%S')"
fi
# Also check P-Chain
P_HEIGHT=$(curl -s -X POST --data '{
"jsonrpc":"2.0",
"id":1,
"method":"platform.getHeight"
}' -H 'content-type:application/json;' http://127.0.0.1:9650/v1/bc/P 2>/dev/null | grep -o '"height":[0-9]*' | cut -d':' -f2)
if [ ! -z "$P_HEIGHT" ]; then
echo "P-Chain Height: $P_HEIGHT"
fi
sleep 5
done