From 38b04b8e0b802f6cd43b4e88730d4d3ed31227fc Mon Sep 17 00:00:00 2001 From: Craig Raw Date: Tue, 11 Jul 2023 11:24:07 +0200 Subject: [PATCH] fix input vbytes type from int to double --- .../sparrowwallet/drongo/protocol/ScriptType.java | 12 ++++++------ .../drongo/wallet/PresetUtxoSelector.java | 7 +++++++ 2 files changed, 13 insertions(+), 6 deletions(-) diff --git a/src/main/java/com/sparrowwallet/drongo/protocol/ScriptType.java b/src/main/java/com/sparrowwallet/drongo/protocol/ScriptType.java index f79cd7b..1d45f46 100644 --- a/src/main/java/com/sparrowwallet/drongo/protocol/ScriptType.java +++ b/src/main/java/com/sparrowwallet/drongo/protocol/ScriptType.java @@ -1320,7 +1320,7 @@ public enum ScriptType { //Start with length of output int outputVbytes = output.getLength(); //Add length of spending input (with or without discount depending on script type) - int inputVbytes = getInputVbytes(); + double inputVbytes = getInputVbytes(); //Return fee rate in sats/vByte multiplied by the calculated output and input vByte lengths return (long)(feeRate * outputVbytes + longTermFeeRate * inputVbytes); @@ -1333,17 +1333,17 @@ public enum ScriptType { * * @return The number of vBytes required for an input of this script type */ - public int getInputVbytes() { + public double getInputVbytes() { if(P2SH_P2WPKH.equals(this)) { - return (32 + 4 + 1 + 13 + (107 / WITNESS_SCALE_FACTOR) + 4); + return (32 + 4 + 1 + 13 + ((double)107 / WITNESS_SCALE_FACTOR) + 4); } else if(P2SH_P2WSH.equals(this)) { - return (32 + 4 + 1 + 35 + (107 / WITNESS_SCALE_FACTOR) + 4); + return (32 + 4 + 1 + 35 + ((double)107 / WITNESS_SCALE_FACTOR) + 4); } else if(P2TR.equals(this)) { //Assume a default keypath spend - return (32 + 4 + 1 + (66 / WITNESS_SCALE_FACTOR) + 4); + return (32 + 4 + 1 + ((double)66 / WITNESS_SCALE_FACTOR) + 4); } else if(Arrays.asList(WITNESS_TYPES).contains(this)) { //Return length of spending input with 75% discount to script size - return (32 + 4 + 1 + (107 / WITNESS_SCALE_FACTOR) + 4); + return (32 + 4 + 1 + ((double)107 / WITNESS_SCALE_FACTOR) + 4); } else if(Arrays.asList(NON_WITNESS_TYPES).contains(this)) { //Return length of spending input with no discount return (32 + 4 + 1 + 107 + 4); diff --git a/src/main/java/com/sparrowwallet/drongo/wallet/PresetUtxoSelector.java b/src/main/java/com/sparrowwallet/drongo/wallet/PresetUtxoSelector.java index 85f4608..64728b4 100644 --- a/src/main/java/com/sparrowwallet/drongo/wallet/PresetUtxoSelector.java +++ b/src/main/java/com/sparrowwallet/drongo/wallet/PresetUtxoSelector.java @@ -59,6 +59,13 @@ public class PresetUtxoSelector extends SingleSetUtxoSelector { return excludedUtxos; } + public TxoFilter asExcludeTxoFilter() { + List utxos = new ArrayList<>(); + utxos.addAll(presetUtxos); + utxos.addAll(excludedUtxos); + return new ExcludeTxoFilter(utxos); + } + @Override public boolean shuffleInputs() { return !maintainOrder;