# Makefile for operating the make_post_sell server using either PyPI packages or source

# Variables (using the current working directory)
VENV_DIR = $(shell pwd)/env
DATA_DIR = $(shell pwd)/data
CONFIG_FILE = development.ini
# Using the provided configuration URL.
CONFIG_URL = https://git.unturf.com/engineering/make-post-sell/make_post_sell/-/raw/master/development.ini

PYTHON   = $(VENV_DIR)/bin/python
PIP      = $(VENV_DIR)/bin/pip
PSERVE   = $(VENV_DIR)/bin/pserve
ALEMBIC  = $(VENV_DIR)/bin/alembic
MPS_INIT = $(VENV_DIR)/bin/initialize_make_post_sell_db

# Default target: show help
.DEFAULT_GOAL := help


# Help target - shows all available commands
help:
	@echo "Make Post Sell - Available Commands"
	@echo "==================================="
	@echo ""
	@echo "SETUP & INSTALLATION:"
	@echo "  make venv                   - Create Python virtual environment"
	@echo "  make config                 - Download configuration file"
	@echo "  make install-from-pypi      - Complete setup using PyPI packages"
	@echo "  make install-from-source    - Complete setup from source (dev mode)"
	@echo "  make install-from-source-prod - Production install from source"
	@echo ""
	@echo "DATABASE:"
	@echo "  make init-db                - Initialize the database"
	@echo ""
	@echo "DEVELOPMENT:"
	@echo "  make serve                  - Start development server with auto-reload"
	@echo "  make test                   - Run test suite"
	@echo "  make test-coverage          - Run tests with coverage report"
	@echo "  make http                   - Start simple HTTP server on port 8000"
	@echo "  make activate               - Show how to activate virtual environment"
	@echo ""
	@echo "CRYPTOCURRENCY (MONERO):"
	@echo "  make check-monero           - Check if Monero tools are installed"
	@echo "  make install-monero         - Install Monero tools automatically"
	@echo "  make monero-wallet-create   - Create new Monero wallet (first time)"
	@echo "  make monero-node            - Start local Monero node (150GB required)"
	@echo "  make monero-wallet          - Start wallet RPC with local node"
	@echo "  make monero-wallet-remote   - Start wallet RPC with remote node (dev)"
	@echo "  make monero-wallet-remote-auth - Start wallet RPC with auth (testing)"
	@echo "  make monero-full-stack      - Show instructions for complete setup"
	@echo "  make crypto-watcher         - Start payment monitoring service"
	@echo "  make crypto-watcher-once    - Run payment check once (testing)"
	@echo ""
	@echo "CRYPTOCURRENCY (DOGECOIN):"
	@echo "  make check-dogecoin         - Check if Dogecoin Core is installed"
	@echo "  make install-dogecoin       - Install Dogecoin Core automatically"
	@echo "  make dogecoin-config        - Create dogecoin.conf for pruned mode"
	@echo "  make dogecoin-node          - Start Dogecoin daemon (pruned mode)"
	@echo "  make dogecoin-node-full     - Start Dogecoin daemon (full blockchain)"
	@echo "  make dogecoin-status        - Check sync status and wallet info"
	@echo ""
	@echo "WALLET MANAGEMENT:"
	@echo "  make sweep-check            - Check hot wallet balances (dry run)"
	@echo "  make sweep                  - Sweep funds to cold storage"
	@echo ""
	@echo "CLEANUP:"
	@echo "  make clean                  - Remove virtual environment"
	@echo ""
	@echo "For more info, see README.md and CRYPTO.rst"

# -----------------------------------------------------------------------------
# Environment Setup Targets
# -----------------------------------------------------------------------------

# Create virtual environment if not present.
$(VENV_DIR)/bin/activate:
	@echo "Creating virtual environment in $(VENV_DIR)..."
	python3 -m venv $(VENV_DIR)

venv: $(VENV_DIR)/bin/activate

# Create data directory and download configuration file if missing.
$(DATA_DIR)/$(CONFIG_FILE):
	@echo "Creating data directory in $(DATA_DIR) and downloading configuration file..."
	mkdir -p $(DATA_DIR)
	cd $(DATA_DIR) && wget -O $(CONFIG_FILE) $(CONFIG_URL)

config: $(DATA_DIR)/$(CONFIG_FILE)

# -----------------------------------------------------------------------------
# Package Installation Targets for PyPI Installation
# -----------------------------------------------------------------------------

# Install the make_post_sell core package from PyPI.
install-core: venv
	@echo "Installing make_post_sell core package from PyPI..."
	$(PIP) install make_post_sell

# Install development extras from PyPI.
install-dev: venv
	@echo "Installing make_post_sell development extras from PyPI..."
	$(PIP) install make_post_sell[dev]

# Combined PyPI installation target.
install: install-core install-dev

# -----------------------------------------------------------------------------
# Package Installation Targets for Source Installation
# -----------------------------------------------------------------------------

# Install from source (editable mode) for development and testing.
install-source-dev-and-test: venv
	@echo "Installing make_post_sell from source (editable mode) for development..."
	$(PIP) install --editable .
	$(PIP) install --upgrade -r requirements-dev.txt
	$(PIP) install --upgrade -r requirements-test.txt

# Install from source for production (non‑editable).
install-source-prod: venv
	@echo "Deleting tests from source code for production..."
	rm -rf make_post_sell/tests
	@echo "Installing make_post_sell from source for production (non‑editable)..."
	$(PIP) install .
	$(PIP) install --upgrade -r requirements-prod.txt

# -----------------------------------------------------------------------------
# Database Initialization and Server Targets
# -----------------------------------------------------------------------------

# Initialize the database using the configuration file.
init-db: venv config
	@echo "Initializing the make_post_sell database..."
	$(MPS_INIT) $(DATA_DIR)/$(CONFIG_FILE)
	$(ALEMBIC) -c $(DATA_DIR)/$(CONFIG_FILE) stamp head

# Start the development server with auto-reload.
serve: venv config
	@echo "Starting the make_post_sell development server..."
	$(PSERVE) $(DATA_DIR)/$(CONFIG_FILE) --reload

# -----------------------------------------------------------------------------
# Combined Setup Targets
# -----------------------------------------------------------------------------

# Install and set up using PyPI packages.
install-from-pypi: venv config install init-db

# Install and set up from source (editable mode) for development and testing.
install-from-source: venv config install-source-dev-and-test init-db

# Install and set up from source for production (non‑editable).
install-from-source-prod: venv config install-source-prod init-db

# -----------------------------------------------------------------------------
# Additional Targets
# -----------------------------------------------------------------------------

# Print instructions for activating the virtual environment.
activate:
	@echo "To activate the virtual environment, run:"
	@echo "  source $(VENV_DIR)/bin/activate"

# Run the test suite.
test: install-source-dev-and-test
	@echo "Running tests..."
	$(VENV_DIR)/bin/py.test

# Run tests with coverage for the full repository.
test-coverage: install-source-dev-and-test
	@echo "Running tests with coverage..."
	$(VENV_DIR)/bin/py.test --cov=make_post_sell --cov-report=term-missing --cov-report=html

# Start a simple HTTP server (if needed for static files).
http: venv
	@echo "Starting simple HTTP server on port 8000..."
	$(PYTHON) -m http.server 8000

# Run the crypto watcher service for monitoring Monero payments.
crypto-watcher: venv config
	@echo "Starting crypto payment watcher..."
	$(VENV_DIR)/bin/crypto_watcher $(DATA_DIR)/$(CONFIG_FILE)

# Run the crypto watcher once (for testing or manual processing).
crypto-watcher-once: venv config
	@echo "Running crypto payment watcher once..."
	$(VENV_DIR)/bin/crypto_watcher $(DATA_DIR)/$(CONFIG_FILE) --once

# Check hot wallet balance (dry run).
sweep-check: venv config
	@echo "Checking hot wallet balance..."
	@echo "IMPORTANT: Set COLD_WALLET_ADDRESS environment variable first!"
	$(VENV_DIR)/bin/sweep_to_cold $(DATA_DIR)/$(CONFIG_FILE) $${COLD_WALLET_ADDRESS:-ADDRESS_NOT_SET} --dry-run

# Sweep excess funds to cold storage.
sweep: venv config
	@echo "Sweeping excess funds to cold storage..."
	@echo "IMPORTANT: Set COLD_WALLET_ADDRESS environment variable first!"
	$(VENV_DIR)/bin/sweep_to_cold $(DATA_DIR)/$(CONFIG_FILE) $${COLD_WALLET_ADDRESS:-ADDRESS_NOT_SET}

# -----------------------------------------------------------------------------
# Monero Infrastructure Targets
# -----------------------------------------------------------------------------

# Start the Monero daemon (blockchain node) - requires ~150GB disk space
monero-node: venv config check-monero
	@echo "Starting Monero daemon (monerod)..."
	@echo "This will download ~150GB blockchain data and may take 1-2 days to sync"
	@mkdir -p $(DATA_DIR)/monero-blockchain
	@echo "Checking available disk space..."
	@available=$$(df -BG $(DATA_DIR) | tail -1 | awk '{print $$4}' | sed 's/G//'); \
	if [ $$available -lt 200 ]; then \
		echo "ERROR: Insufficient disk space!"; \
		echo "Available: $${available}GB"; \
		echo "Required: 200GB+ (150GB blockchain + growth)"; \
		exit 1; \
	else \
		echo "Disk space OK: $${available}GB available"; \
	fi
	@echo "Check sync status at: http://127.0.0.1:18081/get_info"
	@echo "Press Ctrl+C to stop"
	monerod --data-dir=$(DATA_DIR)/monero-blockchain \
		--rpc-bind-ip=127.0.0.1 \
		--rpc-bind-port=18081 \
		--confirm-external-bind \
		--log-level=1

# Start the Monero wallet RPC (requires monerod or remote node)
monero-wallet: venv config check-monero
	@echo "Starting Monero wallet RPC..."
	@echo "Make sure monerod is running and synced first!"
	@echo "Wallet file: $(DATA_DIR)/mps-wallet"
	@echo "RPC will be available at: http://127.0.0.1:18083"
	monero-wallet-rpc \
		--wallet-file=$(DATA_DIR)/mps-wallet \
		--password-file=$(DATA_DIR)/wallet-password.txt \
		--rpc-bind-ip=127.0.0.1 \
		--rpc-bind-port=18083 \
		--disable-rpc-login \
		--daemon-address=127.0.0.1:18081 \
		--trusted-daemon \
		--log-level=1

# Development mode - use remote node (no blockchain download needed)
monero-wallet-remote: venv config check-monero
	@echo "Starting wallet with REMOTE node (development/testing only)..."
	@echo "Using public node - less private but no blockchain download"
	@echo "Wallet file: $(DATA_DIR)/mps-wallet"
	@echo "RPC will be available at: http://127.0.0.1:18083"
	@echo ""
	@echo "Trying primary node: opennode.xmr-tw.org:18089"
	monero-wallet-rpc \
		--wallet-file=$(DATA_DIR)/mps-wallet \
		--password-file=$(DATA_DIR)/wallet-password.txt \
		--rpc-bind-ip=127.0.0.1 \
		--rpc-bind-port=18083 \
		--disable-rpc-login \
		--daemon-address=opennode.xmr-tw.org:18089 \
		--trusted-daemon \
		--log-level=1

# Development mode with RPC authentication for testing Digest auth
monero-wallet-remote-auth: venv config check-monero
	@echo "Starting wallet with REMOTE node and RPC AUTHENTICATION..."
	@echo "This enables RPC login for testing Digest authentication"
	@echo "Wallet file: $(DATA_DIR)/mps-wallet"  
	@echo "RPC will be available at: http://127.0.0.1:18083"
	@echo "RPC User: test_user"
	@echo "RPC Pass: test_pass"
	@echo ""
	@echo "Using remote node: opennode.xmr-tw.org:18089"
	monero-wallet-rpc \
		--wallet-file=$(DATA_DIR)/mps-wallet \
		--password-file=$(DATA_DIR)/wallet-password.txt \
		--rpc-bind-ip=127.0.0.1 \
		--rpc-bind-port=18083 \
		--rpc-login=test_user:test_pass \
		--daemon-address=opennode.xmr-tw.org:18089 \
		--trusted-daemon \
		--log-level=1


# Install Monero tools automatically
install-monero:
	@echo "Installing Monero tools..."
	@if [ "$$(uname)" = "Linux" ]; then \
		mkdir -p $(HOME)/.local/bin && \
		cd /tmp && \
		wget -q --show-progress https://downloads.getmonero.org/cli/linux64 && \
		tar -xf linux64 && \
		cp monero-x*/monero* $(HOME)/.local/bin/ && \
		rm -rf monero-x* linux64 && \
		echo "✓ Monero tools installed to $(HOME)/.local/bin/" && \
		echo "" && \
		echo "Add to your PATH by running:" && \
		echo "  export PATH=\"$(HOME)/.local/bin:\$$PATH\"" && \
		echo "Or add that line to your ~/.bashrc or ~/.zshrc" && \
		echo "" && \
		echo "Then run 'make monero-wallet-create' to create a wallet"; \
	elif [ "$$(uname)" = "Darwin" ]; then \
		if command -v brew >/dev/null 2>&1; then \
			brew install monero; \
		else \
			echo "Please install Homebrew first: https://brew.sh"; \
			exit 1; \
		fi; \
	else \
		echo "Unsupported OS. Please download manually from:"; \
		echo "https://www.getmonero.org/downloads/"; \
		exit 1; \
	fi

# Check if Monero tools are installed and provide install instructions
check-monero:
	@if command -v monero-wallet-rpc >/dev/null 2>&1; then \
		echo "✓ Monero tools found: $$(monero-wallet-rpc --version | head -1)"; \
	else \
		echo "❌ Monero tools not found!"; \
		echo ""; \
		if [ "$$(uname)" = "Linux" ]; then \
			echo "Install on Linux:"; \
			echo "Download latest official release (recommended):"; \
			echo "  wget https://downloads.getmonero.org/cli/linux64"; \
			echo "  tar -xf linux64 && sudo cp monero-x*/monero* /usr/local/bin/"; \
			echo ""; \
			echo "Or install to user directory (no sudo):"; \
			echo "  mkdir -p $$HOME/.local/bin"; \
			echo "  wget https://downloads.getmonero.org/cli/linux64"; \
			echo "  tar -xf linux64 && cp monero-x*/monero* $$HOME/.local/bin/"; \
			echo "  export PATH=\"$$HOME/.local/bin:$$PATH\""; \
		elif [ "$$(uname)" = "Darwin" ]; then \
			echo "Install on macOS:"; \
			echo "  brew install monero"; \
			echo ""; \
			echo "Or download latest official release:"; \
			echo "  wget https://downloads.getmonero.org/cli/mac64"; \
			echo "  tar -xf mac64 && sudo cp monero-x*/monero* /usr/local/bin/"; \
		else \
			echo "Download latest official Monero CLI tools:"; \
			echo "  https://www.getmonero.org/downloads/"; \
			echo "  Extract and copy monero-* binaries to /usr/local/bin/"; \
		fi; \
		echo ""; \
		echo "Package managers may have older versions. Official downloads are recommended."; \
		echo "After installing, run this command again."; \
		exit 1; \
	fi

# Create a new Monero wallet for the shop
monero-wallet-create: check-monero
	@echo "Creating new Monero wallet..."
	@echo "IMPORTANT: Save the 25-word mnemonic seed that will be displayed!"
	@echo "Enter a password for the wallet (or leave empty):"
	@read -s password; echo $$password > $(DATA_DIR)/wallet-password.txt
	monero-wallet-cli --generate-new-wallet=$(DATA_DIR)/mps-wallet \
		--password-file=$(DATA_DIR)/wallet-password.txt
	@echo "Wallet created at: $(DATA_DIR)/mps-wallet"
	@echo "Password saved in: $(DATA_DIR)/wallet-password.txt"
	@echo "Now run 'make monero-wallet' or 'make monero-wallet-remote' to start the RPC server"

# Instructions for running the full Monero stack
monero-full-stack:
	@echo "=== Running Full Monero Payment Stack ==="
	@echo ""
	@echo "For PRODUCTION (most secure, requires ~150GB):"
	@echo "  Terminal 1: make monero-node          # Start blockchain node"
	@echo "  Terminal 2: make monero-wallet        # Start wallet RPC (after node syncs)"
	@echo "  Terminal 3: make crypto-watcher       # Start payment watcher"
	@echo "  Terminal 4: make serve                # Start web application"
	@echo ""
	@echo "For DEVELOPMENT (quick start, uses public node):"
	@echo "  Terminal 1: make monero-wallet-remote # Start wallet with remote node"
	@echo "  Terminal 2: make crypto-watcher       # Start payment watcher"
	@echo "  Terminal 3: make serve                # Start web application"
	@echo ""
	@echo "First time? Run 'make monero-wallet-create' to create a wallet"

# -----------------------------------------------------------------------------
# Dogecoin Infrastructure Targets
# -----------------------------------------------------------------------------

# Check if Dogecoin Core is installed and provide install instructions
check-dogecoin:
	@if command -v dogecoind >/dev/null 2>&1; then \
		echo "✓ Dogecoin Core found: $$(dogecoind --version | head -1)"; \
	else \
		echo "❌ Dogecoin Core not found!"; \
		echo ""; \
		echo "Install options:"; \
		echo "1. Automatic: make install-dogecoin"; \
		echo "2. Manual: Download from https://github.com/dogecoin/dogecoin/releases"; \
		echo ""; \
		echo "See DOGECOIN_SETUP.md for detailed instructions"; \
		exit 1; \
	fi

# Install Dogecoin Core automatically
install-dogecoin:
	@echo "Installing Dogecoin Core..."
	@if [ "$$(uname)" = "Linux" ]; then \
		mkdir -p $(HOME)/.local/bin && \
		cd /tmp && \
		echo "Downloading Dogecoin Core v1.14.6..." && \
		wget -q --show-progress https://github.com/dogecoin/dogecoin/releases/download/v1.14.6/dogecoin-1.14.6-x86_64-linux-gnu.tar.gz && \
		tar -xzf dogecoin-1.14.6-x86_64-linux-gnu.tar.gz && \
		cp dogecoin-1.14.6/bin/* $(HOME)/.local/bin/ && \
		rm -rf dogecoin-1.14.6* && \
		echo "✓ Dogecoin Core installed to $(HOME)/.local/bin/" && \
		echo "" && \
		echo "Add to your PATH by running:" && \
		echo "  export PATH=\"$(HOME)/.local/bin:\$$PATH\"" && \
		echo "Or add that line to your ~/.bashrc or ~/.zshrc" && \
		echo "" && \
		echo "Then run 'make dogecoin-config' to create configuration"; \
	elif [ "$$(uname)" = "Darwin" ]; then \
		if command -v brew >/dev/null 2>&1; then \
			brew install dogecoin; \
		else \
			echo "Please install Homebrew first: https://brew.sh"; \
			echo "Or download manually from: https://github.com/dogecoin/dogecoin/releases"; \
			exit 1; \
		fi; \
	else \
		echo "Unsupported OS. Please download manually from:"; \
		echo "https://github.com/dogecoin/dogecoin/releases"; \
		exit 1; \
	fi

# Create dogecoin.conf for pruned hot wallet mode
dogecoin-config: check-dogecoin
	@echo "Creating Dogecoin configuration for hot wallet (pruned mode)..."
	@mkdir -p $(HOME)/.dogecoin
	@if [ -f $(HOME)/.dogecoin/dogecoin.conf ]; then \
		echo "Backing up existing config to dogecoin.conf.backup"; \
		cp $(HOME)/.dogecoin/dogecoin.conf $(HOME)/.dogecoin/dogecoin.conf.backup; \
	fi
	@echo "# Dogecoin Core Configuration for Make Post Sell Hot Wallet" > $(HOME)/.dogecoin/dogecoin.conf
	@echo "# Generated by: make dogecoin-config" >> $(HOME)/.dogecoin/dogecoin.conf
	@echo "" >> $(HOME)/.dogecoin/dogecoin.conf
	@echo "# Enable server mode for RPC" >> $(HOME)/.dogecoin/dogecoin.conf
	@echo "server=1" >> $(HOME)/.dogecoin/dogecoin.conf
	@echo "daemon=1" >> $(HOME)/.dogecoin/dogecoin.conf
	@echo "" >> $(HOME)/.dogecoin/dogecoin.conf
	@echo "# RPC credentials - CHANGE THESE IN PRODUCTION!" >> $(HOME)/.dogecoin/dogecoin.conf
	@echo "rpcuser=mps_doge_user" >> $(HOME)/.dogecoin/dogecoin.conf
	@echo "rpcpassword=change_this_password_in_production" >> $(HOME)/.dogecoin/dogecoin.conf
	@echo "rpcallowip=127.0.0.1" >> $(HOME)/.dogecoin/dogecoin.conf
	@echo "rpcport=22555" >> $(HOME)/.dogecoin/dogecoin.conf
	@echo "" >> $(HOME)/.dogecoin/dogecoin.conf
	@echo "# PRUNED MODE - keeps only ~2GB instead of 50GB!" >> $(HOME)/.dogecoin/dogecoin.conf
	@echo "prune=2000" >> $(HOME)/.dogecoin/dogecoin.conf
	@echo "" >> $(HOME)/.dogecoin/dogecoin.conf
	@echo "# Connect to reliable peers for faster sync" >> $(HOME)/.dogecoin/dogecoin.conf
	@echo "addnode=seed.dogechain.info" >> $(HOME)/.dogecoin/dogecoin.conf
	@echo "addnode=seed.multidoge.org" >> $(HOME)/.dogecoin/dogecoin.conf
	@echo "addnode=seed.dogecoin.com" >> $(HOME)/.dogecoin/dogecoin.conf
	@echo "" >> $(HOME)/.dogecoin/dogecoin.conf
	@echo "# Hot wallet for Make Post Sell" >> $(HOME)/.dogecoin/dogecoin.conf
	@echo "wallet=make_post_sell_hot_wallet" >> $(HOME)/.dogecoin/dogecoin.conf
	@echo ""
	@echo "✓ Configuration created at: $(HOME)/.dogecoin/dogecoin.conf"
	@echo ""
	@echo "🔐 SECURITY WARNING: Change the RPC password before production use!"
	@echo "Edit $(HOME)/.dogecoin/dogecoin.conf and update rpcpassword"
	@echo ""
	@echo "Next steps:"
	@echo "1. make dogecoin-node       # Start pruned node (recommended)"
	@echo "2. make dogecoin-status     # Check sync progress"

# Start Dogecoin daemon in pruned mode (recommended)
dogecoin-node: check-dogecoin
	@echo "Starting Dogecoin daemon in PRUNED mode..."
	@echo "This will use ~2GB storage instead of 50GB full blockchain"
	@echo "Initial sync takes 2-4 hours (much faster than full node)"
	@echo ""
	@if [ ! -f $(HOME)/.dogecoin/dogecoin.conf ]; then \
		echo "No config found. Run 'make dogecoin-config' first."; \
		exit 1; \
	fi
	@echo "Data directory: $(HOME)/.dogecoin/"
	@echo "RPC available at: http://127.0.0.1:22555"
	@echo "Check sync status: make dogecoin-status"
	@echo "Press Ctrl+C to stop"
	@echo ""
	dogecoind

# Start Dogecoin daemon in full mode (complete blockchain)
dogecoin-node-full: check-dogecoin
	@echo "Starting Dogecoin daemon in FULL mode..."
	@echo "This will download the complete ~50GB blockchain"
	@echo "Initial sync takes 8-12 hours"
	@echo ""
	@mkdir -p $(DATA_DIR)/dogecoin-blockchain
	@echo "Checking available disk space..."
	@available=$$(df -BG $(DATA_DIR) | tail -1 | awk '{print $$4}' | sed 's/G//'); \
	if [ $$available -lt 60 ]; then \
		echo "ERROR: Insufficient disk space!"; \
		echo "Available: $${available}GB"; \
		echo "Required: 60GB+ (50GB blockchain + growth)"; \
		exit 1; \
	else \
		echo "Disk space OK: $${available}GB available"; \
	fi
	@echo "Data directory: $(DATA_DIR)/dogecoin-blockchain"
	@echo "RPC available at: http://127.0.0.1:22555"
	@echo "Check sync status: make dogecoin-status"
	@echo "Press Ctrl+C to stop"
	@echo ""
	dogecoind -datadir=$(DATA_DIR)/dogecoin-blockchain \
		-rpcbind=127.0.0.1 \
		-rpcport=22555 \
		-rpcuser=mps_doge_user \
		-rpcpassword=change_this_password_in_production \
		-rpcallowip=127.0.0.1 \
		-server=1

# Check Dogecoin sync status and wallet info
dogecoin-status: check-dogecoin
	@echo "=== Dogecoin Node Status ==="
	@echo ""
	@if ! dogecoin-cli getblockchaininfo >/dev/null 2>&1; then \
		echo "❌ Dogecoin daemon not running or not responding"; \
		echo "Start with: make dogecoin-node"; \
		exit 1; \
	fi
	@echo "Blockchain info:"
	@dogecoin-cli getblockchaininfo | grep -E "(chain|blocks|headers|verificationprogress|size_on_disk|pruned)"
	@echo ""
	@echo "Network info:"
	@dogecoin-cli getnetworkinfo | grep -E "(version|subversion|connections)"
	@echo ""
	@echo "Wallet info:"
	@dogecoin-cli getwalletinfo | grep -E "(walletname|balance|unconfirmed_balance)" || echo "No wallet loaded"
	@echo ""
	@blocks=$$(dogecoin-cli getblockchaininfo | grep '"blocks"' | cut -d: -f2 | tr -d ' ,'); \
	headers=$$(dogecoin-cli getblockchaininfo | grep '"headers"' | cut -d: -f2 | tr -d ' ,'); \
	if [ "$$blocks" = "$$headers" ]; then \
		echo "✓ Sync complete! Blocks: $$blocks"; \
	else \
		echo "⏳ Syncing... Blocks: $$blocks / Headers: $$headers"; \
		progress=$$(dogecoin-cli getblockchaininfo | grep verificationprogress | cut -d: -f2 | tr -d ' ,'); \
		percent=$$(echo "$$progress * 100" | bc -l | cut -d. -f1); \
		echo "Progress: $$percent%"; \
	fi

# -----------------------------------------------------------------------------
# Cleanup Target
# -----------------------------------------------------------------------------

# Remove the virtual environment directories.
clean:
	@echo "Cleaning up: removing $(VENV_DIR)"
	rm -rf $(VENV_DIR)
