#!/bin/bash
set -e

DATA_DIR="${SYNOR_DATA_DIR:-/data/synor}"
NETWORK="${SYNOR_NETWORK:-testnet}"
GENESIS_MARKER="$DATA_DIR/chainstate/GENESIS"

# Initialize node if not already initialized
if [ ! -f "$GENESIS_MARKER" ]; then
    echo "Initializing Synor node for network: $NETWORK"
    synord --data-dir "$DATA_DIR" --network "$NETWORK" init --network "$NETWORK"
    echo "Node initialized successfully"
fi

# Execute the provided command
exec synord --data-dir "$DATA_DIR" --network "$NETWORK" "$@"
