@@ -933,24 +933,13 @@ func (s *swapClientServer) GetLoopInQuote(ctx context.Context,
933933 "deposits: %w" , err )
934934 }
935935
936- // TODO(hieblmi): add params to deposit for multi-address
937- // support.
938- params , err := s .staticAddressManager .GetStaticAddressParameters (
939- ctx ,
940- )
941- if err != nil {
942- return nil , fmt .Errorf ("unable to retrieve static " +
943- "address parameters: %w" , err )
944- }
945-
946936 info , err := s .lnd .Client .GetInfo (ctx )
947937 if err != nil {
948938 return nil , fmt .Errorf ("unable to get lnd info: %w" ,
949939 err )
950940 }
951941 selectedDeposits , err := loopin .SelectDeposits (
952- selectedAmount , deposits , params .Expiry ,
953- info .BlockHeight ,
942+ selectedAmount , deposits , info .BlockHeight ,
954943 )
955944 if err != nil {
956945 return nil , fmt .Errorf ("unable to select deposits: %w" ,
@@ -2018,7 +2007,10 @@ func (s *swapClientServer) ListStaticAddressDeposits(ctx context.Context,
20182007 return isVisibleDeposit (d ) &&
20192008 slices .Contains (outpoints , d .OutPoint .String ())
20202009 }
2021- filteredDeposits = filter (allDeposits , f )
2010+ filteredDeposits , err = s .filterDeposits (allDeposits , f )
2011+ if err != nil {
2012+ return nil , err
2013+ }
20222014
20232015 if len (outpoints ) != len (filteredDeposits ) {
20242016 return nil , fmt .Errorf ("not all outpoints found in " +
@@ -2038,11 +2030,14 @@ func (s *swapClientServer) ListStaticAddressDeposits(ctx context.Context,
20382030
20392031 return d .IsInState (toServerState (req .StateFilter ))
20402032 }
2041- filteredDeposits = filter (allDeposits , f )
2033+ filteredDeposits , err = s .filterDeposits (allDeposits , f )
2034+ if err != nil {
2035+ return nil , err
2036+ }
20422037 }
20432038
20442039 // Calculate the blocks until expiry for each deposit.
2045- err = s .populateBlocksUntilExpiry (ctx , filteredDeposits )
2040+ err = s .populateBlocksUntilExpiry (ctx , allDeposits , filteredDeposits )
20462041 if err != nil {
20472042 infof ("Failed to populate blocks until expiry: %v" , err )
20482043 }
@@ -2120,13 +2115,6 @@ func (s *swapClientServer) ListStaticAddressSwaps(ctx context.Context,
21202115 return nil , err
21212116 }
21222117
2123- addrParams , err := s .staticAddressManager .GetStaticAddressParameters (
2124- ctx ,
2125- )
2126- if err != nil {
2127- return nil , err
2128- }
2129-
21302118 // Fetch all deposits at once and index them by swap hash for a quick
21312119 // lookup.
21322120 allDeposits , err := s .depositManager .GetAllDeposits (ctx )
@@ -2164,8 +2152,14 @@ func (s *swapClientServer) ListStaticAddressSwaps(ctx context.Context,
21642152 protoDeposits = make ([]* looprpc.Deposit , 0 , len (ds ))
21652153 for _ , d := range ds {
21662154 state := toClientDepositState (d .GetState ())
2155+ if d .AddressParams == nil {
2156+ return nil , fmt .Errorf ("missing static " +
2157+ "address parameters for deposit %v" ,
2158+ d .OutPoint )
2159+ }
21672160 blocksUntilExpiry := depositBlocksUntilExpiry (
2168- d .ConfirmationHeight , addrParams .Expiry ,
2161+ d .ConfirmationHeight ,
2162+ d .AddressParams .Expiry ,
21692163 int64 (lndInfo .BlockHeight ),
21702164 )
21712165
@@ -2322,11 +2316,14 @@ func (s *swapClientServer) StaticAddressLoopIn(ctx context.Context,
23222316 }
23232317
23242318 // Build a list of used deposits for the response.
2325- usedDeposits := filter (
2319+ usedDeposits , err := s . filterDeposits (
23262320 loopIn .Deposits , func (d * deposit.Deposit ) bool { return true },
23272321 )
2322+ if err != nil {
2323+ return nil , err
2324+ }
23282325
2329- err = s .populateBlocksUntilExpiry (ctx , usedDeposits )
2326+ err = s .populateBlocksUntilExpiry (ctx , loopIn . Deposits , usedDeposits )
23302327 if err != nil {
23312328 infof ("Failed to populate blocks until expiry: %v" , err )
23322329 }
@@ -2368,21 +2365,31 @@ func (s *swapClientServer) StaticAddressLoopIn(ctx context.Context,
23682365// Calculate the blocks until expiry for each deposit and return the modified
23692366// StaticAddressLoopInResponse.
23702367func (s * swapClientServer ) populateBlocksUntilExpiry (ctx context.Context ,
2371- deposits []* looprpc.Deposit ) error {
2368+ sourceDeposits [] * deposit. Deposit , deposits []* looprpc.Deposit ) error {
23722369
23732370 lndInfo , err := s .lnd .Client .GetInfo (ctx )
23742371 if err != nil {
23752372 return err
23762373 }
23772374
2378- bestBlockHeight := int64 (lndInfo .BlockHeight )
2379- params , err := s .staticAddressManager .GetStaticAddressParameters (ctx )
2380- if err != nil {
2381- return err
2375+ expiryByOutpoint := make (map [string ]uint32 , len (sourceDeposits ))
2376+ for _ , d := range sourceDeposits {
2377+ if d .AddressParams == nil {
2378+ continue
2379+ }
2380+
2381+ expiryByOutpoint [d .OutPoint .String ()] = d .AddressParams .Expiry
23822382 }
2383+
2384+ bestBlockHeight := int64 (lndInfo .BlockHeight )
23832385 for i := range len (deposits ) {
2386+ expiry , ok := expiryByOutpoint [deposits [i ].Outpoint ]
2387+ if ! ok {
2388+ continue
2389+ }
2390+
23842391 deposits [i ].BlocksUntilExpiry = depositBlocksUntilExpiry (
2385- deposits [i ].ConfirmationHeight , params . Expiry ,
2392+ deposits [i ].ConfirmationHeight , expiry ,
23862393 bestBlockHeight ,
23872394 )
23882395 }
@@ -2453,35 +2460,65 @@ func isVisibleDeposit(d *deposit.Deposit) bool {
24532460 return d .GetState () != deposit .Replaced
24542461}
24552462
2456- func filter (deposits []* deposit.Deposit , f filterFunc ) []* looprpc.Deposit {
2463+ func (s * swapClientServer ) filterDeposits (deposits []* deposit.Deposit ,
2464+ f filterFunc ) ([]* looprpc.Deposit , error ) {
2465+
24572466 var clientDeposits []* looprpc.Deposit
24582467 for _ , d := range deposits {
24592468 if ! f (d ) {
24602469 continue
24612470 }
24622471
2463- swapHash := make ([]byte , 0 , len (lntypes.Hash {}))
2464- if d .SwapHash != nil {
2465- swapHash = d .SwapHash [:]
2466- }
2467-
2468- hash := d .Hash
2469- outpoint := wire .NewOutPoint (& hash , d .Index ).String ()
2470- deposit := & looprpc.Deposit {
2471- Id : d .ID [:],
2472- State : toClientDepositState (
2473- d .GetState (),
2474- ),
2475- Outpoint : outpoint ,
2476- Value : int64 (d .Value ),
2477- ConfirmationHeight : d .ConfirmationHeight ,
2478- SwapHash : swapHash ,
2472+ deposit , err := s .rpcDeposit (d )
2473+ if err != nil {
2474+ return nil , err
24792475 }
24802476
24812477 clientDeposits = append (clientDeposits , deposit )
24822478 }
24832479
2484- return clientDeposits
2480+ return clientDeposits , nil
2481+ }
2482+
2483+ func (s * swapClientServer ) rpcDeposit (d * deposit.Deposit ) (
2484+ * looprpc.Deposit , error ) {
2485+
2486+ swapHash := make ([]byte , 0 , len (lntypes.Hash {}))
2487+ if d .SwapHash != nil {
2488+ swapHash = d .SwapHash [:]
2489+ }
2490+
2491+ hash := d .Hash
2492+ outpoint := wire .NewOutPoint (& hash , d .Index ).String ()
2493+ deposit := & looprpc.Deposit {
2494+ Id : d .ID [:],
2495+ State : toClientDepositState (
2496+ d .GetState (),
2497+ ),
2498+ Outpoint : outpoint ,
2499+ Value : int64 (d .Value ),
2500+ ConfirmationHeight : d .ConfirmationHeight ,
2501+ SwapHash : swapHash ,
2502+ }
2503+
2504+ if d .AddressParams == nil {
2505+ return deposit , nil
2506+ }
2507+
2508+ if s .staticAddressManager == nil {
2509+ return nil , fmt .Errorf ("static address manager not configured" )
2510+ }
2511+
2512+ staticAddress , err := s .staticAddressManager .GetTaprootAddress (
2513+ d .AddressParams .ClientPubkey , d .AddressParams .ServerPubkey ,
2514+ int64 (d .AddressParams .Expiry ),
2515+ )
2516+ if err != nil {
2517+ return nil , err
2518+ }
2519+ deposit .StaticAddress = staticAddress .String ()
2520+
2521+ return deposit , nil
24852522}
24862523
24872524func toClientDepositState (state fsm.StateType ) looprpc.DepositState {
0 commit comments