Skip to content
This repository has been archived by the owner on Jun 17, 2020. It is now read-only.

Sync up with changes from voting branch #136

Merged
merged 1 commit into from Jul 11, 2018
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.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
Expand Up @@ -15,9 +15,14 @@
* along with Bisq. If not, see <http://www.gnu.org/licenses/>.
*/

package bisq.core.app;
package bisq.core;

import bisq.core.alert.AlertModule;
import bisq.core.app.AppOptionKeys;
import bisq.core.app.BisqEnvironment;
import bisq.core.app.BisqSetup;
import bisq.core.app.P2PNetworkSetup;
import bisq.core.app.WalletAppSetup;
import bisq.core.arbitration.ArbitratorModule;
import bisq.core.btc.BitcoinModule;
import bisq.core.dao.DaoModule;
Expand Down
16 changes: 8 additions & 8 deletions src/main/java/bisq/core/app/BisqEnvironment.java
Expand Up @@ -27,6 +27,7 @@
import bisq.network.NetworkOptionKeys;

import bisq.common.CommonOptionKeys;
import bisq.common.app.DevEnv;
import bisq.common.app.Version;
import bisq.common.crypto.KeyStorage;
import bisq.common.storage.Storage;
Expand Down Expand Up @@ -109,12 +110,7 @@ public static BaseCurrencyNetwork getDefaultBaseCurrencyNetwork() {

public static boolean isDAOActivatedAndBaseCurrencySupportingBsq() {
//noinspection ConstantConditions,PointlessBooleanExpression
return isDAOEnabled() && isBaseCurrencySupportingBsq();
}

public static boolean isDAOEnabled() {
//noinspection ConstantConditions,PointlessBooleanExpression
return !getBaseCurrencyNetwork().isMainnet() && isBaseCurrencySupportingBsq();
return DevEnv.isDaoActivated() && isBaseCurrencySupportingBsq();
}

public static boolean isBaseCurrencySupportingBsq() {
Expand Down Expand Up @@ -195,7 +191,7 @@ 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;
socks5ProxyHttpAddress, useAllProvidedNodes, numConnectionForBtc, genesisTxId, genesisBlockHeight, referralId, daoActivated;


public BisqEnvironment(OptionSet options) {
Expand Down Expand Up @@ -289,6 +285,9 @@ public BisqEnvironment(PropertySource commandLineProperties) {
genesisBlockHeight = commandLineProperties.containsProperty(DaoOptionKeys.GENESIS_BLOCK_HEIGHT) ?
(String) commandLineProperties.getProperty(DaoOptionKeys.GENESIS_BLOCK_HEIGHT) :
"";
daoActivated = commandLineProperties.containsProperty(DaoOptionKeys.DAO_ACTIVATED) ?
(String) commandLineProperties.getProperty(DaoOptionKeys.DAO_ACTIVATED) :
"";

btcNodes = commandLineProperties.containsProperty(BtcOptionKeys.BTC_NODES) ?
(String) commandLineProperties.getProperty(BtcOptionKeys.BTC_NODES) :
Expand Down Expand Up @@ -419,6 +418,7 @@ private PropertySource<?> defaultProperties() {
return new PropertiesPropertySource(BISQ_DEFAULT_PROPERTY_SOURCE_NAME, new Properties() {
{
setProperty(CommonOptionKeys.LOG_LEVEL_KEY, logLevel);
setProperty(CommonOptionKeys.USE_DEV_MODE, useDevMode);

setProperty(NetworkOptionKeys.SEED_NODES_KEY, seedNodes);
setProperty(NetworkOptionKeys.MY_ADDRESS, myAddress);
Expand All @@ -432,7 +432,6 @@ private PropertySource<?> defaultProperties() {
setProperty(AppOptionKeys.IGNORE_DEV_MSG_KEY, ignoreDevMsg);
setProperty(AppOptionKeys.USE_DEV_PRIVILEGE_KEYS, useDevPrivilegeKeys);
setProperty(AppOptionKeys.REFERRAL_ID, referralId);
setProperty(CommonOptionKeys.USE_DEV_MODE, useDevMode);
setProperty(AppOptionKeys.DUMP_STATISTICS, dumpStatistics);
setProperty(AppOptionKeys.APP_NAME_KEY, appName);
setProperty(AppOptionKeys.MAX_MEMORY, maxMemory);
Expand All @@ -447,6 +446,7 @@ private PropertySource<?> defaultProperties() {
setProperty(DaoOptionKeys.FULL_DAO_NODE, fullDaoNode);
setProperty(DaoOptionKeys.GENESIS_TX_ID, genesisTxId);
setProperty(DaoOptionKeys.GENESIS_BLOCK_HEIGHT, genesisBlockHeight);
setProperty(DaoOptionKeys.DAO_ACTIVATED, daoActivated);

setProperty(BtcOptionKeys.BTC_NODES, btcNodes);
setProperty(BtcOptionKeys.USE_TOR_FOR_BTC, useTorForBtc);
Expand Down
23 changes: 22 additions & 1 deletion src/main/java/bisq/core/app/BisqExecutable.java
Expand Up @@ -55,6 +55,8 @@

import com.google.inject.Guice;
import com.google.inject.Injector;
import com.google.inject.Key;
import com.google.inject.name.Names;

import java.nio.file.Files;
import java.nio.file.Path;
Expand Down Expand Up @@ -197,13 +199,18 @@ protected Injector getInjector() {
}

protected void applyInjector() {
DevEnv.setup(injector);
setupDevEnv();

setCorruptedDataBaseFilesHandler();

setupPersistedDataHosts(injector);
}

protected void setupDevEnv() {
DevEnv.setDevMode(injector.getInstance(Key.get(Boolean.class, Names.named(CommonOptionKeys.USE_DEV_MODE))));
DevEnv.setDaoActivated(injector.getInstance(Key.get(Boolean.class, Names.named(DaoOptionKeys.DAO_ACTIVATED))));
}

private void setCorruptedDataBaseFilesHandler() {
CorruptedDatabaseFilesHandler corruptedDatabaseFilesHandler = injector.getInstance(CorruptedDatabaseFilesHandler.class);
Storage.setCorruptedDatabaseFilesHandler(corruptedDatabaseFilesHandler);
Expand All @@ -215,6 +222,16 @@ protected void setupPersistedDataHosts(Injector injector) {

protected abstract void startApplication();

// Once the application is ready we get that callback and we start the setup
protected void onApplicationStarted() {
startAppSetup();
}

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


///////////////////////////////////////////////////////////////////////////////////////////
// GracefulShutDownHandler implementation
Expand Down Expand Up @@ -399,6 +416,10 @@ protected void customizeOptionParsing(OptionParser parser) {
parser.accepts(DaoOptionKeys.GENESIS_BLOCK_HEIGHT,
description("Genesis transaction block height when not using the hard coded one", ""))
.withRequiredArg();
parser.accepts(DaoOptionKeys.DAO_ACTIVATED,
description("Developer flag. If true it enables dao phase 2 features.", false))
.withRequiredArg()
.ofType(boolean.class);
}

public static BisqEnvironment getBisqEnvironment(OptionSet options) {
Expand Down
Expand Up @@ -21,7 +21,6 @@

import bisq.common.UserThread;
import bisq.common.setup.GracefulShutDownHandler;
import bisq.common.setup.UncaughtExceptionHandler;
import bisq.common.storage.CorruptedDatabaseFilesHandler;
import bisq.common.util.Profiler;

Expand All @@ -34,33 +33,33 @@
import lombok.extern.slf4j.Slf4j;

@Slf4j
public class BisqCoreApp implements UncaughtExceptionHandler {
public class BisqHeadlessApp implements HeadlessApp {
private static final long LOG_MEMORY_PERIOD_MIN = 10;
@Getter
private static Runnable shutDownHandler;

@Setter
private Injector injector;
protected Injector injector;
@Setter
private GracefulShutDownHandler gracefulShutDownHandler;
private boolean shutDownRequested;
private BisqSetup bisqSetup;
private CorruptedDatabaseFilesHandler corruptedDatabaseFilesHandler;
private TradeManager tradeManager;

public BisqCoreApp() {
public BisqHeadlessApp() {
shutDownHandler = this::stop;
}


public void startApplication() {
try {
bisqSetup = injector.getInstance(BisqSetup.class);
bisqSetup.addBisqSetupCompleteListener(this);

corruptedDatabaseFilesHandler = injector.getInstance(CorruptedDatabaseFilesHandler.class);
tradeManager = injector.getInstance(TradeManager.class);

setupHandlers();
bisqSetup.start(this::onSetupComplete);

UserThread.runPeriodically(() -> Profiler.printSystemLoad(log), LOG_MEMORY_PERIOD_MIN, TimeUnit.MINUTES);
} catch (Throwable throwable) {
Expand All @@ -69,11 +68,12 @@ public void startApplication() {
}
}

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

private void setupHandlers() {
protected void setupHandlers() {
bisqSetup.setDisplayTacHandler(acceptedHandler -> {
log.info("onDisplayTacHandler: We accept the tacs automatically in headless mode");
acceptedHandler.run();
Expand All @@ -90,8 +90,10 @@ private void setupHandlers() {
bisqSetup.setDisplayPrivateNotificationHandler(privateNotification -> log.info("onDisplayPrivateNotificationHandler. privateNotification={}", privateNotification));
bisqSetup.setDaoSetupErrorHandler(errorMessage -> log.info("onDaoSetupErrorHandler. errorMessage={}", errorMessage));
bisqSetup.setDisplaySecurityRecommendationHandler(key -> log.info("onDisplaySecurityRecommendationHandler"));
bisqSetup.setDisplayLocalhostHandler(key -> log.info("onDisplayLocalhostHandler"));
bisqSetup.setWrongOSArchitectureHandler(msg -> log.info("onWrongOSArchitectureHandler. msg={}", msg));

//TODO move to bisqSetup
corruptedDatabaseFilesHandler.getCorruptedDatabaseFiles().ifPresent(files -> log.info("getCorruptedDatabaseFiles. files={}", files));
tradeManager.setTakeOfferRequestErrorMessageHandler(errorMessage -> log.info("onTakeOfferRequestErrorMessageHandler"));
}
Expand Down
Expand Up @@ -17,6 +17,8 @@

package bisq.core.app;

import bisq.core.CoreModule;

import bisq.common.UserThread;
import bisq.common.app.AppModule;
import bisq.common.setup.CommonSetup;
Expand All @@ -31,16 +33,16 @@
import lombok.extern.slf4j.Slf4j;

@Slf4j
public class BisqCoreAppMain extends BisqExecutable {
private BisqCoreApp application;
public class BisqHeadlessAppMain extends BisqExecutable {
protected HeadlessApp headlessApp;

public static void main(String[] args) throws Exception {
if (BisqExecutable.setupInitialOptionParser(args)) {
// For some reason the JavaFX launch process results in us losing the thread context class loader: reset it.
// In order to work around a bug in JavaFX 8u25 and below, you must include the following code as the first line of your realMain method:
Thread.currentThread().setContextClassLoader(BisqCoreAppMain.class.getClassLoader());
Thread.currentThread().setContextClassLoader(BisqHeadlessAppMain.class.getClassLoader());

new BisqCoreAppMain().execute(args);
new BisqHeadlessAppMain().execute(args);
}
}

Expand All @@ -66,16 +68,16 @@ protected void configUserThread() {

@Override
protected void launchApplication() {
application = new BisqCoreApp();
CommonSetup.setup(BisqCoreAppMain.this.application);
headlessApp = new BisqHeadlessApp();
CommonSetup.setup(BisqHeadlessAppMain.this.headlessApp);

UserThread.execute(this::onApplicationLaunched);
}

@Override
protected void onApplicationLaunched() {
super.onApplicationLaunched();
application.setGracefulShutDownHandler(this);
headlessApp.setGracefulShutDownHandler(this);
}

///////////////////////////////////////////////////////////////////////////////////////////
Expand All @@ -91,18 +93,19 @@ protected AppModule getModule() {
protected void applyInjector() {
super.applyInjector();

application.setInjector(injector);
headlessApp.setInjector(injector);
}

@Override
protected void startApplication() {
// We need to be in user thread! We mapped at launchApplication already...
application.startApplication();

headlessApp.startApplication();

// In headless mode we don't have an async behaviour so we trigger the setup by calling onApplicationStarted
onApplicationStarted();
}

protected void keepRunning() {
private void keepRunning() {
while (true) {
try {
Thread.sleep(Long.MAX_VALUE);
Expand Down