From 0070cbfb1e62d109b9f4a5b97f5293418d401fa3 Mon Sep 17 00:00:00 2001 From: Craig Raw Date: Mon, 8 Mar 2021 16:22:22 +0200 Subject: [PATCH] use and display fractional tx virtual size, indicate sizes on unfinalized txes may change --- drongo | 2 +- .../sparrow/control/EntryCell.java | 2 +- .../sparrow/control/TransactionDiagram.java | 2 +- .../transaction/HeadersController.java | 19 +++++++++++++++---- 4 files changed, 18 insertions(+), 7 deletions(-) diff --git a/drongo b/drongo index 5b2e21b3..533791ed 160000 --- a/drongo +++ b/drongo @@ -1 +1 @@ -Subproject commit 5b2e21b3d7cc5d6dff730baeec5efbb419f3555c +Subproject commit 533791edcf38a6ca05857483df15a5c54a4554f0 diff --git a/src/main/java/com/sparrowwallet/sparrow/control/EntryCell.java b/src/main/java/com/sparrowwallet/sparrow/control/EntryCell.java index 30d41b9f..2b08d3fc 100644 --- a/src/main/java/com/sparrowwallet/sparrow/control/EntryCell.java +++ b/src/main/java/com/sparrowwallet/sparrow/control/EntryCell.java @@ -183,7 +183,7 @@ public class EntryCell extends TreeTableCell { long changeTotal = ourOutputs.stream().mapToLong(TransactionOutput::getValue).sum(); Transaction tx = blockTransaction.getTransaction(); - int vSize = tx.getVirtualSize(); + double vSize = tx.getVirtualSize(); int inputSize = tx.getInputs().get(0).getLength() + (tx.getInputs().get(0).hasWitness() ? tx.getInputs().get(0).getWitness().getLength() / Transaction.WITNESS_SCALE_FACTOR : 0); List walletUtxos = new ArrayList<>(transactionEntry.getWallet().getWalletUtxos().keySet()); Collections.shuffle(walletUtxos); diff --git a/src/main/java/com/sparrowwallet/sparrow/control/TransactionDiagram.java b/src/main/java/com/sparrowwallet/sparrow/control/TransactionDiagram.java index 06b426a7..a63cb53f 100644 --- a/src/main/java/com/sparrowwallet/sparrow/control/TransactionDiagram.java +++ b/src/main/java/com/sparrowwallet/sparrow/control/TransactionDiagram.java @@ -397,7 +397,7 @@ public class TransactionDiagram extends GridPane { String txDesc = "Transaction"; Label txLabel = new Label(txDesc); - Tooltip tooltip = new Tooltip(walletTx.getTransaction().getLength() + " bytes\n" + walletTx.getTransaction().getVirtualSize() + " vBytes"); + Tooltip tooltip = new Tooltip(walletTx.getTransaction().getLength() + " bytes\n" + String.format("%.2f", walletTx.getTransaction().getVirtualSize()) + " vBytes"); tooltip.setShowDelay(new Duration(TOOLTIP_SHOW_DELAY)); tooltip.getStyleClass().add("transaction-tooltip"); txLabel.setTooltip(tooltip); diff --git a/src/main/java/com/sparrowwallet/sparrow/transaction/HeadersController.java b/src/main/java/com/sparrowwallet/sparrow/transaction/HeadersController.java index 01e8c693..402ad84f 100644 --- a/src/main/java/com/sparrowwallet/sparrow/transaction/HeadersController.java +++ b/src/main/java/com/sparrowwallet/sparrow/transaction/HeadersController.java @@ -29,6 +29,7 @@ import javafx.collections.ObservableMap; import javafx.event.ActionEvent; import javafx.fxml.FXML; import javafx.fxml.Initializable; +import javafx.scene.Node; import javafx.scene.control.*; import javafx.scene.input.Clipboard; import javafx.scene.input.ClipboardContent; @@ -451,7 +452,7 @@ public class HeadersController extends TransactionFormController implements Init private void updateSize() { size.setText(headersForm.getTransaction().getSize() + " B"); - virtualSize.setText(headersForm.getTransaction().getVirtualSize() + " vB"); + virtualSize.setText(String.format("%.2f", headersForm.getTransaction().getVirtualSize()) + " vB"); } private Long calculateFee(Map inputTransactions) { @@ -599,11 +600,21 @@ public class HeadersController extends TransactionFormController implements Init private void updateTxId() { id.setText(headersForm.getTransaction().calculateTxId(false).toString()); if(!headersForm.isTransactionFinalized()) { - if(!id.getStyleClass().contains(UNFINALIZED_TXID_CLASS)) { - id.getStyleClass().add(UNFINALIZED_TXID_CLASS); - } + addStyleClass(id, UNFINALIZED_TXID_CLASS); + addStyleClass(size, UNFINALIZED_TXID_CLASS); + addStyleClass(virtualSize, UNFINALIZED_TXID_CLASS); + addStyleClass(feeRate, UNFINALIZED_TXID_CLASS); } else { id.getStyleClass().remove(UNFINALIZED_TXID_CLASS); + size.getStyleClass().remove(UNFINALIZED_TXID_CLASS); + virtualSize.getStyleClass().remove(UNFINALIZED_TXID_CLASS); + feeRate.getStyleClass().remove(UNFINALIZED_TXID_CLASS); + } + } + + private void addStyleClass(Node node, String styleClass) { + if(!node.getStyleClass().contains(styleClass)) { + node.getStyleClass().add(styleClass); } }