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 java.util.ArrayList;
import java.util.Collections;
public class UtxosFragment extends Fragment implements CoinsInfoAdapter.CoinsInfoAdapterListener {
@ -64,6 +65,7 @@ public class UtxosFragment extends Fragment implements CoinsInfoAdapter.CoinsInf
filteredUtxos.add(coinsInfo);
}
}
Collections.sort(filteredUtxos);
if (filteredUtxos.isEmpty()) {
utxosRecyclerView.setVisibility(View.GONE);
} else {

View File

@ -24,7 +24,7 @@ import androidx.annotation.NonNull;
import java.util.ArrayList;
import java.util.List;
public class CoinsInfo implements Parcelable {
public class CoinsInfo implements Parcelable, Comparable<CoinsInfo> {
static {
System.loadLibrary("monerujo");
}
@ -94,4 +94,17 @@ public class CoinsInfo implements Parcelable {
public void writeToParcel(@NonNull Parcel parcel, int i) {
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<>();
List<CoinsInfo> utxos = getUtxos();
long amountSelected = 0;
Collections.shuffle(utxos);
Collections.sort(utxos);
//loop through each utxo
for (CoinsInfo coinsInfo : utxos) {
if(!coinsInfo.isSpent()) { //filter out spent outputs