@@ -1744,6 +1744,20 @@ 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+ depositsBySwap := make (map [string ][]* deposit.Deposit )
1753+ for _ , d := range allDeposits {
1754+ if len (d .SwapHash ) == 0 {
1755+ continue
1756+ }
1757+ key := hex .EncodeToString (d .SwapHash )
1758+ depositsBySwap [key ] = append (depositsBySwap [key ], d )
1759+ }
1760+
17471761 var clientSwaps []* looprpc.StaticAddressLoopInSwap
17481762 for _ , swp := range swaps {
17491763 chainParams , err := s .network .ChainParams ()
@@ -1752,19 +1766,34 @@ func (s *swapClientServer) ListStaticAddressSwaps(ctx context.Context,
17521766 }
17531767 swapPayReq , err := zpay32 .Decode (swp .SwapInvoice , chainParams )
17541768 if err != nil {
1755- return nil , fmt .Errorf ("error decoding swap invoice: " +
1756- "%v" , err )
1769+ return nil , fmt .Errorf ("error decoding swap invoice: %v" , err )
1770+ }
1771+
1772+ // Assemble the deposits associated with this swap, if any.
1773+ var protoDeposits []* looprpc.Deposit
1774+ key := hex .EncodeToString (swp .SwapHash [:])
1775+ if ds , ok := depositsBySwap [key ]; ok {
1776+ protoDeposits = make ([]* looprpc.Deposit , 0 , len (ds ))
1777+ for _ , d := range ds {
1778+ pd := & looprpc.Deposit {
1779+ Id : d .ID [:],
1780+ State : toClientDepositState (d .GetState ()),
1781+ Outpoint : d .OutPoint .String (),
1782+ Value : int64 (d .Value ),
1783+ ConfirmationHeight : d .ConfirmationHeight ,
1784+ SwapHash : d .SwapHash ,
1785+ }
1786+ protoDeposits = append (protoDeposits , pd )
1787+ }
17571788 }
1789+
17581790 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- ),
1791+ SwapHash : swp .SwapHash [:],
1792+ DepositOutpoints : swp .DepositOutpoints ,
1793+ State : toClientStaticAddressLoopInState (swp .GetState ()),
1794+ SwapAmountSatoshis : int64 (swp .TotalDepositAmount ()),
1795+ PaymentRequestAmountSatoshis : int64 (swapPayReq .MilliSat .ToSatoshis ()),
1796+ Deposits : protoDeposits ,
17681797 }
17691798
17701799 clientSwaps = append (clientSwaps , swap )
0 commit comments