swap: refactor htlc construction to allow passing of internal keys

This commit is a refactor of how we construct htlcs to make it possible
to pass in internal keys for the sender and receiver when creating P2TR
htlcs. Furthermore the commit also cleans up constructors to not pass in
script versions and output types to make the code more readable.
This commit is contained in:
Andras Banki-Horvath 2022-11-16 19:01:28 +01:00
parent 35e0120e8f
commit bdb4b773ed
No known key found for this signature in database
GPG key ID: 80E5375C094198D8
9 changed files with 212 additions and 182 deletions

View file

@ -404,26 +404,26 @@ func validateLoopInContract(lnd *lndclient.LndServices,
// initHtlcs creates and updates the native and nested segwit htlcs
// of the loopInSwap.
func (s *loopInSwap) initHtlcs() error {
if IsTaprootSwap(&s.SwapContract) {
htlcP2TR, err := s.swapKit.getHtlc(swap.HtlcP2TR)
if err != nil {
return err
}
s.swapKit.log.Infof("Htlc address (P2TR): %v", htlcP2TR.Address)
s.htlcP2TR = htlcP2TR
return nil
}
htlcP2WSH, err := s.swapKit.getHtlc(swap.HtlcP2WSH)
htlc, err := GetHtlc(
s.hash, &s.SwapContract, s.swapKit.lnd.ChainParams,
)
if err != nil {
return err
}
// Log htlc addresses for debugging.
s.swapKit.log.Infof("Htlc address (P2WSH): %v", htlcP2WSH.Address)
s.htlcP2WSH = htlcP2WSH
switch htlc.OutputType {
case swap.HtlcP2WSH:
s.htlcP2WSH = htlc
case swap.HtlcP2TR:
s.htlcP2TR = htlc
default:
return fmt.Errorf("invalid output type")
}
s.swapKit.log.Infof("Htlc address (%s): %v", htlc.OutputType,
htlc.Address)
return nil
}