sort UTXOs by value

This commit is contained in:
pokkst 2022-09-22 19:37:54 -05:00
parent 1e1fffae00
commit 693b342393
No known key found for this signature in database
GPG key ID: 90C2ED85E67A50FF
3 changed files with 17 additions and 2 deletions

View file

@ -19,6 +19,7 @@ import net.mynero.wallet.model.CoinsInfo;
import net.mynero.wallet.service.UTXOService; import net.mynero.wallet.service.UTXOService;
import java.util.ArrayList; import java.util.ArrayList;
import java.util.Collections;
public class UtxosFragment extends Fragment implements CoinsInfoAdapter.CoinsInfoAdapterListener { public class UtxosFragment extends Fragment implements CoinsInfoAdapter.CoinsInfoAdapterListener {
@ -64,6 +65,7 @@ public class UtxosFragment extends Fragment implements CoinsInfoAdapter.CoinsInf
filteredUtxos.add(coinsInfo); filteredUtxos.add(coinsInfo);
} }
} }
Collections.sort(filteredUtxos);
if (filteredUtxos.isEmpty()) { if (filteredUtxos.isEmpty()) {
utxosRecyclerView.setVisibility(View.GONE); utxosRecyclerView.setVisibility(View.GONE);
} else { } else {

View file

@ -24,7 +24,7 @@ import androidx.annotation.NonNull;
import java.util.ArrayList; import java.util.ArrayList;
import java.util.List; import java.util.List;
public class CoinsInfo implements Parcelable { public class CoinsInfo implements Parcelable, Comparable<CoinsInfo> {
static { static {
System.loadLibrary("monerujo"); System.loadLibrary("monerujo");
} }
@ -94,4 +94,17 @@ public class CoinsInfo implements Parcelable {
public void writeToParcel(@NonNull Parcel parcel, int i) { public void writeToParcel(@NonNull Parcel parcel, int i) {
parcel.writeLong(globalOutputIndex); parcel.writeLong(globalOutputIndex);
} }
@Override
public int compareTo(CoinsInfo another) {
long b1 = this.amount;
long b2 = another.amount;
if (b1 > b2) {
return -1;
} else if (b1 < b2) {
return 1;
} else {
return this.hash.compareTo(another.hash);
}
}
} }

View file

@ -38,7 +38,7 @@ public class UTXOService extends ServiceBase {
ArrayList<String> seenTxs = new ArrayList<>(); ArrayList<String> seenTxs = new ArrayList<>();
List<CoinsInfo> utxos = getUtxos(); List<CoinsInfo> utxos = getUtxos();
long amountSelected = 0; long amountSelected = 0;
Collections.shuffle(utxos); Collections.sort(utxos);
//loop through each utxo //loop through each utxo
for (CoinsInfo coinsInfo : utxos) { for (CoinsInfo coinsInfo : utxos) {
if(!coinsInfo.isSpent()) { //filter out spent outputs if(!coinsInfo.isSpent()) { //filter out spent outputs