Merge pull request #1726 from ManfredKarrer/master

Small improvements
This commit is contained in:
Christoph Atteneder 2018-09-26 08:30:15 +02:00 committed by GitHub
commit ede420375f
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
14 changed files with 92 additions and 56 deletions

View file

@ -1,5 +1,6 @@
<component name="ProjectCodeStyleConfiguration">
<state>
<option name="USE_PER_PROJECT_SETTINGS" value="true" />
<option name="PREFERRED_PROJECT_CODE_STYLE" value="Default" />
</state>
</component>

View file

@ -18,6 +18,7 @@
package bisq.core.app;
import bisq.core.arbitration.ArbitratorManager;
import bisq.core.btc.BaseCurrencyNetwork;
import bisq.core.btc.BtcOptionKeys;
import bisq.core.btc.setup.RegTestHost;
import bisq.core.btc.setup.WalletsSetup;
@ -208,7 +209,11 @@ public abstract class BisqExecutable implements GracefulShutDownHandler {
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))));
BaseCurrencyNetwork baseCurrencyNetwork = BisqEnvironment.getBaseCurrencyNetwork();
boolean isRegTestOrTestNet = (baseCurrencyNetwork.isTestnet() || baseCurrencyNetwork.isRegtest());
boolean isDaoActivatedOptionSet = injector.getInstance(Key.get(Boolean.class, Names.named(DaoOptionKeys.DAO_ACTIVATED)));
DevEnv.setDaoActivated(isDaoActivatedOptionSet || isRegTestOrTestNet);
}
private void setCorruptedDataBaseFilesHandler() {

View file

@ -67,6 +67,10 @@ public enum BaseCurrencyNetwork {
return "MAINNET".equals(network);
}
public boolean isTestnet() {
return "TESTNET".equals(network);
}
public boolean isRegtest() {
return "REGTEST".equals(network);
}

View file

@ -122,7 +122,7 @@ public class BlockParser {
private void validateIfBlockIsConnecting(RawBlock rawBlock) throws BlockNotConnectingException {
LinkedList<Block> blocks = bsqStateService.getBlocks();
if (!isBlockConnecting(rawBlock, blocks)) {
final Block last = blocks.getLast();
Block last = blocks.getLast();
log.warn("addBlock called with a not connecting block. New block:\n" +
"height()={}, hash()={}, lastBlock.height()={}, lastBlock.hash()={}",
rawBlock.getHeight(),

View file

@ -17,6 +17,8 @@
package bisq.core.dao.state;
import bisq.core.app.BisqEnvironment;
import bisq.core.btc.BaseCurrencyNetwork;
import bisq.core.dao.DaoOptionKeys;
import org.bitcoinj.core.Coin;
@ -45,8 +47,11 @@ public class GenesisTxInfo {
public static final Coin GENESIS_TOTAL_SUPPLY = Coin.parseCoin("2.5");
private static final String DEFAULT_GENESIS_TX_ID = "81855816eca165f17f0668898faa8724a105196e90ffc4993f4cac980176674e";
private static final int DEFAULT_GENESIS_BLOCK_HEIGHT = 524717; // 2018-05-27
private static final String MAINNET_GENESIS_TX_ID = "81855816eca165f17f0668898faa8724a105196e90ffc4993f4cac980176674e";
private static final int MAINNET_GENESIS_BLOCK_HEIGHT = 524717; // 2018-05-27
private static final String TESTNET_GENESIS_TX_ID = "7085539068b4fc27dfc6c39b0feae2adc7fe20f925e79ca0ba064725fe6c9991";
private static final int TESTNET_GENESIS_BLOCK_HEIGHT = 1414332; // 2018-09-25
///////////////////////////////////////////////////////////////////////////////////////////
@ -60,14 +65,6 @@ public class GenesisTxInfo {
@Getter
private final int genesisBlockHeight;
//TODO not sure if we will use that
/* private static final int ISSUANCE_MATURITY = 144 * 30; // 30 days
static int getIssuanceMaturity() {
return ISSUANCE_MATURITY;
}*/
// mainnet
// this tx has a lot of outputs
// https://blockchain.info/de/tx/ee921650ab3f978881b8fe291e0c025e0da2b7dc684003d7a03d9649dfee2e15
@ -85,7 +82,6 @@ public class GenesisTxInfo {
// private static final String DEFAULT_GENESIS_TX_ID = "--";
// private static final int DEFAULT_GENESIS_BLOCK_HEIGHT = 499000; // recursive test 137298, 499000 dec 2017
///////////////////////////////////////////////////////////////////////////////////////////
// Constructor
///////////////////////////////////////////////////////////////////////////////////////////
@ -93,7 +89,27 @@ public class GenesisTxInfo {
@Inject
public GenesisTxInfo(@Nullable @Named(DaoOptionKeys.GENESIS_TX_ID) String genesisTxId,
@Named(DaoOptionKeys.GENESIS_BLOCK_HEIGHT) int genesisBlockHeight) {
this.genesisTxId = genesisTxId != null ? genesisTxId : DEFAULT_GENESIS_TX_ID;
this.genesisBlockHeight = genesisBlockHeight != 0 ? genesisBlockHeight : DEFAULT_GENESIS_BLOCK_HEIGHT;
BaseCurrencyNetwork baseCurrencyNetwork = BisqEnvironment.getBaseCurrencyNetwork();
boolean isMainnet = baseCurrencyNetwork.isMainnet();
boolean isTestnet = baseCurrencyNetwork.isTestnet();
if (genesisTxId != null && !genesisTxId.isEmpty()) {
this.genesisTxId = genesisTxId;
} else if (isMainnet) {
this.genesisTxId = MAINNET_GENESIS_TX_ID;
} else if (isTestnet) {
this.genesisTxId = TESTNET_GENESIS_TX_ID;
} else {
this.genesisTxId = "genesisTxId is undefined";
}
if (genesisBlockHeight != 0) {
this.genesisBlockHeight = genesisBlockHeight;
} else if (isMainnet) {
this.genesisBlockHeight = MAINNET_GENESIS_BLOCK_HEIGHT;
} else if (isTestnet) {
this.genesisBlockHeight = TESTNET_GENESIS_BLOCK_HEIGHT;
} else {
this.genesisBlockHeight = 0;
}
}
}

View file

@ -45,6 +45,7 @@ public class SnapshotManager implements BsqStateListener {
private final BsqState bsqState;
private final BsqStateService bsqStateService;
private final GenesisTxInfo genesisTxInfo;
private final Storage<BsqState> storage;
private BsqState snapshotCandidate;
@ -53,9 +54,11 @@ public class SnapshotManager implements BsqStateListener {
public SnapshotManager(BsqState bsqState,
BsqStateService bsqStateService,
PersistenceProtoResolver persistenceProtoResolver,
GenesisTxInfo genesisTxInfo,
@Named(Storage.STORAGE_DIR) File storageDir) {
this.bsqState = bsqState;
this.bsqStateService = bsqStateService;
this.genesisTxInfo = genesisTxInfo;
storage = new Storage<>(storageDir, persistenceProtoResolver);
this.bsqStateService.addBsqStateListener(this);
@ -80,7 +83,8 @@ public class SnapshotManager implements BsqStateListener {
if (snapshotCandidate != null) {
// We clone because storage is in a threaded context
final BsqState cloned = bsqState.getClone(snapshotCandidate);
storage.queueUpForSave(cloned);
if (cloned.getBlocks().getLast().getHeight() >= genesisTxInfo.getGenesisBlockHeight())
storage.queueUpForSave(cloned);
log.info("Saved snapshotCandidate to Disc at height " + chainHeadHeight);
}
// Now we clone and keep it in memory for the next trigger
@ -104,7 +108,8 @@ public class SnapshotManager implements BsqStateListener {
BsqState persisted = storage.initAndGetPersisted(bsqState, 100);
if (persisted != null) {
log.info("applySnapshot persisted.chainHeadHeight=" + new LinkedList<>(persisted.getBlocks()).getLast().getHeight());
bsqStateService.applySnapshot(persisted);
if (persisted.getBlocks().getLast().getHeight() >= genesisTxInfo.getGenesisBlockHeight())
bsqStateService.applySnapshot(persisted);
} else {
log.info("Try to apply snapshot but no stored snapshot available");
}

View file

@ -17,17 +17,15 @@
package bisq.core.dao.state.period;
import bisq.core.dao.DaoOptionKeys;
import bisq.core.dao.DaoSetupService;
import bisq.core.dao.state.BsqStateListener;
import bisq.core.dao.state.BsqStateService;
import bisq.core.dao.state.GenesisTxInfo;
import bisq.core.dao.state.blockchain.Block;
import bisq.core.dao.state.governance.Param;
import com.google.inject.Inject;
import javax.inject.Named;
import com.google.common.collect.ImmutableList;
import java.util.Arrays;
@ -51,9 +49,9 @@ public class CycleService implements BsqStateListener, DaoSetupService {
@Inject
public CycleService(BsqStateService bsqStateService,
@Named(DaoOptionKeys.GENESIS_BLOCK_HEIGHT) int genesisBlockHeight) {
GenesisTxInfo genesisTxInfo) {
this.bsqStateService = bsqStateService;
this.genesisBlockHeight = genesisBlockHeight;
this.genesisBlockHeight = genesisTxInfo.getGenesisBlockHeight();
}

View file

@ -79,8 +79,9 @@ class DefaultSeedNodeAddresses {
// new NodeAddress("uqxi3zrpobhtoes6.onion:8000"),
// BTC testnet
new NodeAddress("nbphlanpgbei4okt.onion:8001"),
// new NodeAddress("vjkh4ykq7x5skdlt.onion:8001"), // dev test
new NodeAddress("nbphlanpgbei4okt.onion:8001"), // 88.99.216.98
new NodeAddress("o5qw2hy6l7jsf654.onion:8001"), // explorer node
new NodeAddress("vjkh4ykq7x5skdlt.onion:8001"), // local dev test
// BTC regtest
// For development you need to change that to your local onion addresses

View file

@ -854,7 +854,7 @@ setting.preferences.resetAllFlags=Reset all \"Don't show again\" flags:
setting.preferences.reset=Reset
settings.preferences.languageChange=To apply the language change to all screens requires a restart.
settings.preferences.arbitrationLanguageWarning=In case of a dispute, please note that arbitration is handled in {0}.
settings.preferences.selectCurrencyNetwork=Select base currency
settings.preferences.selectCurrencyNetwork=Select network
settings.net.btcHeader=Bitcoin network
settings.net.p2pHeader=P2P network

View file

@ -46,6 +46,7 @@ public class SnapshotManagerTest {
snapshotManager = new SnapshotManager(mock(BsqState.class),
mock(BsqStateService.class),
mock(PersistenceProtoResolver.class),
mock(GenesisTxInfo.class),
mock(File.class));
}

View file

@ -17,7 +17,6 @@
package bisq.desktop.app;
import bisq.desktop.SystemTray;
import bisq.desktop.common.view.CachingViewLoader;
import bisq.desktop.common.view.View;
import bisq.desktop.common.view.ViewLoader;
@ -35,6 +34,7 @@ import bisq.desktop.util.ImageUtil;
import bisq.core.alert.AlertManager;
import bisq.core.app.AppOptionKeys;
import bisq.core.app.AvoidStandbyMode;
import bisq.core.app.BisqEnvironment;
import bisq.core.btc.wallet.BtcWalletService;
import bisq.core.btc.wallet.WalletsManager;
import bisq.core.filter.FilterManager;
@ -219,6 +219,10 @@ public class BisqApp extends Application implements UncaughtExceptionHandler {
// configure the primary stage
String appName = injector.getInstance(Key.get(String.class, Names.named(AppOptionKeys.APP_NAME_KEY)));
if (BisqEnvironment.getBaseCurrencyNetwork().isTestnet())
appName += " [TESTNET]";
else if (BisqEnvironment.getBaseCurrencyNetwork().isRegtest())
appName += " [REGTEST]";
stage.setTitle(appName);
stage.setScene(scene);
stage.setMinWidth(1020);

View file

@ -15,7 +15,7 @@
* along with Bisq. If not, see <http://www.gnu.org/licenses/>.
*/
package bisq.desktop;
package bisq.desktop.app;
import bisq.desktop.util.GUIUtil;
import bisq.desktop.util.ImageUtil;

View file

@ -47,7 +47,8 @@ public class CycleListItem {
public String getCycle() {
int displayIndex = resultsOfCycle.getCycleIndex() + 1;
String dateTime = bsqFormatter.formatDateTime(new Date(resultsOfCycle.getCycleStartTime()));
long cycleStartTime = resultsOfCycle.getCycleStartTime();
String dateTime = cycleStartTime > 0 ? bsqFormatter.formatDateTime(new Date(cycleStartTime)) : Res.get("shared.na");
return Res.get("dao.results.results.table.item.cycle", displayIndex, dateTime);
}

View file

@ -17,6 +17,7 @@
package bisq.desktop.main.settings.preferences;
import bisq.desktop.app.BisqApp;
import bisq.desktop.common.view.ActivatableViewAndModel;
import bisq.desktop.common.view.FxmlView;
import bisq.desktop.components.AutoTooltipButton;
@ -45,7 +46,6 @@ import bisq.core.user.Preferences;
import bisq.core.util.BSFormatter;
import bisq.common.UserThread;
import bisq.common.app.DevEnv;
import bisq.common.util.Tuple2;
import bisq.common.util.Tuple3;
@ -92,7 +92,7 @@ public class PreferencesView extends ActivatableViewAndModel<GridPane, Preferenc
private ComboBox<String> userLanguageComboBox;
private ComboBox<Country> userCountryComboBox;
private ComboBox<TradeCurrency> preferredTradeCurrencyComboBox;
// private ComboBox<BaseCurrencyNetwork> selectBaseCurrencyNetworkComboBox;
private ComboBox<BaseCurrencyNetwork> selectBaseCurrencyNetworkComboBox;
private CheckBox useAnimationsCheckBox, autoSelectArbitratorsCheckBox, avoidStandbyModeCheckBox,
showOwnOffersInOfferBook, sortMarketCurrenciesNumericallyCheckBox, useCustomFeeCheckbox;
@ -102,6 +102,7 @@ public class PreferencesView extends ActivatableViewAndModel<GridPane, Preferenc
private final Preferences preferences;
private final FeeService feeService;
private final ReferralIdService referralIdService;
private final BisqEnvironment bisqEnvironment;
private final BSFormatter formatter;
private ListView<FiatCurrency> fiatCurrenciesListView;
@ -129,12 +130,13 @@ public class PreferencesView extends ActivatableViewAndModel<GridPane, Preferenc
///////////////////////////////////////////////////////////////////////////////////////////
@Inject
public PreferencesView(PreferencesViewModel model, Preferences preferences, FeeService feeService, ReferralIdService referralIdService,
BSFormatter formatter) {
public PreferencesView(PreferencesViewModel model, Preferences preferences, FeeService feeService,
ReferralIdService referralIdService, BisqEnvironment bisqEnvironment, BSFormatter formatter) {
super(model);
this.preferences = preferences;
this.feeService = feeService;
this.referralIdService = referralIdService;
this.bisqEnvironment = bisqEnvironment;
this.formatter = formatter;
}
@ -178,28 +180,29 @@ public class PreferencesView extends ActivatableViewAndModel<GridPane, Preferenc
///////////////////////////////////////////////////////////////////////////////////////////
private void initializeGeneralOptions() {
TitledGroupBg titledGroupBg = addTitledGroupBg(root, gridRow, 9, Res.get("setting.preferences.general"));
TitledGroupBg titledGroupBg = addTitledGroupBg(root, gridRow, 10, Res.get("setting.preferences.general"));
GridPane.setColumnSpan(titledGroupBg, 4);
// selectBaseCurrencyNetwork
/* selectBaseCurrencyNetworkComboBox = addLabelComboBox(root, gridRow,
selectBaseCurrencyNetworkComboBox = FormBuilder.<BaseCurrencyNetwork>addLabelComboBox(root, gridRow,
Res.getWithCol("settings.preferences.selectCurrencyNetwork"), Layout.FIRST_ROW_DISTANCE).second;
selectBaseCurrencyNetworkComboBox.setConverter(new StringConverter<BaseCurrencyNetwork>() {
selectBaseCurrencyNetworkComboBox.setConverter(new StringConverter<>() {
@Override
public String toString(BaseCurrencyNetwork baseCurrencyNetwork) {
return DevEnv.isDevMode() ? (baseCurrencyNetwork.getCurrencyName() + "_" + baseCurrencyNetwork.getNetwork()) :
baseCurrencyNetwork.getCurrencyName();
return baseCurrencyNetwork != null ?
(baseCurrencyNetwork.getCurrencyName() + "_" + baseCurrencyNetwork.getNetwork())
: "";
}
@Override
public BaseCurrencyNetwork fromString(String string) {
return null;
}
});*/
});
userLanguageComboBox = FormBuilder.<String>addLabelComboBox(root, gridRow,
Res.getWithCol("shared.language"), Layout.FIRST_ROW_DISTANCE).second;
userLanguageComboBox = FormBuilder.<String>addLabelComboBox(root, ++gridRow,
Res.getWithCol("shared.language")).second;
userCountryComboBox = FormBuilder.<Country>addLabelComboBox(root, ++gridRow,
Res.getWithCol("shared.country")).second;
blockChainExplorerComboBox = FormBuilder.<BlockChainExplorer>addLabelComboBox(root, ++gridRow,
@ -472,17 +475,14 @@ public class PreferencesView extends ActivatableViewAndModel<GridPane, Preferenc
private void activateGeneralOptions() {
List<BaseCurrencyNetwork> baseCurrencyNetworks = Arrays.asList(BaseCurrencyNetwork.values());
// We don't support Dash anymore due lack of activity but leave it in the code in case it will get
// re-activated some day
// show ony mainnet in production version
if (!DevEnv.isDevMode())
baseCurrencyNetworks = baseCurrencyNetworks.stream()
.filter(e -> !e.isDash())
.filter(BaseCurrencyNetwork::isMainnet)
.collect(Collectors.toList());
/* selectBaseCurrencyNetworkComboBox.setItems(FXCollections.observableArrayList(baseCurrencyNetworks));
// We allow switching to testnet to make it easier for users to test the testnet DAO version
baseCurrencyNetworks = baseCurrencyNetworks.stream()
.filter(BaseCurrencyNetwork::isBitcoin)
.filter(e -> !e.isRegtest())
.collect(Collectors.toList());
selectBaseCurrencyNetworkComboBox.setItems(FXCollections.observableArrayList(baseCurrencyNetworks));
selectBaseCurrencyNetworkComboBox.setOnAction(e -> onSelectNetwork());
selectBaseCurrencyNetworkComboBox.getSelectionModel().select(BisqEnvironment.getBaseCurrencyNetwork());*/
selectBaseCurrencyNetworkComboBox.getSelectionModel().select(BisqEnvironment.getBaseCurrencyNetwork());
boolean useCustomWithdrawalTxFee = preferences.isUseCustomWithdrawalTxFee();
useCustomFeeCheckbox.setSelected(useCustomWithdrawalTxFee);
@ -658,29 +658,29 @@ public class PreferencesView extends ActivatableViewAndModel<GridPane, Preferenc
avoidStandbyModeCheckBox.setOnAction(e -> preferences.setUseStandbyMode(!avoidStandbyModeCheckBox.isSelected()));
}
/* private void onSelectNetwork() {
private void onSelectNetwork() {
if (selectBaseCurrencyNetworkComboBox.getSelectionModel().getSelectedItem() != BisqEnvironment.getBaseCurrencyNetwork())
selectNetwork();
}*/
}
/* private void selectNetwork() {
private void selectNetwork() {
new Popup().warning(Res.get("settings.net.needRestart"))
.onAction(() -> {
bisqEnvironment.saveBaseCryptoNetwork(selectBaseCurrencyNetworkComboBox.getSelectionModel().getSelectedItem());
UserThread.runAfter(BisqApp.getShutDownHandler()::run, 500, TimeUnit.MILLISECONDS);
UserThread.runAfter(BisqApp.getShutDownHandler(), 500, TimeUnit.MILLISECONDS);
})
.actionButtonText(Res.get("shared.shutDown"))
.closeButtonText(Res.get("shared.cancel"))
.onClose(() -> selectBaseCurrencyNetworkComboBox.getSelectionModel().select(BisqEnvironment.getBaseCurrencyNetwork()))
.show();
}*/
}
///////////////////////////////////////////////////////////////////////////////////////////
// Deactivate
///////////////////////////////////////////////////////////////////////////////////////////
private void deactivateGeneralOptions() {
// selectBaseCurrencyNetworkComboBox.setOnAction(null);
selectBaseCurrencyNetworkComboBox.setOnAction(null);
userLanguageComboBox.setOnAction(null);
userCountryComboBox.setOnAction(null);
blockChainExplorerComboBox.setOnAction(null);