Skip to content

Commit

Permalink
Merge pull request #2355 from ManfredKarrer/dao-add-filter-flag-for-d…
Browse files Browse the repository at this point in the history
…isable-dao

Dao add filter flag for disable dao
  • Loading branch information
ManfredKarrer authored Feb 3, 2019
2 parents ac670e1 + 002f225 commit 3f4e641
Show file tree
Hide file tree
Showing 12 changed files with 160 additions and 18 deletions.
1 change: 1 addition & 0 deletions common/src/main/proto/pb.proto
Original file line number Diff line number Diff line change
Expand Up @@ -476,6 +476,7 @@ message Filter {
repeated string price_relay_nodes = 11;
bool prevent_public_btc_network = 12;
repeated string btc_nodes = 13;
bool disable_dao = 14;
}

// not used anymore from v0.6 on. But leave it for receiving TradeStatistics objects from older
Expand Down
8 changes: 8 additions & 0 deletions core/src/main/java/bisq/core/btc/wallet/BsqWalletService.java
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@
import bisq.core.btc.exceptions.WalletException;
import bisq.core.btc.listeners.BsqBalanceListener;
import bisq.core.btc.setup.WalletsSetup;
import bisq.core.dao.DaoKillSwitch;
import bisq.core.dao.state.DaoStateListener;
import bisq.core.dao.state.DaoStateService;
import bisq.core.dao.state.model.blockchain.Block;
Expand Down Expand Up @@ -466,6 +467,7 @@ public void commitTx(Transaction tx) {

public Transaction getPreparedSendTx(String receiverAddress, Coin receiverAmount)
throws AddressFormatException, InsufficientBsqException, WalletException, TransactionVerificationException {
DaoKillSwitch.assertDaoIsNotDisabled();
Transaction tx = new Transaction(params);
checkArgument(Restrictions.isAboveDust(receiverAmount),
"The amount is too low (dust limit).");
Expand Down Expand Up @@ -497,6 +499,7 @@ public Transaction getPreparedSendTx(String receiverAddress, Coin receiverAmount

public Transaction getPreparedSendBtcTx(String receiverAddress, Coin receiverAmount)
throws AddressFormatException, InsufficientBsqException, WalletException, TransactionVerificationException {
DaoKillSwitch.assertDaoIsNotDisabled();
Transaction tx = new Transaction(params);
checkArgument(Restrictions.isAboveDust(receiverAmount),
"The amount is too low (dust limit).");
Expand Down Expand Up @@ -535,6 +538,7 @@ public Transaction getPreparedProposalTx(Coin fee) throws InsufficientBsqExcepti
}

public Transaction getPreparedBurnFeeTx(Coin fee) throws InsufficientBsqException {
DaoKillSwitch.assertDaoIsNotDisabled();
final Transaction tx = new Transaction(params);
addInputsAndChangeOutputForTx(tx, fee, bsqCoinSelector);
// printTx("getPreparedFeeTx", tx);
Expand Down Expand Up @@ -572,6 +576,7 @@ private void addInputsAndChangeOutputForTx(Transaction tx, Coin fee, BsqCoinSele
// We create a tx with Bsq inputs for the fee, one output for the stake and optional one BSQ change output.
// As the fee amount will be missing in the output those BSQ fees are burned.
public Transaction getPreparedBlindVoteTx(Coin fee, Coin stake) throws InsufficientBsqException {
DaoKillSwitch.assertDaoIsNotDisabled();
Transaction tx = new Transaction(params);
tx.addOutput(new TransactionOutput(params, tx, stake, getUnusedAddress()));
addInputsAndChangeOutputForTx(tx, fee.add(stake), bsqCoinSelector);
Expand All @@ -585,6 +590,7 @@ public Transaction getPreparedBlindVoteTx(Coin fee, Coin stake) throws Insuffici
///////////////////////////////////////////////////////////////////////////////////////////

public Transaction getPreparedVoteRevealTx(TxOutput stakeTxOutput) {
DaoKillSwitch.assertDaoIsNotDisabled();
Transaction tx = new Transaction(params);
final Coin stake = Coin.valueOf(stakeTxOutput.getValue());
Transaction blindVoteTx = getTransaction(stakeTxOutput.getTxId());
Expand All @@ -603,6 +609,7 @@ public Transaction getPreparedVoteRevealTx(TxOutput stakeTxOutput) {
///////////////////////////////////////////////////////////////////////////////////////////

public Transaction getPreparedLockupTx(Coin lockupAmount) throws AddressFormatException, InsufficientBsqException {
DaoKillSwitch.assertDaoIsNotDisabled();
Transaction tx = new Transaction(params);
checkArgument(Restrictions.isAboveDust(lockupAmount), "The amount is too low (dust limit).");
tx.addOutput(new TransactionOutput(params, tx, lockupAmount, getUnusedAddress()));
Expand All @@ -616,6 +623,7 @@ public Transaction getPreparedLockupTx(Coin lockupAmount) throws AddressFormatEx
///////////////////////////////////////////////////////////////////////////////////////////

public Transaction getPreparedUnlockTx(TxOutput lockupTxOutput) throws AddressFormatException {
DaoKillSwitch.assertDaoIsNotDisabled();
Transaction tx = new Transaction(params);
// Unlocking means spending the full value of the locked txOutput to another txOutput with the same value
Coin amountToUnlock = Coin.valueOf(lockupTxOutput.getValue());
Expand Down
62 changes: 62 additions & 0 deletions core/src/main/java/bisq/core/dao/DaoKillSwitch.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,62 @@
/*
* This file is part of Bisq.
*
* Bisq is free software: you can redistribute it and/or modify it
* under the terms of the GNU Affero General Public License as published by
* the Free Software Foundation, either version 3 of the License, or (at
* your option) any later version.
*
* Bisq is distributed in the hope that it will be useful, but WITHOUT
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU Affero General Public
* License for more details.
*
* You should have received a copy of the GNU Affero General Public License
* along with Bisq. If not, see <http://www.gnu.org/licenses/>.
*/

package bisq.core.dao;

import bisq.core.dao.exceptions.DaoDisabledException;
import bisq.core.filter.Filter;
import bisq.core.filter.FilterManager;

import javax.inject.Inject;

import lombok.Getter;

public class DaoKillSwitch implements DaoSetupService {
private static DaoKillSwitch INSTANCE;
private final FilterManager filterManager;

@Getter
private boolean daoDisabled;

@Inject
public DaoKillSwitch(FilterManager filterManager) {
this.filterManager = filterManager;

DaoKillSwitch.INSTANCE = this;
}

@Override
public void addListeners() {
filterManager.filterProperty().addListener((observable, oldValue, newValue) -> applyFilter(newValue));
}

@Override
public void start() {
applyFilter(filterManager.getFilter());
}

private void applyFilter(Filter filter) {
daoDisabled = filter != null && filter.isDisableDao();
}

public static void assertDaoIsNotDisabled() {
if (INSTANCE.isDaoDisabled()) {
throw new DaoDisabledException("The DAO features have been disabled by the Bisq developers. " +
"Please check out the Bisq Forum for further information.");
}
}
}
1 change: 1 addition & 0 deletions core/src/main/java/bisq/core/dao/DaoModule.java
Original file line number Diff line number Diff line change
Expand Up @@ -98,6 +98,7 @@ public DaoModule(Environment environment) {
protected void configure() {
bind(DaoSetup.class).in(Singleton.class);
bind(DaoFacade.class).in(Singleton.class);
bind(DaoKillSwitch.class).in(Singleton.class);

// Node, parser
bind(BsqNodeProvider.class).in(Singleton.class);
Expand Down
4 changes: 3 additions & 1 deletion core/src/main/java/bisq/core/dao/DaoSetup.java
Original file line number Diff line number Diff line change
Expand Up @@ -68,7 +68,8 @@ public DaoSetup(BsqNodeProvider bsqNodeProvider,
AssetService assetService,
ProofOfBurnService proofOfBurnService,
DaoFacade daoFacade,
ExportJsonFilesService exportJsonFilesService) {
ExportJsonFilesService exportJsonFilesService,
DaoKillSwitch daoKillSwitch) {

bsqNode = bsqNodeProvider.getBsqNode();

Expand All @@ -90,6 +91,7 @@ public DaoSetup(BsqNodeProvider bsqNodeProvider,
daoSetupServices.add(proofOfBurnService);
daoSetupServices.add(daoFacade);
daoSetupServices.add(exportJsonFilesService);
daoSetupServices.add(daoKillSwitch);
daoSetupServices.add(bsqNodeProvider.getBsqNode());
}

Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
/*
* This file is part of Bisq.
*
* Bisq is free software: you can redistribute it and/or modify it
* under the terms of the GNU Affero General Public License as published by
* the Free Software Foundation, either version 3 of the License, or (at
* your option) any later version.
*
* Bisq is distributed in the hope that it will be useful, but WITHOUT
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU Affero General Public
* License for more details.
*
* You should have received a copy of the GNU Affero General Public License
* along with Bisq. If not, see <http://www.gnu.org/licenses/>.
*/

package bisq.core.dao.exceptions;

public class DaoDisabledException extends RuntimeException {
public DaoDisabledException() {
}

public DaoDisabledException(String message) {
super(message);
}

public DaoDisabledException(String message, Throwable cause) {
super(message, cause);
}

public DaoDisabledException(Throwable cause) {
super(cause);
}

public DaoDisabledException(String message, Throwable cause, boolean enableSuppression, boolean writableStackTrace) {
super(message, cause, enableSuppression, writableStackTrace);
}
}
32 changes: 21 additions & 11 deletions core/src/main/java/bisq/core/filter/Filter.java
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@

import java.security.PublicKey;

import java.util.ArrayList;
import java.util.List;
import java.util.Map;
import java.util.Optional;
Expand Down Expand Up @@ -85,6 +86,9 @@ public final class Filter implements ProtectedStoragePayload, ExpirablePayload {
private Map<String, String> extraDataMap;
private PublicKey ownerPubKey;

// added in v0.9.4
private final boolean disableDao;

public Filter(List<String> bannedOfferIds,
List<String> bannedNodeAddress,
List<PaymentAccountFilter> bannedPaymentAccounts,
Expand All @@ -94,7 +98,8 @@ public Filter(List<String> bannedOfferIds,
@Nullable List<String> seedNodes,
@Nullable List<String> priceRelayNodes,
boolean preventPublicBtcNetwork,
@Nullable List<String> btcNodes) {
@Nullable List<String> btcNodes,
boolean disableDao) {
this.bannedOfferIds = bannedOfferIds;
this.bannedNodeAddress = bannedNodeAddress;
this.bannedPaymentAccounts = bannedPaymentAccounts;
Expand All @@ -105,6 +110,7 @@ public Filter(List<String> bannedOfferIds,
this.priceRelayNodes = priceRelayNodes;
this.preventPublicBtcNetwork = preventPublicBtcNetwork;
this.btcNodes = btcNodes;
this.disableDao = disableDao;
}


Expand All @@ -123,6 +129,7 @@ public Filter(List<String> bannedOfferIds,
@Nullable List<String> priceRelayNodes,
boolean preventPublicBtcNetwork,
@Nullable List<String> btcNodes,
boolean disableDao,
String signatureAsBase64,
byte[] ownerPubKeyBytes,
@Nullable Map<String, String> extraDataMap) {
Expand All @@ -135,7 +142,8 @@ public Filter(List<String> bannedOfferIds,
seedNodes,
priceRelayNodes,
preventPublicBtcNetwork,
btcNodes);
btcNodes,
disableDao);
this.signatureAsBase64 = signatureAsBase64;
this.ownerPubKeyBytes = ownerPubKeyBytes;
this.extraDataMap = extraDataMap;
Expand All @@ -156,7 +164,8 @@ public PB.StoragePayload toProtoMessage() {
.addAllBannedPaymentAccounts(paymentAccountFilterList)
.setSignatureAsBase64(signatureAsBase64)
.setOwnerPubKeyBytes(ByteString.copyFrom(ownerPubKeyBytes))
.setPreventPublicBtcNetwork(preventPublicBtcNetwork);
.setPreventPublicBtcNetwork(preventPublicBtcNetwork)
.setDisableDao(disableDao);

Optional.ofNullable(bannedCurrencies).ifPresent(builder::addAllBannedCurrencies);
Optional.ofNullable(bannedPaymentMethods).ifPresent(builder::addAllBannedPaymentMethods);
Expand All @@ -170,18 +179,19 @@ public PB.StoragePayload toProtoMessage() {
}

public static Filter fromProto(PB.Filter proto) {
return new Filter(proto.getBannedOfferIdsList().stream().collect(Collectors.toList()),
proto.getBannedNodeAddressList().stream().collect(Collectors.toList()),
return new Filter(new ArrayList<>(proto.getBannedOfferIdsList()),
new ArrayList<>(proto.getBannedNodeAddressList()),
proto.getBannedPaymentAccountsList().stream()
.map(PaymentAccountFilter::fromProto)
.collect(Collectors.toList()),
CollectionUtils.isEmpty(proto.getBannedCurrenciesList()) ? null : proto.getBannedCurrenciesList().stream().collect(Collectors.toList()),
CollectionUtils.isEmpty(proto.getBannedPaymentMethodsList()) ? null : proto.getBannedPaymentMethodsList().stream().collect(Collectors.toList()),
CollectionUtils.isEmpty(proto.getArbitratorsList()) ? null : proto.getArbitratorsList().stream().collect(Collectors.toList()),
CollectionUtils.isEmpty(proto.getSeedNodesList()) ? null : proto.getSeedNodesList().stream().collect(Collectors.toList()),
CollectionUtils.isEmpty(proto.getPriceRelayNodesList()) ? null : proto.getPriceRelayNodesList().stream().collect(Collectors.toList()),
CollectionUtils.isEmpty(proto.getBannedCurrenciesList()) ? null : new ArrayList<>(proto.getBannedCurrenciesList()),
CollectionUtils.isEmpty(proto.getBannedPaymentMethodsList()) ? null : new ArrayList<>(proto.getBannedPaymentMethodsList()),
CollectionUtils.isEmpty(proto.getArbitratorsList()) ? null : new ArrayList<>(proto.getArbitratorsList()),
CollectionUtils.isEmpty(proto.getSeedNodesList()) ? null : new ArrayList<>(proto.getSeedNodesList()),
CollectionUtils.isEmpty(proto.getPriceRelayNodesList()) ? null : new ArrayList<>(proto.getPriceRelayNodesList()),
proto.getPreventPublicBtcNetwork(),
CollectionUtils.isEmpty(proto.getBtcNodesList()) ? null : proto.getBtcNodesList().stream().collect(Collectors.toList()),
CollectionUtils.isEmpty(proto.getBtcNodesList()) ? null : new ArrayList<>(proto.getBtcNodesList()),
proto.getDisableDao(),
proto.getSignatureAsBase64(),
proto.getOwnerPubKeyBytes().toByteArray(),
CollectionUtils.isEmpty(proto.getExtraDataMap()) ? null : proto.getExtraDataMap());
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@
import bisq.core.btc.wallet.TradeWalletService;
import bisq.core.btc.wallet.TxBroadcaster;
import bisq.core.btc.wallet.WalletService;
import bisq.core.dao.exceptions.DaoDisabledException;
import bisq.core.offer.Offer;
import bisq.core.offer.availability.ArbitratorSelection;
import bisq.core.offer.placeoffer.PlaceOfferModel;
Expand Down Expand Up @@ -154,9 +155,16 @@ public void onFailure(TxBroadcastException exception) {
});
}
} catch (Throwable t) {
offer.setErrorMessage("An error occurred.\n" +
"Error message:\n"
+ t.getMessage());
if (t instanceof DaoDisabledException) {
offer.setErrorMessage("You cannot pay the trade fee in BSQ at the moment because the DAO features have been " +
"disabled due technical problems. Please use the BTC fee option until the issues are resolved. " +
"For more information please visit the Bisq Forum.");
} else {
offer.setErrorMessage("An error occurred.\n" +
"Error message:\n"
+ t.getMessage());
}

failed(t);
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@
import bisq.core.btc.wallet.TradeWalletService;
import bisq.core.btc.wallet.TxBroadcaster;
import bisq.core.btc.wallet.WalletService;
import bisq.core.dao.exceptions.DaoDisabledException;
import bisq.core.offer.availability.ArbitratorSelection;
import bisq.core.trade.Trade;
import bisq.core.trade.protocol.tasks.TradeTask;
Expand Down Expand Up @@ -147,7 +148,13 @@ public void onFailure(TxBroadcastException exception) {
});
}
} catch (Throwable t) {
failed(t);
if (t instanceof DaoDisabledException) {
failed("You cannot pay the trade fee in BSQ at the moment because the DAO features have been " +
"disabled due technical problems. Please use the BTC fee option until the issues are resolved. " +
"For more information please visit the Bisq Forum.");
} else {
failed(t);
}
}
}
}
1 change: 1 addition & 0 deletions core/src/main/resources/i18n/displayStrings.properties
Original file line number Diff line number Diff line change
Expand Up @@ -1838,6 +1838,7 @@ filterWindow.seedNode=Filtered seed nodes (comma sep. onion addresses)
filterWindow.priceRelayNode=Filtered price relay nodes (comma sep. onion addresses)
filterWindow.btcNode=Filtered Bitcoin nodes (comma sep. addresses + port)
filterWindow.preventPublicBtcNetwork=Prevent usage of public Bitcoin network
filterWindow.disableDao=Disable DAO
filterWindow.add=Add filter
filterWindow.remove=Remove filter

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@ public void testRoundtripFull() {
vo.setDisplayedAlert(new Alert("message", true, "version", new byte[]{12, -64, 12}, "string", null));
vo.setDevelopersFilter(new Filter(Lists.newArrayList(), Lists.newArrayList(), Lists.newArrayList(),
Lists.newArrayList(), Lists.newArrayList(), Lists.newArrayList(), Lists.newArrayList(), Lists.newArrayList(),
false, Lists.newArrayList(), "string", new byte[]{10, 0, 0}, null));
false, Lists.newArrayList(), false, "string", new byte[]{10, 0, 0}, null));
vo.setRegisteredArbitrator(ArbitratorTest.getArbitratorMock());
vo.setRegisteredMediator(MediatorTest.getMediatorMock());
vo.setAcceptedArbitrators(Lists.newArrayList(ArbitratorTest.getArbitratorMock()));
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -140,6 +140,7 @@ private void addContent() {
InputTextField priceRelayNodesInputTextField = addInputTextField(gridPane, ++rowIndex, Res.get("filterWindow.priceRelayNode"));
InputTextField btcNodesInputTextField = addInputTextField(gridPane, ++rowIndex, Res.get("filterWindow.btcNode"));
CheckBox preventPublicBtcNetworkCheckBox = addLabelCheckBox(gridPane, ++rowIndex, Res.get("filterWindow.preventPublicBtcNetwork"));
CheckBox disableDaoCheckBox = addLabelCheckBox(gridPane, ++rowIndex, Res.get("filterWindow.disableDao"));

final Filter filter = filterManager.getDevelopersFilter();
if (filter != null) {
Expand Down Expand Up @@ -180,6 +181,7 @@ private void addContent() {

preventPublicBtcNetworkCheckBox.setSelected(filter.isPreventPublicBtcNetwork());

disableDaoCheckBox.setSelected(filter.isDisableDao());
}
Button sendButton = new AutoTooltipButton(Res.get("filterWindow.add"));
sendButton.setOnAction(e -> {
Expand Down Expand Up @@ -264,7 +266,8 @@ private void addContent() {
seedNodes,
priceRelayNodes,
preventPublicBtcNetworkCheckBox.isSelected(),
btcNodes),
btcNodes,
disableDaoCheckBox.isSelected()),
keyInputTextField.getText()))
hide();
else
Expand Down

0 comments on commit 3f4e641

Please sign in to comment.