Skip to content

Commit

Permalink
Enforce inclusion of TradeLimits for headless apps
Browse files Browse the repository at this point in the history
PaymentMethod use an instance of TradeLimits and expect that it
has been injected, which is the case for desktop but not for
headless apps, so we enforce injection in the app base classes
used for headless apps.

The validation of trade statistics use a method in PaymentMethod where that
dependency is required.

Tha hack how the PaymentMethod use TradeLimits is not nice, but
would require more effort for refactoring.
  • Loading branch information
chimp1984 committed Nov 23, 2021
1 parent 4f1f689 commit 31c2d62
Show file tree
Hide file tree
Showing 5 changed files with 20 additions and 0 deletions.
6 changes: 6 additions & 0 deletions core/src/main/java/bisq/core/app/BisqHeadlessAppMain.java
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,8 @@

package bisq.core.app;

import bisq.core.payment.TradeLimits;

import bisq.common.UserThread;
import bisq.common.app.AppModule;
import bisq.common.app.Version;
Expand All @@ -31,6 +33,7 @@
@Slf4j
public class BisqHeadlessAppMain extends BisqExecutable {
protected HeadlessApp headlessApp;
private TradeLimits tradeLimits;

public BisqHeadlessAppMain() {
super("Bisq Daemon", "bisqd", "Bisq", Version.VERSION);
Expand Down Expand Up @@ -108,6 +111,9 @@ protected void applyInjector() {

@Override
protected void startApplication() {
// Pin that as it is used in PaymentMethods and verification in TradeStatistics
tradeLimits = injector.getInstance(TradeLimits.class);

// We need to be in user thread! We mapped at launchApplication already...
headlessApp.startApplication();

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@
import bisq.core.dao.node.full.RpcService;
import bisq.core.offer.OpenOfferManager;
import bisq.core.offer.bsq_swap.OpenBsqSwapOfferService;
import bisq.core.payment.TradeLimits;
import bisq.core.support.dispute.arbitration.arbitrator.ArbitratorManager;

import bisq.network.p2p.NodeAddress;
Expand Down Expand Up @@ -62,6 +63,7 @@ public abstract class ExecutableForAppWithP2p extends BisqExecutable {
private static final long SHUTDOWN_INTERVAL = TimeUnit.HOURS.toMillis(24);
private volatile boolean stopped;
private final long startTime = System.currentTimeMillis();
private TradeLimits tradeLimits;

public ExecutableForAppWithP2p(String fullName, String scriptName, String appName, String version) {
super(fullName, scriptName, appName, version);
Expand All @@ -76,6 +78,12 @@ protected void configUserThread() {
UserThread.setExecutor(Executors.newSingleThreadExecutor(threadFactory));
}

@Override
protected void startApplication() {
// Pin that as it is used in PaymentMethods and verification in TradeStatistics
tradeLimits = injector.getInstance(TradeLimits.class);
}

@Override
public void onSetupComplete() {
log.info("onSetupComplete");
Expand Down
2 changes: 2 additions & 0 deletions daemon/src/main/java/bisq/daemon/app/BisqDaemonMain.java
Original file line number Diff line number Diff line change
Expand Up @@ -90,6 +90,8 @@ protected void applyInjector() {

@Override
protected void startApplication() {
super.startApplication();

// We need to be in user thread! We mapped at launchApplication already...
headlessApp.startApplication();

Expand Down
2 changes: 2 additions & 0 deletions seednode/src/main/java/bisq/seednode/SeedNodeMain.java
Original file line number Diff line number Diff line change
Expand Up @@ -137,6 +137,8 @@ private int getMyIndex() {

@Override
protected void startApplication() {
super.startApplication();

Cookie cookie = injector.getInstance(User.class).getCookie();
cookie.getAsOptionalBoolean(CookieKey.CLEAN_TOR_DIR_AT_RESTART).ifPresent(wasCleanTorDirSet -> {
if (wasCleanTorDirSet) {
Expand Down
2 changes: 2 additions & 0 deletions statsnode/src/main/java/bisq/statistics/StatisticsMain.java
Original file line number Diff line number Diff line change
Expand Up @@ -88,6 +88,8 @@ protected void applyInjector() {

@Override
protected void startApplication() {
super.startApplication();

statistics.startApplication();
}
}

0 comments on commit 31c2d62

Please sign in to comment.