@@ -1788,20 +1788,9 @@ func (s *swapClientServer) ListStaticAddressDeposits(ctx context.Context,
17881788 }
17891789
17901790 // Calculate the blocks until expiry for each deposit.
1791- lndInfo , err : = s .lnd . Client . GetInfo (ctx )
1791+ err = s .populateBlocksUntilExpiry (ctx , filteredDeposits )
17921792 if err != nil {
1793- return nil , err
1794- }
1795-
1796- bestBlockHeight := int64 (lndInfo .BlockHeight )
1797- params , err := s .staticAddressManager .GetStaticAddressParameters (ctx )
1798- if err != nil {
1799- return nil , err
1800- }
1801- for i := 0 ; i < len (filteredDeposits ); i ++ {
1802- filteredDeposits [i ].BlocksUntilExpiry =
1803- filteredDeposits [i ].ConfirmationHeight +
1804- int64 (params .Expiry ) - bestBlockHeight
1793+ infof ("Failed to populate blocks until expiry: %v" , err )
18051794 }
18061795
18071796 return & looprpc.ListStaticAddressDepositsResponse {
@@ -2083,6 +2072,11 @@ func (s *swapClientServer) StaticAddressLoopIn(ctx context.Context,
20832072 loopIn .Deposits , func (d * deposit.Deposit ) bool { return true },
20842073 )
20852074
2075+ err = s .populateBlocksUntilExpiry (ctx , usedDeposits )
2076+ if err != nil {
2077+ infof ("Failed to populate blocks until expiry: %v" , err )
2078+ }
2079+
20862080 // Determine the actual swap amount and change based on the selected
20872081 // amount and the total value of the selected deposits.
20882082 total := loopIn .TotalDepositAmount ()
@@ -2117,6 +2111,29 @@ func (s *swapClientServer) StaticAddressLoopIn(ctx context.Context,
21172111 }, nil
21182112}
21192113
2114+ // Calculate the blocks until expiry for each deposit and return the modified
2115+ // StaticAddressLoopInResponse.
2116+ func (s * swapClientServer ) populateBlocksUntilExpiry (ctx context.Context ,
2117+ deposits []* looprpc.Deposit ) error {
2118+
2119+ lndInfo , err := s .lnd .Client .GetInfo (ctx )
2120+ if err != nil {
2121+ return err
2122+ }
2123+
2124+ bestBlockHeight := int64 (lndInfo .BlockHeight )
2125+ params , err := s .staticAddressManager .GetStaticAddressParameters (ctx )
2126+ if err != nil {
2127+ return err
2128+ }
2129+ for i := 0 ; i < len (deposits ); i ++ {
2130+ deposits [i ].BlocksUntilExpiry =
2131+ deposits [i ].ConfirmationHeight +
2132+ int64 (params .Expiry ) - bestBlockHeight
2133+ }
2134+ return nil
2135+ }
2136+
21202137type filterFunc func (deposits * deposit.Deposit ) bool
21212138
21222139func filter (deposits []* deposit.Deposit , f filterFunc ) []* looprpc.Deposit {
0 commit comments