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

Porting Manfred's HTTP API changes from bisq-core to the mono repo #1686

Closed
wants to merge 2 commits into from
Closed
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
2 changes: 2 additions & 0 deletions core/src/main/java/bisq/core/app/AppOptionKeys.java
Original file line number Diff line number Diff line change
Expand Up @@ -29,4 +29,6 @@ public class AppOptionKeys {
public static final String IGNORE_DEV_MSG_KEY = "ignoreDevMsg";
public static final String USE_DEV_PRIVILEGE_KEYS = "useDevPrivilegeKeys";
public static final String REFERRAL_ID = "referralId";
public static final String HTTP_API_HOST = "httpApiHost";
public static final String HTTP_API_PORT = "httpApiPort";
}
12 changes: 10 additions & 2 deletions core/src/main/java/bisq/core/app/BisqEnvironment.java
Original file line number Diff line number Diff line change
Expand Up @@ -193,8 +193,10 @@ private static String appDataDir(String userDataDir, String appName) {
protected final String btcNodes, seedNodes, ignoreDevMsg, useDevPrivilegeKeys, useDevMode, useTorForBtc, rpcUser, rpcPassword,
rpcPort, rpcBlockNotificationPort, dumpBlockchainData, fullDaoNode,
myAddress, banList, dumpStatistics, maxMemory, socks5ProxyBtcAddress,
socks5ProxyHttpAddress, useAllProvidedNodes, numConnectionForBtc, genesisTxId, genesisBlockHeight, referralId, daoActivated;

socks5ProxyHttpAddress, useAllProvidedNodes, numConnectionForBtc, genesisTxId, genesisBlockHeight,
referralId, daoActivated;
@Getter
protected final String httpApiHost, httpApiPort;

public BisqEnvironment(OptionSet options) {
this(new JOptCommandLinePropertySource(BISQ_COMMANDLINE_PROPERTY_SOURCE_NAME, checkNotNull(
Expand Down Expand Up @@ -237,6 +239,12 @@ public BisqEnvironment(PropertySource commandLineProperties) {
referralId = commandLineProperties.containsProperty(AppOptionKeys.REFERRAL_ID) ?
(String) commandLineProperties.getProperty(AppOptionKeys.REFERRAL_ID) :
"";
httpApiHost = commandLineProperties.containsProperty(AppOptionKeys.HTTP_API_HOST) ?
(String) commandLineProperties.getProperty(AppOptionKeys.HTTP_API_HOST) :
"127.0.0.1";
httpApiPort = commandLineProperties.containsProperty(AppOptionKeys.HTTP_API_PORT) ?
(String) commandLineProperties.getProperty(AppOptionKeys.HTTP_API_PORT) :
"8080";
useDevMode = commandLineProperties.containsProperty(CommonOptionKeys.USE_DEV_MODE) ?
(String) commandLineProperties.getProperty(CommonOptionKeys.USE_DEV_MODE) :
"";
Expand Down
11 changes: 10 additions & 1 deletion core/src/main/java/bisq/core/app/BisqExecutable.java
Original file line number Diff line number Diff line change
Expand Up @@ -73,7 +73,7 @@
import static java.lang.String.join;

@Slf4j
public abstract class BisqExecutable implements GracefulShutDownHandler {
public abstract class BisqExecutable implements GracefulShutDownHandler, BisqSetup.BisqSetupCompleteListener {
static {
Utilities.removeCryptographyRestrictions();
}
Expand Down Expand Up @@ -239,9 +239,12 @@ protected void onApplicationStarted() {

protected void startAppSetup() {
BisqSetup bisqSetup = injector.getInstance(BisqSetup.class);
bisqSetup.addBisqSetupCompleteListener(this);
bisqSetup.start();
}

public abstract void onSetupComplete();


///////////////////////////////////////////////////////////////////////////////////////////
// GracefulShutDownHandler implementation
Expand Down Expand Up @@ -360,6 +363,12 @@ protected void customizeOptionParsing(OptionParser parser) {
parser.accepts(AppOptionKeys.REFERRAL_ID,
description("Optional Referral ID (e.g. for API users or pro market makers)", ""))
.withRequiredArg();
parser.accepts(AppOptionKeys.HTTP_API_HOST,
description("Optional HTTP API host", "127.0.0.1"))
.withRequiredArg();
parser.accepts(AppOptionKeys.HTTP_API_PORT,
description("Optional HTTP API port", "8080"))
.withRequiredArg();
parser.accepts(CommonOptionKeys.USE_DEV_MODE,
description("Enables dev mode which is used for convenience for developer testing", false))
.withRequiredArg()
Expand Down
11 changes: 5 additions & 6 deletions core/src/main/java/bisq/core/app/BisqFacade.java
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@

package bisq.core.app;

import bisq.core.btc.BalanceModel;
import bisq.core.btc.Balances;
import bisq.core.presentation.BalancePresentation;

import bisq.common.app.Version;
Expand All @@ -29,12 +29,12 @@
* E.g. useful for different APIs to access data of different domains of Bisq.
*/
public class BisqFacade {
private final BalanceModel balanceModel;
private final Balances balances;
private final BalancePresentation balancePresentation;

@Inject
public BisqFacade(BalanceModel balanceModel, BalancePresentation balancePresentation) {
this.balanceModel = balanceModel;
public BisqFacade(Balances balances, BalancePresentation balancePresentation) {
this.balances = balances;
this.balancePresentation = balancePresentation;
}

Expand All @@ -43,8 +43,7 @@ public String getVersion() {
}

public long getAvailableBalance() {
balanceModel.updateBalance();
return balanceModel.getAvailableBalance().get().getValue();
return balances.getAvailableBalance().get().getValue();
}

public String getAvailableBalanceAsString() {
Expand Down
1 change: 0 additions & 1 deletion core/src/main/java/bisq/core/app/BisqHeadlessApp.java
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,6 @@ public BisqHeadlessApp() {
public void startApplication() {
try {
bisqSetup = injector.getInstance(BisqSetup.class);
bisqSetup.addBisqSetupCompleteListener(this);

corruptedDatabaseFilesHandler = injector.getInstance(CorruptedDatabaseFilesHandler.class);
tradeManager = injector.getInstance(TradeManager.class);
Expand Down
5 changes: 5 additions & 0 deletions core/src/main/java/bisq/core/app/BisqHeadlessAppMain.java
Original file line number Diff line number Diff line change
Expand Up @@ -80,6 +80,11 @@ protected void onApplicationLaunched() {
headlessApp.setGracefulShutDownHandler(this);
}

@Override
public void onSetupComplete() {
log.info("onSetupComplete");
}

///////////////////////////////////////////////////////////////////////////////////////////
// We continue with a series of synchronous execution tasks
///////////////////////////////////////////////////////////////////////////////////////////
Expand Down
32 changes: 5 additions & 27 deletions core/src/main/java/bisq/core/app/BisqSetup.java
Original file line number Diff line number Diff line change
Expand Up @@ -24,8 +24,7 @@
import bisq.core.arbitration.ArbitratorManager;
import bisq.core.arbitration.DisputeManager;
import bisq.core.btc.AddressEntry;
import bisq.core.btc.BalanceModel;
import bisq.core.btc.listeners.BalanceListener;
import bisq.core.btc.Balances;
import bisq.core.btc.wallet.BtcWalletService;
import bisq.core.btc.wallet.WalletsManager;
import bisq.core.btc.wallet.WalletsSetup;
Expand All @@ -38,14 +37,12 @@
import bisq.core.notifications.alerts.TradeEvents;
import bisq.core.notifications.alerts.market.MarketAlerts;
import bisq.core.notifications.alerts.price.PriceAlert;
import bisq.core.offer.OpenOffer;
import bisq.core.offer.OpenOfferManager;
import bisq.core.payment.AccountAgeWitnessService;
import bisq.core.payment.PaymentAccount;
import bisq.core.payment.payload.PaymentMethod;
import bisq.core.provider.fee.FeeService;
import bisq.core.provider.price.PriceFeedService;
import bisq.core.trade.Trade;
import bisq.core.trade.TradeManager;
import bisq.core.trade.statistics.TradeStatisticsManager;
import bisq.core.user.Preferences;
Expand All @@ -68,7 +65,6 @@
import bisq.common.util.Utilities;

import org.bitcoinj.core.Coin;
import org.bitcoinj.core.Transaction;

import javax.inject.Inject;

Expand All @@ -83,7 +79,6 @@
import javafx.beans.property.StringProperty;
import javafx.beans.value.ChangeListener;

import javafx.collections.ListChangeListener;
import javafx.collections.SetChangeListener;

import org.spongycastle.crypto.params.KeyParameter;
Expand Down Expand Up @@ -120,7 +115,7 @@ public interface BisqSetupCompleteListener {
private final WalletsManager walletsManager;
private final WalletsSetup walletsSetup;
private final BtcWalletService btcWalletService;
private final BalanceModel balanceModel;
private final Balances balances;
private final PriceFeedService priceFeedService;
private final ArbitratorManager arbitratorManager;
private final P2PService p2PService;
Expand Down Expand Up @@ -189,7 +184,7 @@ public BisqSetup(P2PNetworkSetup p2PNetworkSetup,
WalletsManager walletsManager,
WalletsSetup walletsSetup,
BtcWalletService btcWalletService,
BalanceModel balanceModel,
Balances balances,
PriceFeedService priceFeedService,
ArbitratorManager arbitratorManager,
P2PService p2PService,
Expand Down Expand Up @@ -224,7 +219,7 @@ public BisqSetup(P2PNetworkSetup p2PNetworkSetup,
this.walletsManager = walletsManager;
this.walletsSetup = walletsSetup;
this.btcWalletService = btcWalletService;
this.balanceModel = balanceModel;
this.balances = balances;
this.priceFeedService = priceFeedService;
this.arbitratorManager = arbitratorManager;
this.p2PService = p2PService;
Expand Down Expand Up @@ -568,29 +563,12 @@ private void initDomainServices() {
disputeManager.onAllServicesInitialized();

tradeManager.onAllServicesInitialized();
tradeManager.getTradableList().addListener((ListChangeListener<Trade>) change -> balanceModel.updateBalance());
tradeManager.getAddressEntriesForAvailableBalanceStream()
.filter(addressEntry -> addressEntry.getOfferId() != null)
.forEach(addressEntry -> {
log.debug("swapPendingOfferFundingEntries, offerId={}, OFFER_FUNDING", addressEntry.getOfferId());
btcWalletService.swapTradeEntryToAvailableEntry(addressEntry.getOfferId(), AddressEntry.Context.OFFER_FUNDING);
});

btcWalletService.addBalanceListener(new BalanceListener() {
@Override
public void onBalanceChanged(Coin balance, Transaction tx) {
balanceModel.updateBalance();
}
});

if (walletsSetup.downloadPercentageProperty().get() == 1)
checkForLockedUpFunds();

balanceModel.updateBalance();

openOfferManager.getObservableList().addListener((ListChangeListener<OpenOffer>) c -> balanceModel.updateBalance());
openOfferManager.onAllServicesInitialized();

balances.onAllServicesInitialized();
arbitratorManager.onAllServicesInitialized();

alertManager.alertMessageProperty().addListener((observable, oldValue, newValue) ->
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -60,6 +60,11 @@ protected void configUserThread() {
UserThread.setExecutor(Executors.newSingleThreadExecutor(threadFactory));
}

@Override
public void onSetupComplete() {
log.info("onSetupComplete");
}

// We don't use the gracefulShutDown implementation of the super class as we have a limited set of modules
@Override
public void gracefulShutDown(ResultHandler resultHandler) {
Expand Down
116 changes: 0 additions & 116 deletions core/src/main/java/bisq/core/btc/BalanceModel.java

This file was deleted.

Loading