@@ -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 {
@@ -2078,21 +2067,73 @@ func (s *swapClientServer) StaticAddressLoopIn(ctx context.Context,
20782067 return nil , err
20792068 }
20802069
2070+ // Build a list of used deposits for the response.
2071+ usedDeposits := filter (
2072+ loopIn .Deposits , func (d * deposit.Deposit ) bool { return true },
2073+ )
2074+
2075+ err = s .populateBlocksUntilExpiry (ctx , usedDeposits )
2076+ if err != nil {
2077+ infof ("Failed to populate blocks until expiry: %v" , err )
2078+ }
2079+
2080+ // Determine the actual swap amount and change based on the selected
2081+ // amount and the total value of the selected deposits.
2082+ total := loopIn .TotalDepositAmount ()
2083+ swapAmt := total
2084+ var changeAmt btcutil.Amount
2085+ if loopIn .SelectedAmount > 0 {
2086+ amt , err := loopin .DeduceSwapAmount (
2087+ total , loopIn .SelectedAmount ,
2088+ )
2089+ if err == nil {
2090+ swapAmt = amt
2091+ changeAmt = total - amt
2092+ }
2093+ }
2094+
20812095 return & looprpc.StaticAddressLoopInResponse {
20822096 SwapHash : loopIn .SwapHash [:],
20832097 State : string (loopIn .GetState ()),
2084- Amount : uint64 (loopIn .TotalDepositAmount ()),
2098+ Amount : uint64 (total ),
2099+ SwapAmount : uint64 (swapAmt ),
2100+ Change : int64 (changeAmt ),
2101+ QuotedSwapFeeSatoshis : int64 (loopIn .QuotedSwapFee ),
2102+ Fast : loopIn .Fast ,
20852103 HtlcCltv : loopIn .HtlcCltvExpiry ,
20862104 MaxSwapFeeSatoshis : int64 (loopIn .MaxSwapFee ),
20872105 InitiationHeight : loopIn .InitiationHeight ,
20882106 ProtocolVersion : loopIn .ProtocolVersion .String (),
20892107 Initiator : loopIn .Initiator ,
20902108 Label : loopIn .Label ,
20912109 PaymentTimeoutSeconds : loopIn .PaymentTimeoutSeconds ,
2092- QuotedSwapFeeSatoshis : int64 ( loopIn . QuotedSwapFee ) ,
2110+ UsedDeposits : usedDeposits ,
20932111 }, nil
20942112}
20952113
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+
20962137type filterFunc func (deposits * deposit.Deposit ) bool
20972138
20982139func filter (deposits []* deposit.Deposit , f filterFunc ) []* looprpc.Deposit {
0 commit comments