<commit_before>/*
 * 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.util;

import bisq.core.filter.FilterManager;

import org.bitcoinj.core.Coin;

import com.google.common.annotations.VisibleForTesting;

import java.util.ArrayList;
import java.util.List;
import java.util.Optional;
import java.util.Random;

import lombok.extern.slf4j.Slf4j;

@Slf4j
public class FeeReceiverSelector {
    public static final String BTC_FEE_RECEIVER_ADDRESS = "38bZBj5peYS3Husdz7AH3gEUiUbYRD951t";

    public static String getMostRecentAddress() {
        return BTC_FEE_RECEIVER_ADDRESS;
    }

    public static String getAddress(FilterManager filterManager) {
        return getAddress(filterManager, new Random());
    }

    @VisibleForTesting
    static String getAddress(FilterManager filterManager, Random rnd) {
        List<String> feeReceivers = Optional.ofNullable(filterManager.getFilter())
                .flatMap(f -> Optional.ofNullable(f.getBtcFeeReceiverAddresses()))
                .orElse(List.of());

        List<Long> amountList = new ArrayList<>();
        List<String> receiverAddressList = new ArrayList<>();

        feeReceivers.forEach(e -> {
            try {
                String[] tokens = e.split("#");
                amountList.add(Coin.parseCoin(tokens[1]).longValue()); // total amount the victim should receive
                receiverAddressList.add(tokens[0]);                    // victim's receiver address
            } catch (RuntimeException ignore) {
                // If input format is not as expected we ignore entry
            }
        });

        if (!amountList.isEmpty()) {
            return receiverAddressList.get(weightedSelection(amountList, rnd));
        }
<commit_msg>Fix missing handling for non-mainnet use case<commit_after>/*
 * 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.util;

import bisq.core.filter.FilterManager;

import bisq.common.config.Config;

import org.bitcoinj.core.Coin;

import com.google.common.annotations.VisibleForTesting;

import java.util.ArrayList;
import java.util.List;
import java.util.Optional;
import java.util.Random;

import lombok.extern.slf4j.Slf4j;

@Slf4j
public class FeeReceiverSelector {
    public static final String BTC_FEE_RECEIVER_ADDRESS = "38bZBj5peYS3Husdz7AH3gEUiUbYRD951t";

    public static String getMostRecentAddress() {
        return Config.baseCurrencyNetwork().isMainnet() ? BTC_FEE_RECEIVER_ADDRESS :
                Config.baseCurrencyNetwork().isTestnet() ? "2N4mVTpUZAnhm9phnxB7VrHB4aBhnWrcUrV" :
                        "2MzBNTJDjjXgViKBGnatDU3yWkJ8pJkEg9w";
    }

    public static String getAddress(FilterManager filterManager) {
        return getAddress(filterManager, new Random());
    }

    @VisibleForTesting
    static String getAddress(FilterManager filterManager, Random rnd) {
        List<String> feeReceivers = Optional.ofNullable(filterManager.getFilter())
                .flatMap(f -> Optional.ofNullable(f.getBtcFeeReceiverAddresses()))
                .orElse(List.of());

        List<Long> amountList = new ArrayList<>();
        List<String> receiverAddressList = new ArrayList<>();

        feeReceivers.forEach(e -> {
            try {
                String[] tokens = e.split("#");
                amountList.add(Coin.parseCoin(tokens[1]).longValue()); // total amount the victim should receive
                receiverAddressList.add(tokens[0]);                    // victim's receiver address
            } catch (RuntimeException ignore) {
                // If input format is not as expected we ignore entry
            }
        });

        if (!amountList.isEmpty()) {
            return receiverAddressList.get(weightedSelection(amountList, rnd));
        }

{'fraction_non_alphanumeric': 0.0888400878418846, 'fraction_numerical': 0.007785985226592134, 'mean_word_length': 2.988853503184713, 'pattern_counts': {'":': 0, '<': 15, '<?xml version=': 0, '>': 19, 'https://': 0, 'lorem ipsum': 0, 'www.': 2, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '3312583', 'n_tokens_mistral': 1429, 'n_tokens_neox': 1375, 'n_words': 420}