From 1616943afe14904b7a1c11cf4c7834b5d05aa380 Mon Sep 17 00:00:00 2001 From: Carla Kirk-Cohen Date: Tue, 29 Mar 2022 13:58:07 +0200 Subject: [PATCH] swap: add taproot inputs to fee estimation --- swap/htlc.go | 32 ++++++++++++++++++++++++++++++++ 1 file changed, 32 insertions(+) diff --git a/swap/htlc.go b/swap/htlc.go index 24d9434..65a941c 100644 --- a/swap/htlc.go +++ b/swap/htlc.go @@ -298,6 +298,21 @@ func (h *Htlc) AddSuccessToEstimator(estimator *input.TxWeightEstimator) { case HtlcNP2WSH: estimator.AddNestedP2WSHInput(maxSuccessWitnessSize) + + case HtlcP2TR: + claimLeaf := txscript.NewBaseTapLeaf( + h.HtlcScript.SuccessScript(), + ) + + // TODO - find a cleaner way rather than cast to get internal + // pubkey? + htlcV3 := h.HtlcScript.(*HtlcScriptV3) + + tapScript := input.TapscriptPartialReveal( + htlcV3.InternalPubKey, claimLeaf, claimLeaf.TapHash(), + ) + + estimator.AddTapscriptInput(maxSuccessWitnessSize, tapScript) } } @@ -311,6 +326,23 @@ func (h *Htlc) AddTimeoutToEstimator(estimator *input.TxWeightEstimator) { case HtlcNP2WSH: estimator.AddNestedP2WSHInput(maxTimeoutWitnessSize) + + case HtlcP2TR: + timeoutLeaf := txscript.NewBaseTapLeaf( + h.HtlcScript.TimeoutScript(), + ) + + // TODO - find a cleaner way rather than cast to get internal + // pubkey? + htlcV3 := h.HtlcScript.(*HtlcScriptV3) + + tapScript := input.TapscriptPartialReveal( + htlcV3.InternalPubKey, timeoutLeaf, + timeoutLeaf.TapHash(), + ) + + estimator.AddTapscriptInput(maxTimeoutWitnessSize, tapScript) + } }