lnwallet/chanfunding: add Inputs/Outputs to assemblers

This will be used to try to estimate how much the funding transaction
will decrease our wallet balance.
This commit is contained in:
Johan T. Halseth 2021-01-10 21:06:47 +01:00
parent b2857bf392
commit 4a4e0c73f7
No known key found for this signature in database
GPG Key ID: 15BAADA29DA20D26
4 changed files with 103 additions and 0 deletions

@ -103,6 +103,16 @@ type Intent interface {
// change. // change.
LocalFundingAmt() btcutil.Amount 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. // Cancel allows the caller to cancel a funding Intent at any time.
// This will return any resources such as coins back to the eligible // This will return any resources such as coins back to the eligible
// pool to be used in order channel fundings. // pool to be used in order channel fundings.

@ -98,6 +98,30 @@ func (s *ShimIntent) ThawHeight() uint32 {
return s.thawHeight 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. // FundingKeys couples our multi-sig key along with the remote party's key.
type FundingKeys struct { type FundingKeys struct {
// LocalKey is our multi-sig key. // LocalKey is our multi-sig key.

@ -392,6 +392,53 @@ func (i *PsbtIntent) Cancel() {
i.ShimIntent.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 // PsbtAssembler is a type of chanfunding.Assembler wherein the funding
// transaction is constructed outside of lnd by using partially signed bitcoin // transaction is constructed outside of lnd by using partially signed bitcoin
// transactions (PSBT). // transactions (PSBT).

@ -152,6 +152,28 @@ func (f *FullIntent) CompileFundingTx(extraInputs []*wire.TxIn,
return fundingTx, nil 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 // 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 // return any resources such as coins back to the eligible pool to be used in
// order channel fundings. // order channel fundings.