improve transaction entry sort and unconfirmed tx tooltip

This commit is contained in:
Craig Raw 2022-07-20 16:56:26 +02:00
parent 19551671bd
commit 13a576e871
4 changed files with 35 additions and 15 deletions

2
drongo

@ -1 +1 @@
Subproject commit f10688279a7a761c734c80c051237c0a4a90928b
Subproject commit b4b2534e7a69c272a4d8b089cd88b3502f6d4b39

View file

@ -373,11 +373,11 @@ public class EntryCell extends TreeTableCell<Entry, Entry> {
private String getTooltip(TransactionEntry transactionEntry) {
String tooltip = transactionEntry.getBlockTransaction().getHash().toString();
if(transactionEntry.getBlockTransaction().getHeight() <= 0) {
if(!AppServices.getMempoolHistogram().isEmpty()) {
Set<MempoolRateSize> rateSizes = AppServices.getMempoolHistogram().get(AppServices.getMempoolHistogram().lastKey());
double vSize = transactionEntry.getBlockTransaction().getTransaction().getVirtualSize();
double feeRate = transactionEntry.getBlockTransaction().getFee() / vSize;
long vSizefromTip = rateSizes.stream().filter(rateSize -> rateSize.getFee() > feeRate).mapToLong(MempoolRateSize::getVSize).sum();
Double feeRate = transactionEntry.getBlockTransaction().getFeeRate();
Long vSizefromTip = transactionEntry.getVSizeFromTip();
if(feeRate != null && vSizefromTip != null) {
long blocksFromTip = (long)Math.ceil((double)vSizefromTip / Transaction.MAX_BLOCK_SIZE);
String amount = vSizefromTip + " vB";
if(vSizefromTip > 1000 * 1000) {
amount = String.format("%.2f", (double)vSizefromTip / (1000 * 1000)) + " MvB";
@ -385,7 +385,11 @@ public class EntryCell extends TreeTableCell<Entry, Entry> {
amount = String.format("%.2f", (double)vSizefromTip / 1000) + " kvB";
}
tooltip += "\nFee rate: " + String.format("%.2f", feeRate) + " sats/vB (" + amount + " from tip)";
tooltip += "\nConfirms in: ±" + blocksFromTip + " block" + (blocksFromTip > 1 ? "s" : "") + " (" + amount + " from tip)";
}
if(feeRate != null) {
tooltip += "\nFee rate: " + String.format("%.2f", feeRate) + " sats/vB";
}
tooltip += "\nRBF: " + (transactionEntry.getBlockTransaction().getTransaction().isReplaceByFee() ? "Enabled" : "Disabled");

View file

@ -12,6 +12,7 @@ import com.sparrowwallet.sparrow.WalletTabData;
import com.sparrowwallet.sparrow.event.WalletBlockHeightChangedEvent;
import com.sparrowwallet.sparrow.event.WalletEntryLabelsChangedEvent;
import com.sparrowwallet.sparrow.event.WalletTabsClosedEvent;
import com.sparrowwallet.sparrow.net.MempoolRateSize;
import javafx.beans.property.IntegerProperty;
import javafx.beans.property.IntegerPropertyBase;
import javafx.beans.property.LongProperty;
@ -181,9 +182,12 @@ public class TransactionEntry extends Entry implements Comparable<TransactionEnt
@Override
public int compareTo(TransactionEntry other) {
int blockOrder = blockTransaction.compareBlockOrder(other.blockTransaction);
if(blockOrder != 0) {
return blockOrder;
//This comparison must be identical to that of WalletTransactionsEntry.WalletTransaction
if(blockTransaction.getHeight() != other.blockTransaction.getHeight()) {
int blockOrder = blockTransaction.getComparisonHeight() - other.blockTransaction.getComparisonHeight();
if(blockOrder != 0) {
return blockOrder;
}
}
int valueOrder = Long.compare(other.getValue(), getValue());
@ -191,7 +195,7 @@ public class TransactionEntry extends Entry implements Comparable<TransactionEnt
return valueOrder;
}
return blockTransaction.compareTo(other.blockTransaction);
return blockTransaction.getHash().compareTo(other.blockTransaction.getHash());
}
/**
@ -244,6 +248,16 @@ public class TransactionEntry extends Entry implements Comparable<TransactionEnt
return balance;
}
public Long getVSizeFromTip() {
if(!AppServices.getMempoolHistogram().isEmpty()) {
Set<MempoolRateSize> rateSizes = AppServices.getMempoolHistogram().get(AppServices.getMempoolHistogram().lastKey());
double feeRate = blockTransaction.getFeeRate();
return rateSizes.stream().filter(rateSize -> rateSize.getFee() > feeRate).mapToLong(MempoolRateSize::getVSize).sum();
}
return null;
}
@Subscribe
public void blockHeightChanged(WalletBlockHeightChangedEvent event) {
if(event.getWallet().equals(getWallet())) {

View file

@ -246,9 +246,11 @@ public class WalletTransactionsEntry extends Entry {
@Override
public int compareTo(WalletTransactionsEntry.WalletTransaction other) {
//This comparison must be identical to that of TransactionEntry so we can avoid a resort calculating balances when creating WalletTransactionsEntry
int blockOrder = blockTransaction.compareBlockOrder(other.blockTransaction);
if(blockOrder != 0) {
return blockOrder;
if(blockTransaction.getHeight() != other.blockTransaction.getHeight()) {
int blockOrder = blockTransaction.getComparisonHeight() - other.blockTransaction.getComparisonHeight();
if(blockOrder != 0) {
return blockOrder;
}
}
int valueOrder = Long.compare(other.getValue(), getValue());
@ -256,7 +258,7 @@ public class WalletTransactionsEntry extends Entry {
return valueOrder;
}
return blockTransaction.compareTo(other.blockTransaction);
return blockTransaction.getHash().compareTo(other.blockTransaction.getHash());
}
}
}