From a3e4db60cd474139f3db0bf6ac5a9276c39eeede Mon Sep 17 00:00:00 2001 From: Oliver Gugger Date: Fri, 10 Jun 2022 14:04:15 +0200 Subject: [PATCH] sweep: allow sweeper to sweep P2TR inputs --- sweep/tx_input_set.go | 25 ++++++++++++++----------- 1 file changed, 14 insertions(+), 11 deletions(-) diff --git a/sweep/tx_input_set.go b/sweep/tx_input_set.go index e215f6768..9dc48901c 100644 --- a/sweep/tx_input_set.go +++ b/sweep/tx_input_set.go @@ -355,17 +355,6 @@ func (t *txInputSet) tryAddWalletInputsIfNeeded() error { // createWalletTxInput converts a wallet utxo into an object that can be added // to the other inputs to sweep. func createWalletTxInput(utxo *lnwallet.Utxo) (input.Input, error) { - var witnessType input.WitnessType - switch utxo.AddressType { - case lnwallet.WitnessPubKey: - witnessType = input.WitnessKeyHash - case lnwallet.NestedWitnessPubKey: - witnessType = input.NestedWitnessKeyHash - default: - return nil, fmt.Errorf("unknown address type %v", - utxo.AddressType) - } - signDesc := &input.SignDescriptor{ Output: &wire.TxOut{ PkScript: utxo.PkScript, @@ -374,6 +363,20 @@ func createWalletTxInput(utxo *lnwallet.Utxo) (input.Input, error) { HashType: txscript.SigHashAll, } + var witnessType input.WitnessType + switch utxo.AddressType { + case lnwallet.WitnessPubKey: + witnessType = input.WitnessKeyHash + case lnwallet.NestedWitnessPubKey: + witnessType = input.NestedWitnessKeyHash + case lnwallet.TaprootPubkey: + witnessType = input.TaprootPubKeySpend + signDesc.HashType = txscript.SigHashDefault + default: + return nil, fmt.Errorf("unknown address type %v", + utxo.AddressType) + } + // A height hint doesn't need to be set, because we don't monitor these // inputs for spend. heightHint := uint32(0)