-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathstart-dashboard.sh
More file actions
executable file
·115 lines (99 loc) · 4.28 KB
/
Copy pathstart-dashboard.sh
File metadata and controls
executable file
·115 lines (99 loc) · 4.28 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
#!/usr/bin/env bash
set -euo pipefail
# Launch the buyer-side AgentPay dashboard from the public bundle.
# This script intentionally does not require the full x402-polymarket-data repo.
SCRIPT_DIR="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)"
REPO_ROOT="${SCRIPT_DIR}"
ENV_FILE="${BUYER_ENV_FILE:-/tmp/buyer-agentpay.env}"
if [ -f "${ENV_FILE}" ]; then
# shellcheck disable=SC1090
source "${ENV_FILE}"
else
echo "WARN: ${ENV_FILE} not found; dashboard will show setup guidance."
if [ -f "${REPO_ROOT}/skills/codex-buyer-agentpay/templates/buyer.env.template" ]; then
cp "${REPO_ROOT}/skills/codex-buyer-agentpay/templates/buyer.env.template" "${ENV_FILE}"
echo " Created ${ENV_FILE}; set BUYER_KEY there before running paid flows."
fi
fi
: "${SELLER_HOST:=polymarket-x402-seller.brevis.network}"
: "${SELLER_HTTP:=http://${SELLER_HOST}:8403}"
: "${SELLER_GRPC:=}"
: "${RELAY_ADMIN:=}"
: "${NETWORK:=eip155:8453}"
: "${CHAIN_ID:=8453}"
: "${RPC_URL:=https://mainnet.base.org}"
: "${CHANNEL_TOKEN_ADDR:=833589fcd6edb6e08f4c7c32d4f71b54bda02913}"
: "${CHANNEL_DEPOSIT:=500000}"
: "${BATCH_MARKET_ID:=2239711}"
: "${BATCH_COIN:=btc}"
: "${BATCH_LIMIT:=500}"
: "${BATCH_FROM_MINS:=5}"
: "${BATCH_FROM:=}"
: "${BATCH_TO:=}"
: "${AGENT_NAME:=Buyer Agent Portal}"
: "${DASHBOARD_PORT:=9100}"
: "${BUYER_PROFILE:=${HOME}/.x402/buyer-profile.json}"
: "${BUYER_DATA_DIR:=${HOME}/.x402/buyer-data}"
: "${NODE_BIN:=${REPO_ROOT}/skills/codex-buyer-agentpay/bin/node}"
: "${X402_CLIENT_BIN:=${REPO_ROOT}/skills/codex-buyer-agentpay/bin/x402-client}"
: "${STATUS_BRIDGE_BIN:=${REPO_ROOT}/skills/codex-buyer-agentpay/bin/status-bridge}"
if [ -z "${BUYER_KEY:-}" ] || [ "${BUYER_KEY:-}" = "<SET_ME_64_HEX_NO_0x>" ]; then
echo "WARN: BUYER_KEY is not set; dashboard will open, but RUN AGENT stays disabled."
echo " Generate a fresh key: ${X402_CLIENT_BIN} -genkey"
elif [ "${#BUYER_KEY}" -ne 64 ]; then
echo "WARN: BUYER_KEY must be exactly 64 hex characters without 0x."
fi
[ -x "${STATUS_BRIDGE_BIN}" ] || { echo "ERROR: status-bridge not executable: ${STATUS_BRIDGE_BIN}" >&2; exit 1; }
[ -x "${X402_CLIENT_BIN}" ] || { echo "ERROR: x402-client not executable: ${X402_CLIENT_BIN}" >&2; exit 1; }
[ -x "${NODE_BIN}" ] || { echo "ERROR: node not executable: ${NODE_BIN}" >&2; exit 1; }
# Always regenerate the buyer profile so script/template updates (new defaults,
# new fields) take effect on the next launch — no manual cleanup needed after
# upgrade or reinstall. User-tunable values still come from env vars
# (SELLER_HOST, OSP_ADDR, CHAIN_ID, ETH_GATEWAY, DISPUTE_TIMEOUT) and persistent
# channel state in BUYER_DATA_DIR is untouched.
echo "==> Generating buyer profile -> ${BUYER_PROFILE}"
mkdir -p "$(dirname "${BUYER_PROFILE}")"
if [ -f "${BUYER_PROFILE}" ]; then
cp "${BUYER_PROFILE}" "${BUYER_PROFILE}.prev"
fi
OUT="${BUYER_PROFILE}" SELLER_HOST="${SELLER_HOST}" RPC_URL="${RPC_URL}" \
bash "${REPO_ROOT}/deploy/gen-buyer-profile.sh"
mkdir -p "${BUYER_DATA_DIR}"
if command -v lsof >/dev/null 2>&1 && lsof -ti ":${DASHBOARD_PORT}" >/dev/null 2>&1; then
echo "==> Stopping existing process on :${DASHBOARD_PORT}"
lsof -ti ":${DASHBOARD_PORT}" | xargs kill -9 2>/dev/null || true
fi
export SELLER_HTTP SELLER_GRPC RELAY_ADMIN
export REPO_ROOT BUYER_KEY BUYER_PROFILE BUYER_DATA_DIR NODE_BIN
export RPC_URL CHAIN_ID NETWORK CHANNEL_TOKEN_ADDR CHANNEL_DEPOSIT
export BATCH_MARKET_ID BATCH_COIN BATCH_LIMIT BATCH_FROM_MINS BATCH_FROM BATCH_TO AGENT_NAME
export X402_CLIENT_BIN
export STATUS_BRIDGE_URL="http://127.0.0.1:${DASHBOARD_PORT}"
DATA_DIR="${HOME}/.x402/status-bridge"
mkdir -p "${DATA_DIR}"
echo ""
echo "==> Dashboard: http://localhost:${DASHBOARD_PORT}"
echo " Seller : ${SELLER_HTTP}"
echo " Market : ${BATCH_MARKET_ID}"
echo ""
"${STATUS_BRIDGE_BIN}" -addr ":${DASHBOARD_PORT}" -data-dir "${DATA_DIR}" &
BRIDGE_PID=$!
cleanup() {
echo
echo "Stopping dashboard..."
kill -TERM "${BRIDGE_PID}" 2>/dev/null || true
exit 0
}
trap cleanup INT TERM
for _ in $(seq 1 20); do
curl -sf "http://127.0.0.1:${DASHBOARD_PORT}/config" >/dev/null 2>&1 && break
sleep 0.3
done
URL="http://localhost:${DASHBOARD_PORT}"
if command -v open >/dev/null 2>&1; then
open "${URL}"
elif command -v xdg-open >/dev/null 2>&1; then
xdg-open "${URL}" >/dev/null 2>&1 &
fi
echo "Press Ctrl-C to stop."
wait "${BRIDGE_PID}"