# ============================================================
# Genex Chain Block Explorer — Docker Compose
#
# Blockscout deployment for Genex Chain (chain-id: 8888)
# Start:
#   docker compose -f docker-compose.yml -f docker-compose.explorer.yml up -d
# Access: http://localhost:4000
# ============================================================

services:
  # ── Blockscout Block Explorer ──
  blockscout:
    image: blockscout/blockscout:latest
    container_name: genex-blockscout
    restart: unless-stopped
    depends_on:
      blockscout-db:
        condition: service_healthy
      blockscout-redis:
        condition: service_healthy
      smart-contract-verifier:
        condition: service_started
    environment:
      # Chain Connection (cosmos/evm 兼容 geth JSON-RPC)
      ETHEREUM_JSONRPC_VARIANT: geth
      ETHEREUM_JSONRPC_HTTP_URL: ${ETHEREUM_JSONRPC_HTTP_URL:-http://genex-node-1:8545}
      ETHEREUM_JSONRPC_WS_URL: ${ETHEREUM_JSONRPC_WS_URL:-ws://genex-node-1:8546}
      ETHEREUM_JSONRPC_TRACE_URL: ${ETHEREUM_JSONRPC_TRACE_URL:-http://genex-node-1:8545}

      # Database
      DATABASE_URL: postgresql://blockscout:${BLOCKSCOUT_DB_PASSWORD:-blockscout_secure_2024}@blockscout-db:5432/blockscout

      # Chain Identity
      CHAIN_ID: "8888"
      COIN: GNX
      COIN_NAME: Genex
      NETWORK: Genex Chain
      SUBNETWORK: ${SUBNETWORK:-Mainnet}
      LOGO: /images/genex-logo.svg

      # Blockscout Core
      BLOCK_TRANSFORMER: base
      ECTO_USE_SSL: "false"
      SECRET_KEY_BASE: ${SECRET_KEY_BASE:-RMgI4C1HSkxsEjdhtGMfwAHfyT6CKWXOgzCboJflfSm4jeAlic52io05KB6mqzc5}
      PORT: "4000"
      POOL_SIZE: "80"
      POOL_SIZE_API: "10"

      # Indexer
      INDEXER_DISABLE_PENDING_TRANSACTIONS_FETCHER: "false"
      INDEXER_DISABLE_INTERNAL_TRANSACTIONS_FETCHER: "false"
      FETCH_REWARDS_WAY: trace
      FIRST_BLOCK: "0"
      INDEXER_MEMORY_LIMIT: "10gb"

      # Token & NFT
      TOKEN_METADATA_UPDATE_INTERVAL: "1800"
      EIP_1559_ELASTICITY_MULTIPLIER: "2"

      # Smart Contract Verification
      MICROSERVICE_SC_VERIFIER_ENABLED: "true"
      MICROSERVICE_SC_VERIFIER_URL: http://smart-contract-verifier:8050
      MICROSERVICE_SC_VERIFIER_TYPE: sc_verifier

      # API & UI
      API_RATE_LIMIT: "50"
      API_RATE_LIMIT_BY_KEY: "150"
      API_V2_ENABLED: "true"
      DISABLE_EXCHANGE_RATES: "true"
      SHOW_TXS_CHART: "true"
      RE_CAPTCHA_DISABLED: "true"

      # Cache (Redis)
      CACHE_ENABLED: "true"
      ACCOUNT_REDIS_URL: redis://blockscout-redis:6379/0

      # Genex External Apps
      APPS_MENU: "true"
      EXTERNAL_APPS: '[{"title":"Genex Platform","url":"https://app.gogenex.com","description":"Genex coupon finance platform"},{"title":"Admin Dashboard","url":"https://admin.gogenex.com","description":"Genex admin console"}]'
    ports:
      - "${BLOCKSCOUT_PORT:-4000}:4000"
    volumes:
      - blockscout-logs:/app/logs
      - ./explorer:/app/custom
    networks:
      - genex-net
    healthcheck:
      test: ["CMD", "curl", "-f", "http://localhost:4000/api/v2/stats"]
      interval: 30s
      timeout: 10s
      retries: 10
      start_period: 120s

  # ── Blockscout PostgreSQL ──
  blockscout-db:
    image: postgres:16-alpine
    container_name: genex-blockscout-db
    restart: unless-stopped
    environment:
      POSTGRES_DB: blockscout
      POSTGRES_USER: blockscout
      POSTGRES_PASSWORD: ${BLOCKSCOUT_DB_PASSWORD:-blockscout_secure_2024}
    ports:
      - "${BLOCKSCOUT_DB_PORT:-5433}:5432"
    volumes:
      - blockscout-db-data:/var/lib/postgresql/data
    networks:
      - genex-net
    command:
      - "postgres"
      - "-c"
      - "max_connections=200"
      - "-c"
      - "shared_buffers=2GB"
      - "-c"
      - "effective_cache_size=6GB"
    healthcheck:
      test: ["CMD-SHELL", "pg_isready -U blockscout -d blockscout"]
      interval: 10s
      timeout: 5s
      retries: 5

  # ── Redis Cache ──
  blockscout-redis:
    image: redis:7-alpine
    container_name: genex-blockscout-redis
    restart: unless-stopped
    command: redis-server --maxmemory 512mb --maxmemory-policy allkeys-lru
    ports:
      - "${BLOCKSCOUT_REDIS_PORT:-6380}:6379"
    volumes:
      - blockscout-redis-data:/data
    networks:
      - genex-net
    healthcheck:
      test: ["CMD", "redis-cli", "ping"]
      interval: 10s
      timeout: 5s
      retries: 5

  # ── Smart Contract Verifier ──
  smart-contract-verifier:
    image: ghcr.io/blockscout/smart-contract-verifier:latest
    container_name: genex-sc-verifier
    restart: unless-stopped
    environment:
      SMART_CONTRACT_VERIFIER__SERVER__HTTP__ADDR: 0.0.0.0:8050
      SMART_CONTRACT_VERIFIER__SOLIDITY__ENABLED: "true"
      SMART_CONTRACT_VERIFIER__SOLIDITY__COMPILERS_DIR: /tmp/solidity-compilers
      SMART_CONTRACT_VERIFIER__VYPER__ENABLED: "false"
      SMART_CONTRACT_VERIFIER__SOURCIFY__ENABLED: "false"
    ports:
      - "${SC_VERIFIER_PORT:-8050}:8050"
    volumes:
      - sc-verifier-compilers:/tmp/solidity-compilers
    networks:
      - genex-net

volumes:
  blockscout-db-data:
  blockscout-redis-data:
  blockscout-logs:
  sc-verifier-compilers:

networks:
  genex-net:
    external: true
    name: blockchain_genex-net
