Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Refactor build, adjust script paths, apply IDE formatting #6

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions .gitmodules
Original file line number Diff line number Diff line change
@@ -1,3 +1,7 @@
[submodule "bisq"]
path = bisq
url = https://github.com/bisq-network/bisq.git
[submodule "bisq-gradle"]
path = bisq-gradle
url = https://github.com/ghubstan/bisq-gradle.git
branch = add-post-build-task
1 change: 1 addition & 0 deletions bisq-gradle
Submodule bisq-gradle added at 5cd0c5
44 changes: 2 additions & 42 deletions build.gradle
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
plugins {
id 'application'
alias(libs.plugins.osdetector)
alias(libs.plugins.springboot)
}

Expand All @@ -11,7 +10,6 @@ repositories {

group 'bisq'

apply plugin: 'com.google.osdetector'
apply plugin: "org.springframework.boot"
apply plugin: 'io.spring.dependency-management'

Expand Down Expand Up @@ -67,49 +65,11 @@ dependencies {
testImplementation libs.mockito.core
}

assemble {
doLast {
// Copy generated bisq-pricenode scripts to project's root dir.
copy {
from layout.buildDirectory.dir('scripts')
into projectDir
}
// Copy zipped distribution libs to project's top-level lib dir.
copy {
def distFolderName = project.name + '-' + version
def distZipName = buildDir.name + '/distributions/' + distFolderName + '.zip'
from(zipTree(distZipName)) {
include "$distFolderName/lib/**"
eachFile { fcd ->
fcd.relativePath = new RelativePath(true, fcd.relativePath.segments.drop(2))
}
includeEmptyDirs = false
}
into "${projectDir}/lib"
}
// Edit generated shell script so it expects to be executed in
// the project's root dir as opposed to a 'bin' subdirectory.
if (osdetector.os != 'windows') {
// Delete the windows .bat script, not the *nix script alone.
delete fileTree(dir: projectDir, include: 'bisq-*.bat')
// Reset APP_HOME variable in *nix script.
def nixScriptFile = file("${projectDir}/${project.name}")
def oldAppHome = 'APP_HOME=$( cd "${APP_HOME:-./}.." && pwd -P ) || exit'
def newAppHome = 'APP_HOME=$( cd "${APP_HOME:-./}" && pwd -P ) || exit'
nixScriptFile.text = nixScriptFile.text.replace(oldAppHome, newAppHome)
} else {
// Delete the *nix script, not the windows .bat script.
delete fileTree(dir: projectDir, include: 'bisq-*', exclude: '*.bat')
// Reset APP_HOME variable in windows .bat script.
def windowsScriptFile = file("${projectDir}/${project.name}.bat")
windowsScriptFile.text = windowsScriptFile.text.replace('set APP_HOME=%DIRNAME%..', 'set APP_HOME=%DIRNAME%')
}
}
}
apply from: 'bisq-gradle/task/postBuild.gradle'

clean.doFirst {
// Remove the project root level 'bisq-*' scripts and 'lib' dir generated at the end of the assemble task.
delete fileTree(dir: projectDir, include: 'bisq-*'), 'lib'
delete fileTree(dir: projectDir, include: ['bisq-pricenode', 'bisq-pricenode.bat']), 'lib'
}

test {
Expand Down
4 changes: 2 additions & 2 deletions gradle/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -9,9 +9,9 @@ Visit the [Gradle website](https://gradle.org/releases) and decide the:
Adjust the following command with tha arguments above and execute it twice:

```asciidoc
$ ./gradlew wrapper --gradle-version 7.4.2 \
$ ./gradlew wrapper --gradle-version 7.5 \
--distribution-type bin \
--gradle-distribution-sha256-sum 29e49b10984e585d8118b7d0bc452f944e386458df27371b49b4ac1dec4b7fda
--gradle-distribution-sha256-sum cb87f222c5585bd46838ad4db78463a5c5f3d336e5e2b98dc7c0c586527351c2
```

The first execution should automatically update:
Expand Down
6 changes: 1 addition & 5 deletions gradle/libs.versions.toml
Original file line number Diff line number Diff line change
Expand Up @@ -4,13 +4,11 @@
# Convention: mark all versions using 'strictly'. This ensures only one version is allowed in the dependency tree, even
# when multiple versions are attempted to be brought in as transitive dependencies of other requirements.
[versions]

junit-jupiter-lib = { strictly = '5.8.2' }
knowm-xchange-lib = { strictly = '5.0.13' }
logback-lib = { strictly = '1.2.6' }
lombok-lib = { strictly = '1.18.22' }
mockito-lib = { strictly = '4.0.0' }
osdetector-plugin-lib = { strictly = '1.7.0' }
slf4j-lib = { strictly = '1.7.36' }
spring-dependency-management-plugin-lib = { strictly = '1.0.12.RELEASE' }
spring-plugin-lib = { strictly = '2.5.6' }
Expand All @@ -20,7 +18,6 @@ spring-boot-starter-web-lib = { strictly = '2.5.6' }
# Note: keys can contain dash (protobuf-java) but the dash is replaced by dot when referenced
# in a build.gradle ('implementation libs.protobuf.java')
[libraries]

junit-jupiter = { module = 'org.junit.jupiter:junit-jupiter', version.ref = 'junit-jupiter-lib' }
knowm-xchange-binance = { module = 'org.knowm.xchange:xchange-binance', version.ref = 'knowm-xchange-lib' }
knowm-xchange-bitbay = { module = 'org.knowm.xchange:xchange-bitbay', version.ref = 'knowm-xchange-lib' }
Expand Down Expand Up @@ -62,6 +59,5 @@ knowm-xchange-libs = [
]

[plugins]
osdetector = { id = 'com.google.osdetector', version.ref = 'osdetector-plugin-lib' }
springboot = { id = 'org.springframework.boot', version.ref = 'spring-plugin-lib' }
springdependency = { id = 'io.spring.dependency-management', version.ref = 'spring-dependency-management-plugin-lib' }
springdependency = { id = 'io.spring.dependency-management', version.ref = 'spring-dependency-management-plugin-lib' }
Binary file modified gradle/wrapper/gradle-wrapper.jar
Binary file not shown.
4 changes: 2 additions & 2 deletions gradle/wrapper/gradle-wrapper.properties
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
distributionBase=GRADLE_USER_HOME
distributionPath=wrapper/dists
distributionSha256Sum=29e49b10984e585d8118b7d0bc452f944e386458df27371b49b4ac1dec4b7fda
distributionUrl=https\://services.gradle.org/distributions/gradle-7.4.2-bin.zip
distributionSha256Sum=cb87f222c5585bd46838ad4db78463a5c5f3d336e5e2b98dc7c0c586527351c2
distributionUrl=https\://services.gradle.org/distributions/gradle-7.5-bin.zip
zipStoreBase=GRADLE_USER_HOME
zipStorePath=wrapper/dists
6 changes: 6 additions & 0 deletions gradlew
Original file line number Diff line number Diff line change
Expand Up @@ -205,6 +205,12 @@ set -- \
org.gradle.wrapper.GradleWrapperMain \
"$@"

# Stop when "xargs" is not available.
if ! command -v xargs >/dev/null 2>&1
then
die "xargs is not available"
fi

# Use "xargs" to parse quoted args.
#
# With -n1 it outputs one arg per line, with the quotes and backslashes removed.
Expand Down
14 changes: 8 additions & 6 deletions gradlew.bat
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@
@rem limitations under the License.
@rem

@if "%DEBUG%" == "" @echo off
@if "%DEBUG%"=="" @echo off
@rem ##########################################################################
@rem
@rem Gradle startup script for Windows
Expand All @@ -25,7 +25,7 @@
if "%OS%"=="Windows_NT" setlocal

set DIRNAME=%~dp0
if "%DIRNAME%" == "" set DIRNAME=.
if "%DIRNAME%"=="" set DIRNAME=.
set APP_BASE_NAME=%~n0
set APP_HOME=%DIRNAME%

Expand All @@ -40,7 +40,7 @@ if defined JAVA_HOME goto findJavaFromJavaHome

set JAVA_EXE=java.exe
%JAVA_EXE% -version >NUL 2>&1
if "%ERRORLEVEL%" == "0" goto execute
if %ERRORLEVEL% equ 0 goto execute

echo.
echo ERROR: JAVA_HOME is not set and no 'java' command could be found in your PATH.
Expand Down Expand Up @@ -75,13 +75,15 @@ set CLASSPATH=%APP_HOME%\gradle\wrapper\gradle-wrapper.jar

:end
@rem End local scope for the variables with windows NT shell
if "%ERRORLEVEL%"=="0" goto mainEnd
if %ERRORLEVEL% equ 0 goto mainEnd

:fail
rem Set variable GRADLE_EXIT_CONSOLE if you need the _script_ return code instead of
rem the _cmd.exe /c_ return code!
if not "" == "%GRADLE_EXIT_CONSOLE%" exit 1
exit /b 1
set EXIT_CODE=%ERRORLEVEL%
if %EXIT_CODE% equ 0 set EXIT_CODE=1
if not ""=="%GRADLE_EXIT_CONSOLE%" exit %EXIT_CODE%
exit /b %EXIT_CODE%

:mainEnd
if "%OS%"=="Windows_NT" endlocal
Expand Down
2 changes: 1 addition & 1 deletion scripts/bisq-pricenode.service
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ After=network.target
[Service]
SyslogIdentifier=bisq-pricenode
EnvironmentFile=/etc/default/bisq-pricenode.env
ExecStart=/bisq/bisq/bisq-pricenode 2
ExecStart=/bisq/bisq-pricenode/bisq-pricenode 2
ExecStop=/bin/kill -TERM ${MAINPID}
Restart=on-failure

Expand Down
4 changes: 2 additions & 2 deletions scripts/install_hsversion_debian.sh
Original file line number Diff line number Diff line change
Expand Up @@ -25,11 +25,11 @@ if ! grep -q "journalreader" /etc/passwd; then
fi

echo "[*] Installing journal parser script"
curl -s https://raw.githubusercontent.com/bisq-network/bisq/master/pricenode/journalscraper_hsversion.sh > /tmp/journalscraper_hsversion.sh
curl -s https://raw.githubusercontent.com/bisq-network/bisq-pricenode/main/scripts/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
curl -s https://raw.githubusercontent.com/bisq-network/bisq-pricenode/main/scripts/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
Expand Down
4 changes: 2 additions & 2 deletions scripts/install_networksize_debian.sh
Original file line number Diff line number Diff line change
Expand Up @@ -25,11 +25,11 @@ 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
curl -s https://raw.githubusercontent.com/bisq-network/bisq-pricenode/main/scripts/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
curl -s https://raw.githubusercontent.com/bisq-network/bisq-pricenode/main/scripts/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
Expand Down
21 changes: 12 additions & 9 deletions scripts/install_pricenode_debian.sh
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
#!/usr/bin/env bash
set -e

# Usage: `$ sudo ./install_pricenode_debian.sh`

echo "[*] Bisq bisq-pricenode installation script"

##### change as necessary for your system
Expand All @@ -16,11 +18,11 @@ BISQ_USER=bisq
BISQ_GROUP=bisq
BISQ_HOME=/bisq

BISQ_REPO_URL=https://github.com/bisq-network/bisq
BISQ_REPO_NAME=bisq
BISQ_REPO_TAG=master
BISQ_LATEST_RELEASE=master
BISQ_TORHS=pricenode
BISQ_REPO_URL=https://github.com/bisq-network/bisq-pricenode
BISQ_REPO_NAME=bisq-pricenode
BISQ_REPO_TAG=main
BISQ_LATEST_RELEASE=main
BISQ_TORHS=bisq-pricenode

TOR_PKG="tor"
#TOR_USER=debian-tor
Expand Down Expand Up @@ -58,7 +60,7 @@ sudo -H -i -u "${ROOT_USER}" chown "${BISQ_USER}":"${BISQ_GROUP}" ${BISQ_HOME}

echo "[*] Cloning Bisq repo"
sudo -H -i -u "${BISQ_USER}" git config --global advice.detachedHead false
sudo -H -i -u "${BISQ_USER}" git clone --branch "${BISQ_REPO_TAG}" "${BISQ_REPO_URL}" "${BISQ_HOME}/${BISQ_REPO_NAME}"
sudo -H -i -u "${BISQ_USER}" git clone --recursive --branch "${BISQ_REPO_TAG}" "${BISQ_REPO_URL}" "${BISQ_HOME}/${BISQ_REPO_NAME}"

echo "[*] Installing OpenJDK 11"
sudo -H -i -u "${ROOT_USER}" apt-get install -qq -y openjdk-11-jdk
Expand All @@ -70,11 +72,12 @@ echo "[*] Performing Git LFS pull"
sudo -H -i -u "${BISQ_USER}" sh -c "cd ${BISQ_HOME}/${BISQ_REPO_NAME} && git lfs pull"

echo "[*] Building Bisq from source"
sudo -H -i -u "${BISQ_USER}" sh -c "cd ${BISQ_HOME}/${BISQ_REPO_NAME} && ./gradlew :pricenode:installDist -x test < /dev/null" # redirect from /dev/null is necessary to workaround gradlew non-interactive shell hanging issue
# Redirect from /dev/null is necessary to workaround gradlew non-interactive shell hanging issue.
sudo -H -i -u "${BISQ_USER}" sh -c "cd ${BISQ_HOME}/${BISQ_REPO_NAME} && ./gradlew build -x test < /dev/null"

echo "[*] Installing bisq-pricenode systemd service"
sudo -H -i -u "${ROOT_USER}" install -c -o "${ROOT_USER}" -g "${ROOT_GROUP}" -m 644 "${BISQ_HOME}/${BISQ_REPO_NAME}/pricenode/bisq-pricenode.service" "${SYSTEMD_SERVICE_HOME}"
sudo -H -i -u "${ROOT_USER}" install -c -o "${ROOT_USER}" -g "${ROOT_GROUP}" -m 644 "${BISQ_HOME}/${BISQ_REPO_NAME}/pricenode/bisq-pricenode.env" "${SYSTEMD_ENV_HOME}"
sudo -H -i -u "${ROOT_USER}" install -c -o "${ROOT_USER}" -g "${ROOT_GROUP}" -m 644 "${BISQ_HOME}/${BISQ_REPO_NAME}/scripts/bisq-pricenode.service" "${SYSTEMD_SERVICE_HOME}"
sudo -H -i -u "${ROOT_USER}" install -c -o "${ROOT_USER}" -g "${ROOT_GROUP}" -m 644 "${BISQ_HOME}/${BISQ_REPO_NAME}/scripts/bisq-pricenode.env" "${SYSTEMD_ENV_HOME}"

echo "[*] Reloading systemd daemon configuration"
sudo -H -i -u "${ROOT_USER}" systemctl daemon-reload
Expand Down
1 change: 1 addition & 0 deletions settings.gradle
Original file line number Diff line number Diff line change
@@ -1,2 +1,3 @@
rootProject.name = 'bisq-pricenode'
includeBuild('bisq')
includeBuild('bisq-gradle')
25 changes: 12 additions & 13 deletions src/main/java/bisq/price/spot/ExchangeRate.java
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,6 @@
import com.fasterxml.jackson.annotation.JsonProperty;

import java.math.BigDecimal;

import java.util.Date;
import java.util.Objects;

Expand All @@ -37,10 +36,10 @@ public class ExchangeRate {

public ExchangeRate(String currency, BigDecimal price, Date timestamp, String provider) {
this(
currency,
price.doubleValue(),
timestamp.getTime(),
provider
currency,
price.doubleValue(),
timestamp.getTime(),
provider
);
}

Expand Down Expand Up @@ -77,9 +76,9 @@ public boolean equals(Object o) {
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);
timestamp == exchangeRate.timestamp &&
Objects.equals(currency, exchangeRate.currency) &&
Objects.equals(provider, exchangeRate.provider);
}

@Override
Expand All @@ -90,10 +89,10 @@ public int hashCode() {
@Override
public String toString() {
return "ExchangeRate{" +
"currency='" + currency + '\'' +
", price=" + price +
", timestamp=" + timestamp +
", provider=" + provider +
'}';
"currency='" + currency + '\'' +
", price=" + price +
", timestamp=" + timestamp +
", provider=" + provider +
'}';
}
}
8 changes: 2 additions & 6 deletions src/main/java/bisq/price/spot/ExchangeRateController.java
Original file line number Diff line number Diff line change
Expand Up @@ -17,11 +17,9 @@

package bisq.price.spot;

import bisq.common.config.Config;
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;

Expand All @@ -43,9 +41,7 @@ public Map<String, Object> getAllMarketPrices() {
Map<String, Object> retVal = exchangeRateService.getAllMarketPrices();

// add the fee info to results
feeRateService.getFees().forEach((key, value) -> {
retVal.put(translateFieldName(key), value);
});
feeRateService.getFees().forEach((key, value) -> retVal.put(translateFieldName(key), value));

return retVal;
}
Expand Down
Loading