Skip to content

Commit 00a52e6

Browse files
committed
gui: fix coin control input size accounting for taproot spends
1 parent 54bdb6e commit 00a52e6

File tree

1 file changed

+13
-1
lines changed

1 file changed

+13
-1
lines changed

src/qt/coincontroldialog.cpp

Lines changed: 13 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -421,7 +421,19 @@ void CoinControlDialog::updateLabels(CCoinControl& m_coin_control, WalletModel *
421421
std::vector<unsigned char> witnessprogram;
422422
if (out.txout.scriptPubKey.IsWitnessProgram(witnessversion, witnessprogram))
423423
{
424-
nBytesInputs += (32 + 4 + 1 + (107 / WITNESS_SCALE_FACTOR) + 4);
424+
// add input skeleton bytes (outpoint, scriptSig size, nSequence)
425+
nBytesInputs += (32 + 4 + 1 + 4);
426+
427+
if (witnessversion == 0) { // P2WPKH
428+
// 1 WU (witness item count) + 72 WU (ECDSA signature with len byte) + 34 WU (pubkey with len byte)
429+
nBytesInputs += 107 / WITNESS_SCALE_FACTOR;
430+
} else if (witnessversion == 1) { // P2TR key-path spend
431+
// 1 WU (witness item count) + 65 WU (Schnorr signature with len byte)
432+
nBytesInputs += 66 / WITNESS_SCALE_FACTOR;
433+
} else {
434+
// not supported, should be unreachable
435+
throw std::runtime_error("Trying to spend future segwit version script");
436+
}
425437
fWitness = true;
426438
}
427439
else if(ExtractDestination(out.txout.scriptPubKey, address))

0 commit comments

Comments
 (0)