@@ -1744,6 +1744,37 @@ func (s *swapClientServer) ListStaticAddressSwaps(ctx context.Context,
17441744 return & looprpc.ListStaticAddressSwapsResponse {}, nil
17451745 }
17461746
1747+ // Query lnd's info to get the current block height.
1748+ lndInfo , err := s .lnd .Client .GetInfo (ctx )
1749+ if err != nil {
1750+ return nil , err
1751+ }
1752+
1753+ addrParams , err := s .staticAddressManager .GetStaticAddressParameters (
1754+ ctx ,
1755+ )
1756+ if err != nil {
1757+ return nil , err
1758+ }
1759+
1760+ // Fetch all deposits once and index them by swap hash for quick lookup.
1761+ allDeposits , err := s .depositManager .GetAllDeposits (ctx )
1762+ if err != nil {
1763+ return nil , err
1764+ }
1765+
1766+ depositsBySwap := make (map [lntypes.Hash ][]* deposit.Deposit , len (swaps ))
1767+ for _ , d := range allDeposits {
1768+ if d .SwapHash == lntypes .ZeroHash {
1769+ // This deposit is not associated with a swap, so we
1770+ // skip it.
1771+ continue
1772+ }
1773+ depositsBySwap [d .SwapHash ] = append (
1774+ depositsBySwap [d .SwapHash ], d ,
1775+ )
1776+ }
1777+
17471778 var clientSwaps []* looprpc.StaticAddressLoopInSwap
17481779 for _ , swp := range swaps {
17491780 chainParams , err := s .network .ChainParams ()
@@ -1752,19 +1783,43 @@ func (s *swapClientServer) ListStaticAddressSwaps(ctx context.Context,
17521783 }
17531784 swapPayReq , err := zpay32 .Decode (swp .SwapInvoice , chainParams )
17541785 if err != nil {
1755- return nil , fmt .Errorf ("error decoding swap invoice: " +
1756- "%v" , err )
1786+ return nil , fmt .Errorf ("error decoding swap " +
1787+ "invoice: %v" , err )
1788+ }
1789+
1790+ // Assemble the deposits associated with this swap, if any.
1791+ var protoDeposits []* looprpc.Deposit
1792+ if ds , ok := depositsBySwap [swp .SwapHash ]; ok {
1793+ protoDeposits = make ([]* looprpc.Deposit , 0 , len (ds ))
1794+ for _ , d := range ds {
1795+ state := toClientDepositState (d .GetState ())
1796+ blocksUntilExpiry := d .ConfirmationHeight +
1797+ int64 (addrParams .Expiry ) -
1798+ int64 (lndInfo .BlockHeight )
1799+
1800+ pd := & looprpc.Deposit {
1801+ Id : d .ID [:],
1802+ State : state ,
1803+ Outpoint : d .OutPoint .String (),
1804+ Value : int64 (d .Value ),
1805+ ConfirmationHeight : d .ConfirmationHeight ,
1806+ SwapHash : d .SwapHash [:],
1807+ BlocksUntilExpiry : blocksUntilExpiry ,
1808+ }
1809+ protoDeposits = append (protoDeposits , pd )
1810+ }
17571811 }
1812+
1813+ state := toClientStaticAddressLoopInState (swp .GetState ())
1814+ swapAmount := int64 (swp .TotalDepositAmount ())
1815+ payReqAmount := int64 (swapPayReq .MilliSat .ToSatoshis ())
17581816 swap := & looprpc.StaticAddressLoopInSwap {
1759- SwapHash : swp .SwapHash [:],
1760- DepositOutpoints : swp .DepositOutpoints ,
1761- State : toClientStaticAddressLoopInState (
1762- swp .GetState (),
1763- ),
1764- SwapAmountSatoshis : int64 (swp .TotalDepositAmount ()),
1765- PaymentRequestAmountSatoshis : int64 (
1766- swapPayReq .MilliSat .ToSatoshis (),
1767- ),
1817+ SwapHash : swp .SwapHash [:],
1818+ DepositOutpoints : swp .DepositOutpoints ,
1819+ State : state ,
1820+ SwapAmountSatoshis : swapAmount ,
1821+ PaymentRequestAmountSatoshis : payReqAmount ,
1822+ Deposits : protoDeposits ,
17681823 }
17691824
17701825 clientSwaps = append (clientSwaps , swap )
0 commit comments