From 36d6656d0ddc332386418287ff3ccdb79d4f06f5 Mon Sep 17 00:00:00 2001 From: Oliver Gugger Date: Fri, 10 Jun 2022 14:03:46 +0200 Subject: [PATCH 1/3] walletrpc: add p2tr to NextAddr and BumpFee RPCs --- lnrpc/walletrpc/walletkit_server.go | 27 +++++++++++++++++---------- 1 file changed, 17 insertions(+), 10 deletions(-) diff --git a/lnrpc/walletrpc/walletkit_server.go b/lnrpc/walletrpc/walletkit_server.go index bb8fb8d06c5..9acd5fa0fe5 100644 --- a/lnrpc/walletrpc/walletkit_server.go +++ b/lnrpc/walletrpc/walletkit_server.go @@ -542,6 +542,9 @@ func (w *WalletKit) NextAddr(ctx context.Context, case AddressType_HYBRID_NESTED_WITNESS_PUBKEY_HASH: return nil, fmt.Errorf("invalid address type for next "+ "address: %v", req.Type) + + case AddressType_TAPROOT_PUBKEY: + addrType = lnwallet.TaprootPubkey } addr, err := w.cfg.Wallet.NewAddress(addrType, req.Change, account) @@ -858,24 +861,27 @@ func (w *WalletKit) BumpFee(ctx context.Context, "transaction") } + signDesc := &input.SignDescriptor{ + Output: &wire.TxOut{ + PkScript: utxo.PkScript, + Value: int64(utxo.Value), + }, + 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 input witness %v", op) } - signDesc := &input.SignDescriptor{ - Output: &wire.TxOut{ - PkScript: utxo.PkScript, - Value: int64(utxo.Value), - }, - HashType: txscript.SigHashAll, - } - // We'll use the current height as the height hint since we're dealing // with an unconfirmed transaction. _, currentHeight, err := w.cfg.Chain.GetBestBlock() @@ -884,8 +890,9 @@ func (w *WalletKit) BumpFee(ctx context.Context, err) } - input := input.NewBaseInput(op, witnessType, signDesc, uint32(currentHeight)) - if _, err = w.cfg.Sweeper.SweepInput(input, sweep.Params{Fee: feePreference}); err != nil { + inp := input.NewBaseInput(op, witnessType, signDesc, uint32(currentHeight)) + sweepParams := sweep.Params{Fee: feePreference} + if _, err = w.cfg.Sweeper.SweepInput(inp, sweepParams); err != nil { return nil, err } From a3e4db60cd474139f3db0bf6ac5a9276c39eeede Mon Sep 17 00:00:00 2001 From: Oliver Gugger Date: Fri, 10 Jun 2022 14:04:15 +0200 Subject: [PATCH 2/3] sweep: allow sweeper to sweep P2TR inputs --- sweep/tx_input_set.go | 19 +++++++++++-------- 1 file changed, 11 insertions(+), 8 deletions(-) diff --git a/sweep/tx_input_set.go b/sweep/tx_input_set.go index e215f67683b..9dc48901c85 100644 --- a/sweep/tx_input_set.go +++ b/sweep/tx_input_set.go @@ -355,25 +355,28 @@ 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) { + signDesc := &input.SignDescriptor{ + Output: &wire.TxOut{ + PkScript: utxo.PkScript, + Value: int64(utxo.Value), + }, + 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) } - signDesc := &input.SignDescriptor{ - Output: &wire.TxOut{ - PkScript: utxo.PkScript, - Value: int64(utxo.Value), - }, - HashType: txscript.SigHashAll, - } - // A height hint doesn't need to be set, because we don't monitor these // inputs for spend. heightHint := uint32(0) From 427702dbe6a1efd7e8a4c124f6817b899933fe92 Mon Sep 17 00:00:00 2001 From: Oliver Gugger Date: Fri, 10 Jun 2022 20:12:54 +0200 Subject: [PATCH 3/3] rpcwallet: use PSBT prev out fetcher --- lnwallet/rpcwallet/rpcwallet.go | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/lnwallet/rpcwallet/rpcwallet.go b/lnwallet/rpcwallet/rpcwallet.go index de47a0759c8..cb746775224 100644 --- a/lnwallet/rpcwallet/rpcwallet.go +++ b/lnwallet/rpcwallet/rpcwallet.go @@ -259,7 +259,8 @@ func (r *RPCKeyRing) FinalizePsbt(packet *psbt.Packet, _ string) error { // ones to sign. If there is any input without witness data that we // cannot sign because it's not our UTXO, this will be a hard failure. tx := packet.UnsignedTx - sigHashes := input.NewTxSigHashesV0Only(tx) + prevOutFetcher := basewallet.PsbtPrevOutputFetcher(packet) + sigHashes := txscript.NewTxSigHashes(tx, prevOutFetcher) for idx, txIn := range tx.TxIn { in := packet.Inputs[idx]