cd /home/mempool/mempool/
git fetch
latestrelease=$(curl -s https://api.github.com/repos/mempool/mempool/releases/latest|grep tag_name|head -1|cut -d '"' -f4)
git checkout $latestrelease
cd /home/mempool/mempool/backend
npm install --prod
npm run build
#
cat << EOF | tee /home/mempool/mempool/backend/mempool-config.json
{
  "MEMPOOL": {
    "NETWORK": "mainnet",
    "BACKEND": "electrum",
    "HTTP_PORT": 8999,
    "SPAWN_CLUSTER_PROCS": 0,
    "API_URL_PREFIX": "/api/v1/",
    "POLL_RATE_MS": 2000,
    "CACHE_DIR": "./cache",
    "CLEAR_PROTECTION_MINUTES": 20,
    "RECOMMENDED_FEE_PERCENTILE": 50,
    "BLOCK_WEIGHT_UNITS": 4000000,
    "INITIAL_BLOCKS_AMOUNT": 8,
    "MEMPOOL_BLOCKS_AMOUNT": 8,
    "PRICE_FEED_UPDATE_INTERVAL": 3600,
    "USE_SECOND_NODE_FOR_MINFEE": false,
    "EXTERNAL_ASSETS": []
  },
  "CORE_RPC": {
    "HOST": "127.0.0.1",
    "PORT": 8332,
    "USERNAME": "BTCUSER",
    "PASSWORD": "BTCPASS"
  },
  "ELECTRUM": {
    "HOST": "127.0.0.1",
    "PORT": 50002,
    "TLS_ENABLED": true
  },
  "DATABASE": {
    "ENABLED": true,
    "HOST": "127.0.0.1",
    "PORT": 3306,
    "USERNAME": "mempool",
    "PASSWORD": "WEGOTTHIS",
    "DATABASE": "mempool"
  },
  "SOCKS5PROXY": {
    "ENABLED": true,
    "USE_ONION": true,
    "HOST": "127.0.0.1",
    "PORT": 9050
  },
  "MAXMIND": {
    "ENABLED": true,
    "GEOLITE2_CITY": "/home/mempool/mempool/GeoIP/GeoLite2-City.mmdb",
    "GEOLITE2_ASN": "/home/mempool/mempool//GeoIP/GeoLite2-ASN.mmdb",
    "GEOIP2_ISP": "/home/mempool/mempool/GeoIP/GeoIP2-ISP.mmdb"
  },
  "LIGHTNING": {
    "ENABLED": true,
    "BACKEND": "lnd",
    "TOPOLOGY_FOLDER": "",
    "STATS_REFRESH_INTERVAL": 600,
    "GRAPH_REFRESH_INTERVAL": 600,
    "LOGGER_UPDATE_INTERVAL": 30
  },
  "LND": {
    "TLS_CERT_PATH": "/data/lnd/tls.cert",
    "MACAROON_PATH": "/data/lnd/data/chain/bitcoin/mainnet/readonly.macaroon",
    "REST_API_URL": "https://127.0.0.1:8080",
    "TIMEOUT":10000
  },
  "PRICE_DATA_SERVER": {
    "TOR_URL": "http://emzypricpidesmyqg2hc6dkwitqzaxrqnpkdg3ae2wef5znncu2ambqd.onion/getAllMarketPrices"
  }
}
EOF
####

cat << EOF | tee /home/mempool/mempool/frontend/mempool-frontend-config.json
{
  "TESTNET_ENABLED": false,
  "SIGNET_ENABLED": false,
  "LIQUID_ENABLED": false,
  "LIQUID_TESTNET_ENABLED": false,
  "BISQ_ENABLED": false,
  "BISQ_SEPARATE_BACKEND": false,
  "ITEMS_PER_PAGE": 10,
  "KEEP_BLOCKS_AMOUNT": 8,
  "NGINX_PROTOCOL": "http",
  "NGINX_HOSTNAME": "127.0.0.1",
  "NGINX_PORT": "80",
  "BLOCK_WEIGHT_UNITS": 4000000,
  "MEMPOOL_BLOCKS_AMOUNT": 8,
  "BASE_MODULE": "mempool",
  "MEMPOOL_WEBSITE_URL": "https://mempool.space",
  "LIQUID_WEBSITE_URL": "https://liquid.network",
  "BISQ_WEBSITE_URL": "https://bisq.markets",
  "MINING_DASHBOARD": true,
  "AUDIT": false,
  "MAINNET_BLOCK_AUDIT_START_HEIGHT": 0,
  "TESTNET_BLOCK_AUDIT_START_HEIGHT": 0,
  "SIGNET_BLOCK_AUDIT_START_HEIGHT": 0,
  "LIGHTNING": true,
  "HISTORICAL_PRICE": true
}
EOF
#
cd /home/mempool/mempool/frontend/
npm install --prod
npm run build
cd
rm mempool_upgrade.sh
exit

