handle longer signature with min relay fee set

This commit is contained in:
Craig Raw 2020-10-01 09:06:02 +02:00
parent b877e94cd0
commit 9c6d3ec94b

View file

@ -462,6 +462,9 @@ public class Wallet {
int 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
noChangeFeeRequiredAmt = (feeRate == Transaction.DEFAULT_MIN_RELAY_FEE ? noChangeFeeRequiredAmt + 1 : noChangeFeeRequiredAmt);
//If sending all selected utxos, set the recipient amount to equal to total of those utxos less the no change fee
long maxSendAmt = totalSelectedAmt - noChangeFeeRequiredAmt;
if(sendAll && recipientAmount != maxSendAmt) {
@ -487,6 +490,7 @@ public class Wallet {
TransactionOutput changeOutput = new TransactionOutput(transaction, changeAmt, getOutputScript(changeNode));
int changeVSize = noChangeVSize + changeOutput.getLength();
long changeFeeRequiredAmt = (fee == null ? (long)(feeRate * changeVSize) : fee);
changeFeeRequiredAmt = (feeRate == Transaction.DEFAULT_MIN_RELAY_FEE ? changeFeeRequiredAmt + 1 : changeFeeRequiredAmt);
//Recalculate the change amount with the new fee
changeAmt = differenceAmt - changeFeeRequiredAmt;