diff --git a/core/src/main/java/bisq/core/trade/DelayedPayoutTxValidation.java b/core/src/main/java/bisq/core/trade/DelayedPayoutTxValidation.java index 8247bf5a065..aaaf026e19f 100644 --- a/core/src/main/java/bisq/core/trade/DelayedPayoutTxValidation.java +++ b/core/src/main/java/bisq/core/trade/DelayedPayoutTxValidation.java @@ -22,6 +22,8 @@ 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; @@ -29,6 +31,8 @@ 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; @@ -36,22 +40,6 @@ @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); @@ -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); @@ -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 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 +