From 533791edcf38a6ca05857483df15a5c54a4554f0 Mon Sep 17 00:00:00 2001 From: Craig Raw Date: Mon, 8 Mar 2021 16:20:35 +0200 Subject: [PATCH] use fractional tx virtual size --- .../java/com/sparrowwallet/drongo/protocol/Transaction.java | 4 ++-- src/main/java/com/sparrowwallet/drongo/wallet/Wallet.java | 4 ++-- 2 files changed, 4 insertions(+), 4 deletions(-) diff --git a/src/main/java/com/sparrowwallet/drongo/protocol/Transaction.java b/src/main/java/com/sparrowwallet/drongo/protocol/Transaction.java index e7c7f22..46425a3 100644 --- a/src/main/java/com/sparrowwallet/drongo/protocol/Transaction.java +++ b/src/main/java/com/sparrowwallet/drongo/protocol/Transaction.java @@ -303,8 +303,8 @@ public class Transaction extends ChildMessage { return length; } - public int getVirtualSize() { - return (int)Math.ceil((double)getWeightUnits() / (double)WITNESS_SCALE_FACTOR); + public double getVirtualSize() { + return (double)getWeightUnits() / (double)WITNESS_SCALE_FACTOR; } public int getWeightUnits() { diff --git a/src/main/java/com/sparrowwallet/drongo/wallet/Wallet.java b/src/main/java/com/sparrowwallet/drongo/wallet/Wallet.java index d772166..17f3d06 100644 --- a/src/main/java/com/sparrowwallet/drongo/wallet/Wallet.java +++ b/src/main/java/com/sparrowwallet/drongo/wallet/Wallet.java @@ -489,7 +489,7 @@ public class Wallet { transaction.addOutput(payment.getAmount(), payment.getAddress()); } - int noChangeVSize = transaction.getVirtualSize(); + double noChangeVSize = transaction.getVirtualSize(); long noChangeFeeRequiredAmt = (fee == null ? (long)(feeRate * noChangeVSize) : fee); //Add 1 satoshi to accommodate longer signatures when feeRate equals default min relay fee to ensure fee is sufficient @@ -528,7 +528,7 @@ public class Wallet { //Change output is required, determine new fee once change output has been added WalletNode changeNode = getFreshNode(KeyPurpose.CHANGE); TransactionOutput changeOutput = new TransactionOutput(transaction, changeAmt, getOutputScript(changeNode)); - int changeVSize = noChangeVSize + changeOutput.getLength(); + double changeVSize = noChangeVSize + changeOutput.getLength(); long changeFeeRequiredAmt = (fee == null ? (long)(feeRate * changeVSize) : fee); changeFeeRequiredAmt = (feeRate == Transaction.DEFAULT_MIN_RELAY_FEE ? changeFeeRequiredAmt + 1 : changeFeeRequiredAmt);