Skip to content

Commit

Permalink
Add DAO resync option to preferences
Browse files Browse the repository at this point in the history
  • Loading branch information
ManfredKarrer committed Oct 18, 2018
1 parent 10fcd62 commit b47678d
Show file tree
Hide file tree
Showing 4 changed files with 54 additions and 5 deletions.
10 changes: 9 additions & 1 deletion core/src/main/java/bisq/core/dao/DaoFacade.java
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,7 @@
import bisq.core.dao.governance.role.BondedRolesService;
import bisq.core.dao.state.DaoStateListener;
import bisq.core.dao.state.DaoStateService;
import bisq.core.dao.state.DaoStateStorageService;
import bisq.core.dao.state.blockchain.Block;
import bisq.core.dao.state.blockchain.Tx;
import bisq.core.dao.state.blockchain.TxOutput;
Expand Down Expand Up @@ -107,6 +108,7 @@ public class DaoFacade implements DaoSetupService {
private final BondedRolesService bondedRolesService;
private final LockupService lockupService;
private final UnlockService unlockService;
private final DaoStateStorageService daoStateStorageService;

private final ObjectProperty<DaoPhase.Phase> phaseProperty = new SimpleObjectProperty<>(DaoPhase.Phase.UNDEFINED);

Expand All @@ -127,7 +129,8 @@ public DaoFacade(MyProposalListService myProposalListService,
RemoveAssetProposalService removeAssetProposalService,
BondedRolesService bondedRolesService,
LockupService lockupService,
UnlockService unlockService) {
UnlockService unlockService,
DaoStateStorageService daoStateStorageService) {
this.proposalListPresentation = proposalListPresentation;
this.ballotListService = ballotListService;
this.ballotListPresentation = ballotListPresentation;
Expand All @@ -145,6 +148,7 @@ public DaoFacade(MyProposalListService myProposalListService,
this.bondedRolesService = bondedRolesService;
this.lockupService = lockupService;
this.unlockService = unlockService;
this.daoStateStorageService = daoStateStorageService;
}


Expand Down Expand Up @@ -522,4 +526,8 @@ public Coin getMaxCompensationRequestAmount() {
public long getPramValue(Param param) {
return daoStateService.getParamValue(param, periodService.getChainHeight());
}

public void resyncDao(Runnable resultHandler) {
daoStateStorageService.resetDaoState(resultHandler);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -20,13 +20,16 @@
import bisq.network.p2p.storage.persistence.ResourceDataStoreService;
import bisq.network.p2p.storage.persistence.StoreService;

import bisq.common.UserThread;
import bisq.common.storage.Storage;

import javax.inject.Inject;
import javax.inject.Named;

import java.io.File;

import java.util.concurrent.TimeUnit;

import lombok.extern.slf4j.Slf4j;

/**
Expand Down Expand Up @@ -65,14 +68,23 @@ public String getFileName() {
}

public void persist(DaoState daoState) {
persist(daoState, 200);
}

public void persist(DaoState daoState, long delayInMilli) {
store.setDaoState(daoState);
storage.queueUpForSave(store);
storage.queueUpForSave(store, delayInMilli);
}

public DaoState getPersistedBsqState() {
return store.getDaoState();
}

public void resetDaoState(Runnable resultHandler) {
persist(new DaoState(), 1);
UserThread.runAfter(resultHandler::run, 300, TimeUnit.MILLISECONDS);
}


///////////////////////////////////////////////////////////////////////////////////////////
// Protected
Expand Down
4 changes: 4 additions & 0 deletions core/src/main/resources/i18n/displayStrings.properties
Original file line number Diff line number Diff line change
Expand Up @@ -855,6 +855,10 @@ 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 network
setting.preferences.daoOptions=DAO options
setting.preferences.dao.resync.label=Rebuild DAO state from genesis tx:
setting.preferences.dao.resync.button=Resync
setting.preferences.dao.resync.popup=After an application restart the BSQ consensus state will be rebuilt from the genesis transaction.

settings.net.btcHeader=Bitcoin network
settings.net.p2pHeader=P2P network
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@

import bisq.core.app.BisqEnvironment;
import bisq.core.btc.BaseCurrencyNetwork;
import bisq.core.dao.DaoFacade;
import bisq.core.dao.governance.asset.AssetService;
import bisq.core.locale.Country;
import bisq.core.locale.CountryUtil;
Expand Down Expand Up @@ -105,13 +106,14 @@ public class PreferencesView extends ActivatableViewAndModel<GridPane, Preferenc
private final ReferralIdService referralIdService;
private final BisqEnvironment bisqEnvironment;
private final AssetService assetService;
private final DaoFacade daoFacade;
private final BSFormatter formatter;

private ListView<FiatCurrency> fiatCurrenciesListView;
private ComboBox<FiatCurrency> fiatCurrenciesComboBox;
private ListView<CryptoCurrency> cryptoCurrenciesListView;
private ComboBox<CryptoCurrency> cryptoCurrenciesComboBox;
private Button resetDontShowAgainButton;
private Button resetDontShowAgainButton, resyncDaoButton;
// private ListChangeListener<TradeCurrency> displayCurrenciesListChangeListener;
private ObservableList<BlockChainExplorer> blockExplorers;
private ObservableList<String> languageCodes;
Expand All @@ -134,13 +136,14 @@ public class PreferencesView extends ActivatableViewAndModel<GridPane, Preferenc
@Inject
public PreferencesView(PreferencesViewModel model, Preferences preferences, FeeService feeService,
ReferralIdService referralIdService, BisqEnvironment bisqEnvironment,
AssetService assetService, BSFormatter formatter) {
AssetService assetService, DaoFacade daoFacade, BSFormatter formatter) {
super(model);
this.preferences = preferences;
this.feeService = feeService;
this.referralIdService = referralIdService;
this.bisqEnvironment = bisqEnvironment;
this.assetService = assetService;
this.daoFacade = daoFacade;
this.formatter = formatter;
}

Expand All @@ -159,6 +162,7 @@ public void initialize() {
initializeGeneralOptions();
initializeDisplayCurrencies();
initializeDisplayOptions();
initializeDaoOptions();
}


Expand All @@ -171,13 +175,15 @@ protected void activate() {
activateGeneralOptions();
activateDisplayCurrencies();
activateDisplayPreferences();
activateDaoPreferences();
}

@Override
protected void deactivate() {
deactivateGeneralOptions();
deactivateDisplayCurrencies();
deactivateDisplayPreferences();
deactivateDaoPreferences();
}

///////////////////////////////////////////////////////////////////////////////////////////
Expand Down Expand Up @@ -482,7 +488,6 @@ public CryptoCurrency fromString(String s) {
});
}


private void initializeDisplayOptions() {
TitledGroupBg titledGroupBg = addTitledGroupBg(root, ++gridRow, 4, Res.get("setting.preferences.displayOptions"), Layout.GROUP_DISTANCE);
GridPane.setColumnSpan(titledGroupBg, 4);
Expand All @@ -495,6 +500,13 @@ private void initializeDisplayOptions() {
Res.get("setting.preferences.reset"), 0).second;
}

private void initializeDaoOptions() {
TitledGroupBg titledGroupBg = addTitledGroupBg(root, ++gridRow, 1, Res.get("setting.preferences.daoOptions"), Layout.GROUP_DISTANCE);
GridPane.setColumnSpan(titledGroupBg, 4);
resyncDaoButton = addLabelButton(root, gridRow, Res.get("setting.preferences.dao.resync.label"),
Res.get("setting.preferences.dao.resync.button"), Layout.FIRST_ROW_AND_GROUP_DISTANCE).second;
}

///////////////////////////////////////////////////////////////////////////////////////////
// Activate
///////////////////////////////////////////////////////////////////////////////////////////
Expand Down Expand Up @@ -682,6 +694,15 @@ private void activateDisplayPreferences() {
avoidStandbyModeCheckBox.setOnAction(e -> preferences.setUseStandbyMode(!avoidStandbyModeCheckBox.isSelected()));
}

private void activateDaoPreferences() {
resyncDaoButton.setOnAction(e -> daoFacade.resyncDao(() -> {
new Popup<>().attention(Res.get("setting.preferences.dao.resync.popup"))
.useShutDownButton()
.hideCloseButton()
.show();
}));
}

private void onSelectNetwork() {
if (selectBaseCurrencyNetworkComboBox.getSelectionModel().getSelectedItem() != BisqEnvironment.getBaseCurrencyNetwork())
selectNetwork();
Expand Down Expand Up @@ -730,4 +751,8 @@ private void deactivateDisplayPreferences() {
resetDontShowAgainButton.setOnAction(null);
avoidStandbyModeCheckBox.setOnAction(null);
}

private void deactivateDaoPreferences() {
resyncDaoButton.setOnAction(null);
}
}

0 comments on commit b47678d

Please sign in to comment.