Skip to content

Commit

Permalink
Fix issues when buyer has dao deactivated
Browse files Browse the repository at this point in the history
  • Loading branch information
chimp1984 authored and ripcurlx committed Apr 8, 2020
1 parent b145616 commit 79e4572
Showing 1 changed file with 26 additions and 21 deletions.
47 changes: 26 additions & 21 deletions core/src/main/java/bisq/core/trade/DelayedPayoutTxValidation.java
Original file line number Diff line number Diff line change
Expand Up @@ -22,36 +22,24 @@
import bisq.core.dao.governance.param.Param;
import bisq.core.offer.Offer;

import bisq.common.config.Config;

import org.bitcoinj.core.Address;
import org.bitcoinj.core.Coin;
import org.bitcoinj.core.NetworkParameters;
import org.bitcoinj.core.Transaction;
import org.bitcoinj.core.TransactionInput;
import org.bitcoinj.core.TransactionOutput;

import java.util.List;

import lombok.extern.slf4j.Slf4j;

import static com.google.common.base.Preconditions.checkNotNull;

@Slf4j
public class DelayedPayoutTxValidation {

/* @Getter
public static class DonationAddressException extends Exception {
private final String addressAsString;
private final String recentDonationAddressString;
private final String defaultDonationAddressString;
DonationAddressException(String addressAsString,
String recentDonationAddressString,
String defaultDonationAddressString) {
this.addressAsString = addressAsString;
this.recentDonationAddressString = recentDonationAddressString;
this.defaultDonationAddressString = defaultDonationAddressString;
}
}*/

public static class DonationAddressException extends Exception {
DonationAddressException(String msg) {
super(msg);
Expand Down Expand Up @@ -142,10 +130,7 @@ public static void validatePayoutTx(Trade trade,
// Get most recent donation address.
// We do not support past DAO param addresses to avoid that those receive funds (no bond set up anymore).
// Users who have not synced the DAO cannot trade.
String recentDonationAddressString = daoFacade.getParamValue(Param.RECIPIENT_BTC_ADDRESS);

// In case the seller has deactivated the DAO the default address will be used.
String defaultDonationAddressString = Param.RECIPIENT_BTC_ADDRESS.getDefaultValue();

NetworkParameters params = btcWalletService.getParams();
Address address = output.getAddressFromP2PKHScript(params);
Expand All @@ -161,8 +146,28 @@ public static void validatePayoutTx(Trade trade,
}

String addressAsString = address.toString();
if (!recentDonationAddressString.equals(addressAsString) &&
!defaultDonationAddressString.equals(addressAsString)) {

// In case the seller has deactivated the DAO the default address will be used.
String defaultDonationAddressString = Param.RECIPIENT_BTC_ADDRESS.getDefaultValue();
boolean defaultNotMatching = !defaultDonationAddressString.equals(addressAsString);
String recentDonationAddressString = daoFacade.getParamValue(Param.RECIPIENT_BTC_ADDRESS);
boolean recentFromDaoNotMatching = !recentDonationAddressString.equals(addressAsString);

// If buyer has DAO deactivated or not synced he will not be able to see recent address used by the seller, so
// we add it hard coded here. We need to support also the default one as
// FIXME This is a quick fix and should be improved in future.
// We use the default addresses for non mainnet networks. For dev testing it need to be changed here.
// We use a list to gain more flexibility at updates of DAO param, but still might fail if buyer has not updated
// software. Needs a better solution....
List<String> hardCodedAddresses = Config.baseCurrencyNetwork().isMainnet() ? List.of("3A8Zc1XioE2HRzYfbb5P8iemCS72M6vRJV") : // mainnet
Config.baseCurrencyNetwork().isDaoBetaNet() ? List.of("1BVxNn3T12veSK6DgqwU4Hdn7QHcDDRag7") : // daoBetaNet
Config.baseCurrencyNetwork().isTestnet() ? List.of("2N4mVTpUZAnhm9phnxB7VrHB4aBhnWrcUrV") : // testnet
List.of("2MzBNTJDjjXgViKBGnatDU3yWkJ8pJkEg9w"); // regtest or DAO testnet (regtest)

boolean noneOfHardCodedMatching = hardCodedAddresses.stream().noneMatch(e -> e.equals(addressAsString));

// If seller has DAO deactivated as well we get default address
if (recentFromDaoNotMatching && defaultNotMatching && noneOfHardCodedMatching) {
errorMsg = "Donation address is invalid." +
"\nAddress used by BTC seller: " + addressAsString +
"\nRecent donation address:" + recentDonationAddressString +
Expand Down

0 comments on commit 79e4572

Please sign in to comment.