[bisq-network/bisq] [WIP] Add list to filter to set btc fee receiver addresses (#4150)

chimp1984 notifications at github.com
Sun May 17 00:26:44 UTC 2020


@stejbac @sqrrm 

Here is a quick'n'dirty implementation for a weighted algorithm using a list of address/amount tuples separated with a `#` (e.g. "3A8Zc1XioE2HRzYfbb5P8iemCS72M6vRJV#1.231, 1BVxNn3T12veSK6DgqwU4Hdn7QHcDDRag7#12.12345678"). 
Not tested (not even compiled)....
Feel free to make it more elegant but I think it should be pretty simple.

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.

```
  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;
    }
```

-- 
You are receiving this because you are subscribed to this thread.
Reply to this email directly or view it on GitHub:
https://github.com/bisq-network/bisq/pull/4150#issuecomment-629724202
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.bisq.network/pipermail/bisq-github/attachments/20200516/57b11d11/attachment-0001.html>


More information about the bisq-github mailing list