@echo off
setlocal EnableExtensions
cd /d "%~dp0"

echo ============================================
echo  Export miner_key AND owner_key
echo  Both are required in eid-node.cfg
echo ============================================
echo.

set "WALLET_CLI="
if exist "%~dp0eid-wallet.exe" set "WALLET_CLI=%~dp0eid-wallet.exe"
if exist "%~dp0..\build\wallet\eid-wallet.exe" set "WALLET_CLI=%~dp0..\build\wallet\eid-wallet.exe"
if exist "%~dp0..\build\wallet\Release\eid-wallet.exe" set "WALLET_CLI=%~dp0..\build\wallet\Release\eid-wallet.exe"
if exist "%~dp0..\miner-build\wallet\eid-wallet.exe" set "WALLET_CLI=%~dp0..\miner-build\wallet\eid-wallet.exe"
if exist "%~dp0..\miner-build\wallet\Release\eid-wallet.exe" set "WALLET_CLI=%~dp0..\miner-build\wallet\Release\eid-wallet.exe"

if not defined WALLET_CLI (
  echo ERROR: eid-wallet.exe not found.
  echo This script is only for local node mining.
  echo For GPU mining, run start-gpu-mine.bat
  echo.
  pause
  exit /b 1
)

echo Using: %WALLET_CLI%
echo.
set /p WPASS=Wallet password: 
echo.
echo Exporting miner_key subkey=1 ...
"%WALLET_CLI%" --command=export_miner_key --subkey=1 --pass=%WPASS%
echo.
echo Exporting owner_key ...
"%WALLET_CLI%" --command=export_owner_key --pass=%WPASS%
echo.
echo Put BOTH keys into eid-node.cfg:
echo   miner_key=  (Secret Subkey 1)
echo   owner_key=  (Owner Viewer key)
echo   pass=       (same wallet password)
echo Without owner_key the node will not send GPU jobs.
echo.
pause
