diff --git a/build.gradle b/build.gradle index d07b2ed12b..edc148d96c 100644 --- a/build.gradle +++ b/build.gradle @@ -64,7 +64,6 @@ configure(subprojects) { junitVersion = '4.12' jupiterVersion = '5.7.0' kotlinVersion = '1.3.41' - knowmXchangeVersion = '5.0.13' langVersion = '3.11' logbackVersion = '1.1.11' loggingVersion = '1.2' @@ -77,7 +76,6 @@ configure(subprojects) { qrgenVersion = '1.3' slf4jVersion = '1.7.30' sparkVersion = '2.5.2' - springBootVersion = '2.5.6' os = osdetector.os == 'osx' ? 'mac' : osdetector.os == 'windows' ? 'win' : osdetector.os } @@ -115,7 +113,6 @@ configure([project(':cli'), project(':relay'), project(':seednode'), project(':statsnode'), - project(':pricenode'), project(':inventory'), project(':apitest')]) { @@ -678,81 +675,6 @@ configure(project(':monitor')) { } -configure(project(':pricenode')) { - apply plugin: "org.springframework.boot" - - apply plugin: 'io.spring.dependency-management' - - mainClassName = 'bisq.price.Main' - - version = file("src/main/resources/version.txt").text.trim() - - jar.manifest.attributes( - "Implementation-Title": project.name, - "Implementation-Version": version) - - ext['log4j2.version'] = '2.17.0' - - dependencies { - implementation project(":common") - implementation project(":core") - annotationProcessor "org.projectlombok:lombok:$lombokVersion" - compileOnly "org.projectlombok:lombok:$lombokVersion" - implementation "com.google.code.gson:gson:$gsonVersion" - implementation "com.google.guava:guava:$guavaVersion" - implementation "commons-codec:commons-codec:$codecVersion" - implementation "org.apache.httpcomponents:httpcore:$httpcoreVersion" - implementation("org.apache.httpcomponents:httpclient:$httpclientVersion") { - exclude(module: 'commons-codec') - } - implementation("org.knowm.xchange:xchange-binance:$knowmXchangeVersion") - implementation("org.knowm.xchange:xchange-bitbay:$knowmXchangeVersion") - implementation("org.knowm.xchange:xchange-bitfinex:$knowmXchangeVersion") - implementation("org.knowm.xchange:xchange-bitflyer:$knowmXchangeVersion") - implementation("org.knowm.xchange:xchange-bitstamp:$knowmXchangeVersion") - implementation("org.knowm.xchange:xchange-btcmarkets:$knowmXchangeVersion") - implementation("org.knowm.xchange:xchange-cexio:$knowmXchangeVersion") - implementation("org.knowm.xchange:xchange-coinbasepro:$knowmXchangeVersion") - implementation("org.knowm.xchange:xchange-coinmarketcap:$knowmXchangeVersion") - implementation("org.knowm.xchange:xchange-coinmate:$knowmXchangeVersion") - implementation("org.knowm.xchange:xchange-coinone:$knowmXchangeVersion") - implementation("org.knowm.xchange:xchange-exmo:$knowmXchangeVersion") - implementation("org.knowm.xchange:xchange-hitbtc:$knowmXchangeVersion") - implementation("org.knowm.xchange:xchange-huobi:$knowmXchangeVersion") - implementation("org.knowm.xchange:xchange-independentreserve:$knowmXchangeVersion") - implementation("org.knowm.xchange:xchange-kraken:$knowmXchangeVersion") - implementation("org.knowm.xchange:xchange-luno:$knowmXchangeVersion") - implementation("org.knowm.xchange:xchange-mercadobitcoin:$knowmXchangeVersion") - implementation("org.knowm.xchange:xchange-paribu:$knowmXchangeVersion") - implementation("org.knowm.xchange:xchange-poloniex:$knowmXchangeVersion") - implementation("org.knowm.xchange:xchange-quoine:$knowmXchangeVersion") - implementation("org.springframework.boot:spring-boot-starter-web:$springBootVersion") - testAnnotationProcessor "org.projectlombok:lombok:$lombokVersion" - testCompileOnly "org.projectlombok:lombok:$lombokVersion" - testImplementation "org.junit.jupiter:junit-jupiter-api:$jupiterVersion" - testImplementation "org.junit.jupiter:junit-jupiter-params:$jupiterVersion" - testImplementation "org.mockito:mockito-core:$mockitoVersion" - testRuntimeOnly("org.junit.jupiter:junit-jupiter-engine:$jupiterVersion") - } - - test { - useJUnitPlatform() - - // Disabled by default, since spot provider tests include connections to external API endpoints - // Can be enabled by adding -Dtest.pricenode.includeSpotProviderTests=true to the gradle command: - // ./gradlew test -Dtest.pricenode.includeSpotProviderTests=true - if (System.properties['test.pricenode.includeSpotProviderTests'] != 'true') { - project.logger.lifecycle('Pricenode: Skipping spot provider tests') - exclude 'bisq/price/spot/providers/**' - } - } - - task stage { - dependsOn assemble - } -} - - configure(project(':relay')) { mainClassName = 'bisq.relay.RelayMain' diff --git a/pricenode/Procfile b/pricenode/Procfile deleted file mode 100644 index 00c7115ebe..0000000000 --- a/pricenode/Procfile +++ /dev/null @@ -1 +0,0 @@ -web: if [ "$HIDDEN" == true ]; then ./tor/bin/run_tor java -jar -Dserver.port=$PORT build/libs/haveno-pricenode.jar; else java -jar -Dserver.port=$PORT build/libs/haveno-pricenode.jar; fi diff --git a/pricenode/README-HEROKU.md b/pricenode/README-HEROKU.md deleted file mode 100644 index ab6081cd96..0000000000 --- a/pricenode/README-HEROKU.md +++ /dev/null @@ -1,42 +0,0 @@ -Deploy on Heroku --------- - -Run the following commands: - - heroku create - heroku buildpacks:add heroku/gradle - git push heroku master - curl https://your-app-123456.herokuapp.com/getAllMarketPrices - -To register the node as a Tor hidden service, first install the Heroku Tor buildpack: - - heroku buildpacks:add https://github.com/cbeams/heroku-buildpack-tor.git - git push heroku master - -> NOTE: this deployment will take a while, because the new buildpack must download and build Tor from source. - -Next, generate your Tor hidden service private key and .onion address: - - heroku run bash - ./tor/bin/tor -f torrc - -When the process reports that it is "100% bootstrapped", kill it, then copy the generated private key and .onion hostname values: - - cat build/tor-hidden-service/hostname - cat build/tor-hidden-service/private_key - exit - -> IMPORTANT: Save the private key value in a secure location so that this node can be re-created elsewhere with the same .onion address in the future if necessary. - -Now configure the hostname and private key values as environment variables for your Heroku app: - - heroku config:set HIDDEN=true HIDDEN_DOT_ONION=[your .onion] HIDDEN_PRIVATE_KEY="[your tor privkey]" - git push heroku master - -When the application finishes restarting, you should still be able to access it via the clearnet, e.g. with: - - curl https://your-app-123456.herokuapp.com/getAllMarketPrices - -And via your Tor Browser at: - - http://$YOUR_ONION/getAllMarketPrices diff --git a/pricenode/README.md b/pricenode/README.md deleted file mode 100644 index 8b366432dd..0000000000 --- a/pricenode/README.md +++ /dev/null @@ -1,84 +0,0 @@ -# Haveno-pricenode - -## Overview - -The Haveno pricenode is a simple HTTP service that fetches, transforms and relays data from third-party price providers to Haveno exchange clients on request. Available prices include: - - - Bitcoin exchange rates, available at `/getAllMarketPrices`, and - - Bitcoin mining fee rates, available at `/getFees` - -Pricenodes are deployed in production as Tor hidden services. This is not because the location of these nodes needs to be kept secret, but rather so that Haveno exchange clients do not need to exit the Tor network in order to get price data. - -Anyone can run a pricenode, but it must be _discoverable_ in order for it to do any good. For exchange clients to discover your pricenode, its .onion address must be hard-coded in the Haveno exchange client's `ProvidersRepository` class. Alternatively, users can point explicitly to given pricenode (or set of pricenodes) with the exchange client's `--providers` command line option. - -Pricenodes can be deployed anywhere Java and Tor binaries can be run. Instructions below cover deployment on localhost, and instructions [how to deploy on Heroku](README-HEROKU.md) are also available. - -Pricenodes should be cheap to run with regard to both time and money. The application itself is non-resource intensive and can be run on the low-end of most providers' paid tiers. - -A pricenode operator's main responsibilities are to ensure their node(s) are available and up-to-date. Releases are currently source-only, with the assumption that most operators will favor Git-based "push to deploy" workflows. - -## Prerequisites for running a pricenode - -To run a pricenode, you will need: - - - JDK 8 if you want to build and run a node locally. - - The `tor` binary (e.g. `brew install tor`) if you want to run a hidden service locally. - -## How to deploy for production - -### Install - -Run the one-command installer: - -```bash -curl -s https://raw.githubusercontent.com/haveno-dex/haveno/master/pricenode/install_pricenode_debian.sh | sudo bash -``` - -This will install the pricenode under the user `pricenode`. At the end of the installer script, it should print your Tor onion hostname. - -### Test - -To manually test endpoints, run each of the following: - -``` bash -curl http://localhost:8078/getAllMarketPrices -curl http://localhost:8078/getFees -curl http://localhost:8078/getParams -curl http://localhost:8078/info -``` - -### Monitoring - -If you run a main pricenode, you also are obliged to activate the monitoring feed by running - -```bash -bash <(curl -s https://raw.githubusercontent.com/haveno-dex/haveno/master/monitor/install_collectd_debian.sh) -``` - -Furthermore, you are obliged to provide network size data to the monitor by running - -```bash -curl -s https://raw.githubusercontent.com/haveno-dex/Haveno/master/pricenode/install_networksize_debian.sh | sudo bash -``` - -### Updating - -Update your Haveno code in /Haveno with ```git pull``` - -Then build an updated pricenode: - -```./gradlew :pricenode:installDist -x test``` - -## How to deploy elsewhere - - - [README-HEROKU.md](README-HEROKU.md) - - [docker/README.md](docker/README.md) - - -## Bitcoin mining fee estimates - -The pricenode exposes a service API to Haveno clients under `/getFees`. - -This API returns a mining fee rate estimate, representing an average of several mining fee rate values retrieved from different `mempool.space` instances. - -To configure which `mempool.space` instances are queried to calculate this average, see the relevant section in the file `application.properties`. diff --git a/pricenode/collectd.conf.snippet b/pricenode/collectd.conf.snippet deleted file mode 100644 index 49d93c5eda..0000000000 --- a/pricenode/collectd.conf.snippet +++ /dev/null @@ -1,5 +0,0 @@ -LoadPlugin exec - - - Exec "__USER_GROUP__" "__SCRAPERSCRIPT__" - diff --git a/pricenode/docker/Dockerfile b/pricenode/docker/Dockerfile deleted file mode 100644 index 75401beeb9..0000000000 --- a/pricenode/docker/Dockerfile +++ /dev/null @@ -1,33 +0,0 @@ -### -# Haveno pricenode dockerfile -### - -# pull base image -FROM openjdk:11-jdk - -# install tor -RUN apt-get update && apt-get install -y --no-install-recommends \ - tor && rm -rf /var/lib/apt/lists/* - -# copy tor configuration file -COPY torrc /etc/tor/ -# give proper permissions for tor configuration file -RUN chown debian-tor:debian-tor /etc/tor/torrc -# add haveno user -RUN useradd -d /haveno -G debian-tor haveno -# make haveno directory -RUN mkdir -p /haveno -# give haveno user proper permissions -RUN chown haveno:haveno /haveno -# clone haveno repository -RUN git clone https://github.com/haveno-dex/haveno.git /haveno/haveno -# build pricenode -WORKDIR /haveno/haveno -RUN ./gradlew :pricenode:installDist -x test -# set proper java options -ENV JAVA_OPTS="" -# expose ports -EXPOSE 80 -EXPOSE 8078 -# set launch command (tor and pricenode) -CMD tor && /haveno/haveno/haveno-pricenode 2 diff --git a/pricenode/docker/README.md b/pricenode/docker/README.md deleted file mode 100644 index 34fdafd3ff..0000000000 --- a/pricenode/docker/README.md +++ /dev/null @@ -1,26 +0,0 @@ -Needed software to start a pricenode -== - -* docker -* docker-compose - -How to start -== - -`docker compose up -d` - - -How to monitor -== - -See if it's running: `docker ps` - -Check the logs: `docker-compose logs` - -Check the tor hostname: `docker exec docker_pricenode_1 cat /var/lib/tor/pricenode/hostname` - - -How to test -== - -Refer to the main pricenode [README](../README.md). \ No newline at end of file diff --git a/pricenode/docker/docker-compose.yml b/pricenode/docker/docker-compose.yml deleted file mode 100644 index 65815f6c60..0000000000 --- a/pricenode/docker/docker-compose.yml +++ /dev/null @@ -1,10 +0,0 @@ -version: '3' - -services: - pricenode: - restart: unless-stopped - build: - context: . - ports: - - 80:80 - - 8078:8078 diff --git a/pricenode/docker/torrc b/pricenode/docker/torrc deleted file mode 100644 index 4c39cdb6e6..0000000000 --- a/pricenode/docker/torrc +++ /dev/null @@ -1,4 +0,0 @@ -HiddenServiceDir /var/lib/tor/pricenode/ -HiddenServicePort 80 127.0.0.1:8078 -HiddenServiceVersion 3 -RunAsDaemon 1 diff --git a/pricenode/haveno-pricenode.env b/pricenode/haveno-pricenode.env deleted file mode 100644 index f77a6675c4..0000000000 --- a/pricenode/haveno-pricenode.env +++ /dev/null @@ -1 +0,0 @@ -JAVA_OPTS="-XX:+ExitOnOutOfMemoryError" diff --git a/pricenode/haveno-pricenode.service b/pricenode/haveno-pricenode.service deleted file mode 100644 index 6aa1a1b86f..0000000000 --- a/pricenode/haveno-pricenode.service +++ /dev/null @@ -1,25 +0,0 @@ -[Unit] -Description=Haveno Price Node -After=network.target - -[Service] -SyslogIdentifier=Haveno-pricenode -EnvironmentFile=/etc/default/haveno-pricenode.env -ExecStart=/pricenode/haveno/haveno-pricenode 2 -ExecStop=/bin/kill -TERM ${MAINPID} -Restart=on-failure - -User=pricenode -Group=pricenode - -PrivateTmp=true -ProtectSystem=full -NoNewPrivileges=true -PrivateDevices=true -MemoryDenyWriteExecute=false -ProtectControlGroups=true -ProtectKernelTunables=true -RestrictSUIDSGID=true - -[Install] -WantedBy=multi-user.target diff --git a/pricenode/install_hsversion_debian.sh b/pricenode/install_hsversion_debian.sh deleted file mode 100755 index 631a02787c..0000000000 --- a/pricenode/install_hsversion_debian.sh +++ /dev/null @@ -1,41 +0,0 @@ -#!/bin/sh -set -e - -echo "[*] Network Size Monitoring installation script" - -##### change paths if necessary for your system - -ROOT_USER=root - -SCRAPER_HOME=/journalreader -SCRAPER_USER=journalreader -SCRAPER_GROUP=systemd-journal - -##### -echo "[*] Checking environment..." -if [ ! -f "/etc/collectd/collectd.conf" ]; then - echo 'Collectd is not installed. Did you do the install_monitoring_debian.sh?' - echo 'Exiting...' - exit -fi -if ! grep -q "journalreader" /etc/passwd; then - echo 'User not found. Did you run the install_networksize_debian.sh?' - echo 'Exiting...' - exit -fi - -echo "[*] Installing journal parser script" -curl -s https://raw.githubusercontent.com/bisq-network/bisq/master/pricenode/journalscraper_hsversion.sh > /tmp/journalscraper_hsversion.sh -sudo -H -i -u "${ROOT_USER}" install -c -o "${SCRAPER_USER}" -g "${SCRAPER_GROUP}" -m 744 /tmp/journalscraper_hsversion.sh "${SCRAPER_HOME}/scraperscript_hsversion.sh" - -echo "[*] Installing collectd config" -curl -s https://raw.githubusercontent.com/bisq-network/bisq/master/pricenode/collectd.conf.snippet > /tmp/collectd.conf.snippet -sudo -H -i -u "${ROOT_USER}" sed -i -e "s/LoadPlugin exec//" /tmp/collectd.conf.snippet -sudo -H -i -u "${ROOT_USER}" /bin/sh -c "cat /tmp/collectd.conf.snippet >> /etc/collectd/collectd.conf" -sudo -H -i -u "${ROOT_USER}" sed -i -e "s/__USER_GROUP__/${SCRAPER_USER}:${SCRAPER_GROUP}/" /etc/collectd/collectd.conf -sudo -H -i -u "${ROOT_USER}" sed -i -e "s!__SCRAPERSCRIPT__!${SCRAPER_HOME}/scraperscript_hsversion.sh!" /etc/collectd/collectd.conf - -echo "[*] Restarting services" -sudo -H -i -u "${ROOT_USER}" systemctl restart collectd.service - -echo '[*] Done!' diff --git a/pricenode/install_networksize_debian.sh b/pricenode/install_networksize_debian.sh deleted file mode 100755 index bc25b3c6dd..0000000000 --- a/pricenode/install_networksize_debian.sh +++ /dev/null @@ -1,42 +0,0 @@ -#!/bin/sh -set -e - -echo "[*] Network Size Monitoring installation script" - -##### change paths if necessary for your system - -ROOT_USER=root - -SCRAPER_HOME=/journalreader -SCRAPER_USER=journalreader -SCRAPER_GROUP=systemd-journal - -##### -echo "[*] Checking environment..." -if [ ! -f "/etc/collectd/collectd.conf" ]; then - echo 'Collectd is not installed. Did you do the install_monitoring_debian.sh?' - echo 'Exiting...' - exit -fi - -echo "[*] Creating journal reader user" -sudo -H -i -u "${ROOT_USER}" useradd -d "${SCRAPER_HOME}" -G "${SCRAPER_GROUP}" "${SCRAPER_USER}" -sudo -H -i -u "${ROOT_USER}" mkdir -p "${SCRAPER_HOME}" -sudo -H -i -u "${ROOT_USER}" chown "${SCRAPER_USER}":"${SCRAPER_GROUP}" ${SCRAPER_HOME} - -echo "[*] Installing journal parser script" -curl -s https://raw.githubusercontent.com/bisq-network/bisq/master/pricenode/journalscraper.sh > /tmp/journalscraper.sh -sudo -H -i -u "${ROOT_USER}" install -c -o "${SCRAPER_USER}" -g "${SCRAPER_GROUP}" -m 744 /tmp/journalscraper.sh "${SCRAPER_HOME}/scraperscript.sh" - -echo "[*] Installing collectd config" -curl -s https://raw.githubusercontent.com/bisq-network/bisq/master/pricenode/collectd.conf.snippet > /tmp/collectd.conf.snippet -sudo -H -i -u "${ROOT_USER}" /bin/sh -c "cat /tmp/collectd.conf.snippet >> /etc/collectd/collectd.conf" -sudo -H -i -u "${ROOT_USER}" sed -i -e "s/__USER_GROUP__/${SCRAPER_USER}:${SCRAPER_GROUP}/" /etc/collectd/collectd.conf -sudo -H -i -u "${ROOT_USER}" sed -i -e "s!__SCRAPERSCRIPT__!${SCRAPER_HOME}/scraperscript.sh!" /etc/collectd/collectd.conf - -sudo -H -i -u "${ROOT_USER}" systemctl enable collectd.service - -echo "[*] Restarting services" -sudo -H -i -u "${ROOT_USER}" systemctl restart collectd.service - -echo '[*] Done!' diff --git a/pricenode/install_pricenode_debian.sh b/pricenode/install_pricenode_debian.sh deleted file mode 100755 index 311d9727c6..0000000000 --- a/pricenode/install_pricenode_debian.sh +++ /dev/null @@ -1,90 +0,0 @@ -#!/usr/bin/env bash -set -e - -echo "[*] haveno-pricenode installation script" - -##### change as necessary for your system - -SYSTEMD_SERVICE_HOME=/etc/systemd/system -SYSTEMD_ENV_HOME=/etc/default - -ROOT_USER=root -ROOT_GROUP=root -#ROOT_HOME=/root - -HAVENO_USER=pricenode -HAVENO_GROUP=pricenode -HAVENO_HOME=/pricenode - -HAVENO_REPO_URL=https://github.com/haveno-dex/haveno -HAVENO_REPO_NAME=haveno -HAVENO_REPO_TAG=master -HAVENO_LATEST_RELEASE=master -HAVENO_TORHS=pricenode - -TOR_PKG="tor" -#TOR_USER=debian-tor -TOR_GROUP=debian-tor -TOR_CONF=/etc/tor/torrc -TOR_RESOURCES=/var/lib/tor - -##### - -echo "[*] Upgrading apt packages" -sudo -H -i -u "${ROOT_USER}" DEBIAN_FRONTEND=noninteractive apt-get update -q -sudo -H -i -u "${ROOT_USER}" DEBIAN_FRONTEND=noninteractive apt-get upgrade -qq -y - -echo "[*] Installing Tor" -sudo -H -i -u "${ROOT_USER}" DEBIAN_FRONTEND=noninteractive apt-get install -qq -y "${TOR_PKG}" - -echo "[*] Adding Tor configuration" -if ! grep "${HAVENO_TORHS}" /etc/tor/torrc >/dev/null 2>&1;then - sudo -H -i -u "${ROOT_USER}" sh -c "echo HiddenServiceDir ${TOR_RESOURCES}/${HAVENO_TORHS}/ >> ${TOR_CONF}" - sudo -H -i -u "${ROOT_USER}" sh -c "echo HiddenServicePort 80 127.0.0.1:8078 >> ${TOR_CONF}" - sudo -H -i -u "${ROOT_USER}" sh -c "echo HiddenServiceVersion 3 >> ${TOR_CONF}" -fi - -echo "[*] Creating Haveno user with Tor access" -sudo -H -i -u "${ROOT_USER}" useradd -d "${HAVENO_HOME}" -G "${TOR_GROUP}" "${HAVENO_USER}" - -echo "[*] Creating Haveno homedir" -sudo -H -i -u "${ROOT_USER}" mkdir -p "${HAVENO_HOME}" -sudo -H -i -u "${ROOT_USER}" chown "${HAVENO_USER}":"${HAVENO_GROUP}" ${HAVENO_HOME} - -echo "[*] Cloning Haveno repo" -sudo -H -i -u "${HAVENO_USER}" git config --global advice.detachedHead false -sudo -H -i -u "${HAVENO_USER}" git clone --branch "${HAVENO_REPO_TAG}" "${HAVENO_REPO_URL}" "${HAVENO_HOME}/${HAVENO_REPO_NAME}" - -echo "[*] Installing OpenJDK 11" -sudo -H -i -u "${ROOT_USER}" apt-get install -qq -y openjdk-11-jdk - -echo "[*] Checking out Haveno ${HAVENO_LATEST_RELEASE}" -sudo -H -i -u "${HAVENO_USER}" sh -c "cd ${HAVENO_HOME}/${HAVENO_REPO_NAME} && git checkout ${HAVENO_LATEST_RELEASE}" - -echo "[*] Building Haveno from source" -sudo -H -i -u "${HAVENO_USER}" sh -c "cd ${HAVENO_HOME}/${HAVENO_REPO_NAME} && ./gradlew :pricenode:installDist -x test < /dev/null" # redirect from /dev/null is necessary to workaround gradlew non-interactive shell hanging issue - -echo "[*] Installing haveno-pricenode systemd service" -sudo -H -i -u "${ROOT_USER}" install -c -o "${ROOT_USER}" -g "${ROOT_GROUP}" -m 644 "${HAVENO_HOME}/${HAVENO_REPO_NAME}/pricenode/haveno-pricenode.service" "${SYSTEMD_SERVICE_HOME}" -sudo -H -i -u "${ROOT_USER}" install -c -o "${ROOT_USER}" -g "${ROOT_GROUP}" -m 644 "${HAVENO_HOME}/${HAVENO_REPO_NAME}/pricenode/haveno-pricenode.env" "${SYSTEMD_ENV_HOME}" - -echo "[*] Reloading systemd daemon configuration" -sudo -H -i -u "${ROOT_USER}" systemctl daemon-reload - -echo "[*] Enabling haveno-pricenode service" -sudo -H -i -u "${ROOT_USER}" systemctl enable haveno-pricenode.service - -echo "[*] Starting haveno-pricenode service" -sudo -H -i -u "${ROOT_USER}" systemctl start haveno-pricenode.service -sleep 5 -sudo -H -i -u "${ROOT_USER}" journalctl --no-pager --unit haveno-pricenode - -echo "[*] Restarting Tor" -sudo -H -i -u "${ROOT_USER}" service tor restart -sleep 5 - -echo '[*] Done!' -echo -n '[*] Access your pricenode at http://' -cat "${TOR_RESOURCES}/${HAVENO_TORHS}/hostname" - -exit 0 diff --git a/pricenode/journalscraper.sh b/pricenode/journalscraper.sh deleted file mode 100755 index df80ddc3ad..0000000000 --- a/pricenode/journalscraper.sh +++ /dev/null @@ -1,20 +0,0 @@ -#!/bin/bash - -HOSTNAME="${COLLECTD_HOSTNAME:-localhost}" -INTERVAL=750 - -last=$(date +"%F %T" -d "$INTERVAL seconds ago") -while true; -do - now=$(date +"%F %T") - - journalctl -u bisq-pricenode --since="$last" --until="$now" | grep -Eo "getAllMarketPrices.*bisq/[0-9].[0-9].[0-9]" | cut -d / -f 2 | sort | uniq -c | while read -r line; do - number=$(echo "${line}" | cut -d ' ' -f 1); - version=$(echo "${line}" | cut -d \ -f 2); - version=${version//./_}; - echo "PUTVAL $HOSTNAME/requestsPer750Seconds/gauge-v$version interval=$INTERVAL N:$number"; - done - last=$now - - sleep $INTERVAL -done diff --git a/pricenode/journalscraper_hsversion.sh b/pricenode/journalscraper_hsversion.sh deleted file mode 100755 index f5d710b8b7..0000000000 --- a/pricenode/journalscraper_hsversion.sh +++ /dev/null @@ -1,20 +0,0 @@ -#!/bin/bash - -HOSTNAME="${COLLECTD_HOSTNAME:-localhost}" -INTERVAL=750 - -last=$(date +"%F %T" -d "$INTERVAL seconds ago") -while true; -do - now=$(date +"%F %T") - - journalctl -u bisq-pricenode --since="$last" --until="$now" | grep -Eo "getAllMarketPrices.*HSv[0-9]" | grep -o "HSv[0-9]" | sort | uniq -c | while read -r line; do - number=$(echo "${line}" | cut -d ' ' -f 1); - version=$(echo "${line}" | cut -d \ -f 2); - version=${version//./_}; - echo "PUTVAL $HOSTNAME/hsversionStats/gauge-$version interval=$INTERVAL N:$number"; - done - last=$now - - sleep $INTERVAL -done diff --git a/pricenode/src/main/java/bisq/price/Main.java b/pricenode/src/main/java/bisq/price/Main.java deleted file mode 100644 index 3e83fc497f..0000000000 --- a/pricenode/src/main/java/bisq/price/Main.java +++ /dev/null @@ -1,51 +0,0 @@ -/* - * This file is part of Haveno. - * - * Haveno is free software: you can redistribute it and/or modify it - * under the terms of the GNU Affero General Public License as published by - * the Free Software Foundation, either version 3 of the License, or (at - * your option) any later version. - * - * Haveno is distributed in the hope that it will be useful, but WITHOUT - * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or - * FITNESS FOR A PARTICULAR PURPOSE. See the GNU Affero General Public - * License for more details. - * - * You should have received a copy of the GNU Affero General Public License - * along with Haveno. If not, see . - */ - -package bisq.price; - -import org.springframework.boot.autoconfigure.SpringBootApplication; -import org.springframework.boot.builder.SpringApplicationBuilder; - -import java.io.File; -import java.io.FileInputStream; -import java.io.IOException; -import java.io.UncheckedIOException; - -import java.util.Properties; - -@SpringBootApplication -public class Main { - - public static void main(String[] args) { - new SpringApplicationBuilder(Main.class) - .properties(bisqProperties()) - .run(args); - } - - private static Properties bisqProperties() { - Properties props = new Properties(); - File propsFile = new File(System.getenv("HOME"), ".config/haveno.properties"); - if (propsFile.exists()) { - try { - props.load(new FileInputStream(propsFile)); - } catch (IOException ex) { - throw new UncheckedIOException(ex); - } - } - return props; - } -} diff --git a/pricenode/src/main/java/bisq/price/PriceController.java b/pricenode/src/main/java/bisq/price/PriceController.java deleted file mode 100644 index dbea4ebab7..0000000000 --- a/pricenode/src/main/java/bisq/price/PriceController.java +++ /dev/null @@ -1,35 +0,0 @@ -/* - * This file is part of Haveno. - * - * Haveno is free software: you can redistribute it and/or modify it - * under the terms of the GNU Affero General Public License as published by - * the Free Software Foundation, either version 3 of the License, or (at - * your option) any later version. - * - * Haveno is distributed in the hope that it will be useful, but WITHOUT - * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or - * FITNESS FOR A PARTICULAR PURPOSE. See the GNU Affero General Public - * License for more details. - * - * You should have received a copy of the GNU Affero General Public License - * along with Haveno. If not, see . - */ - -package bisq.price; - -import org.springframework.web.bind.annotation.ModelAttribute; - -import javax.servlet.http.HttpServletRequest; - -import org.slf4j.Logger; -import org.slf4j.LoggerFactory; - -public abstract class PriceController { - - protected final Logger log = LoggerFactory.getLogger(this.getClass()); - - @ModelAttribute - public void logRequest(HttpServletRequest request) { - log.info("Incoming {} request from: {}", request.getServletPath(), request.getHeader("User-Agent")); - } -} diff --git a/pricenode/src/main/java/bisq/price/PriceProvider.java b/pricenode/src/main/java/bisq/price/PriceProvider.java deleted file mode 100644 index 20af8ef56c..0000000000 --- a/pricenode/src/main/java/bisq/price/PriceProvider.java +++ /dev/null @@ -1,121 +0,0 @@ -/* - * This file is part of Haveno. - * - * Haveno is free software: you can redistribute it and/or modify it - * under the terms of the GNU Affero General Public License as published by - * the Free Software Foundation, either version 3 of the License, or (at - * your option) any later version. - * - * Haveno is distributed in the hope that it will be useful, but WITHOUT - * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or - * FITNESS FOR A PARTICULAR PURPOSE. See the GNU Affero General Public - * License for more details. - * - * You should have received a copy of the GNU Affero General Public License - * along with Haveno. If not, see . - */ - -package bisq.price; - -import bisq.common.UserThread; - -import org.springframework.context.SmartLifecycle; - -import java.time.Duration; - -import java.util.Timer; -import java.util.TimerTask; -import java.util.concurrent.TimeUnit; -import java.util.function.Supplier; - -import org.slf4j.Logger; -import org.slf4j.LoggerFactory; - -public abstract class PriceProvider implements SmartLifecycle, Supplier { - - protected final Logger log = LoggerFactory.getLogger(this.getClass()); - - private final Timer timer = new Timer(true); - - protected final Duration refreshInterval; - - private T cachedResult; - - public PriceProvider(Duration refreshInterval) { - this.refreshInterval = refreshInterval; - log.info("will refresh every {}", refreshInterval); - } - - @Override - public final T get() { - return cachedResult; - } - - @Override - public final void start() { - // do the initial refresh asynchronously - UserThread.runAfter(() -> { - try { - refresh(); - } catch (Throwable t) { - log.warn("initial refresh failed", t); - } - }, 1, TimeUnit.MILLISECONDS); - - timer.scheduleAtFixedRate(new TimerTask() { - @Override - public void run() { - try { - refresh(); - } catch (Throwable t) { - // we only log scheduled calls to refresh that fail to ensure that - // the application does *not* halt, assuming the failure is temporary - // and on the side of the upstream price provider, eg. BitcoinAverage - log.warn("refresh failed", t); - } - } - }, refreshInterval.toMillis(), refreshInterval.toMillis()); - } - - private void refresh() { - try { - long ts = System.currentTimeMillis(); - cachedResult = doGet(); - log.info("refresh took {} ms.", (System.currentTimeMillis() - ts)); - onRefresh(); - } catch (Exception e) { - log.warn("Error refreshing price provider {}", getClass()); - } - } - - protected abstract T doGet(); - - protected void onRefresh() { - } - - @Override - public void stop() { - timer.cancel(); - } - - @Override - public void stop(Runnable callback) { - stop(); - callback.run(); - } - - @Override - public boolean isAutoStartup() { - return true; - } - - @Override - public boolean isRunning() { - return cachedResult != null; - } - - @Override - public int getPhase() { - return 0; - } -} diff --git a/pricenode/src/main/java/bisq/price/mining/FeeRate.java b/pricenode/src/main/java/bisq/price/mining/FeeRate.java deleted file mode 100644 index 5c23576fde..0000000000 --- a/pricenode/src/main/java/bisq/price/mining/FeeRate.java +++ /dev/null @@ -1,52 +0,0 @@ -/* - * This file is part of Haveno. - * - * Haveno is free software: you can redistribute it and/or modify it - * under the terms of the GNU Affero General Public License as published by - * the Free Software Foundation, either version 3 of the License, or (at - * your option) any later version. - * - * Haveno is distributed in the hope that it will be useful, but WITHOUT - * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or - * FITNESS FOR A PARTICULAR PURPOSE. See the GNU Affero General Public - * License for more details. - * - * You should have received a copy of the GNU Affero General Public License - * along with Haveno. If not, see . - */ - -package bisq.price.mining; - -/** - * A value object representing the mining fee rate for a given base currency. - */ -public class FeeRate { - - private final String currency; - private final long price; - private final long minimumFee; - private final long timestamp; - - public FeeRate(String currency, long price, long minimumFee, long timestamp) { - this.currency = currency; - this.price = price; - this.minimumFee = minimumFee; - this.timestamp = timestamp; - } - - public String getCurrency() { - return currency; - } - - public long getPrice() { - return price; - } - - public long getMinimumFee() { - return minimumFee; - } - - public long getTimestamp() { - return timestamp; - } -} diff --git a/pricenode/src/main/java/bisq/price/mining/FeeRateController.java b/pricenode/src/main/java/bisq/price/mining/FeeRateController.java deleted file mode 100644 index 6b69cd17c9..0000000000 --- a/pricenode/src/main/java/bisq/price/mining/FeeRateController.java +++ /dev/null @@ -1,40 +0,0 @@ -/* - * This file is part of Haveno. - * - * Haveno is free software: you can redistribute it and/or modify it - * under the terms of the GNU Affero General Public License as published by - * the Free Software Foundation, either version 3 of the License, or (at - * your option) any later version. - * - * Haveno is distributed in the hope that it will be useful, but WITHOUT - * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or - * FITNESS FOR A PARTICULAR PURPOSE. See the GNU Affero General Public - * License for more details. - * - * You should have received a copy of the GNU Affero General Public License - * along with Haveno. If not, see . - */ - -package bisq.price.mining; - -import bisq.price.PriceController; - -import org.springframework.web.bind.annotation.GetMapping; -import org.springframework.web.bind.annotation.RestController; - -import java.util.Map; - -@RestController -class FeeRateController extends PriceController { - - private final FeeRateService feeRateService; - - public FeeRateController(FeeRateService feeRateService) { - this.feeRateService = feeRateService; - } - - @GetMapping(path = "/getFees") - public Map getFees() { - return feeRateService.getFees(); - } -} diff --git a/pricenode/src/main/java/bisq/price/mining/FeeRateProvider.java b/pricenode/src/main/java/bisq/price/mining/FeeRateProvider.java deleted file mode 100644 index 62dabf3f1a..0000000000 --- a/pricenode/src/main/java/bisq/price/mining/FeeRateProvider.java +++ /dev/null @@ -1,36 +0,0 @@ -/* - * This file is part of Haveno. - * - * Haveno is free software: you can redistribute it and/or modify it - * under the terms of the GNU Affero General Public License as published by - * the Free Software Foundation, either version 3 of the License, or (at - * your option) any later version. - * - * Haveno is distributed in the hope that it will be useful, but WITHOUT - * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or - * FITNESS FOR A PARTICULAR PURPOSE. See the GNU Affero General Public - * License for more details. - * - * You should have received a copy of the GNU Affero General Public License - * along with Haveno. If not, see . - */ - -package bisq.price.mining; - -import bisq.price.PriceProvider; - -import java.time.Duration; - -/** - * Abstract base class for providers of mining {@link FeeRate} data. - */ -public abstract class FeeRateProvider extends PriceProvider { - - public static final long MIN_FEE_RATE_FOR_WITHDRAWAL = 2; // satoshi/vbyte - public static final long MIN_FEE_RATE_FOR_TRADING = 10; // satoshi/vbyte - public static final long MAX_FEE_RATE = 1000; - - public FeeRateProvider(Duration refreshInterval) { - super(refreshInterval); - } -} diff --git a/pricenode/src/main/java/bisq/price/mining/FeeRateService.java b/pricenode/src/main/java/bisq/price/mining/FeeRateService.java deleted file mode 100644 index 509daacb04..0000000000 --- a/pricenode/src/main/java/bisq/price/mining/FeeRateService.java +++ /dev/null @@ -1,107 +0,0 @@ -/* - * This file is part of Haveno. - * - * Haveno is free software: you can redistribute it and/or modify it - * under the terms of the GNU Affero General Public License as published by - * the Free Software Foundation, either version 3 of the License, or (at - * your option) any later version. - * - * Haveno is distributed in the hope that it will be useful, but WITHOUT - * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or - * FITNESS FOR A PARTICULAR PURPOSE. See the GNU Affero General Public - * License for more details. - * - * You should have received a copy of the GNU Affero General Public License - * along with Haveno. If not, see . - */ - -package bisq.price.mining; - -import bisq.common.config.Config; - -import org.springframework.stereotype.Service; - -import java.time.Instant; - -import java.util.HashMap; -import java.util.List; -import java.util.Map; -import java.util.concurrent.atomic.AtomicInteger; -import java.util.concurrent.atomic.AtomicLong; - -import org.slf4j.Logger; -import org.slf4j.LoggerFactory; - -/** - * High-level mining {@link FeeRate} operations. - */ -@Service -public class FeeRateService { - - private final List providers; - protected final Logger log = LoggerFactory.getLogger(this.getClass()); - - /** - * Construct a {@link FeeRateService} with a list of all {@link FeeRateProvider} - * implementations discovered via classpath scanning. - * - * @param providers all {@link FeeRateProvider} implementations in ascending - * order of precedence - */ - public FeeRateService(List providers) { - this.providers = providers; - } - - public Map getFees() { - Map metadata = new HashMap<>(); - Map allFeeRates = new HashMap<>(); - - AtomicLong sumOfAllFeeRates = new AtomicLong(); - AtomicLong sumOfAllMinFeeRates = new AtomicLong(); - AtomicInteger amountOfFeeRates = new AtomicInteger(); - - // Process each provider, retrieve and store their fee rate - providers.forEach(p -> { - FeeRate feeRate = p.get(); - if (feeRate == null) { - log.warn("feeRate is null, provider={} ", p.toString()); - return; - } - String currency = feeRate.getCurrency(); - if ("BTC".equals(currency)) { - sumOfAllFeeRates.getAndAdd(feeRate.getPrice()); - sumOfAllMinFeeRates.getAndAdd(feeRate.getMinimumFee()); - amountOfFeeRates.getAndAdd(1); - } - }); - - // Calculate the average - long averageFeeRate = (amountOfFeeRates.intValue() > 0) - ? sumOfAllFeeRates.longValue() / amountOfFeeRates.intValue() - : FeeRateProvider.MIN_FEE_RATE_FOR_TRADING; - long averageMinFeeRate = (amountOfFeeRates.intValue() > 0) - ? sumOfAllMinFeeRates.longValue() / amountOfFeeRates.intValue() - : FeeRateProvider.MIN_FEE_RATE_FOR_WITHDRAWAL; - - // Make sure the returned value is within the min-max range - averageFeeRate = Math.max(averageFeeRate, FeeRateProvider.MIN_FEE_RATE_FOR_TRADING); - averageFeeRate = Math.min(averageFeeRate, FeeRateProvider.MAX_FEE_RATE); - averageMinFeeRate = Math.max(averageMinFeeRate, FeeRateProvider.MIN_FEE_RATE_FOR_WITHDRAWAL); - averageMinFeeRate = Math.min(averageMinFeeRate, FeeRateProvider.MAX_FEE_RATE); - - // Prepare response: Add timestamp of now - // Since this is an average, the timestamp is associated with when the moment in - // time when the avg was computed - metadata.put(Config.BTC_FEES_TS, Instant.now().getEpochSecond()); - - // Prepare response: Add the fee average - allFeeRates.put(Config.BTC_TX_FEE, averageFeeRate); - allFeeRates.put(Config.BTC_MIN_TX_FEE, averageMinFeeRate); - - // Build response - return new HashMap<>() {{ - putAll(metadata); - put(Config.LEGACY_FEE_DATAMAP, allFeeRates); - }}; - } -} diff --git a/pricenode/src/main/java/bisq/price/mining/providers/MempoolFeeRateProvider.java b/pricenode/src/main/java/bisq/price/mining/providers/MempoolFeeRateProvider.java deleted file mode 100644 index d885aa3d37..0000000000 --- a/pricenode/src/main/java/bisq/price/mining/providers/MempoolFeeRateProvider.java +++ /dev/null @@ -1,229 +0,0 @@ -/* - * This file is part of Haveno. - * - * Haveno is free software: you can redistribute it and/or modify it - * under the terms of the GNU Affero General Public License as published by - * the Free Software Foundation, either version 3 of the License, or (at - * your option) any later version. - * - * Haveno is distributed in the hope that it will be useful, but WITHOUT - * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or - * FITNESS FOR A PARTICULAR PURPOSE. See the GNU Affero General Public - * License for more details. - * - * You should have received a copy of the GNU Affero General Public License - * along with Haveno. If not, see . - */ - -package bisq.price.mining.providers; - -import bisq.price.PriceController; -import bisq.price.mining.FeeRate; -import bisq.price.mining.FeeRateProvider; - -import org.springframework.boot.autoconfigure.condition.ConditionalOnProperty; -import org.springframework.context.annotation.Primary; -import org.springframework.core.ParameterizedTypeReference; -import org.springframework.core.annotation.Order; -import org.springframework.core.env.CommandLinePropertySource; -import org.springframework.core.env.Environment; -import org.springframework.http.RequestEntity; -import org.springframework.stereotype.Component; -import org.springframework.web.bind.annotation.GetMapping; -import org.springframework.web.bind.annotation.RestController; -import org.springframework.web.client.RestTemplate; -import org.springframework.web.util.UriComponentsBuilder; - -import java.time.Duration; -import java.time.Instant; - -import java.util.Map; -import java.util.Optional; -import java.util.Set; - -/** - * {@link FeeRateProvider} that interprets the Mempool API format to retrieve a mining - * fee estimate. See https://mempool.space. - */ -abstract class MempoolFeeRateProvider extends FeeRateProvider { - - private static final int DEFAULT_MAX_BLOCKS = 2; - private static final int DEFAULT_REFRESH_INTERVAL = 2; - - // Keys of properties defining the available Mempool API endpoints. To enable them, - // simply uncomment and adjust the corresponding lines in application.properties - private static final String MEMPOOL_HOSTNAME_KEY_1 = "bisq.price.mining.providers.mempoolHostname.1"; - private static final String MEMPOOL_HOSTNAME_KEY_2 = "bisq.price.mining.providers.mempoolHostname.2"; - private static final String MEMPOOL_HOSTNAME_KEY_3 = "bisq.price.mining.providers.mempoolHostname.3"; - private static final String MEMPOOL_HOSTNAME_KEY_4 = "bisq.price.mining.providers.mempoolHostname.4"; - private static final String MEMPOOL_HOSTNAME_KEY_5 = "bisq.price.mining.providers.mempoolHostname.5"; - - private static final RestTemplate restTemplate = new RestTemplate(); - - // TODO: As of the switch to the mempool.space API this field and related members are - // now dead code and should be removed, including removing the positional - // command-line argument from startup scripts. Operators need to be notified of this - // when it happens. - private final int maxBlocks; - - protected Environment env; - - public MempoolFeeRateProvider(Environment env) { - super(Duration.ofMinutes(refreshInterval(env))); - this.env = env; - this.maxBlocks = maxBlocks(env); - } - - protected FeeRate doGet() { - // Default value is the minimum rate. If the connection to the fee estimate - // provider fails, we fall back to this value. - try { - return getEstimatedFeeRate(); - } - catch (Exception e) { - // Something happened with the connection - log.error("Error retrieving bitcoin mining fee estimation: " + e.getMessage()); - } - - return new FeeRate("BTC", MIN_FEE_RATE_FOR_TRADING, MIN_FEE_RATE_FOR_WITHDRAWAL, Instant.now().getEpochSecond()); - } - - private FeeRate getEstimatedFeeRate() { - Set> feeRatePredictions = getFeeRatePredictions(); - long estimatedFeeRate = feeRatePredictions.stream() - .filter(p -> p.getKey().equalsIgnoreCase("halfHourFee")) - .map(Map.Entry::getValue) - .findFirst() - .map(r -> Math.max(r, MIN_FEE_RATE_FOR_TRADING)) - .map(r -> Math.min(r, MAX_FEE_RATE)) - .orElse(MIN_FEE_RATE_FOR_TRADING); - long minimumFee = feeRatePredictions.stream() - .filter(p -> p.getKey().equalsIgnoreCase("minimumFee")) - .map(Map.Entry::getValue) - .findFirst() - .map(r -> Math.multiplyExact(r, 2)) // multiply the minimumFee by 2 (per wiz) - .orElse(MIN_FEE_RATE_FOR_WITHDRAWAL); - log.info("Retrieved estimated mining fee of {} sat/vB and minimumFee of {} sat/vB from {}", estimatedFeeRate, minimumFee, getMempoolApiHostname()); - return new FeeRate("BTC", estimatedFeeRate, minimumFee, Instant.now().getEpochSecond()); - } - - private Set> getFeeRatePredictions() { - return restTemplate.exchange( - RequestEntity - .get(UriComponentsBuilder - // See https://github.com/bisq-network/projects/issues/27 - .fromUriString("https://" + getMempoolApiHostname() + "/api/v1/fees/recommended") - .build().toUri()) - .build(), - new ParameterizedTypeReference>() { } - ).getBody().entrySet(); - } - - /** - * Return the hostname of the fee estimation API endpoint. No prefix (https://), no - * suffix (trailing slashes, etc). - */ - protected abstract String getMempoolApiHostname(); - - private static Optional args(Environment env) { - return Optional.ofNullable( - env.getProperty(CommandLinePropertySource.DEFAULT_NON_OPTION_ARGS_PROPERTY_NAME, String[].class)); - } - - private static int maxBlocks(Environment env) { - return args(env) - .filter(args -> args.length >= 1) - .map(args -> Integer.valueOf(args[0])) - .orElse(DEFAULT_MAX_BLOCKS); - } - - private static long refreshInterval(Environment env) { - return args(env) - .filter(args -> args.length >= 2) - .map(args -> Integer.valueOf(args[1])) - .orElse(DEFAULT_REFRESH_INTERVAL); - } - - @Primary - @Component - @Order(1) - public static class First extends MempoolFeeRateProvider { - - public First(Environment env) { - super(env); - } - - protected String getMempoolApiHostname() { - // This is the primary instance, so if no API point is set in - // application.properties file, then it defaults to mempool.space - // This ensures there is at least one provider attempting to connect, - // even if the properties file is corrupt or empty - return env.getProperty(MEMPOOL_HOSTNAME_KEY_1, "mempool.space"); - } - } - - @Component - @Order(2) - @ConditionalOnProperty(name = MEMPOOL_HOSTNAME_KEY_2) - public static class Second extends MempoolFeeRateProvider { - - public Second(Environment env) { - super(env); - } - - protected String getMempoolApiHostname() { - return env.getProperty(MEMPOOL_HOSTNAME_KEY_2); - } - } - - @Component - @Order(3) - @ConditionalOnProperty(name = MEMPOOL_HOSTNAME_KEY_3) - public static class Third extends MempoolFeeRateProvider { - - public Third(Environment env) { - super(env); - } - - protected String getMempoolApiHostname() { - return env.getProperty(MEMPOOL_HOSTNAME_KEY_3); - } - } - - @Component - @Order(4) - @ConditionalOnProperty(name = MEMPOOL_HOSTNAME_KEY_4) - public static class Fourth extends MempoolFeeRateProvider { - - public Fourth(Environment env) { - super(env); - } - - protected String getMempoolApiHostname() { - return env.getProperty(MEMPOOL_HOSTNAME_KEY_4); - } - } - - @Component - @Order(5) - @ConditionalOnProperty(name = MEMPOOL_HOSTNAME_KEY_5) - public static class Fifth extends MempoolFeeRateProvider { - - public Fifth(Environment env) { - super(env); - } - - protected String getMempoolApiHostname() { - return env.getProperty(MEMPOOL_HOSTNAME_KEY_5); - } - } - - @RestController - class Controller extends PriceController { - - @GetMapping(path = "/getParams") - public String getParams() { - return String.format("%s;%s", maxBlocks, refreshInterval.toMillis()); - } - } -} diff --git a/pricenode/src/main/java/bisq/price/spot/ExchangeRate.java b/pricenode/src/main/java/bisq/price/spot/ExchangeRate.java deleted file mode 100644 index 854b574ee5..0000000000 --- a/pricenode/src/main/java/bisq/price/spot/ExchangeRate.java +++ /dev/null @@ -1,99 +0,0 @@ -/* - * This file is part of Haveno. - * - * Haveno is free software: you can redistribute it and/or modify it - * under the terms of the GNU Affero General Public License as published by - * the Free Software Foundation, either version 3 of the License, or (at - * your option) any later version. - * - * Haveno is distributed in the hope that it will be useful, but WITHOUT - * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or - * FITNESS FOR A PARTICULAR PURPOSE. See the GNU Affero General Public - * License for more details. - * - * You should have received a copy of the GNU Affero General Public License - * along with Haveno. If not, see . - */ - -package bisq.price.spot; - -import com.fasterxml.jackson.annotation.JsonProperty; - -import java.math.BigDecimal; - -import java.util.Date; -import java.util.Objects; - -/** - * A value object representing the spot price in bitcoin for a given currency at a given - * time as reported by a given provider. - */ -public class ExchangeRate { - - private final String currency; - private final double price; - private final long timestamp; - private final String provider; - - public ExchangeRate(String currency, BigDecimal price, Date timestamp, String provider) { - this( - currency, - price.doubleValue(), - timestamp.getTime(), - provider - ); - } - - public ExchangeRate(String currency, double price, long timestamp, String provider) { - this.currency = currency; - this.price = price; - this.timestamp = timestamp; - this.provider = provider; - } - - @JsonProperty(value = "currencyCode", index = 1) - public String getCurrency() { - return currency; - } - - @JsonProperty(value = "price", index = 2) - public double getPrice() { - return this.price; - } - - @JsonProperty(value = "timestampSec", index = 3) - public long getTimestamp() { - return this.timestamp; - } - - @JsonProperty(value = "provider", index = 4) - public String getProvider() { - return provider; - } - - @Override - public boolean equals(Object o) { - if (this == o) return true; - if (o == null || getClass() != o.getClass()) return false; - ExchangeRate exchangeRate = (ExchangeRate) o; - return Double.compare(exchangeRate.price, price) == 0 && - timestamp == exchangeRate.timestamp && - Objects.equals(currency, exchangeRate.currency) && - Objects.equals(provider, exchangeRate.provider); - } - - @Override - public int hashCode() { - return Objects.hash(currency, price, timestamp, provider); - } - - @Override - public String toString() { - return "ExchangeRate{" + - "currency='" + currency + '\'' + - ", price=" + price + - ", timestamp=" + timestamp + - ", provider=" + provider + - '}'; - } -} diff --git a/pricenode/src/main/java/bisq/price/spot/ExchangeRateController.java b/pricenode/src/main/java/bisq/price/spot/ExchangeRateController.java deleted file mode 100644 index 07846f1839..0000000000 --- a/pricenode/src/main/java/bisq/price/spot/ExchangeRateController.java +++ /dev/null @@ -1,58 +0,0 @@ -/* - * This file is part of Haveno. - * - * Haveno is free software: you can redistribute it and/or modify it - * under the terms of the GNU Affero General Public License as published by - * the Free Software Foundation, either version 3 of the License, or (at - * your option) any later version. - * - * Haveno is distributed in the hope that it will be useful, but WITHOUT - * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or - * FITNESS FOR A PARTICULAR PURPOSE. See the GNU Affero General Public - * License for more details. - * - * You should have received a copy of the GNU Affero General Public License - * along with Haveno. If not, see . - */ - -package bisq.price.spot; - -import bisq.price.PriceController; -import bisq.price.mining.FeeRateService; - -import bisq.common.config.Config; - -import org.springframework.web.bind.annotation.GetMapping; -import org.springframework.web.bind.annotation.RestController; - -import java.util.Map; - -@RestController -class ExchangeRateController extends PriceController { - - private final ExchangeRateService exchangeRateService; - private final FeeRateService feeRateService; - - public ExchangeRateController(ExchangeRateService exchangeRateService, FeeRateService feeRateService) { - this.exchangeRateService = exchangeRateService; - this.feeRateService = feeRateService; - } - - @GetMapping(path = "/getAllMarketPrices") - public Map getAllMarketPrices() { - Map retVal = exchangeRateService.getAllMarketPrices(); - - // add the fee info to results - feeRateService.getFees().forEach((key, value) -> { - retVal.put(translateFieldName(key), value); - }); - - return retVal; - } - - static String translateFieldName(String name) { - if (name.equals(Config.LEGACY_FEE_DATAMAP)) - name = Config.BTC_FEE_INFO; // name changed for clarity - return name; - } -} diff --git a/pricenode/src/main/java/bisq/price/spot/ExchangeRateProvider.java b/pricenode/src/main/java/bisq/price/spot/ExchangeRateProvider.java deleted file mode 100644 index b19c04154c..0000000000 --- a/pricenode/src/main/java/bisq/price/spot/ExchangeRateProvider.java +++ /dev/null @@ -1,339 +0,0 @@ -/* - * This file is part of Haveno. - * - * Haveno is free software: you can redistribute it and/or modify it - * under the terms of the GNU Affero General Public License as published by - * the Free Software Foundation, either version 3 of the License, or (at - * your option) any later version. - * - * Haveno is distributed in the hope that it will be useful, but WITHOUT - * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or - * FITNESS FOR A PARTICULAR PURPOSE. See the GNU Affero General Public - * License for more details. - * - * You should have received a copy of the GNU Affero General Public License - * along with Haveno. If not, see . - */ - -package bisq.price.spot; - -import bisq.price.PriceProvider; - -import bisq.core.locale.CurrencyUtil; -import bisq.core.locale.TradeCurrency; - -import org.knowm.xchange.Exchange; -import org.knowm.xchange.ExchangeFactory; -import org.knowm.xchange.currency.Currency; -import org.knowm.xchange.currency.CurrencyPair; -import org.knowm.xchange.dto.marketdata.Ticker; -import org.knowm.xchange.exceptions.ExchangeException; -import org.knowm.xchange.exceptions.NotYetImplementedForExchangeException; -import org.knowm.xchange.service.marketdata.MarketDataService; -import org.knowm.xchange.service.marketdata.params.CurrencyPairsParam; -import org.knowm.xchange.service.marketdata.params.Params; - -import org.springframework.core.env.Environment; - -import java.time.Duration; - -import java.io.IOException; - -import java.util.ArrayList; -import java.util.Arrays; -import java.util.Collection; -import java.util.Collections; -import java.util.Date; -import java.util.HashSet; -import java.util.List; -import java.util.Set; -import java.util.function.Predicate; -import java.util.stream.Collectors; -import java.util.stream.Stream; - -/** - * Abstract base class for providers of bitcoin {@link ExchangeRate} data. Implementations - * are marked with the {@link org.springframework.stereotype.Component} annotation in - * order to be discovered via classpath scanning. If multiple - * {@link ExchangeRateProvider}s retrieve rates for the same currency, then the - * {@link ExchangeRateService} will average them out and expose an aggregate rate. - * - * @see ExchangeRateService#getAllMarketPrices() - */ -public abstract class ExchangeRateProvider extends PriceProvider> { - - private static Set SUPPORTED_CRYPTO_CURRENCIES = new HashSet<>(); - private static Set SUPPORTED_FIAT_CURRENCIES = new HashSet<>(); - private Set providerExclusionList = new HashSet<>(); - private final String name; - private final String prefix; - private final Environment env; - - public ExchangeRateProvider(Environment env, String name, String prefix, Duration refreshInterval) { - super(refreshInterval); - this.name = name; - this.prefix = prefix; - this.env = env; - List excludedByProvider = - Arrays.asList(env.getProperty("bisq.price.fiatcurrency.excludedByProvider", "") - .toUpperCase().trim().split("\\s*,\\s*")); - for (String s: excludedByProvider) { - String[] splits = s.split(":"); - if (splits.length == 2 && splits[0].equalsIgnoreCase(name) && CurrencyUtil.isFiatCurrency(splits[1])) { - providerExclusionList.add(splits[1]); - } - } - if (providerExclusionList.size() > 0) { - log.info("{} specific exclusion list={}", name, providerExclusionList.toString()); - } - } - - public Set getSupportedFiatCurrencies() { - if (SUPPORTED_FIAT_CURRENCIES.isEmpty()) { // one-time initialization - List excludedFiatCurrencies = - Arrays.asList(env.getProperty("bisq.price.fiatcurrency.excluded", "") - .toUpperCase().trim().split("\\s*,\\s*")); - String validatedExclusionList = excludedFiatCurrencies.stream() - .filter(ccy -> !ccy.isEmpty()) - .filter(CurrencyUtil::isFiatCurrency) - .collect(Collectors.toList()).toString(); - SUPPORTED_FIAT_CURRENCIES = CurrencyUtil.getAllSortedFiatCurrencies().stream() - .map(TradeCurrency::getCode) - .filter(ccy -> !validatedExclusionList.contains(ccy.toUpperCase())) - .collect(Collectors.toSet()); - log.info("fiat currencies excluded: {}", validatedExclusionList); - log.info("fiat currencies supported: {}", SUPPORTED_FIAT_CURRENCIES.size()); - } - // filter out any provider specific ccy exclusions - return SUPPORTED_FIAT_CURRENCIES.stream() - .filter(ccy -> !providerExclusionList.contains(ccy.toUpperCase())) - .collect(Collectors.toSet()); - } - - public Set getSupportedCryptoCurrencies() { - if (SUPPORTED_CRYPTO_CURRENCIES.isEmpty()) { // one-time initialization - List excludedCryptoCurrencies = - Arrays.asList(env.getProperty("bisq.price.cryptocurrency.excluded", "") - .toUpperCase().trim().split("\\s*,\\s*")); - String validatedExclusionList = excludedCryptoCurrencies.stream() - .filter(ccy -> !ccy.isEmpty()) - .filter(CurrencyUtil::isCryptoCurrency) - .collect(Collectors.toList()).toString(); - SUPPORTED_CRYPTO_CURRENCIES = CurrencyUtil.getAllSortedCryptoCurrencies().stream() - .map(TradeCurrency::getCode) - .filter(ccy -> !validatedExclusionList.contains(ccy.toUpperCase())) - .collect(Collectors.toSet()); - SUPPORTED_CRYPTO_CURRENCIES.add("XMR"); // XMR is skipped because it's a base currency - log.info("crypto currencies excluded: {}", validatedExclusionList); - log.info("crypto currencies supported: {}", SUPPORTED_CRYPTO_CURRENCIES.size()); - } - return SUPPORTED_CRYPTO_CURRENCIES; - } - - public String getName() { - return name; - } - - public String getPrefix() { - return prefix; - } - - @Override - protected void onRefresh() { - get().stream() - .filter(e -> "USD".equals(e.getCurrency()) || "XMR".equals(e.getCurrency()) || "ETH".equals(e.getCurrency()) || "BCH".equals(e.getCurrency())) - .forEach(e -> log.info("BTC/{}: {}", e.getCurrency(), e.getPrice())); - } - - /** - * @param exchangeClass Class of the {@link Exchange} for which the rates should be - * polled - * @return Exchange rates for Bisq-supported fiat currencies and altcoins in the - * specified {@link Exchange} - * - * @see CurrencyUtil#getAllSortedFiatCurrencies() - * @see CurrencyUtil#getAllSortedCryptoCurrencies() - */ - protected Set doGet(Class exchangeClass) { - Set result = new HashSet(); - - // Initialize XChange objects - Exchange exchange = ExchangeFactory.INSTANCE.createExchange(exchangeClass.getName()); - MarketDataService marketDataService = exchange.getMarketDataService(); - - // Retrieve all currency pairs supported by the exchange - List allCurrencyPairsOnExchange = exchange.getExchangeSymbols(); - - // Find out which currency pairs we are interested in polling ("desired pairs") - // This will be the intersection of: - // 1) the pairs available on the exchange, and - // 2) the pairs Bisq considers relevant / valid - // This will result in two lists of desired pairs (fiat and alts) - - // Find the desired fiat pairs (pair format is BTC-FIAT) - List desiredFiatPairs = allCurrencyPairsOnExchange.stream() - .filter(cp -> cp.base.equals(Currency.BTC)) - .filter(cp -> getSupportedFiatCurrencies().contains(cp.counter.getCurrencyCode())) - .collect(Collectors.toList()); - - // Find the desired altcoin pairs (pair format is ALT-BTC) - List desiredCryptoPairs = allCurrencyPairsOnExchange.stream() - .filter(cp -> cp.counter.equals(Currency.BTC)) - .filter(cp -> getSupportedCryptoCurrencies().contains(cp.base.getCurrencyCode())) - .collect(Collectors.toList()); - - // Retrieve in bulk all tickers offered by the exchange - // The benefits of this approach (vs polling each ticker) are twofold: - // 1) the polling of the exchange is faster (one HTTP call vs several) - // 2) it's easier to stay below any API rate limits the exchange might have - List tickersRetrievedFromExchange = new ArrayList<>(); - try { - tickersRetrievedFromExchange = marketDataService.getTickers(new CurrencyPairsParam() { - - /** - * The {@link MarketDataService#getTickers(Params)} interface requires a - * {@link CurrencyPairsParam} argument when polling for tickers in bulk. - * This parameter is meant to indicate a list of currency pairs for which - * the tickers should be polled. However, the actual implementations for - * the different exchanges differ, for example: - * - some will ignore it (and retrieve all available tickers) - * - some will require it (and will fail if a null or empty list is given) - * - some will properly handle it - * - * We take a simplistic approach, namely: - * - for providers that require such a filter, specify one - * - for all others, do not specify one - * - * We make this distinction using - * {@link ExchangeRateProvider#requiresFilterDuringBulkTickerRetrieval} - * - * @return Filter (list of desired currency pairs) to be used during bulk - * ticker retrieval - */ - @Override - public Collection getCurrencyPairs() { - // If required by the exchange implementation, specify a filter - // (list of pairs which should be retrieved) - if (requiresFilterDuringBulkTickerRetrieval()) { - return Stream.of(desiredFiatPairs, desiredCryptoPairs) - .flatMap(Collection::stream) - .collect(Collectors.toList()); - } - - // Otherwise, specify an empty list, indicating that the API should - // simply return all available tickers - return Collections.emptyList(); - } - }); - - if (tickersRetrievedFromExchange.isEmpty()) { - // If the bulk ticker retrieval went through, but no tickers were - // retrieved, this is a strong indication that this specific exchange - // needs a specific list of pairs given as argument, for bulk retrieval to - // work. See requiresFilterDuringBulkTickerRetrieval() - throw new IllegalArgumentException("No tickers retrieved, " + - "exchange requires explicit filter argument during bulk retrieval?"); - } - } catch (NotYetImplementedForExchangeException e) { - // Thrown when a provider has no marketDataService.getTickers() implementation - // either because the exchange API does not provide it, or because it has not - // been implemented yet in the knowm xchange library - - // In this case (retrieval of bulk tickers is not possible) retrieve the - // tickers one by one - List finalTickersRetrievedFromExchange = tickersRetrievedFromExchange; - Stream.of(desiredFiatPairs, desiredCryptoPairs) - .flatMap(Collection::stream) - .collect(Collectors.toList()) - .forEach(cp -> { - try { - - // This is done in a loop, and can therefore result in a burst - // of API calls. Some exchanges do not allow bursts - // A simplistic solution is to delay every call by 1 second - // TODO Switch to using a more elegant solution (per exchange) - // like ResilienceSpecification (needs knowm xchange libs v5) - if (getMarketDataCallDelay() > 0) { - Thread.sleep(getMarketDataCallDelay()); - } - - Ticker ticker = marketDataService.getTicker(cp); - finalTickersRetrievedFromExchange.add(ticker); - - } catch (IOException | InterruptedException ioException) { - ioException.printStackTrace(); - log.error("Could not query tickers for " + getName(), e); - } - }); - } catch (ExchangeException | // Errors reported by the exchange (rate limit, etc) - IOException | // Errors while trying to connect to the API (timeouts, etc) - // Potential error when integrating new exchange (hints that exchange - // provider implementation needs to overwrite - // requiresFilterDuringBulkTickerRetrieval() and have it return true ) - IllegalArgumentException e) { - // Catch and handle all other possible exceptions - // If there was a problem with polling this exchange, return right away, - // since there are no results to parse and process - log.error("Could not query tickers for provider " + getName(), e); - return result; - } - - // Create an ExchangeRate for each desired currency pair ticker that was retrieved - Predicate isDesiredFiatPair = t -> desiredFiatPairs.contains(t.getCurrencyPair()); - Predicate isDesiredCryptoPair = t -> desiredCryptoPairs.contains(t.getCurrencyPair()); - tickersRetrievedFromExchange.stream() - .filter(isDesiredFiatPair.or(isDesiredCryptoPair)) // Only consider desired pairs - .forEach(t -> { - // All tickers here match all requirements - - // We have two kinds of currency pairs, BTC-FIAT and ALT-BTC - // In the first one, BTC is the first currency of the pair - // In the second type, BTC is listed as the second currency - // Distinguish between the two and create ExchangeRates accordingly - - // In every Bisq ExchangeRate, BTC is one currency in the pair - // Extract the other currency from the ticker, to create ExchangeRates - String otherExchangeRateCurrency; - if (t.getCurrencyPair().base.equals(Currency.BTC)) { - otherExchangeRateCurrency = t.getCurrencyPair().counter.getCurrencyCode(); - } else { - otherExchangeRateCurrency = t.getCurrencyPair().base.getCurrencyCode(); - } - - result.add(new ExchangeRate( - otherExchangeRateCurrency, - t.getLast(), - // Some exchanges do not provide timestamps - t.getTimestamp() == null ? new Date() : t.getTimestamp(), - this.getName() - )); - }); - - return result; - } - - /** - * Specifies optional delay between certain kind of API calls that can result in - * bursts. We want to avoid bursts, because this can cause certain exchanges to - * temporarily restrict access to the pricenode IP. - * - * @return Amount of milliseconds of delay between marketDataService.getTicker calls. - * By default 0, but can be overwritten by each provider. - */ - protected long getMarketDataCallDelay() { - return 0; - } - - /** - * @return Whether or not the bulk retrieval of tickers from the exchange requires an - * explicit filter (list of desired pairs) or not. If true, the - * {@link MarketDataService#getTickers(Params)} call will be constructed and given as - * argument, which acts as a filter indicating for which pairs the ticker should be - * retrieved. If false, {@link MarketDataService#getTickers(Params)} will be called - * with an empty argument, indicating that the API should simply return all available - * tickers on the exchange - */ - protected boolean requiresFilterDuringBulkTickerRetrieval() { - return false; - } -} diff --git a/pricenode/src/main/java/bisq/price/spot/ExchangeRateService.java b/pricenode/src/main/java/bisq/price/spot/ExchangeRateService.java deleted file mode 100644 index 932d8dc648..0000000000 --- a/pricenode/src/main/java/bisq/price/spot/ExchangeRateService.java +++ /dev/null @@ -1,187 +0,0 @@ -/* - * This file is part of Haveno. - * - * Haveno is free software: you can redistribute it and/or modify it - * under the terms of the GNU Affero General Public License as published by - * the Free Software Foundation, either version 3 of the License, or (at - * your option) any later version. - * - * Haveno is distributed in the hope that it will be useful, but WITHOUT - * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or - * FITNESS FOR A PARTICULAR PURPOSE. See the GNU Affero General Public - * License for more details. - * - * You should have received a copy of the GNU Affero General Public License - * along with Haveno. If not, see . - */ - -package bisq.price.spot; - -import org.springframework.stereotype.Service; - -import java.math.BigDecimal; - -import java.util.ArrayList; -import java.util.Comparator; -import java.util.Date; -import java.util.HashMap; -import java.util.LinkedHashMap; -import java.util.List; -import java.util.Map; -import java.util.OptionalDouble; -import java.util.Set; - -import org.slf4j.Logger; -import org.slf4j.LoggerFactory; - -import static java.util.Arrays.asList; - -/** - * High-level {@link ExchangeRate} data operations. - */ -@Service -class ExchangeRateService { - protected final Logger log = LoggerFactory.getLogger(this.getClass()); - - private final List providers; - - /** - * Construct an {@link ExchangeRateService} with a list of all - * {@link ExchangeRateProvider} implementations discovered via classpath scanning. - * - * @param providers all {@link ExchangeRateProvider} implementations in ascending - * order of precedence - */ - public ExchangeRateService(List providers) { - this.providers = providers; - } - - public Map getAllMarketPrices() { - Map metadata = new LinkedHashMap<>(); - Map aggregateExchangeRates = getAggregateExchangeRates(); - - providers.forEach(p -> { - if (p.get() == null) - return; - Set exchangeRates = p.get(); - - // Specific metadata fields for specific providers are expected by the client, - // mostly for historical reasons - // Therefore, add metadata fields for all known providers - // Rates are encapsulated in the "data" map below - metadata.putAll(getMetadata(p, exchangeRates)); - }); - - LinkedHashMap result = new LinkedHashMap<>(); - result.putAll(metadata); - // Use a sorted list by currency code to make comparision of json data between - // different price nodes easier - List values = new ArrayList<>(aggregateExchangeRates.values()); - values.sort(Comparator.comparing(ExchangeRate::getCurrency)); - result.put("data", values); - - return result; - } - - /** - * For each currency, create an aggregate {@link ExchangeRate} based on the currency's - * rates from all providers. If multiple providers have rates for the currency, then - * aggregate price = average of retrieved prices. If a single provider has rates for - * the currency, then aggregate price = the rate from that provider. - * - * @return Aggregate {@link ExchangeRate}s based on info from all providers, indexed - * by currency code - */ - private Map getAggregateExchangeRates() { - Map aggregateExchangeRates = new HashMap<>(); - - // Query all providers and collect all exchange rates, grouped by currency code - // key = currency code - // value = list of exchange rates - Map> currencyCodeToExchangeRates = getCurrencyCodeToExchangeRates(); - - // For each currency code, calculate aggregate rate - currencyCodeToExchangeRates.forEach((currencyCode, exchangeRateList) -> { - if (exchangeRateList.isEmpty()) { - // If the map was built incorrectly and this currency points to an empty - // list of rates, skip it - return; - } - - ExchangeRate aggregateExchangeRate; - if (exchangeRateList.size() == 1) { - // If a single provider has rates for this currency, then aggregate = rate - // from that provider - aggregateExchangeRate = exchangeRateList.get(0); - } else { - // If multiple providers have rates for this currency, then - // aggregate = average of the rates - OptionalDouble opt = exchangeRateList.stream().mapToDouble(ExchangeRate::getPrice).average(); - // List size > 1, so opt is always set - double priceAvg = opt.orElseThrow(IllegalStateException::new); - - aggregateExchangeRate = new ExchangeRate( - currencyCode, - BigDecimal.valueOf(priceAvg), - new Date(), // timestamp = time when avg is calculated - "Bisq-Aggregate"); - } - aggregateExchangeRates.put(aggregateExchangeRate.getCurrency(), aggregateExchangeRate); - }); - - return aggregateExchangeRates; - } - - /** - * @return All {@link ExchangeRate}s from all providers, grouped by currency code - */ - private Map> getCurrencyCodeToExchangeRates() { - Map> currencyCodeToExchangeRates = new HashMap<>(); - for (ExchangeRateProvider p : providers) { - if (p.get() == null) - continue; - for (ExchangeRate exchangeRate : p.get()) { - String currencyCode = exchangeRate.getCurrency(); - if (currencyCodeToExchangeRates.containsKey(currencyCode)) { - List l = new ArrayList<>(currencyCodeToExchangeRates.get(currencyCode)); - l.add(exchangeRate); - currencyCodeToExchangeRates.put(currencyCode, l); - } else { - currencyCodeToExchangeRates.put(currencyCode, asList(exchangeRate)); - } - } - } - return currencyCodeToExchangeRates; - } - - private Map getMetadata(ExchangeRateProvider provider, Set exchangeRates) { - Map metadata = new LinkedHashMap<>(); - - // In case a provider is not available we still want to deliver the data of the - // other providers, so we catch a possible exception and leave timestamp at 0. The - // Bisq app will check if the timestamp is in a tolerance window and if it is too - // old it will show that the price is not available. - long timestamp = 0; - try { - timestamp = getTimestamp(provider, exchangeRates); - } catch (Throwable t) { - log.error(t.toString()); - if (log.isDebugEnabled()) - t.printStackTrace(); - } - - String prefix = provider.getPrefix(); - metadata.put(prefix + "Ts", timestamp); - metadata.put(prefix + "Count", exchangeRates.size()); - - return metadata; - } - - private long getTimestamp(ExchangeRateProvider provider, Set exchangeRates) { - return exchangeRates.stream() - .filter(e -> provider.getName().equals(e.getProvider())) - .findFirst() - .orElseThrow(() -> new IllegalStateException("No exchange rate data found for " + provider.getName())) - .getTimestamp(); - } -} diff --git a/pricenode/src/main/java/bisq/price/spot/providers/BTCMarkets.java b/pricenode/src/main/java/bisq/price/spot/providers/BTCMarkets.java deleted file mode 100644 index 34e884898f..0000000000 --- a/pricenode/src/main/java/bisq/price/spot/providers/BTCMarkets.java +++ /dev/null @@ -1,46 +0,0 @@ -/* - * This file is part of Haveno. - * - * Haveno is free software: you can redistribute it and/or modify it - * under the terms of the GNU Affero General Public License as published by - * the Free Software Foundation, either version 3 of the License, or (at - * your option) any later version. - * - * Haveno is distributed in the hope that it will be useful, but WITHOUT - * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or - * FITNESS FOR A PARTICULAR PURPOSE. See the GNU Affero General Public - * License for more details. - * - * You should have received a copy of the GNU Affero General Public License - * along with Haveno. If not, see . - */ - -package bisq.price.spot.providers; - -import bisq.price.spot.ExchangeRate; -import bisq.price.spot.ExchangeRateProvider; - -import org.knowm.xchange.btcmarkets.BTCMarketsExchange; - -import org.springframework.core.env.Environment; -import org.springframework.stereotype.Component; - -import java.time.Duration; - -import java.util.Set; - -@Component -class BTCMarkets extends ExchangeRateProvider { - - public BTCMarkets(Environment env) { - super(env, "BTCMARKETS", "btcmarkets", Duration.ofMinutes(1)); - } - - @Override - public Set doGet() { - // Supported fiat: AUD - // Supported alts: ETH, LTC - return doGet(BTCMarketsExchange.class); - } - -} diff --git a/pricenode/src/main/java/bisq/price/spot/providers/Binance.java b/pricenode/src/main/java/bisq/price/spot/providers/Binance.java deleted file mode 100644 index 9107cc08ee..0000000000 --- a/pricenode/src/main/java/bisq/price/spot/providers/Binance.java +++ /dev/null @@ -1,46 +0,0 @@ -/* - * This file is part of Haveno. - * - * Haveno is free software: you can redistribute it and/or modify it - * under the terms of the GNU Affero General Public License as published by - * the Free Software Foundation, either version 3 of the License, or (at - * your option) any later version. - * - * Haveno is distributed in the hope that it will be useful, but WITHOUT - * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or - * FITNESS FOR A PARTICULAR PURPOSE. See the GNU Affero General Public - * License for more details. - * - * You should have received a copy of the GNU Affero General Public License - * along with Haveno. If not, see . - */ - -package bisq.price.spot.providers; - -import bisq.price.spot.ExchangeRate; -import bisq.price.spot.ExchangeRateProvider; - -import org.knowm.xchange.binance.BinanceExchange; - -import org.springframework.core.env.Environment; -import org.springframework.stereotype.Component; - -import java.time.Duration; - -import java.util.Set; - -@Component -class Binance extends ExchangeRateProvider { - - public Binance(Environment env) { - super(env, "BINANCE", "binance", Duration.ofMinutes(1)); - } - - @Override - public Set doGet() { - // Supported fiat: EUR, GBP, NGN, RUB, TRY, UAH, ZAR - // Supported alts: BEAM, DAI, DASH, DCR, DOGE, ETC, ETH, LTC, NAV, PIVX, XMR, XZC, - // ZEC, ZEN - return doGet(BinanceExchange.class); - } -} diff --git a/pricenode/src/main/java/bisq/price/spot/providers/BitcoinAverage.java b/pricenode/src/main/java/bisq/price/spot/providers/BitcoinAverage.java deleted file mode 100644 index dae71fc06f..0000000000 --- a/pricenode/src/main/java/bisq/price/spot/providers/BitcoinAverage.java +++ /dev/null @@ -1,57 +0,0 @@ -/* - * This file is part of Haveno. - * - * Haveno is free software: you can redistribute it and/or modify it - * under the terms of the GNU Affero General Public License as published by - * the Free Software Foundation, either version 3 of the License, or (at - * your option) any later version. - * - * Haveno is distributed in the hope that it will be useful, but WITHOUT - * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or - * FITNESS FOR A PARTICULAR PURPOSE. See the GNU Affero General Public - * License for more details. - * - * You should have received a copy of the GNU Affero General Public License - * along with Haveno. If not, see . - */ - -package bisq.price.spot.providers; - -import bisq.price.spot.ExchangeRate; -import bisq.price.spot.ExchangeRateProvider; - -import org.springframework.core.env.Environment; -import org.springframework.stereotype.Component; - -import java.time.Duration; - -import java.util.HashSet; -import java.util.Set; - -/** - * Stub implementation (similar to #CoinMarketCap) for backward compatibility with legacy - * Bisq clients - */ -@Component -class BitcoinAverage extends ExchangeRateProvider { - - public BitcoinAverage(Environment env) { - // Simulate a deactivated BitcoinAverage provider - // We still need the class to exist and be registered as a provider though, - // because the returned data structure must contain the "btcAverageTs" key - // for backward compatibility with Bisq clients which hardcode that key - super(env, "BA", "btcAverage", Duration.ofMinutes(100)); - } - - /** - * @see CoinMarketCap#doGet() - * @return - */ - @Override - public Set doGet() { - - HashSet exchangeRates = new HashSet<>(); - exchangeRates.add(new ExchangeRate("NON_EXISTING_SYMBOL_BA", 0, 0L, getName())); - return exchangeRates; - } -} diff --git a/pricenode/src/main/java/bisq/price/spot/providers/Bitfinex.java b/pricenode/src/main/java/bisq/price/spot/providers/Bitfinex.java deleted file mode 100644 index 9c93a574d3..0000000000 --- a/pricenode/src/main/java/bisq/price/spot/providers/Bitfinex.java +++ /dev/null @@ -1,45 +0,0 @@ -/* - * This file is part of Haveno. - * - * Haveno is free software: you can redistribute it and/or modify it - * under the terms of the GNU Affero General Public License as published by - * the Free Software Foundation, either version 3 of the License, or (at - * your option) any later version. - * - * Haveno is distributed in the hope that it will be useful, but WITHOUT - * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or - * FITNESS FOR A PARTICULAR PURPOSE. See the GNU Affero General Public - * License for more details. - * - * You should have received a copy of the GNU Affero General Public License - * along with Haveno. If not, see . - */ - -package bisq.price.spot.providers; - -import bisq.price.spot.ExchangeRate; -import bisq.price.spot.ExchangeRateProvider; - -import org.knowm.xchange.bitfinex.BitfinexExchange; - -import org.springframework.core.env.Environment; -import org.springframework.stereotype.Component; - -import java.time.Duration; - -import java.util.Set; - -@Component -class Bitfinex extends ExchangeRateProvider { - - public Bitfinex(Environment env) { - super(env, "BITFINEX", "bitfinex", Duration.ofMinutes(1)); - } - - @Override - public Set doGet() { - // Supported fiat: EUR, GBP, JPY, USD - // Supported alts: DAI, ETC, ETH, LTC, XMR, ZEC - return doGet(BitfinexExchange.class); - } -} diff --git a/pricenode/src/main/java/bisq/price/spot/providers/Bitflyer.java b/pricenode/src/main/java/bisq/price/spot/providers/Bitflyer.java deleted file mode 100644 index cdf392ed70..0000000000 --- a/pricenode/src/main/java/bisq/price/spot/providers/Bitflyer.java +++ /dev/null @@ -1,45 +0,0 @@ -/* - * This file is part of Haveno. - * - * Haveno is free software: you can redistribute it and/or modify it - * under the terms of the GNU Affero General Public License as published by - * the Free Software Foundation, either version 3 of the License, or (at - * your option) any later version. - * - * Haveno is distributed in the hope that it will be useful, but WITHOUT - * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or - * FITNESS FOR A PARTICULAR PURPOSE. See the GNU Affero General Public - * License for more details. - * - * You should have received a copy of the GNU Affero General Public License - * along with Haveno. If not, see . - */ - -package bisq.price.spot.providers; - -import bisq.price.spot.ExchangeRate; -import bisq.price.spot.ExchangeRateProvider; - -import org.knowm.xchange.bitflyer.BitflyerExchange; - -import org.springframework.core.env.Environment; -import org.springframework.stereotype.Component; - -import java.time.Duration; - -import java.util.Set; - -@Component -class Bitflyer extends ExchangeRateProvider { - - public Bitflyer(Environment env) { - super(env, "BITFLYER", "bitflyer", Duration.ofMinutes(1)); - } - - @Override - public Set doGet() { - // Supported fiat: JPY - // Supported alts: ETH - return doGet(BitflyerExchange.class); - } -} diff --git a/pricenode/src/main/java/bisq/price/spot/providers/Bitstamp.java b/pricenode/src/main/java/bisq/price/spot/providers/Bitstamp.java deleted file mode 100644 index 355155a23a..0000000000 --- a/pricenode/src/main/java/bisq/price/spot/providers/Bitstamp.java +++ /dev/null @@ -1,45 +0,0 @@ -/* - * This file is part of Haveno. - * - * Haveno is free software: you can redistribute it and/or modify it - * under the terms of the GNU Affero General Public License as published by - * the Free Software Foundation, either version 3 of the License, or (at - * your option) any later version. - * - * Haveno is distributed in the hope that it will be useful, but WITHOUT - * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or - * FITNESS FOR A PARTICULAR PURPOSE. See the GNU Affero General Public - * License for more details. - * - * You should have received a copy of the GNU Affero General Public License - * along with Haveno. If not, see . - */ - -package bisq.price.spot.providers; - -import bisq.price.spot.ExchangeRate; -import bisq.price.spot.ExchangeRateProvider; - -import org.knowm.xchange.bitstamp.BitstampExchange; - -import org.springframework.core.env.Environment; -import org.springframework.stereotype.Component; - -import java.time.Duration; - -import java.util.Set; - -@Component -class Bitstamp extends ExchangeRateProvider { - - public Bitstamp(Environment env) { - super(env, "BITSTAMP", "bitstamp", Duration.ofMinutes(1)); - } - - @Override - public Set doGet() { - // Supported fiat: EUR, GBP, USD - // Supported alts: ETH, LTC - return doGet(BitstampExchange.class); - } -} diff --git a/pricenode/src/main/java/bisq/price/spot/providers/CoinGecko.java b/pricenode/src/main/java/bisq/price/spot/providers/CoinGecko.java deleted file mode 100644 index 49bb97a9d5..0000000000 --- a/pricenode/src/main/java/bisq/price/spot/providers/CoinGecko.java +++ /dev/null @@ -1,105 +0,0 @@ -/* - * This file is part of Haveno. - * - * Haveno is free software: you can redistribute it and/or modify it - * under the terms of the GNU Affero General Public License as published by - * the Free Software Foundation, either version 3 of the License, or (at - * your option) any later version. - * - * Haveno is distributed in the hope that it will be useful, but WITHOUT - * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or - * FITNESS FOR A PARTICULAR PURPOSE. See the GNU Affero General Public - * License for more details. - * - * You should have received a copy of the GNU Affero General Public License - * along with Haveno. If not, see . - */ - -package bisq.price.spot.providers; - -import bisq.price.spot.ExchangeRate; -import bisq.price.spot.ExchangeRateProvider; -import bisq.price.util.coingecko.CoinGeckoMarketData; - -import org.springframework.core.ParameterizedTypeReference; -import org.springframework.core.env.Environment; -import org.springframework.http.RequestEntity; -import org.springframework.stereotype.Component; -import org.springframework.web.client.RestTemplate; -import org.springframework.web.util.UriComponentsBuilder; - -import java.time.Duration; - -import java.math.BigDecimal; -import java.math.RoundingMode; - -import java.util.Date; -import java.util.HashSet; -import java.util.Map; -import java.util.Set; -import java.util.function.Predicate; -import java.util.stream.Collectors; - -@Component -class CoinGecko extends ExchangeRateProvider { - - private final RestTemplate restTemplate = new RestTemplate(); - - public CoinGecko(Environment env) { - super(env, "COINGECKO", "coingecko", Duration.ofMinutes(1)); - } - - @Override - public Set doGet() { - - // Rate limit for the CoinGecko API is 10 calls each second per IP address - // We retrieve all rates in bulk, so we only make 1 call per provider poll - - Set result = new HashSet(); - - Predicate isDesiredFiatPair = t -> getSupportedFiatCurrencies().contains(t.getKey()); - Predicate isDesiredCryptoPair = t -> getSupportedCryptoCurrencies().contains(t.getKey()); - - getMarketData().getRates().entrySet().stream() - .filter(isDesiredFiatPair.or(isDesiredCryptoPair)) - .collect(Collectors.toMap(Map.Entry::getKey, Map.Entry::getValue)) - .forEach((key, ticker) -> { - - boolean useInverseRate = false; - if (getSupportedCryptoCurrencies().contains(key)) { - // Use inverse rate for alts, because the API returns the - // conversion rate in the opposite direction than what we need - // API returns the BTC/Alt rate, we need the Alt/BTC rate - useInverseRate = true; - } - - BigDecimal rate = ticker.getValue(); - // Find the inverse rate, while using enough decimals to reflect very - // small exchange rates - BigDecimal inverseRate = (rate.compareTo(BigDecimal.ZERO) > 0) ? - BigDecimal.ONE.divide(rate, 8, RoundingMode.HALF_UP) : - BigDecimal.ZERO; - - result.add(new ExchangeRate( - key, - (useInverseRate ? inverseRate : rate), - new Date(), - this.getName() - )); - }); - - return result; - } - - private CoinGeckoMarketData getMarketData() { - return restTemplate.exchange( - RequestEntity - .get(UriComponentsBuilder - .fromUriString("https://api.coingecko.com/api/v3/exchange_rates").build() - .toUri()) - .build(), - new ParameterizedTypeReference() { - } - ).getBody(); - } -} diff --git a/pricenode/src/main/java/bisq/price/spot/providers/CoinMarketCap.java b/pricenode/src/main/java/bisq/price/spot/providers/CoinMarketCap.java deleted file mode 100644 index ce882f5490..0000000000 --- a/pricenode/src/main/java/bisq/price/spot/providers/CoinMarketCap.java +++ /dev/null @@ -1,54 +0,0 @@ -/* - * This file is part of Haveno. - * - * Haveno is free software: you can redistribute it and/or modify it - * under the terms of the GNU Affero General Public License as published by - * the Free Software Foundation, either version 3 of the License, or (at - * your option) any later version. - * - * Haveno is distributed in the hope that it will be useful, but WITHOUT - * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or - * FITNESS FOR A PARTICULAR PURPOSE. See the GNU Affero General Public - * License for more details. - * - * You should have received a copy of the GNU Affero General Public License - * along with Haveno. If not, see . - */ - -package bisq.price.spot.providers; - -import bisq.price.spot.ExchangeRate; -import bisq.price.spot.ExchangeRateProvider; - -import org.springframework.core.env.Environment; -import org.springframework.stereotype.Component; - -import java.time.Duration; - -import java.util.HashSet; -import java.util.Set; - -/** - * Stub implementation of CoinMarketCap price provider to prevent NullPointerExceptions within legacy clients - */ -@Component -class CoinMarketCap extends ExchangeRateProvider { - - public CoinMarketCap(Environment env) { - super(env, "CMC", "coinmarketcap", Duration.ofMinutes(5)); // large data structure, so don't request it too often - } - - /** - * Returns a Set with a non existing symbol for the CoinMarketCap price provider. - * Price data of CMC provider is not used in the client anymore, except for the last update timestamp. - * To prevent a unnecessary warning log in that case we have to pass at least one element. - * - * @return Empty Set - */ - @Override - public Set doGet() { - HashSet exchangeRates = new HashSet<>(); - exchangeRates.add(new ExchangeRate("NON_EXISTING_SYMBOL", 0, 0L, "CMC")); - return exchangeRates; - } -} diff --git a/pricenode/src/main/java/bisq/price/spot/providers/CoinbasePro.java b/pricenode/src/main/java/bisq/price/spot/providers/CoinbasePro.java deleted file mode 100644 index bf6781b3fe..0000000000 --- a/pricenode/src/main/java/bisq/price/spot/providers/CoinbasePro.java +++ /dev/null @@ -1,49 +0,0 @@ -/* - * This file is part of Haveno. - * - * Haveno is free software: you can redistribute it and/or modify it - * under the terms of the GNU Affero General Public License as published by - * the Free Software Foundation, either version 3 of the License, or (at - * your option) any later version. - * - * Haveno is distributed in the hope that it will be useful, but WITHOUT - * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or - * FITNESS FOR A PARTICULAR PURPOSE. See the GNU Affero General Public - * License for more details. - * - * You should have received a copy of the GNU Affero General Public License - * along with Haveno. If not, see . - */ -package bisq.price.spot.providers; - -import bisq.price.spot.ExchangeRate; -import bisq.price.spot.ExchangeRateProvider; - -import org.knowm.xchange.coinbasepro.CoinbaseProExchange; - -import org.springframework.core.env.Environment; -import org.springframework.stereotype.Component; - -import java.time.Duration; - -import java.util.Set; - -@Component -class CoinbasePro extends ExchangeRateProvider { - - public CoinbasePro(Environment env) { - super(env, "COINBASEPRO", "coinbasepro", Duration.ofMinutes(1)); - } - - @Override - public Set doGet() { - // Supported fiat: EUR, USD, GBP - // Supported alts: DASH, DOGE, ETC, ETH, LTC, ZEC, ZEN - return doGet(CoinbaseProExchange.class); - } - - @Override - protected boolean requiresFilterDuringBulkTickerRetrieval() { - return true; - } -} diff --git a/pricenode/src/main/java/bisq/price/spot/providers/Coinone.java b/pricenode/src/main/java/bisq/price/spot/providers/Coinone.java deleted file mode 100644 index 8ca7235aa6..0000000000 --- a/pricenode/src/main/java/bisq/price/spot/providers/Coinone.java +++ /dev/null @@ -1,46 +0,0 @@ -/* - * This file is part of Haveno. - * - * Haveno is free software: you can redistribute it and/or modify it - * under the terms of the GNU Affero General Public License as published by - * the Free Software Foundation, either version 3 of the License, or (at - * your option) any later version. - * - * Haveno is distributed in the hope that it will be useful, but WITHOUT - * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or - * FITNESS FOR A PARTICULAR PURPOSE. See the GNU Affero General Public - * License for more details. - * - * You should have received a copy of the GNU Affero General Public License - * along with Haveno. If not, see . - */ - -package bisq.price.spot.providers; - -import bisq.price.spot.ExchangeRate; -import bisq.price.spot.ExchangeRateProvider; - -import org.knowm.xchange.coinone.CoinoneExchange; - -import org.springframework.core.env.Environment; -import org.springframework.stereotype.Component; - -import java.time.Duration; - -import java.util.Set; - -@Component -class Coinone extends ExchangeRateProvider { - - public Coinone(Environment env) { - super(env, "COINONE", "coinone", Duration.ofMinutes(1)); - } - - @Override - public Set doGet() { - // Supported fiat: KRW - // Supported alts: - - return doGet(CoinoneExchange.class); - } - -} diff --git a/pricenode/src/main/java/bisq/price/spot/providers/IndependentReserve.java b/pricenode/src/main/java/bisq/price/spot/providers/IndependentReserve.java deleted file mode 100644 index 930f995f38..0000000000 --- a/pricenode/src/main/java/bisq/price/spot/providers/IndependentReserve.java +++ /dev/null @@ -1,46 +0,0 @@ -/* - * This file is part of Haveno. - * - * Haveno is free software: you can redistribute it and/or modify it - * under the terms of the GNU Affero General Public License as published by - * the Free Software Foundation, either version 3 of the License, or (at - * your option) any later version. - * - * Haveno is distributed in the hope that it will be useful, but WITHOUT - * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or - * FITNESS FOR A PARTICULAR PURPOSE. See the GNU Affero General Public - * License for more details. - * - * You should have received a copy of the GNU Affero General Public License - * along with Haveno. If not, see . - */ - -package bisq.price.spot.providers; - -import bisq.price.spot.ExchangeRate; -import bisq.price.spot.ExchangeRateProvider; - -import org.knowm.xchange.independentreserve.IndependentReserveExchange; - -import org.springframework.core.env.Environment; -import org.springframework.stereotype.Component; - -import java.time.Duration; - -import java.util.Set; - -@Component -class IndependentReserve extends ExchangeRateProvider { - - public IndependentReserve(Environment env) { - super(env, "IndependentReserve", "independentreserve", Duration.ofMinutes(1)); - } - - @Override - public Set doGet() { - // Supported fiat: AUD, NZD (New Zealand Dollar), USD - // Supported alts: - - return doGet(IndependentReserveExchange.class); - } - -} diff --git a/pricenode/src/main/java/bisq/price/spot/providers/Kraken.java b/pricenode/src/main/java/bisq/price/spot/providers/Kraken.java deleted file mode 100644 index 98c899f1d4..0000000000 --- a/pricenode/src/main/java/bisq/price/spot/providers/Kraken.java +++ /dev/null @@ -1,50 +0,0 @@ -/* - * This file is part of Haveno. - * - * Haveno is free software: you can redistribute it and/or modify it - * under the terms of the GNU Affero General Public License as published by - * the Free Software Foundation, either version 3 of the License, or (at - * your option) any later version. - * - * Haveno is distributed in the hope that it will be useful, but WITHOUT - * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or - * FITNESS FOR A PARTICULAR PURPOSE. See the GNU Affero General Public - * License for more details. - * - * You should have received a copy of the GNU Affero General Public License - * along with Haveno. If not, see . - */ - -package bisq.price.spot.providers; - -import bisq.price.spot.ExchangeRate; -import bisq.price.spot.ExchangeRateProvider; - -import org.knowm.xchange.kraken.KrakenExchange; - -import org.springframework.core.env.Environment; -import org.springframework.stereotype.Component; - -import java.time.Duration; - -import java.util.Set; - -@Component -class Kraken extends ExchangeRateProvider { - - public Kraken(Environment env) { - super(env, "KRAKEN", "kraken", Duration.ofMinutes(1)); - } - - @Override - public Set doGet() { - // Supported fiat: AUD, CAD, CHF, EUR, GBP, JPY, USD - // Supported alts: DASH, DOGE, ETC, ETH, LTC, XMR, ZEC - return doGet(KrakenExchange.class); - } - - @Override - protected boolean requiresFilterDuringBulkTickerRetrieval() { - return true; - } -} diff --git a/pricenode/src/main/java/bisq/price/spot/providers/Luno.java b/pricenode/src/main/java/bisq/price/spot/providers/Luno.java deleted file mode 100644 index 371d4005e7..0000000000 --- a/pricenode/src/main/java/bisq/price/spot/providers/Luno.java +++ /dev/null @@ -1,53 +0,0 @@ -/* - * This file is part of Haveno. - * - * Haveno is free software: you can redistribute it and/or modify it - * under the terms of the GNU Affero General Public License as published by - * the Free Software Foundation, either version 3 of the License, or (at - * your option) any later version. - * - * Haveno is distributed in the hope that it will be useful, but WITHOUT - * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or - * FITNESS FOR A PARTICULAR PURPOSE. See the GNU Affero General Public - * License for more details. - * - * You should have received a copy of the GNU Affero General Public License - * along with Haveno. If not, see . - */ - -package bisq.price.spot.providers; - -import bisq.price.spot.ExchangeRate; -import bisq.price.spot.ExchangeRateProvider; - -import org.knowm.xchange.luno.LunoExchange; - -import org.springframework.core.env.Environment; -import org.springframework.stereotype.Component; - -import java.time.Duration; - -import java.util.Set; - -@Component -class Luno extends ExchangeRateProvider { - - public Luno(Environment env) { - super(env, "LUNO", "luno", Duration.ofMinutes(1)); - } - - @Override - public Set doGet() { - // Supported fiat: IDR (Indonesian rupiah), MYR (Malaysian ringgit), - // NGN (Nigerian Naira), ZAR (South African rand) - // Supported alts: - - return doGet(LunoExchange.class); - } - - @Override - protected long getMarketDataCallDelay() { - // Luno allows only 1 MarketData call per second - // (see https://www.luno.com/en/developers/api ) - return 1000; - } -} diff --git a/pricenode/src/main/java/bisq/price/spot/providers/MercadoBitcoin.java b/pricenode/src/main/java/bisq/price/spot/providers/MercadoBitcoin.java deleted file mode 100644 index 9deed9d264..0000000000 --- a/pricenode/src/main/java/bisq/price/spot/providers/MercadoBitcoin.java +++ /dev/null @@ -1,46 +0,0 @@ -/* - * This file is part of Haveno. - * - * Haveno is free software: you can redistribute it and/or modify it - * under the terms of the GNU Affero General Public License as published by - * the Free Software Foundation, either version 3 of the License, or (at - * your option) any later version. - * - * Haveno is distributed in the hope that it will be useful, but WITHOUT - * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or - * FITNESS FOR A PARTICULAR PURPOSE. See the GNU Affero General Public - * License for more details. - * - * You should have received a copy of the GNU Affero General Public License - * along with Haveno. If not, see . - */ - -package bisq.price.spot.providers; - -import bisq.price.spot.ExchangeRate; -import bisq.price.spot.ExchangeRateProvider; - -import org.knowm.xchange.mercadobitcoin.MercadoBitcoinExchange; - -import org.springframework.core.env.Environment; -import org.springframework.stereotype.Component; - -import java.time.Duration; - -import java.util.Set; - -@Component -class MercadoBitcoin extends ExchangeRateProvider { - - public MercadoBitcoin(Environment env) { - super(env, "MercadoBitcoin", "mercadobitcoin", Duration.ofMinutes(1)); - } - - @Override - public Set doGet() { - // Supported fiat: BRL (Brazilian Real) - // Supported alts: - - return doGet(MercadoBitcoinExchange.class); - } - -} diff --git a/pricenode/src/main/java/bisq/price/spot/providers/Paribu.java b/pricenode/src/main/java/bisq/price/spot/providers/Paribu.java deleted file mode 100644 index 3d3b3875eb..0000000000 --- a/pricenode/src/main/java/bisq/price/spot/providers/Paribu.java +++ /dev/null @@ -1,45 +0,0 @@ -/* - * This file is part of Haveno. - * - * Haveno is free software: you can redistribute it and/or modify it - * under the terms of the GNU Affero General Public License as published by - * the Free Software Foundation, either version 3 of the License, or (at - * your option) any later version. - * - * Haveno is distributed in the hope that it will be useful, but WITHOUT - * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or - * FITNESS FOR A PARTICULAR PURPOSE. See the GNU Affero General Public - * License for more details. - * - * You should have received a copy of the GNU Affero General Public License - * along with Haveno. If not, see . - */ - -package bisq.price.spot.providers; - -import bisq.price.spot.ExchangeRate; -import bisq.price.spot.ExchangeRateProvider; - -import org.knowm.xchange.paribu.ParibuExchange; - -import org.springframework.core.env.Environment; -import org.springframework.stereotype.Component; - -import java.time.Duration; - -import java.util.Set; - -@Component -class Paribu extends ExchangeRateProvider { - - public Paribu(Environment env) { - super(env, "PARIBU", "paribu", Duration.ofMinutes(1)); - } - - @Override - public Set doGet() { - // Supported fiat: TRY (Turkish Lira) - // Supported alts: - - return doGet(ParibuExchange.class); - } -} diff --git a/pricenode/src/main/java/bisq/price/spot/providers/Poloniex.java b/pricenode/src/main/java/bisq/price/spot/providers/Poloniex.java deleted file mode 100644 index d24368e561..0000000000 --- a/pricenode/src/main/java/bisq/price/spot/providers/Poloniex.java +++ /dev/null @@ -1,45 +0,0 @@ -/* - * This file is part of Haveno. - * - * Haveno is free software: you can redistribute it and/or modify it - * under the terms of the GNU Affero General Public License as published by - * the Free Software Foundation, either version 3 of the License, or (at - * your option) any later version. - * - * Haveno is distributed in the hope that it will be useful, but WITHOUT - * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or - * FITNESS FOR A PARTICULAR PURPOSE. See the GNU Affero General Public - * License for more details. - * - * You should have received a copy of the GNU Affero General Public License - * along with Haveno. If not, see . - */ - -package bisq.price.spot.providers; - -import bisq.price.spot.ExchangeRate; -import bisq.price.spot.ExchangeRateProvider; - -import org.knowm.xchange.poloniex.PoloniexExchange; - -import org.springframework.core.env.Environment; -import org.springframework.stereotype.Component; - -import java.time.Duration; - -import java.util.Set; - -@Component -class Poloniex extends ExchangeRateProvider { - - public Poloniex(Environment env) { - super(env, "POLO", "poloniex", Duration.ofMinutes(1)); - } - - @Override - public Set doGet() { - // Supported fiat: - - // Supported alts: DASH, DCR, DOGE, ETC, ETH, LTC, XMR, ZEC - return doGet(PoloniexExchange.class); - } -} diff --git a/pricenode/src/main/java/bisq/price/spot/providers/Quoine.java b/pricenode/src/main/java/bisq/price/spot/providers/Quoine.java deleted file mode 100644 index 0fa82f28bd..0000000000 --- a/pricenode/src/main/java/bisq/price/spot/providers/Quoine.java +++ /dev/null @@ -1,50 +0,0 @@ -/* - * This file is part of Haveno. - * - * Haveno is free software: you can redistribute it and/or modify it - * under the terms of the GNU Affero General Public License as published by - * the Free Software Foundation, either version 3 of the License, or (at - * your option) any later version. - * - * Haveno is distributed in the hope that it will be useful, but WITHOUT - * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or - * FITNESS FOR A PARTICULAR PURPOSE. See the GNU Affero General Public - * License for more details. - * - * You should have received a copy of the GNU Affero General Public License - * along with Haveno. If not, see . - */ - -package bisq.price.spot.providers; - -import bisq.price.spot.ExchangeRate; -import bisq.price.spot.ExchangeRateProvider; - -import org.knowm.xchange.quoine.QuoineExchange; - -import org.springframework.core.env.Environment; -import org.springframework.stereotype.Component; - -import java.time.Duration; - -import java.util.Set; - -@Component -class Quoine extends ExchangeRateProvider { - - public Quoine(Environment env) { - super(env, "QUOINE", "quoine", Duration.ofMinutes(1)); - } - - @Override - public Set doGet() { - // Supported fiat: AUD, CNY, EUR, HKD, IDR, INR, JPY, PHP, SGD, USD - // Supported alts: ETH - return doGet(QuoineExchange.class); - } - - @Override - protected boolean requiresFilterDuringBulkTickerRetrieval() { - return true; - } -} diff --git a/pricenode/src/main/java/bisq/price/util/Altcoins.java b/pricenode/src/main/java/bisq/price/util/Altcoins.java deleted file mode 100644 index 6aa145a00a..0000000000 --- a/pricenode/src/main/java/bisq/price/util/Altcoins.java +++ /dev/null @@ -1,32 +0,0 @@ -/* - * This file is part of Haveno. - * - * Haveno is free software: you can redistribute it and/or modify it - * under the terms of the GNU Affero General Public License as published by - * the Free Software Foundation, either version 3 of the License, or (at - * your option) any later version. - * - * Haveno is distributed in the hope that it will be useful, but WITHOUT - * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or - * FITNESS FOR A PARTICULAR PURPOSE. See the GNU Affero General Public - * License for more details. - * - * You should have received a copy of the GNU Affero General Public License - * along with Haveno. If not, see . - */ - -package bisq.price.util; - -import bisq.core.locale.CurrencyUtil; -import bisq.core.locale.TradeCurrency; - -import java.util.Set; -import java.util.stream.Collectors; - -public abstract class Altcoins { - - public static final Set ALL_SUPPORTED = - CurrencyUtil.getAllSortedCryptoCurrencies().stream() - .map(TradeCurrency::getCode) - .collect(Collectors.toSet()); -} diff --git a/pricenode/src/main/java/bisq/price/util/bitpay/BitpayMarketData.java b/pricenode/src/main/java/bisq/price/util/bitpay/BitpayMarketData.java deleted file mode 100644 index 73ab946a9b..0000000000 --- a/pricenode/src/main/java/bisq/price/util/bitpay/BitpayMarketData.java +++ /dev/null @@ -1,13 +0,0 @@ -package bisq.price.util.bitpay; - - -import lombok.Getter; -import lombok.Setter; - -@Getter -@Setter -public class BitpayMarketData { - - private BitpayTicker[] data; - -} diff --git a/pricenode/src/main/java/bisq/price/util/bitpay/BitpayTicker.java b/pricenode/src/main/java/bisq/price/util/bitpay/BitpayTicker.java deleted file mode 100644 index 8cc63773ac..0000000000 --- a/pricenode/src/main/java/bisq/price/util/bitpay/BitpayTicker.java +++ /dev/null @@ -1,18 +0,0 @@ -package bisq.price.util.bitpay; - -import java.math.BigDecimal; - -import lombok.Getter; -import lombok.Setter; - -@Getter -@Setter -public class BitpayTicker { - - private String code; - - private String name; - - private BigDecimal rate; - -} diff --git a/pricenode/src/main/java/bisq/price/util/coingecko/CoinGeckoMarketData.java b/pricenode/src/main/java/bisq/price/util/coingecko/CoinGeckoMarketData.java deleted file mode 100644 index b96ba10dca..0000000000 --- a/pricenode/src/main/java/bisq/price/util/coingecko/CoinGeckoMarketData.java +++ /dev/null @@ -1,22 +0,0 @@ -package bisq.price.util.coingecko; - - -import java.util.Map; -import java.util.stream.Collectors; - -import lombok.Getter; -import lombok.Setter; - -@Getter -@Setter -public class CoinGeckoMarketData { - - private Map rates; - - public void setRates(Map rates) { - // Convert keys to uppercase ("usd" -> "USD") when deserializing API response - this.rates = rates.entrySet().stream() - .collect(Collectors.toMap(entry -> entry.getKey().toUpperCase(), entry -> entry.getValue())); - } - -} diff --git a/pricenode/src/main/java/bisq/price/util/coingecko/CoinGeckoTicker.java b/pricenode/src/main/java/bisq/price/util/coingecko/CoinGeckoTicker.java deleted file mode 100644 index 2326203a10..0000000000 --- a/pricenode/src/main/java/bisq/price/util/coingecko/CoinGeckoTicker.java +++ /dev/null @@ -1,20 +0,0 @@ -package bisq.price.util.coingecko; - -import java.math.BigDecimal; - -import lombok.Getter; -import lombok.Setter; - -@Getter -@Setter -public class CoinGeckoTicker { - - private String name; - - private String unit; - - private BigDecimal value; - - private String type; - -} diff --git a/pricenode/src/main/java/bisq/price/util/coinpaprika/CoinpaprikaMarketData.java b/pricenode/src/main/java/bisq/price/util/coinpaprika/CoinpaprikaMarketData.java deleted file mode 100644 index b5e366ddbc..0000000000 --- a/pricenode/src/main/java/bisq/price/util/coinpaprika/CoinpaprikaMarketData.java +++ /dev/null @@ -1,17 +0,0 @@ -package bisq.price.util.coinpaprika; - - -import java.util.Map; - -import lombok.Getter; -import lombok.Setter; - -@Getter -@Setter -public class CoinpaprikaMarketData { - - // All other json fields can be ignored, we don't need them - - private Map quotes; - -} diff --git a/pricenode/src/main/java/bisq/price/util/coinpaprika/CoinpaprikaTicker.java b/pricenode/src/main/java/bisq/price/util/coinpaprika/CoinpaprikaTicker.java deleted file mode 100644 index 64bb318312..0000000000 --- a/pricenode/src/main/java/bisq/price/util/coinpaprika/CoinpaprikaTicker.java +++ /dev/null @@ -1,16 +0,0 @@ -package bisq.price.util.coinpaprika; - -import java.math.BigDecimal; - -import lombok.Getter; -import lombok.Setter; - -@Getter -@Setter -public class CoinpaprikaTicker { - - // All other json fields can be ignored, we don't need them - - private BigDecimal price; - -} diff --git a/pricenode/src/main/resources/application.properties b/pricenode/src/main/resources/application.properties deleted file mode 100644 index 5765f51ea4..0000000000 --- a/pricenode/src/main/resources/application.properties +++ /dev/null @@ -1,13 +0,0 @@ -server.port=8078 -spring.jackson.serialization.indent_output=true - -# To enable another fee estimation endpoint, simply uncomment one of the following lines -# and set it to hostname exposing the fee estimation API -bisq.price.mining.providers.mempoolHostname.1=mempool.space -bisq.price.mining.providers.mempoolHostname.2=mempool.emzy.de -bisq.price.mining.providers.mempoolHostname.3=mempool.ninja -bisq.price.mining.providers.mempoolHostname.4=mempool.bisq.services -# bisq.price.mining.providers.mempoolHostname.5=someHostOrIP -bisq.price.fiatcurrency.excluded=LBP,ARS -bisq.price.fiatcurrency.excludedByProvider=HUOBI:BRL -bisq.price.cryptocurrency.excluded= diff --git a/pricenode/src/main/resources/banner.txt b/pricenode/src/main/resources/banner.txt deleted file mode 100644 index 08d29b7388..0000000000 --- a/pricenode/src/main/resources/banner.txt +++ /dev/null @@ -1,6 +0,0 @@ - __ _ _ __ - / /_ (_)________ _ ____ _____(_)_______ ____ ____ ____/ /__ - / __ \/ / ___/ __ `/_____/ __ \/ ___/ / ___/ _ \/ __ \/ __ \/ __ / _ \ - / /_/ / (__ ) /_/ /_____/ /_/ / / / / /__/ __/ / / / /_/ / /_/ / __/ -/_.___/_/____/\__, / / .___/_/ /_/\___/\___/_/ /_/\____/\__,_/\___/ - /_/ /_/ ${application.formatted-version} diff --git a/pricenode/src/main/resources/logback.xml b/pricenode/src/main/resources/logback.xml deleted file mode 100644 index 02acbae6f9..0000000000 --- a/pricenode/src/main/resources/logback.xml +++ /dev/null @@ -1,16 +0,0 @@ - - - - - %highlight(%d{MMM-dd HH:mm:ss.SSS} [%thread] %-5level %logger{15}: %msg %xEx%n) - - - - - - - - - - - diff --git a/pricenode/src/main/resources/version.txt b/pricenode/src/main/resources/version.txt deleted file mode 100644 index e87c17ec4a..0000000000 --- a/pricenode/src/main/resources/version.txt +++ /dev/null @@ -1 +0,0 @@ -0.7.2-SNAPSHOT diff --git a/pricenode/src/test/java/bisq/price/AbstractExchangeRateProviderTest.java b/pricenode/src/test/java/bisq/price/AbstractExchangeRateProviderTest.java deleted file mode 100644 index 911f45439d..0000000000 --- a/pricenode/src/test/java/bisq/price/AbstractExchangeRateProviderTest.java +++ /dev/null @@ -1,66 +0,0 @@ -package bisq.price; - -import bisq.price.spot.ExchangeRate; -import bisq.price.spot.ExchangeRateProvider; - -import com.google.common.collect.Sets; - -import java.util.Set; -import java.util.TreeSet; -import java.util.stream.Collectors; - -import lombok.extern.slf4j.Slf4j; - -import static org.junit.Assert.assertTrue; - -@Slf4j -public abstract class AbstractExchangeRateProviderTest { - - protected void doGet_successfulCall(ExchangeRateProvider exchangeProvider) { - - // Use the XChange library to call the provider API, in order to retrieve the - // exchange rates. If the API call fails, or the response body cannot be parsed, - // the test will fail with an exception - Set retrievedExchangeRates = exchangeProvider.doGet(); - - // Log the valid exchange rates which were retrieved - // Useful when running the tests, to easily identify which exchanges provide - // useful pairs - retrievedExchangeRates.forEach(e -> log.info("Found exchange rate " + e.toString())); - - // Sanity checks - assertTrue(retrievedExchangeRates.size() > 0); - checkProviderCurrencyPairs(exchangeProvider, retrievedExchangeRates); - } - - /** - * Check that every retrieved currency pair is between BTC and either - * A) a fiat currency on the list of Bisq-supported fiat currencies, or - * B) an altcoin on the list of Bisq-supported altcoins - * - * @param retrievedExchangeRates Exchange rates retrieved from the provider - */ - private void checkProviderCurrencyPairs(ExchangeRateProvider exchangeProvider, Set retrievedExchangeRates) { - Set retrievedRatesCurrencies = retrievedExchangeRates.stream() - .map(ExchangeRate::getCurrency) - .collect(Collectors.toSet()); - - Set supportedFiatCurrenciesRetrieved = exchangeProvider.getSupportedFiatCurrencies().stream() - .filter(f -> retrievedRatesCurrencies.contains(f)) - .collect(Collectors.toCollection(TreeSet::new)); - log.info("Retrieved rates for supported fiat currencies: " + supportedFiatCurrenciesRetrieved); - - Set supportedCryptoCurrenciesRetrieved = exchangeProvider.getSupportedCryptoCurrencies().stream() - .filter(c -> retrievedRatesCurrencies.contains(c)) - .collect(Collectors.toCollection(TreeSet::new)); - log.info("Retrieved rates for supported altcoins: " + supportedCryptoCurrenciesRetrieved); - - Set supportedCurrencies = Sets.union( - exchangeProvider.getSupportedCryptoCurrencies(), - exchangeProvider.getSupportedFiatCurrencies()); - - Set unsupportedCurrencies = Sets.difference(retrievedRatesCurrencies, supportedCurrencies); - assertTrue("Retrieved exchange rates contain unsupported currencies: " + unsupportedCurrencies, - unsupportedCurrencies.isEmpty()); - } -} diff --git a/pricenode/src/test/java/bisq/price/mining/FeeRateServiceTest.java b/pricenode/src/test/java/bisq/price/mining/FeeRateServiceTest.java deleted file mode 100644 index 8f47584a41..0000000000 --- a/pricenode/src/test/java/bisq/price/mining/FeeRateServiceTest.java +++ /dev/null @@ -1,110 +0,0 @@ -package bisq.price.mining; - -import bisq.price.mining.providers.MempoolFeeRateProviderTest; - -import bisq.common.config.Config; - -import java.util.ArrayList; -import java.util.Collections; -import java.util.List; -import java.util.Map; - -import org.slf4j.Logger; -import org.slf4j.LoggerFactory; - -import org.junit.jupiter.api.Test; - -import static bisq.price.mining.providers.MempoolFeeRateProviderTest.buildDummyReachableMempoolFeeRateProvider; -import static bisq.price.mining.providers.MempoolFeeRateProviderTest.buildDummyUnreachableMempoolFeeRateProvider; -import static java.util.Arrays.asList; -import static org.junit.jupiter.api.Assertions.assertEquals; -import static org.junit.jupiter.api.Assertions.assertNotEquals; - -/** - * Tests the {@link bisq.price.mining.FeeRateService}, which can aggregate data from - * several {@link FeeRateProvider}s. - * @see MempoolFeeRateProviderTest - */ -public class FeeRateServiceTest { - - private static final Logger log = LoggerFactory.getLogger(FeeRateServiceTest.class); - - @Test - public void getFees_noWorkingProvider() { - // Several providers, but all unreachable - List listOfProviders = new ArrayList<>(); - for (int i = 0; i < 3; i++) { - try { - listOfProviders.add(buildDummyUnreachableMempoolFeeRateProvider()); - } catch (Exception e) { - // Expected - log.info("We encountered an expected exception: " + e.getMessage()); - } - } - FeeRateService service = new FeeRateService(listOfProviders); - - Map retrievedData = service.getFees(); - - // Even with no working providers, we expect the service to return pre-configured - // minimum fee rate - doSanityChecksForRetrievedData(retrievedData, FeeRateProvider.MIN_FEE_RATE_FOR_TRADING); - } - - @Test - public void getFees_singleProvider_feeBelowMin() { - // One working provider, which returns a fee lower than the minimum - long providerFee = FeeRateProvider.MIN_FEE_RATE_FOR_TRADING - 3; - FeeRateService service = new FeeRateService( - Collections.singletonList( - buildDummyReachableMempoolFeeRateProvider(providerFee))); - - Map retrievedData = service.getFees(); - - // When the provider returns a value below the expected min, the service should - // return the min - doSanityChecksForRetrievedData(retrievedData, FeeRateProvider.MIN_FEE_RATE_FOR_TRADING); - } - - @Test - public void getFees_singleProvider_feeAboveMax() { - // One working provider, which returns a fee greater than the maximum - long providerFee = FeeRateProvider.MAX_FEE_RATE + 13; - FeeRateService service = new FeeRateService( - Collections.singletonList( - buildDummyReachableMempoolFeeRateProvider(providerFee))); - - Map retrievedData = service.getFees(); - - // When the provider returns a value above the expected max, the service should - // return the max - doSanityChecksForRetrievedData(retrievedData, FeeRateProvider.MAX_FEE_RATE); - } - - @Test - public void getFees_multipleProviders() { - // 3 providers, returning 1xMIN, 2xMIN, 3xMIN - FeeRateService service = new FeeRateService(asList( - buildDummyReachableMempoolFeeRateProvider(FeeRateProvider.MIN_FEE_RATE_FOR_TRADING * 1), - buildDummyReachableMempoolFeeRateProvider(FeeRateProvider.MIN_FEE_RATE_FOR_TRADING * 2), - buildDummyReachableMempoolFeeRateProvider(FeeRateProvider.MIN_FEE_RATE_FOR_TRADING * 3))); - - Map retrievedData = service.getFees(); - - // The service should then return the average, which is 2xMIN - doSanityChecksForRetrievedData(retrievedData, FeeRateProvider.MIN_FEE_RATE_FOR_TRADING * 2); - } - - /** - * Performs a few basic sanity checks on the returned data object - */ - private void doSanityChecksForRetrievedData(Map retrievedData, long expectedFeeRate) { - // Check if the response has the expected format. Since the timestamp is that of - // the average (not that of the individual fee rates reported by the individual - // providers), we always expect a non-zero timestamp - assertNotEquals(0L, retrievedData.get(Config.BTC_FEES_TS)); - - Map retrievedDataMap = (Map) retrievedData.get(Config.LEGACY_FEE_DATAMAP); - assertEquals(2, retrievedDataMap.size()); - assertEquals(expectedFeeRate, retrievedDataMap.get(Config.BTC_TX_FEE)); - } -} diff --git a/pricenode/src/test/java/bisq/price/mining/providers/MempoolFeeRateProviderTest.java b/pricenode/src/test/java/bisq/price/mining/providers/MempoolFeeRateProviderTest.java deleted file mode 100644 index 999e550745..0000000000 --- a/pricenode/src/test/java/bisq/price/mining/providers/MempoolFeeRateProviderTest.java +++ /dev/null @@ -1,100 +0,0 @@ -/* - * This file is part of Haveno. - * - * Haveno is free software: you can redistribute it and/or modify it - * under the terms of the GNU Affero General Public License as published by - * the Free Software Foundation, either version 3 of the License, or (at - * your option) any later version. - * - * Haveno is distributed in the hope that it will be useful, but WITHOUT - * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or - * FITNESS FOR A PARTICULAR PURPOSE. See the GNU Affero General Public - * License for more details. - * - * You should have received a copy of the GNU Affero General Public License - * along with Haveno. If not, see . - */ - -package bisq.price.mining.providers; - -import bisq.price.mining.FeeRate; -import bisq.price.mining.FeeRateProvider; - -import org.springframework.core.env.Environment; -import org.springframework.core.env.StandardEnvironment; -import org.springframework.web.client.RestClientException; - -import java.time.Instant; - -import org.junit.jupiter.api.Test; - -import static java.lang.Thread.sleep; -import static org.junit.Assert.assertTrue; - -/** - * Tests specific to a {@link MempoolFeeRateProvider} which queries one API endpoint. For - * tests related to managing parallel fee API endpoints, see - * {@link bisq.price.mining.FeeRateServiceTest} - */ -public class MempoolFeeRateProviderTest { - - private static final Environment env = new StandardEnvironment(); - - @Test - public void doGet_successfulCall() { - MempoolFeeRateProvider feeRateProvider = new MempoolFeeRateProvider.First(env); - - // Make a call to the API, retrieve the recommended fee rate - // If the API call fails, or the response body cannot be parsed, the test will - // fail with an exception - FeeRate retrievedFeeRate = feeRateProvider.doGet(); - - // Check that the FeeRateProvider returns a fee within the defined parameters - assertTrue(retrievedFeeRate.getPrice() >= FeeRateProvider.MIN_FEE_RATE_FOR_TRADING); - assertTrue(retrievedFeeRate.getPrice() <= FeeRateProvider.MAX_FEE_RATE); - } - - /** - * Simulates a reachable provider, which successfully returns an API response - */ - public static FeeRateProvider buildDummyReachableMempoolFeeRateProvider(long feeRate) { - MempoolFeeRateProvider dummyProvider = new MempoolFeeRateProvider.First(env) { - @Override - protected FeeRate doGet() { - return new FeeRate("BTC", feeRate, MIN_FEE_RATE_FOR_WITHDRAWAL, Instant.now().getEpochSecond()); - } - }; - - // Initialize provider - dummyProvider.start(); - try { - sleep(1000); - } catch (InterruptedException e) { } - dummyProvider.stop(); - - return dummyProvider; - } - - /** - * Simulates an unreachable provider, which for whatever reason cannot deliver a - * response to the API. Reasons for that could be: host went offline, connection - * timeout, connection cannot be established (expired certificate), etc. - */ - public static FeeRateProvider buildDummyUnreachableMempoolFeeRateProvider() throws RestClientException { - MempoolFeeRateProvider dummyProvider = new MempoolFeeRateProvider.First(env) { - @Override - protected FeeRate doGet() { - throw new RestClientException("Simulating connection error when trying to reach API endpoint"); - } - }; - - // Initialize provider - dummyProvider.start(); - try { - sleep(1000); - } catch (InterruptedException e) { } - dummyProvider.stop(); - - return dummyProvider; - } -} diff --git a/pricenode/src/test/java/bisq/price/spot/ExchangeRateServiceTest.java b/pricenode/src/test/java/bisq/price/spot/ExchangeRateServiceTest.java deleted file mode 100644 index cda5814322..0000000000 --- a/pricenode/src/test/java/bisq/price/spot/ExchangeRateServiceTest.java +++ /dev/null @@ -1,414 +0,0 @@ -/* - * This file is part of Haveno. - * - * Haveno is free software: you can redistribute it and/or modify it - * under the terms of the GNU Affero General Public License as published by - * the Free Software Foundation, either version 3 of the License, or (at - * your option) any later version. - * - * Haveno is distributed in the hope that it will be useful, but WITHOUT - * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or - * FITNESS FOR A PARTICULAR PURPOSE. See the GNU Affero General Public - * License for more details. - * - * You should have received a copy of the GNU Affero General Public License - * along with Haveno. If not, see . - */ - -package bisq.price.spot; - -import bisq.core.locale.CurrencyUtil; - -import org.springframework.core.env.Environment; -import org.springframework.core.env.StandardEnvironment; - -import com.google.common.collect.Sets; - -import org.apache.commons.lang3.RandomStringUtils; -import org.apache.commons.lang3.RandomUtils; - -import java.time.Duration; - -import java.util.ArrayList; -import java.util.Collections; -import java.util.HashMap; -import java.util.HashSet; -import java.util.List; -import java.util.Map; -import java.util.OptionalDouble; -import java.util.Set; -import java.util.stream.Collectors; - -import org.slf4j.LoggerFactory; - -import ch.qos.logback.classic.Level; -import ch.qos.logback.classic.Logger; -import ch.qos.logback.classic.spi.ILoggingEvent; -import ch.qos.logback.core.read.ListAppender; - -import org.junit.jupiter.api.BeforeAll; -import org.junit.jupiter.api.Test; - -import static java.lang.Thread.sleep; -import static java.util.Arrays.asList; - -import static org.junit.jupiter.api.Assertions.*; -import static org.mockito.Mockito.*; - -public class ExchangeRateServiceTest { - - /** - * Logback version of the Slf4j logger used by {@link ExchangeRateService}. This - * allows us to test if specific messages were logged. - * See https://stackoverflow.com/a/52229629 - */ - private static Logger exchangeRateServiceLogger; - private static final String LIST_APPENDER_NAME = "testListAppender"; - - @BeforeAll - static void setup() { - // Get the logger object for logs in ExchangeRateService - exchangeRateServiceLogger = (Logger) LoggerFactory.getLogger(ExchangeRateService.class); - - // Initiate and append a ListAppender, which allows us to programmatically inspect - // log messages - ListAppender listAppender = new ListAppender<>(); - listAppender.setName(LIST_APPENDER_NAME); - listAppender.start(); - exchangeRateServiceLogger.addAppender(listAppender); - } - - @Test - public void getAllMarketPrices_withNoExchangeRates_logs_Exception() { - int numberOfCurrencyPairsOnExchange = 0; - ExchangeRateProvider dummyProvider = buildDummyExchangeRateProvider(numberOfCurrencyPairsOnExchange); - ExchangeRateService service = new ExchangeRateService(Collections.singletonList(dummyProvider)); - - Map retrievedData = service.getAllMarketPrices(); - - doSanityChecksForRetrievedDataSingleProvider(retrievedData, dummyProvider, numberOfCurrencyPairsOnExchange); - - // No exchange rates provided by this exchange, two things should happen - // A) the timestamp should be set to 0 - // B) an error should be logged - - // A) Check that timestamp was set to 0 - // This allows Bisq clients to eventually disregard data from this provider - assertEquals(0L, retrievedData.get(dummyProvider.getPrefix() + "Ts")); - - // B) Check that an error is logged - // Log msg has the format: java.lang.IllegalStateException: No exchange rate data - // found for ExchangeName-JzfP1 - List logsList = ((ListAppender) exchangeRateServiceLogger.getAppender(LIST_APPENDER_NAME)).list; - assertEquals(Level.ERROR, logsList.get(0).getLevel()); - assertTrue(logsList.get(0).getMessage().endsWith("No exchange rate data found for " + dummyProvider.getName())); - } - - @Test - public void getAllMarketPrices_withSingleExchangeRate() { - int numberOfCurrencyPairsOnExchange = 1; - ExchangeRateProvider dummyProvider = buildDummyExchangeRateProvider(numberOfCurrencyPairsOnExchange); - ExchangeRateService service = new ExchangeRateService(Collections.singletonList(dummyProvider)); - - Map retrievedData = service.getAllMarketPrices(); - - doSanityChecksForRetrievedDataSingleProvider(retrievedData, dummyProvider, numberOfCurrencyPairsOnExchange); - - // One rate was provided by this provider, so the timestamp should not be 0 - assertNotEquals(0L, retrievedData.get(dummyProvider.getPrefix() + "Ts")); - } - - @Test - public void getAllMarketPrices_withMultipleProviders_differentCurrencyCodes() { - int numberOfCurrencyPairsOnExchange = 1; - ExchangeRateProvider dummyProvider1 = buildDummyExchangeRateProvider(numberOfCurrencyPairsOnExchange); - ExchangeRateProvider dummyProvider2 = buildDummyExchangeRateProvider(numberOfCurrencyPairsOnExchange); - ExchangeRateService service = new ExchangeRateService(asList(dummyProvider1, dummyProvider2)); - - Map retrievedData = service.getAllMarketPrices(); - - doSanityChecksForRetrievedDataMultipleProviders(retrievedData, asList(dummyProvider1, dummyProvider2)); - - // One rate was provided by each provider in this service, so the timestamp - // (for both providers) should not be 0 - assertNotEquals(0L, retrievedData.get(dummyProvider1.getPrefix() + "Ts")); - assertNotEquals(0L, retrievedData.get(dummyProvider2.getPrefix() + "Ts")); - } - - /** - * Tests the scenario when multiple providers have rates for the same currencies - */ - @Test - public void getAllMarketPrices_withMultipleProviders_overlappingCurrencyCodes() { - - // List of currencies for which multiple providers will have exchange rates - Set rateCurrencyCodes = Sets.newHashSet("CURRENCY-1", "CURRENCY-2", "CURRENCY-3"); - - // Create several dummy providers, each providing their own rates for the same set of currencies - ExchangeRateProvider dummyProvider1 = buildDummyExchangeRateProvider(rateCurrencyCodes); - ExchangeRateProvider dummyProvider2 = buildDummyExchangeRateProvider(rateCurrencyCodes); - - ExchangeRateService service = new ExchangeRateService(asList(dummyProvider1, dummyProvider2)); - - Map retrievedData = service.getAllMarketPrices(); - - doSanityChecksForRetrievedDataMultipleProviders(retrievedData, asList(dummyProvider1, dummyProvider2)); - - // At least one rate was provided by each provider in this service, so the - // timestamp (for both providers) should not be 0 - assertNotEquals(0L, retrievedData.get(dummyProvider1.getPrefix() + "Ts")); - assertNotEquals(0L, retrievedData.get(dummyProvider2.getPrefix() + "Ts")); - } - - /** - * Tests the scenario when currencies are excluded from the PriceNode feed via configuration settings - */ - @Test - public void getAllMarketPrices_withMultipleProviders_excludedCurrencyCodes() { - String excludedCcyString = "LBP,USD,EUR"; - String providerExcludedCcyString = "HUOBI:BRL,BINANCE:GBP,BINANCE:SEK"; - Environment mockedEnvironment = mock(Environment.class); - when(mockedEnvironment.getProperty(eq("bisq.price.fiatcurrency.excluded"), anyString())).thenReturn(excludedCcyString); - when(mockedEnvironment.getProperty(eq("bisq.price.fiatcurrency.excludedByProvider"), anyString())).thenReturn(providerExcludedCcyString); - - class MockedExchangeRateProvider extends ExchangeRateProvider { - MockedExchangeRateProvider() { - super(mockedEnvironment, "ExchangeName", "EXCH", Duration.ofDays(1)); - } - - @Override - public boolean isRunning() { - return true; - } - - @Override - public Set doGet() { - HashSet exchangeRates = new HashSet<>(); - // Simulate rates for all the supported ccys - for (String rateCurrencyCode : getSupportedFiatCurrencies()) { - exchangeRates.add(new ExchangeRate( - rateCurrencyCode, - RandomUtils.nextDouble(1, 1000), // random price - System.currentTimeMillis(), - getName())); // ExchangeRateProvider name - } - return exchangeRates; - } - } - - Logger exchangeRateProviderLogger; - String LIST_APPENDER_NAME2 = "testListAppender2"; - exchangeRateProviderLogger = (Logger) LoggerFactory.getLogger(MockedExchangeRateProvider.class); - ListAppender listAppender2 = new ListAppender<>(); - listAppender2.setName(LIST_APPENDER_NAME2); - listAppender2.start(); - exchangeRateProviderLogger.addAppender(listAppender2); - - // we request rates for all currencies, and check that: - // (a) the provider supplies more currency rates than the number of currencies we are trying to exclude (sanity test), - // (b) the number of missing currency rates equals the number of currencies we told PriceNode to exclude, - // (c) none of the rates supplied are for an excluded currency. - - Set excludedFiatCurrencies = new HashSet<>(asList(excludedCcyString.split(","))); - MockedExchangeRateProvider mockedExchangeRateProvider = new MockedExchangeRateProvider(); - Set exchangeRates = mockedExchangeRateProvider.doGet(); - assertTrue(exchangeRates.size() > excludedFiatCurrencies.size()); - int numSortedFiatCurrencies = CurrencyUtil.getAllSortedFiatCurrencies().size(); - int numCurrenciesFromProvider = mockedExchangeRateProvider.getSupportedFiatCurrencies().size(); - int missingCurrencyCount = numSortedFiatCurrencies - numCurrenciesFromProvider; - assertEquals(missingCurrencyCount, excludedFiatCurrencies.size()); - for (ExchangeRate exchangeRate : exchangeRates) { - assertFalse(excludedCcyString.contains(exchangeRate.getCurrency())); - } - List logsList = ((ListAppender) exchangeRateProviderLogger.getAppender(LIST_APPENDER_NAME2)).list; - assertEquals(3, logsList.size()); - assertEquals(Level.INFO, logsList.get(1).getLevel()); - assertTrue(logsList.get(0).getFormattedMessage().endsWith("will refresh every PT24H")); - assertTrue(logsList.get(1).getFormattedMessage().endsWith("fiat currencies excluded: [LBP, USD, EUR]")); - assertTrue(logsList.get(2).getFormattedMessage().endsWith("fiat currencies supported: " + numCurrenciesFromProvider)); - } - - /** - * Performs generic sanity checks on the response format and contents. - * - * @param retrievedData Response data retrieved from the {@link ExchangeRateService} - * @param provider {@link ExchangeRateProvider} available to the - * {@link ExchangeRateService} - * @param numberOfCurrencyPairsOnExchange Number of currency pairs this exchange was - * initiated with - */ - private void doSanityChecksForRetrievedDataSingleProvider(Map retrievedData, - ExchangeRateProvider provider, - int numberOfCurrencyPairsOnExchange) { - // Check response structure - doSanityChecksForRetrievedDataMultipleProviders(retrievedData, asList(provider)); - - // Check that the amount of provided exchange rates matches expected value - // For one provider, the amount of rates of that provider should be the total - // amount of rates in the response - List retrievedMarketPricesData = (List) retrievedData.get("data"); - assertEquals(numberOfCurrencyPairsOnExchange, retrievedMarketPricesData.size()); - } - - /** - * Performs generic sanity checks on the response format and contents. - * - * @param retrievedData Response data retrieved from the {@link ExchangeRateService} - * @param providers List of all {@link ExchangeRateProvider#getPrefix()} the - * {@link ExchangeRateService} uses - */ - private void doSanityChecksForRetrievedDataMultipleProviders(Map retrievedData, - List providers) { - // Check the correct amount of entries were present in the service response: - // The timestamp and the count fields are per provider, so N providers means N - // times those fields timestamp (x N) + count (x N) + price data (stored as a list - // under the key "data"). So expected size is Nx2 + 1. - int n = providers.size(); - assertEquals(n * 2 + 1, retrievedData.size()); - for (ExchangeRateProvider provider : providers) { - String providerPrefix = provider.getPrefix(); - assertNotNull(retrievedData.get(providerPrefix + "Ts")); - assertNotNull(retrievedData.get(providerPrefix + "Count")); - } - - // Check validity of the data field - List retrievedRates = (List) retrievedData.get("data"); - assertNotNull(retrievedRates); - - // It should contain no duplicate ExchangeRate objects - int uniqueRates = Sets.newHashSet(retrievedRates).size(); - int totalRates = retrievedRates.size(); - assertEquals(uniqueRates, totalRates, "Found duplicate rates in data field"); - - // There should be only one ExchangeRate per currency - // In other words, even if multiple providers return rates for the same currency, - // the ExchangeRateService should expose only one (aggregate) ExchangeRate for - // that currency - Map currencyCodeToExchangeRateFromService = retrievedRates.stream() - .collect(Collectors.toMap( - ExchangeRate::getCurrency, exchangeRate -> exchangeRate - )); - int uniqueCurrencyCodes = currencyCodeToExchangeRateFromService.keySet().size(); - assertEquals(uniqueCurrencyCodes, uniqueRates, "Found currency code with multiple exchange rates"); - - // Collect all ExchangeRates from all providers and group them by currency code - Map> currencyCodeToExchangeRatesFromProviders = new HashMap<>(); - for (ExchangeRateProvider p : providers) { - for (ExchangeRate exchangeRate : p.get()) { - String currencyCode = exchangeRate.getCurrency(); - if (currencyCodeToExchangeRatesFromProviders.containsKey(currencyCode)) { - List l = new ArrayList<>(currencyCodeToExchangeRatesFromProviders.get(currencyCode)); - l.add(exchangeRate); - currencyCodeToExchangeRatesFromProviders.put(currencyCode, l); - } else { - currencyCodeToExchangeRatesFromProviders.put(currencyCode, asList(exchangeRate)); - } - } - } - - // For each ExchangeRate which is covered by multiple providers, ensure the rate - // value is an average - currencyCodeToExchangeRatesFromProviders.forEach((currencyCode, exchangeRateList) -> { - ExchangeRate rateFromService = currencyCodeToExchangeRateFromService.get(currencyCode); - double priceFromService = rateFromService.getPrice(); - - OptionalDouble opt = exchangeRateList.stream().mapToDouble(ExchangeRate::getPrice).average(); - double priceAvgFromProviders = opt.getAsDouble(); - - // Ensure that the ExchangeRateService correctly aggregates exchange rates - // from multiple providers. If multiple providers contain rates for a - // currency, the service should return a single aggregate rate - // Expected value for aggregate rate = avg(provider rates) - // This formula works for any number of providers for a specific currency - assertEquals(priceFromService, priceAvgFromProviders, "Service returned incorrect aggregate rate"); - }); - } - - /** - * @param numberOfRatesAvailable Number of exchange rates this provider returns - * @return Dummy {@link ExchangeRateProvider} providing rates for - * "numberOfRatesAvailable" random currency codes - */ - private ExchangeRateProvider buildDummyExchangeRateProvider(int numberOfRatesAvailable) { - ExchangeRateProvider dummyProvider = new ExchangeRateProvider( - new StandardEnvironment(), - "ExchangeName-" + getRandomAlphaNumericString(5), - "EXCH-" + getRandomAlphaNumericString(3), - Duration.ofDays(1)) { - - @Override - public boolean isRunning() { - return true; - } - - @Override - protected Set doGet() { - HashSet exchangeRates = new HashSet<>(); - - // Simulate the required amount of rates - for (int i = 0; i < numberOfRatesAvailable; i++) { - exchangeRates.add(new ExchangeRate( - // random symbol, avoid duplicates - "DUM-" + getRandomAlphaNumericString(3), - RandomUtils.nextDouble(1, 1000), // random price - System.currentTimeMillis(), - getName())); // ExchangeRateProvider name - } - - return exchangeRates; - } - }; - - // Initialize provider - dummyProvider.start(); - try { - sleep(1000); - } catch (InterruptedException e) { } - dummyProvider.stop(); - - return dummyProvider; - } - - private ExchangeRateProvider buildDummyExchangeRateProvider(Set rateCurrencyCodes) { - ExchangeRateProvider dummyProvider = new ExchangeRateProvider( - new StandardEnvironment(), - "ExchangeName-" + getRandomAlphaNumericString(5), - "EXCH-" + getRandomAlphaNumericString(3), - Duration.ofDays(1)) { - - @Override - public boolean isRunning() { - return true; - } - - @Override - protected Set doGet() { - HashSet exchangeRates = new HashSet<>(); - - // Simulate the required amount of rates - for (String rateCurrencyCode : rateCurrencyCodes) { - exchangeRates.add(new ExchangeRate( - rateCurrencyCode, - RandomUtils.nextDouble(1, 1000), // random price - System.currentTimeMillis(), - getName())); // ExchangeRateProvider name - } - - return exchangeRates; - } - }; - - // Initialize provider - dummyProvider.start(); - try { - sleep(1000); - } catch (InterruptedException e) { } - dummyProvider.stop(); - - return dummyProvider; - } - - private static String getRandomAlphaNumericString(int length) { - return RandomStringUtils.random(length, true, true); - } -} diff --git a/pricenode/src/test/java/bisq/price/spot/providers/BTCMarketsTest.java b/pricenode/src/test/java/bisq/price/spot/providers/BTCMarketsTest.java deleted file mode 100644 index b876d2ecd7..0000000000 --- a/pricenode/src/test/java/bisq/price/spot/providers/BTCMarketsTest.java +++ /dev/null @@ -1,36 +0,0 @@ -/* - * This file is part of Haveno. - * - * Haveno is free software: you can redistribute it and/or modify it - * under the terms of the GNU Affero General Public License as published by - * the Free Software Foundation, either version 3 of the License, or (at - * your option) any later version. - * - * Haveno is distributed in the hope that it will be useful, but WITHOUT - * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or - * FITNESS FOR A PARTICULAR PURPOSE. See the GNU Affero General Public - * License for more details. - * - * You should have received a copy of the GNU Affero General Public License - * along with Haveno. If not, see . - */ - -package bisq.price.spot.providers; - -import bisq.price.AbstractExchangeRateProviderTest; - -import org.springframework.core.env.StandardEnvironment; - -import lombok.extern.slf4j.Slf4j; - -import org.junit.jupiter.api.Test; - -@Slf4j -public class BTCMarketsTest extends AbstractExchangeRateProviderTest { - - @Test - public void doGet_successfulCall() { - doGet_successfulCall(new BTCMarkets(new StandardEnvironment())); - } - -} diff --git a/pricenode/src/test/java/bisq/price/spot/providers/BinanceTest.java b/pricenode/src/test/java/bisq/price/spot/providers/BinanceTest.java deleted file mode 100644 index 90c2a59054..0000000000 --- a/pricenode/src/test/java/bisq/price/spot/providers/BinanceTest.java +++ /dev/null @@ -1,36 +0,0 @@ -/* - * This file is part of Haveno. - * - * Haveno is free software: you can redistribute it and/or modify it - * under the terms of the GNU Affero General Public License as published by - * the Free Software Foundation, either version 3 of the License, or (at - * your option) any later version. - * - * Haveno is distributed in the hope that it will be useful, but WITHOUT - * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or - * FITNESS FOR A PARTICULAR PURPOSE. See the GNU Affero General Public - * License for more details. - * - * You should have received a copy of the GNU Affero General Public License - * along with Haveno. If not, see . - */ - -package bisq.price.spot.providers; - -import bisq.price.AbstractExchangeRateProviderTest; - -import org.springframework.core.env.StandardEnvironment; - -import lombok.extern.slf4j.Slf4j; - -import org.junit.jupiter.api.Test; - -@Slf4j -public class BinanceTest extends AbstractExchangeRateProviderTest { - - @Test - public void doGet_successfulCall() { - doGet_successfulCall(new Binance(new StandardEnvironment())); - } - -} diff --git a/pricenode/src/test/java/bisq/price/spot/providers/BitfinexTest.java b/pricenode/src/test/java/bisq/price/spot/providers/BitfinexTest.java deleted file mode 100644 index 26361d6f45..0000000000 --- a/pricenode/src/test/java/bisq/price/spot/providers/BitfinexTest.java +++ /dev/null @@ -1,36 +0,0 @@ -/* - * This file is part of Haveno. - * - * Haveno is free software: you can redistribute it and/or modify it - * under the terms of the GNU Affero General Public License as published by - * the Free Software Foundation, either version 3 of the License, or (at - * your option) any later version. - * - * Haveno is distributed in the hope that it will be useful, but WITHOUT - * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or - * FITNESS FOR A PARTICULAR PURPOSE. See the GNU Affero General Public - * License for more details. - * - * You should have received a copy of the GNU Affero General Public License - * along with Haveno. If not, see . - */ - -package bisq.price.spot.providers; - -import bisq.price.AbstractExchangeRateProviderTest; - -import org.springframework.core.env.StandardEnvironment; - -import lombok.extern.slf4j.Slf4j; - -import org.junit.jupiter.api.Test; - -@Slf4j -public class BitfinexTest extends AbstractExchangeRateProviderTest { - - @Test - public void doGet_successfulCall() { - doGet_successfulCall(new Bitfinex(new StandardEnvironment())); - } - -} diff --git a/pricenode/src/test/java/bisq/price/spot/providers/BitflyerTest.java b/pricenode/src/test/java/bisq/price/spot/providers/BitflyerTest.java deleted file mode 100644 index cf8a7b3ebc..0000000000 --- a/pricenode/src/test/java/bisq/price/spot/providers/BitflyerTest.java +++ /dev/null @@ -1,36 +0,0 @@ -/* - * This file is part of Haveno. - * - * Haveno is free software: you can redistribute it and/or modify it - * under the terms of the GNU Affero General Public License as published by - * the Free Software Foundation, either version 3 of the License, or (at - * your option) any later version. - * - * Haveno is distributed in the hope that it will be useful, but WITHOUT - * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or - * FITNESS FOR A PARTICULAR PURPOSE. See the GNU Affero General Public - * License for more details. - * - * You should have received a copy of the GNU Affero General Public License - * along with Haveno. If not, see . - */ - -package bisq.price.spot.providers; - -import bisq.price.AbstractExchangeRateProviderTest; - -import org.springframework.core.env.StandardEnvironment; - -import lombok.extern.slf4j.Slf4j; - -import org.junit.jupiter.api.Test; - -@Slf4j -public class BitflyerTest extends AbstractExchangeRateProviderTest { - - @Test - public void doGet_successfulCall() { - doGet_successfulCall(new Bitflyer(new StandardEnvironment())); - } - -} diff --git a/pricenode/src/test/java/bisq/price/spot/providers/BitstampTest.java b/pricenode/src/test/java/bisq/price/spot/providers/BitstampTest.java deleted file mode 100644 index 8d6741c232..0000000000 --- a/pricenode/src/test/java/bisq/price/spot/providers/BitstampTest.java +++ /dev/null @@ -1,36 +0,0 @@ -/* - * This file is part of Haveno. - * - * Haveno is free software: you can redistribute it and/or modify it - * under the terms of the GNU Affero General Public License as published by - * the Free Software Foundation, either version 3 of the License, or (at - * your option) any later version. - * - * Haveno is distributed in the hope that it will be useful, but WITHOUT - * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or - * FITNESS FOR A PARTICULAR PURPOSE. See the GNU Affero General Public - * License for more details. - * - * You should have received a copy of the GNU Affero General Public License - * along with Haveno. If not, see . - */ - -package bisq.price.spot.providers; - -import bisq.price.AbstractExchangeRateProviderTest; - -import org.springframework.core.env.StandardEnvironment; - -import lombok.extern.slf4j.Slf4j; - -import org.junit.jupiter.api.Test; - -@Slf4j -public class BitstampTest extends AbstractExchangeRateProviderTest { - - @Test - public void doGet_successfulCall() { - doGet_successfulCall(new Bitstamp(new StandardEnvironment())); - } - -} diff --git a/pricenode/src/test/java/bisq/price/spot/providers/CoinGeckoTest.java b/pricenode/src/test/java/bisq/price/spot/providers/CoinGeckoTest.java deleted file mode 100644 index 714c1c6059..0000000000 --- a/pricenode/src/test/java/bisq/price/spot/providers/CoinGeckoTest.java +++ /dev/null @@ -1,36 +0,0 @@ -/* - * This file is part of Haveno. - * - * Haveno is free software: you can redistribute it and/or modify it - * under the terms of the GNU Affero General Public License as published by - * the Free Software Foundation, either version 3 of the License, or (at - * your option) any later version. - * - * Haveno is distributed in the hope that it will be useful, but WITHOUT - * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or - * FITNESS FOR A PARTICULAR PURPOSE. See the GNU Affero General Public - * License for more details. - * - * You should have received a copy of the GNU Affero General Public License - * along with Haveno. If not, see . - */ - -package bisq.price.spot.providers; - -import bisq.price.AbstractExchangeRateProviderTest; - -import org.springframework.core.env.StandardEnvironment; - -import lombok.extern.slf4j.Slf4j; - -import org.junit.jupiter.api.Test; - -@Slf4j -public class CoinGeckoTest extends AbstractExchangeRateProviderTest { - - @Test - public void doGet_successfulCall() { - doGet_successfulCall(new CoinGecko(new StandardEnvironment())); - } - -} diff --git a/pricenode/src/test/java/bisq/price/spot/providers/CoinbaseProTest.java b/pricenode/src/test/java/bisq/price/spot/providers/CoinbaseProTest.java deleted file mode 100644 index 4214c6700e..0000000000 --- a/pricenode/src/test/java/bisq/price/spot/providers/CoinbaseProTest.java +++ /dev/null @@ -1,36 +0,0 @@ -/* - * This file is part of Haveno. - * - * Haveno is free software: you can redistribute it and/or modify it - * under the terms of the GNU Affero General Public License as published by - * the Free Software Foundation, either version 3 of the License, or (at - * your option) any later version. - * - * Haveno is distributed in the hope that it will be useful, but WITHOUT - * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or - * FITNESS FOR A PARTICULAR PURPOSE. See the GNU Affero General Public - * License for more details. - * - * You should have received a copy of the GNU Affero General Public License - * along with Haveno. If not, see . - */ - -package bisq.price.spot.providers; - -import bisq.price.AbstractExchangeRateProviderTest; - -import org.springframework.core.env.StandardEnvironment; - -import lombok.extern.slf4j.Slf4j; - -import org.junit.jupiter.api.Test; - -@Slf4j -public class CoinbaseProTest extends AbstractExchangeRateProviderTest { - - @Test - public void doGet_successfulCall() { - doGet_successfulCall(new CoinbasePro(new StandardEnvironment())); - } - -} diff --git a/pricenode/src/test/java/bisq/price/spot/providers/CoinoneTest.java b/pricenode/src/test/java/bisq/price/spot/providers/CoinoneTest.java deleted file mode 100644 index 8a318c7bc1..0000000000 --- a/pricenode/src/test/java/bisq/price/spot/providers/CoinoneTest.java +++ /dev/null @@ -1,36 +0,0 @@ -/* - * This file is part of Haveno. - * - * Haveno is free software: you can redistribute it and/or modify it - * under the terms of the GNU Affero General Public License as published by - * the Free Software Foundation, either version 3 of the License, or (at - * your option) any later version. - * - * Haveno is distributed in the hope that it will be useful, but WITHOUT - * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or - * FITNESS FOR A PARTICULAR PURPOSE. See the GNU Affero General Public - * License for more details. - * - * You should have received a copy of the GNU Affero General Public License - * along with Haveno. If not, see . - */ - -package bisq.price.spot.providers; - -import bisq.price.AbstractExchangeRateProviderTest; - -import org.springframework.core.env.StandardEnvironment; - -import lombok.extern.slf4j.Slf4j; - -import org.junit.jupiter.api.Test; - -@Slf4j -public class CoinoneTest extends AbstractExchangeRateProviderTest { - - @Test - public void doGet_successfulCall() { - doGet_successfulCall(new Coinone(new StandardEnvironment())); - } - -} diff --git a/pricenode/src/test/java/bisq/price/spot/providers/IndependentReserveTest.java b/pricenode/src/test/java/bisq/price/spot/providers/IndependentReserveTest.java deleted file mode 100644 index 1c3b7096f7..0000000000 --- a/pricenode/src/test/java/bisq/price/spot/providers/IndependentReserveTest.java +++ /dev/null @@ -1,36 +0,0 @@ -/* - * This file is part of Haveno. - * - * Haveno is free software: you can redistribute it and/or modify it - * under the terms of the GNU Affero General Public License as published by - * the Free Software Foundation, either version 3 of the License, or (at - * your option) any later version. - * - * Haveno is distributed in the hope that it will be useful, but WITHOUT - * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or - * FITNESS FOR A PARTICULAR PURPOSE. See the GNU Affero General Public - * License for more details. - * - * You should have received a copy of the GNU Affero General Public License - * along with Haveno. If not, see . - */ - -package bisq.price.spot.providers; - -import bisq.price.AbstractExchangeRateProviderTest; - -import org.springframework.core.env.StandardEnvironment; - -import lombok.extern.slf4j.Slf4j; - -import org.junit.jupiter.api.Test; - -@Slf4j -public class IndependentReserveTest extends AbstractExchangeRateProviderTest { - - @Test - public void doGet_successfulCall() { - doGet_successfulCall(new IndependentReserve(new StandardEnvironment())); - } - -} diff --git a/pricenode/src/test/java/bisq/price/spot/providers/KrakenTest.java b/pricenode/src/test/java/bisq/price/spot/providers/KrakenTest.java deleted file mode 100644 index 68096f5e0f..0000000000 --- a/pricenode/src/test/java/bisq/price/spot/providers/KrakenTest.java +++ /dev/null @@ -1,36 +0,0 @@ -/* - * This file is part of Haveno. - * - * Haveno is free software: you can redistribute it and/or modify it - * under the terms of the GNU Affero General Public License as published by - * the Free Software Foundation, either version 3 of the License, or (at - * your option) any later version. - * - * Haveno is distributed in the hope that it will be useful, but WITHOUT - * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or - * FITNESS FOR A PARTICULAR PURPOSE. See the GNU Affero General Public - * License for more details. - * - * You should have received a copy of the GNU Affero General Public License - * along with Haveno. If not, see . - */ - -package bisq.price.spot.providers; - -import bisq.price.AbstractExchangeRateProviderTest; - -import org.springframework.core.env.StandardEnvironment; - -import lombok.extern.slf4j.Slf4j; - -import org.junit.jupiter.api.Test; - -@Slf4j -public class KrakenTest extends AbstractExchangeRateProviderTest { - - @Test - public void doGet_successfulCall() { - doGet_successfulCall(new Kraken(new StandardEnvironment())); - } - -} diff --git a/pricenode/src/test/java/bisq/price/spot/providers/LunoTest.java b/pricenode/src/test/java/bisq/price/spot/providers/LunoTest.java deleted file mode 100644 index a11ff36cd1..0000000000 --- a/pricenode/src/test/java/bisq/price/spot/providers/LunoTest.java +++ /dev/null @@ -1,36 +0,0 @@ -/* - * This file is part of Haveno. - * - * Haveno is free software: you can redistribute it and/or modify it - * under the terms of the GNU Affero General Public License as published by - * the Free Software Foundation, either version 3 of the License, or (at - * your option) any later version. - * - * Haveno is distributed in the hope that it will be useful, but WITHOUT - * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or - * FITNESS FOR A PARTICULAR PURPOSE. See the GNU Affero General Public - * License for more details. - * - * You should have received a copy of the GNU Affero General Public License - * along with Haveno. If not, see . - */ - -package bisq.price.spot.providers; - -import bisq.price.AbstractExchangeRateProviderTest; - -import org.springframework.core.env.StandardEnvironment; - -import lombok.extern.slf4j.Slf4j; - -import org.junit.jupiter.api.Test; - -@Slf4j -public class LunoTest extends AbstractExchangeRateProviderTest { - - @Test - public void doGet_successfulCall() { - doGet_successfulCall(new Luno(new StandardEnvironment())); - } - -} diff --git a/pricenode/src/test/java/bisq/price/spot/providers/MercadoBitcoinTest.java b/pricenode/src/test/java/bisq/price/spot/providers/MercadoBitcoinTest.java deleted file mode 100644 index e58bed774e..0000000000 --- a/pricenode/src/test/java/bisq/price/spot/providers/MercadoBitcoinTest.java +++ /dev/null @@ -1,36 +0,0 @@ -/* - * This file is part of Haveno. - * - * Haveno is free software: you can redistribute it and/or modify it - * under the terms of the GNU Affero General Public License as published by - * the Free Software Foundation, either version 3 of the License, or (at - * your option) any later version. - * - * Haveno is distributed in the hope that it will be useful, but WITHOUT - * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or - * FITNESS FOR A PARTICULAR PURPOSE. See the GNU Affero General Public - * License for more details. - * - * You should have received a copy of the GNU Affero General Public License - * along with Haveno. If not, see . - */ - -package bisq.price.spot.providers; - -import bisq.price.AbstractExchangeRateProviderTest; - -import org.springframework.core.env.StandardEnvironment; - -import lombok.extern.slf4j.Slf4j; - -import org.junit.jupiter.api.Test; - -@Slf4j -public class MercadoBitcoinTest extends AbstractExchangeRateProviderTest { - - @Test - public void doGet_successfulCall() { - doGet_successfulCall(new MercadoBitcoin(new StandardEnvironment())); - } - -} diff --git a/pricenode/src/test/java/bisq/price/spot/providers/ParibuTest.java b/pricenode/src/test/java/bisq/price/spot/providers/ParibuTest.java deleted file mode 100644 index 0b0332e599..0000000000 --- a/pricenode/src/test/java/bisq/price/spot/providers/ParibuTest.java +++ /dev/null @@ -1,36 +0,0 @@ -/* - * This file is part of Haveno. - * - * Haveno is free software: you can redistribute it and/or modify it - * under the terms of the GNU Affero General Public License as published by - * the Free Software Foundation, either version 3 of the License, or (at - * your option) any later version. - * - * Haveno is distributed in the hope that it will be useful, but WITHOUT - * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or - * FITNESS FOR A PARTICULAR PURPOSE. See the GNU Affero General Public - * License for more details. - * - * You should have received a copy of the GNU Affero General Public License - * along with Haveno. If not, see . - */ - -package bisq.price.spot.providers; - -import bisq.price.AbstractExchangeRateProviderTest; - -import org.springframework.core.env.StandardEnvironment; - -import lombok.extern.slf4j.Slf4j; - -import org.junit.jupiter.api.Test; - -@Slf4j -public class ParibuTest extends AbstractExchangeRateProviderTest { - - @Test - public void doGet_successfulCall() { - doGet_successfulCall(new Paribu(new StandardEnvironment())); - } - -} diff --git a/pricenode/src/test/java/bisq/price/spot/providers/PoloniexTest.java b/pricenode/src/test/java/bisq/price/spot/providers/PoloniexTest.java deleted file mode 100644 index 57944c2420..0000000000 --- a/pricenode/src/test/java/bisq/price/spot/providers/PoloniexTest.java +++ /dev/null @@ -1,36 +0,0 @@ -/* - * This file is part of Haveno. - * - * Haveno is free software: you can redistribute it and/or modify it - * under the terms of the GNU Affero General Public License as published by - * the Free Software Foundation, either version 3 of the License, or (at - * your option) any later version. - * - * Haveno is distributed in the hope that it will be useful, but WITHOUT - * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or - * FITNESS FOR A PARTICULAR PURPOSE. See the GNU Affero General Public - * License for more details. - * - * You should have received a copy of the GNU Affero General Public License - * along with Haveno. If not, see . - */ - -package bisq.price.spot.providers; - -import bisq.price.AbstractExchangeRateProviderTest; - -import org.springframework.core.env.StandardEnvironment; - -import lombok.extern.slf4j.Slf4j; - -import org.junit.jupiter.api.Test; - -@Slf4j -public class PoloniexTest extends AbstractExchangeRateProviderTest { - - @Test - public void doGet_successfulCall() { - doGet_successfulCall(new Poloniex(new StandardEnvironment())); - } - -} diff --git a/pricenode/src/test/java/bisq/price/spot/providers/QuoineTest.java b/pricenode/src/test/java/bisq/price/spot/providers/QuoineTest.java deleted file mode 100644 index 4bf83c3f48..0000000000 --- a/pricenode/src/test/java/bisq/price/spot/providers/QuoineTest.java +++ /dev/null @@ -1,36 +0,0 @@ -/* - * This file is part of Haveno. - * - * Haveno is free software: you can redistribute it and/or modify it - * under the terms of the GNU Affero General Public License as published by - * the Free Software Foundation, either version 3 of the License, or (at - * your option) any later version. - * - * Haveno is distributed in the hope that it will be useful, but WITHOUT - * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or - * FITNESS FOR A PARTICULAR PURPOSE. See the GNU Affero General Public - * License for more details. - * - * You should have received a copy of the GNU Affero General Public License - * along with Haveno. If not, see . - */ - -package bisq.price.spot.providers; - -import bisq.price.AbstractExchangeRateProviderTest; - -import org.springframework.core.env.StandardEnvironment; - -import lombok.extern.slf4j.Slf4j; - -import org.junit.jupiter.api.Test; - -@Slf4j -public class QuoineTest extends AbstractExchangeRateProviderTest { - - @Test - public void doGet_successfulCall() { - doGet_successfulCall(new Quoine(new StandardEnvironment())); - } - -} diff --git a/pricenode/torrc b/pricenode/torrc deleted file mode 100644 index 3bfc6285ee..0000000000 --- a/pricenode/torrc +++ /dev/null @@ -1,2 +0,0 @@ -HiddenServiceDir build/tor-hidden-service -HiddenServicePort 80 127.0.0.1:8080 diff --git a/pricenode/uninstall_hsversion_debian.sh b/pricenode/uninstall_hsversion_debian.sh deleted file mode 100755 index 618e848953..0000000000 --- a/pricenode/uninstall_hsversion_debian.sh +++ /dev/null @@ -1,29 +0,0 @@ -#!/bin/sh -set -e - -echo "[*] Network Size Monitoring removal script" - -##### change paths if necessary for your system - -ROOT_USER=root - -SCRAPER_HOME=/journalreader - -##### -echo "[*] Checking environment..." -if [ ! -f "${SCRAPER_HOME}/scraperscript_hsversion.sh" ]; then - echo 'There is nothing to be removed.' - echo 'Exiting...' - exit -fi - -echo "[*] Removing journal parser script" -sudo -H -i -u "${ROOT_USER}" rm "${SCRAPER_HOME}/scraperscript_hsversion.sh" - -echo "[*] Reverting collectd config" -sudo -H -i -u "${ROOT_USER}" sed -i '/.*/ {N;N; s/.*scraperscript_hsversion.sh.*<.Plugin>//g}' /etc/collectd/collectd.conf - -echo "[*] Restarting services" -sudo -H -i -u "${ROOT_USER}" systemctl restart collectd.service - -echo '[*] Done!' diff --git a/settings.gradle b/settings.gradle index fe976bf004..2d96ad242a 100644 --- a/settings.gradle +++ b/settings.gradle @@ -7,7 +7,6 @@ include 'cli' include 'daemon' include 'desktop' include 'monitor' -include 'pricenode' include 'relay' include 'seednode' include 'statsnode'