Commit 8cc43509 authored by zeroleak's avatar zeroleak
Browse files

/rest/utxos: sort utxos by lastActivity

parent fdeec878
package com.samourai.whirlpool.cli.api.protocol.beans;
import com.samourai.whirlpool.client.wallet.beans.WhirlpoolUtxo;
import com.samourai.whirlpool.client.wallet.beans.WhirlpoolUtxoPriorityComparator;
import java.util.Collection;
import java.util.Comparator;
import java.util.stream.Collectors;
public class ApiWallet {
......@@ -10,11 +10,12 @@ public class ApiWallet {
private long balance;
private String zpub;
public ApiWallet(Collection<WhirlpoolUtxo> whirlpoolUtxos, String zpub) {
public ApiWallet(
Collection<WhirlpoolUtxo> whirlpoolUtxos, String zpub, Comparator<WhirlpoolUtxo> comparator) {
this.utxos =
whirlpoolUtxos
.stream()
.sorted(new WhirlpoolUtxoPriorityComparator())
.sorted(comparator)
.map(whirlpoolUtxo -> new ApiUtxo(whirlpoolUtxo))
.collect(Collectors.toList());
this.balance =
......
......@@ -2,7 +2,6 @@ package com.samourai.whirlpool.cli.api.protocol.rest;
import com.samourai.whirlpool.cli.api.protocol.beans.ApiUtxo;
import com.samourai.whirlpool.client.wallet.beans.MixOrchestratorState;
import com.samourai.whirlpool.client.wallet.beans.WhirlpoolUtxoPriorityComparator;
import com.samourai.whirlpool.client.wallet.beans.WhirlpoolWalletState;
import java.util.Collection;
import java.util.stream.Collectors;
......@@ -28,7 +27,6 @@ public class ApiWalletStateResponse {
mixState
.getUtxosMixing()
.stream()
.sorted(new WhirlpoolUtxoPriorityComparator())
.map(whirlpoolUtxo -> new ApiUtxo(whirlpoolUtxo))
.collect(Collectors.toList());
}
......
package com.samourai.whirlpool.cli.api.protocol.rest;
import com.google.common.primitives.Ints;
import com.samourai.whirlpool.cli.api.protocol.beans.ApiWallet;
import com.samourai.whirlpool.client.wallet.WhirlpoolWallet;
import com.samourai.whirlpool.client.wallet.beans.WhirlpoolUtxo;
import java.util.Comparator;
import java8.lang.Longs;
public class ApiWalletUtxosResponse {
private ApiWallet deposit;
......@@ -9,11 +13,34 @@ public class ApiWalletUtxosResponse {
private ApiWallet postmix;
public ApiWalletUtxosResponse(WhirlpoolWallet whirlpoolWallet) throws Exception {
Comparator<WhirlpoolUtxo> comparator =
(o1, o2) -> {
// last activity first
if (o1.getLastActivity() != null || o2.getLastActivity() != null) {
if (o1.getLastActivity() != null && o2.getLastActivity() == null) {
return -1;
}
if (o2.getLastActivity() != null && o1.getLastActivity() == null) {
return 1;
}
int compare = Longs.compare(o2.getLastActivity(), o1.getLastActivity());
if (compare != 0) {
return compare;
}
}
// last confirmed
return Ints.compare(o1.getUtxo().confirmations, o2.getUtxo().confirmations);
};
this.deposit =
new ApiWallet(whirlpoolWallet.getUtxosDeposit(), whirlpoolWallet.getZpubDeposit());
this.premix = new ApiWallet(whirlpoolWallet.getUtxosPremix(), whirlpoolWallet.getZpubPremix());
new ApiWallet(
whirlpoolWallet.getUtxosDeposit(), whirlpoolWallet.getZpubDeposit(), comparator);
this.premix =
new ApiWallet(
whirlpoolWallet.getUtxosPremix(), whirlpoolWallet.getZpubPremix(), comparator);
this.postmix =
new ApiWallet(whirlpoolWallet.getUtxosPostmix(), whirlpoolWallet.getZpubPostmix());
new ApiWallet(
whirlpoolWallet.getUtxosPostmix(), whirlpoolWallet.getZpubPostmix(), comparator);
}
public ApiWallet getDeposit() {
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment