lnwallet: add HtlcPoint() resolution helper methods

Co-authored-by: Joost Jager <joost.jager@gmail.com>
This commit is contained in:
Wilmer Paulino 2019-01-22 20:45:29 -08:00
parent 865f7568d6
commit 93754f8d37
No known key found for this signature in database
GPG Key ID: 6DF57B9F9514972F
2 changed files with 26 additions and 24 deletions

@ -1084,33 +1084,11 @@ func (c *ChannelArbitrator) prepContractResolutions(htlcActions ChainActionMap,
inResolutionMap := make(map[wire.OutPoint]lnwallet.IncomingHtlcResolution)
for i := 0; i < len(incomingResolutions); i++ {
inRes := incomingResolutions[i]
// If we have a success transaction, then the htlc's outpoint
// is the transaction's only input. Otherwise, it's the claim
// point.
var htlcPoint wire.OutPoint
if inRes.SignedSuccessTx != nil {
htlcPoint = inRes.SignedSuccessTx.TxIn[0].PreviousOutPoint
} else {
htlcPoint = inRes.ClaimOutpoint
}
inResolutionMap[htlcPoint] = inRes
inResolutionMap[inRes.HtlcPoint()] = inRes
}
for i := 0; i < len(outgoingResolutions); i++ {
outRes := outgoingResolutions[i]
// If we have a timeout transaction, then the htlc's outpoint
// is the transaction's only input. Otherwise, it's the claim
// point.
var htlcPoint wire.OutPoint
if outRes.SignedTimeoutTx != nil {
htlcPoint = outRes.SignedTimeoutTx.TxIn[0].PreviousOutPoint
} else {
htlcPoint = outRes.ClaimOutpoint
}
outResolutionMap[htlcPoint] = outRes
outResolutionMap[outRes.HtlcPoint()] = outRes
}
// We'll create the resolver kit that we'll be cloning for each

@ -5499,6 +5499,30 @@ func newIncomingHtlcResolution(signer Signer, localChanCfg *channeldb.ChannelCon
}, nil
}
// HtlcPoint returns the htlc's outpoint on the commitment tx.
func (r *IncomingHtlcResolution) HtlcPoint() wire.OutPoint {
// If we have a success transaction, then the htlc's outpoint
// is the transaction's only input. Otherwise, it's the claim
// point.
if r.SignedSuccessTx != nil {
return r.SignedSuccessTx.TxIn[0].PreviousOutPoint
}
return r.ClaimOutpoint
}
// HtlcPoint returns the htlc's outpoint on the commitment tx.
func (r *OutgoingHtlcResolution) HtlcPoint() wire.OutPoint {
// If we have a timeout transaction, then the htlc's outpoint
// is the transaction's only input. Otherwise, it's the claim
// point.
if r.SignedTimeoutTx != nil {
return r.SignedTimeoutTx.TxIn[0].PreviousOutPoint
}
return r.ClaimOutpoint
}
// extractHtlcResolutions creates a series of outgoing HTLC resolutions, and
// the local key used when generating the HTLC scrips. This function is to be
// used in two cases: force close, or a unilateral close.