Skip to content

Commit 4d7ff6a

Browse files
authored
Merge pull request #6632 from lightningnetwork/addr-type-taproot
walletkit+sweeper: add forgotten P2TR address type
2 parents 9dea4f3 + 427702d commit 4d7ff6a

File tree

3 files changed

+30
-19
lines changed

3 files changed

+30
-19
lines changed

lnrpc/walletrpc/walletkit_server.go

+17-10
Original file line numberDiff line numberDiff line change
@@ -542,6 +542,9 @@ func (w *WalletKit) NextAddr(ctx context.Context,
542542
case AddressType_HYBRID_NESTED_WITNESS_PUBKEY_HASH:
543543
return nil, fmt.Errorf("invalid address type for next "+
544544
"address: %v", req.Type)
545+
546+
case AddressType_TAPROOT_PUBKEY:
547+
addrType = lnwallet.TaprootPubkey
545548
}
546549

547550
addr, err := w.cfg.Wallet.NewAddress(addrType, req.Change, account)
@@ -858,24 +861,27 @@ func (w *WalletKit) BumpFee(ctx context.Context,
858861
"transaction")
859862
}
860863

864+
signDesc := &input.SignDescriptor{
865+
Output: &wire.TxOut{
866+
PkScript: utxo.PkScript,
867+
Value: int64(utxo.Value),
868+
},
869+
HashType: txscript.SigHashAll,
870+
}
871+
861872
var witnessType input.WitnessType
862873
switch utxo.AddressType {
863874
case lnwallet.WitnessPubKey:
864875
witnessType = input.WitnessKeyHash
865876
case lnwallet.NestedWitnessPubKey:
866877
witnessType = input.NestedWitnessKeyHash
878+
case lnwallet.TaprootPubkey:
879+
witnessType = input.TaprootPubKeySpend
880+
signDesc.HashType = txscript.SigHashDefault
867881
default:
868882
return nil, fmt.Errorf("unknown input witness %v", op)
869883
}
870884

871-
signDesc := &input.SignDescriptor{
872-
Output: &wire.TxOut{
873-
PkScript: utxo.PkScript,
874-
Value: int64(utxo.Value),
875-
},
876-
HashType: txscript.SigHashAll,
877-
}
878-
879885
// We'll use the current height as the height hint since we're dealing
880886
// with an unconfirmed transaction.
881887
_, currentHeight, err := w.cfg.Chain.GetBestBlock()
@@ -884,8 +890,9 @@ func (w *WalletKit) BumpFee(ctx context.Context,
884890
err)
885891
}
886892

887-
input := input.NewBaseInput(op, witnessType, signDesc, uint32(currentHeight))
888-
if _, err = w.cfg.Sweeper.SweepInput(input, sweep.Params{Fee: feePreference}); err != nil {
893+
inp := input.NewBaseInput(op, witnessType, signDesc, uint32(currentHeight))
894+
sweepParams := sweep.Params{Fee: feePreference}
895+
if _, err = w.cfg.Sweeper.SweepInput(inp, sweepParams); err != nil {
889896
return nil, err
890897
}
891898

lnwallet/rpcwallet/rpcwallet.go

+2-1
Original file line numberDiff line numberDiff line change
@@ -259,7 +259,8 @@ func (r *RPCKeyRing) FinalizePsbt(packet *psbt.Packet, _ string) error {
259259
// ones to sign. If there is any input without witness data that we
260260
// cannot sign because it's not our UTXO, this will be a hard failure.
261261
tx := packet.UnsignedTx
262-
sigHashes := input.NewTxSigHashesV0Only(tx)
262+
prevOutFetcher := basewallet.PsbtPrevOutputFetcher(packet)
263+
sigHashes := txscript.NewTxSigHashes(tx, prevOutFetcher)
263264
for idx, txIn := range tx.TxIn {
264265
in := packet.Inputs[idx]
265266

sweep/tx_input_set.go

+11-8
Original file line numberDiff line numberDiff line change
@@ -355,25 +355,28 @@ func (t *txInputSet) tryAddWalletInputsIfNeeded() error {
355355
// createWalletTxInput converts a wallet utxo into an object that can be added
356356
// to the other inputs to sweep.
357357
func createWalletTxInput(utxo *lnwallet.Utxo) (input.Input, error) {
358+
signDesc := &input.SignDescriptor{
359+
Output: &wire.TxOut{
360+
PkScript: utxo.PkScript,
361+
Value: int64(utxo.Value),
362+
},
363+
HashType: txscript.SigHashAll,
364+
}
365+
358366
var witnessType input.WitnessType
359367
switch utxo.AddressType {
360368
case lnwallet.WitnessPubKey:
361369
witnessType = input.WitnessKeyHash
362370
case lnwallet.NestedWitnessPubKey:
363371
witnessType = input.NestedWitnessKeyHash
372+
case lnwallet.TaprootPubkey:
373+
witnessType = input.TaprootPubKeySpend
374+
signDesc.HashType = txscript.SigHashDefault
364375
default:
365376
return nil, fmt.Errorf("unknown address type %v",
366377
utxo.AddressType)
367378
}
368379

369-
signDesc := &input.SignDescriptor{
370-
Output: &wire.TxOut{
371-
PkScript: utxo.PkScript,
372-
Value: int64(utxo.Value),
373-
},
374-
HashType: txscript.SigHashAll,
375-
}
376-
377380
// A height hint doesn't need to be set, because we don't monitor these
378381
// inputs for spend.
379382
heightHint := uint32(0)

0 commit comments

Comments
 (0)