<p></p>
<p><a class="user-mention" data-hovercard-type="user" data-hovercard-url="/users/stejbac/hovercard" data-octo-click="hovercard-link-click" data-octo-dimensions="link_type:self" href="https://github.com/stejbac">@stejbac</a> <a class="user-mention" data-hovercard-type="user" data-hovercard-url="/users/sqrrm/hovercard" data-octo-click="hovercard-link-click" data-octo-dimensions="link_type:self" href="https://github.com/sqrrm">@sqrrm</a></p>
<p>Here is a quick'n'dirty implementation for a weighted algorithm using a list of address/amount tuples separated with a <code>#</code> (e.g. "3A8Zc1XioE2HRzYfbb5P8iemCS72M6vRJV#1.231, 1BVxNn3T12veSK6DgqwU4Hdn7QHcDDRag7#12.12345678").<br>
Not tested (not even compiled)....<br>
Feel free to make it more elegant but I think it should be pretty simple.</p>
<p>If you think a date restriction is needed you can add another entry to the tuple for the expiry date, after which the address is ignored. I doubt it is needed and think its better to keep it as simple as possible to avoid potential bugs.</p>
<pre><code>  public static String getAddress(DaoFacade daoFacade, FilterManager filterManager) {
        // We keep default value as fallback in case no filter value is available or user has old version.
        String feeReceiver = daoFacade.getParamValue(Param.RECIPIENT_BTC_ADDRESS);

        Filter filter = filterManager.getFilter();
        if (filter != null) {
            List<String> feeReceivers = filter.getBtcFeeReceiverAddresses();
            if (feeReceivers != null && !feeReceivers.isEmpty()) {
                AtomicLong totalSum = new AtomicLong();
                List<Long> amountList = new ArrayList<>();
                List<Tuple2<String, Long>> feeReceiverTupleList = feeReceivers.stream()
                        .map(e -> {
                            try {
                                String[] tokens = e.split("#");
                                String address = tokens[0];                             // Victim's receiver address
                                Long amount = Coin.parseCoin(tokens[1]).longValue();    // Total amount the victim should receive
                                totalSum.addAndGet(amount);
                                amountList.add(amount);
                                return new Tuple2<>(address, amount);
                            } catch (Throwable t) {
                                // If input format is not as expected we ignore entry
                                return null;
                            }
                        })
                        .filter(Objects::nonNull)
                        .collect(Collectors.toList());

                long target = Math.abs(new SecureRandom().nextLong()) % totalSum.get();
                int aggregated = 0;
                for (int i = 0; i < amountList.size(); i++) {
                    aggregated += amountList.get(i);
                    if (target <= aggregated) {
                        feeReceiver = feeReceiverTupleList.get(i).first;
                        break;
                    }
                }
            }
        }
        return feeReceiver;
    }
</code></pre>

<p style="font-size:small;-webkit-text-size-adjust:none;color:#666;">—<br />You are receiving this because you are subscribed to this thread.<br />Reply to this email directly, <a href="https://github.com/bisq-network/bisq/pull/4150#issuecomment-629724202">view it on GitHub</a>, or <a href="https://github.com/notifications/unsubscribe-auth/AJFFTNRAYDVOIDANAIBX5KDRR4VMJANCNFSM4MEJRK3Q">unsubscribe</a>.<img src="https://github.com/notifications/beacon/AJFFTNQGCE472U5I6UL7AMLRR4VMJA5CNFSM4MEJRK32YY3PNVWWK3TUL52HS4DFVREXG43VMVBW63LNMVXHJKTDN5WW2ZLOORPWSZGOEWENIKQ.gif" height="1" width="1" alt="" /></p>
<script type="application/ld+json">[
{
"@context": "http://schema.org",
"@type": "EmailMessage",
"potentialAction": {
"@type": "ViewAction",
"target": "https://github.com/bisq-network/bisq/pull/4150#issuecomment-629724202",
"url": "https://github.com/bisq-network/bisq/pull/4150#issuecomment-629724202",
"name": "View Pull Request"
},
"description": "View this Pull Request on GitHub",
"publisher": {
"@type": "Organization",
"name": "GitHub",
"url": "https://github.com"
}
}
]</script>