@@ -21,6 +21,7 @@ import (
2121 "github.com/lightninglabs/loop/staticaddr/address"
2222 "github.com/lightninglabs/loop/staticaddr/deposit"
2323 "github.com/lightninglabs/loop/staticaddr/script"
24+ "github.com/lightninglabs/loop/staticaddr/staticutil"
2425 "github.com/lightninglabs/loop/staticaddr/version"
2526 "github.com/lightninglabs/loop/swap"
2627 "github.com/lightningnetwork/lnd/input"
@@ -169,55 +170,16 @@ func (l *StaticAddressLoopIn) getHtlc(chainParams *chaincfg.Params) (*swap.Htlc,
169170 )
170171}
171172
172- // createMusig2Sessions creates a musig2 session for a number of deposits.
173- func (l * StaticAddressLoopIn ) createMusig2Sessions (ctx context.Context ,
174- signer lndclient.SignerClient ) ([]* input.MuSig2SessionInfo , [][]byte ,
175- error ) {
176-
177- musig2Sessions := make ([]* input.MuSig2SessionInfo , len (l .Deposits ))
178- clientNonces := make ([][]byte , len (l .Deposits ))
179-
180- // Create the sessions and nonces from the deposits.
181- for i := 0 ; i < len (l .Deposits ); i ++ {
182- session , err := l .createMusig2Session (ctx , signer )
183- if err != nil {
184- return nil , nil , err
185- }
186-
187- musig2Sessions [i ] = session
188- clientNonces [i ] = session .PublicNonce [:]
189- }
190-
191- return musig2Sessions , clientNonces , nil
192- }
193-
194- // Musig2CreateSession creates a musig2 session for the deposit.
195- func (l * StaticAddressLoopIn ) createMusig2Session (ctx context.Context ,
196- signer lndclient.SignerClient ) (* input.MuSig2SessionInfo , error ) {
197-
198- signers := [][]byte {
199- l .AddressParams .ClientPubkey .SerializeCompressed (),
200- l .AddressParams .ServerPubkey .SerializeCompressed (),
201- }
202-
203- expiryLeaf := l .Address .TimeoutLeaf
204-
205- rootHash := expiryLeaf .TapHash ()
206-
207- return signer .MuSig2CreateSession (
208- ctx , input .MuSig2Version100RC2 , & l .AddressParams .KeyLocator ,
209- signers , lndclient .MuSig2TaprootTweakOpt (rootHash [:], false ),
210- )
211- }
212-
213173// signMusig2Tx adds the server nonces to the musig2 sessions and signs the
214174// transaction.
215175func (l * StaticAddressLoopIn ) signMusig2Tx (ctx context.Context ,
216176 tx * wire.MsgTx , signer lndclient.SignerClient ,
217177 musig2sessions []* input.MuSig2SessionInfo ,
218178 counterPartyNonces [][musig2 .PubNonceSize ]byte ) ([][]byte , error ) {
219179
220- prevOuts , err := l .toPrevOuts (l .Deposits , l .AddressParams .PkScript )
180+ prevOuts , err := staticutil .ToPrevOuts (
181+ l .Deposits , l .AddressParams .PkScript ,
182+ )
221183 if err != nil {
222184 return nil , err
223185 }
@@ -523,29 +485,6 @@ func (l *StaticAddressLoopIn) Outpoints() []wire.OutPoint {
523485 return outpoints
524486}
525487
526- func (l * StaticAddressLoopIn ) toPrevOuts (deposits []* deposit.Deposit ,
527- pkScript []byte ) (map [wire.OutPoint ]* wire.TxOut , error ) {
528-
529- prevOuts := make (map [wire.OutPoint ]* wire.TxOut , len (deposits ))
530- for _ , d := range deposits {
531- outpoint := wire.OutPoint {
532- Hash : d .Hash ,
533- Index : d .Index ,
534- }
535- txOut := & wire.TxOut {
536- Value : int64 (d .Value ),
537- PkScript : pkScript ,
538- }
539- if _ , ok := prevOuts [outpoint ]; ok {
540- return nil , fmt .Errorf ("duplicate outpoint %v" ,
541- outpoint )
542- }
543- prevOuts [outpoint ] = txOut
544- }
545-
546- return prevOuts , nil
547- }
548-
549488// GetState returns the current state of the loop-in swap.
550489func (l * StaticAddressLoopIn ) GetState () fsm.StateType {
551490 l .mu .Lock ()
0 commit comments