@@ -1744,6 +1744,21 @@ func (s *swapClientServer) ListStaticAddressSwaps(ctx context.Context,
17441744 return & looprpc.ListStaticAddressSwapsResponse {}, nil
17451745 }
17461746
1747+ // Fetch all deposits once and index them by swap hash for quick lookup.
1748+ allDeposits , err := s .depositManager .GetAllDeposits (ctx )
1749+ if err != nil {
1750+ return nil , err
1751+ }
1752+
1753+ depositsBySwap := make (map [string ][]* deposit.Deposit )
1754+ for _ , d := range allDeposits {
1755+ if len (d .SwapHash ) == 0 {
1756+ continue
1757+ }
1758+ swapHash := hex .EncodeToString (d .SwapHash )
1759+ depositsBySwap [swapHash ] = append (depositsBySwap [swapHash ], d )
1760+ }
1761+
17471762 var clientSwaps []* looprpc.StaticAddressLoopInSwap
17481763 for _ , swp := range swaps {
17491764 chainParams , err := s .network .ChainParams ()
@@ -1752,19 +1767,34 @@ func (s *swapClientServer) ListStaticAddressSwaps(ctx context.Context,
17521767 }
17531768 swapPayReq , err := zpay32 .Decode (swp .SwapInvoice , chainParams )
17541769 if err != nil {
1755- return nil , fmt .Errorf ("error decoding swap invoice: " +
1756- "%v" , err )
1770+ return nil , fmt .Errorf ("error decoding swap invoice: %v" , err )
1771+ }
1772+
1773+ // Assemble the deposits associated with this swap, if any.
1774+ var protoDeposits []* looprpc.Deposit
1775+ swapHash := hex .EncodeToString (swp .SwapHash [:])
1776+ if ds , ok := depositsBySwap [swapHash ]; ok {
1777+ protoDeposits = make ([]* looprpc.Deposit , 0 , len (ds ))
1778+ for _ , d := range ds {
1779+ pd := & looprpc.Deposit {
1780+ Id : d .ID [:],
1781+ State : toClientDepositState (d .GetState ()),
1782+ Outpoint : d .OutPoint .String (),
1783+ Value : int64 (d .Value ),
1784+ ConfirmationHeight : d .ConfirmationHeight ,
1785+ SwapHash : d .SwapHash ,
1786+ }
1787+ protoDeposits = append (protoDeposits , pd )
1788+ }
17571789 }
1790+
17581791 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- ),
1792+ SwapHash : swp .SwapHash [:],
1793+ DepositOutpoints : swp .DepositOutpoints ,
1794+ State : toClientStaticAddressLoopInState (swp .GetState ()),
1795+ SwapAmountSatoshis : int64 (swp .TotalDepositAmount ()),
1796+ PaymentRequestAmountSatoshis : int64 (swapPayReq .MilliSat .ToSatoshis ()),
1797+ Deposits : protoDeposits ,
17681798 }
17691799
17701800 clientSwaps = append (clientSwaps , swap )
0 commit comments