diff --git a/lnwallet/chanfunding/assembler.go b/lnwallet/chanfunding/assembler.go index 2a78f375..4fcb8676 100644 --- a/lnwallet/chanfunding/assembler.go +++ b/lnwallet/chanfunding/assembler.go @@ -103,6 +103,16 @@ type Intent interface { // change. LocalFundingAmt() btcutil.Amount + // Inputs returns all inputs to the final funding transaction that we + // know about. Note that there might be more, but we are not (yet) + // aware of. + Inputs() []wire.OutPoint + + // Outputs returns all outputs of the final funding transaction that we + // know about. Note that there might be more, but we are not (yet) + // aware of. + Outputs() []*wire.TxOut + // Cancel allows the caller to cancel a funding Intent at any time. // This will return any resources such as coins back to the eligible // pool to be used in order channel fundings. diff --git a/lnwallet/chanfunding/canned_assembler.go b/lnwallet/chanfunding/canned_assembler.go index b512a722..5bd88682 100644 --- a/lnwallet/chanfunding/canned_assembler.go +++ b/lnwallet/chanfunding/canned_assembler.go @@ -98,6 +98,30 @@ func (s *ShimIntent) ThawHeight() uint32 { return s.thawHeight } +// Inputs returns all inputs to the final funding transaction that we +// know about. For the ShimIntent this will always be none, since it is funded +// externally. +func (s *ShimIntent) Inputs() []wire.OutPoint { + return nil +} + +// Outputs returns all outputs of the final funding transaction that we +// know about. Since this is an externally funded channel, the channel output +// is the only known one. +func (s *ShimIntent) Outputs() []*wire.TxOut { + _, txOut, err := s.FundingOutput() + if err != nil { + log.Warnf("Unable to find funding output for shim intent: %v", + err) + + // Failed finding funding output, return empty list of known + // outputs. + return nil + } + + return []*wire.TxOut{txOut} +} + // FundingKeys couples our multi-sig key along with the remote party's key. type FundingKeys struct { // LocalKey is our multi-sig key. diff --git a/lnwallet/chanfunding/psbt_assembler.go b/lnwallet/chanfunding/psbt_assembler.go index a40bae3c..4d15ff53 100644 --- a/lnwallet/chanfunding/psbt_assembler.go +++ b/lnwallet/chanfunding/psbt_assembler.go @@ -392,6 +392,53 @@ func (i *PsbtIntent) Cancel() { i.ShimIntent.Cancel() } +// Inputs returns all inputs to the final funding transaction that we know +// about. These are only known after the PSBT has been verified. +func (i *PsbtIntent) Inputs() []wire.OutPoint { + var inputs []wire.OutPoint + + switch i.State { + + // We return the inputs to the pending psbt. + case PsbtVerified: + for _, in := range i.PendingPsbt.UnsignedTx.TxIn { + inputs = append(inputs, in.PreviousOutPoint) + } + + // We return the inputs to the final funding tx. + case PsbtFinalized, PsbtFundingTxCompiled: + for _, in := range i.FinalTX.TxIn { + inputs = append(inputs, in.PreviousOutPoint) + } + + // In all other states we cannot know the inputs to the funding tx, and + // return an empty list. + default: + } + + return inputs +} + +// Outputs returns all outputs of the final funding transaction that we +// know about. These are only known after the PSBT has been verified. +func (i *PsbtIntent) Outputs() []*wire.TxOut { + switch i.State { + + // We return the outputs of the pending psbt. + case PsbtVerified: + return i.PendingPsbt.UnsignedTx.TxOut + + // We return the outputs of the final funding tx. + case PsbtFinalized, PsbtFundingTxCompiled: + return i.FinalTX.TxOut + + // In all other states we cannot know the final outputs, and return an + // empty list. + default: + return nil + } +} + // PsbtAssembler is a type of chanfunding.Assembler wherein the funding // transaction is constructed outside of lnd by using partially signed bitcoin // transactions (PSBT). diff --git a/lnwallet/chanfunding/wallet_assembler.go b/lnwallet/chanfunding/wallet_assembler.go index 554654fe..9cdf9b10 100644 --- a/lnwallet/chanfunding/wallet_assembler.go +++ b/lnwallet/chanfunding/wallet_assembler.go @@ -152,6 +152,28 @@ func (f *FullIntent) CompileFundingTx(extraInputs []*wire.TxIn, return fundingTx, nil } +// Inputs returns all inputs to the final funding transaction that we +// know about. Since this funding transaction is created all from our wallet, +// it will be all inputs. +func (f *FullIntent) Inputs() []wire.OutPoint { + var ins []wire.OutPoint + for _, coin := range f.InputCoins { + ins = append(ins, coin.OutPoint) + } + + return ins +} + +// Outputs returns all outputs of the final funding transaction that we +// know about. This will be the funding output and the change outputs going +// back to our wallet. +func (f *FullIntent) Outputs() []*wire.TxOut { + outs := f.ShimIntent.Outputs() + outs = append(outs, f.ChangeOutputs...) + + return outs +} + // Cancel allows the caller to cancel a funding Intent at any time. This will // return any resources such as coins back to the eligible pool to be used in // order channel fundings.