@@ -1744,6 +1744,33 @@ func (s *swapClientServer) ListStaticAddressSwaps(ctx context.Context,
1744
1744
return & looprpc.ListStaticAddressSwapsResponse {}, nil
1745
1745
}
1746
1746
1747
+ lndInfo , err := s .lnd .Client .GetInfo (ctx )
1748
+ if err != nil {
1749
+ return nil , err
1750
+ }
1751
+
1752
+ addrParams , err := s .staticAddressManager .GetStaticAddressParameters (
1753
+ ctx ,
1754
+ )
1755
+ if err != nil {
1756
+ return nil , err
1757
+ }
1758
+
1759
+ // Fetch all deposits once and index them by swap hash for quick lookup.
1760
+ allDeposits , err := s .depositManager .GetAllDeposits (ctx )
1761
+ if err != nil {
1762
+ return nil , err
1763
+ }
1764
+
1765
+ depositsBySwap := make (map [string ][]* deposit.Deposit , len (swaps ))
1766
+ for _ , d := range allDeposits {
1767
+ if len (d .SwapHash ) == 0 {
1768
+ continue
1769
+ }
1770
+ swapHash := hex .EncodeToString (d .SwapHash )
1771
+ depositsBySwap [swapHash ] = append (depositsBySwap [swapHash ], d )
1772
+ }
1773
+
1747
1774
var clientSwaps []* looprpc.StaticAddressLoopInSwap
1748
1775
for _ , swp := range swaps {
1749
1776
chainParams , err := s .network .ChainParams ()
@@ -1752,19 +1779,44 @@ func (s *swapClientServer) ListStaticAddressSwaps(ctx context.Context,
1752
1779
}
1753
1780
swapPayReq , err := zpay32 .Decode (swp .SwapInvoice , chainParams )
1754
1781
if err != nil {
1755
- return nil , fmt .Errorf ("error decoding swap invoice: " +
1756
- "%v" , err )
1782
+ return nil , fmt .Errorf ("error decoding swap " +
1783
+ "invoice: %v" , err )
1784
+ }
1785
+
1786
+ // Assemble the deposits associated with this swap, if any.
1787
+ var protoDeposits []* looprpc.Deposit
1788
+ swapHash := hex .EncodeToString (swp .SwapHash [:])
1789
+ if ds , ok := depositsBySwap [swapHash ]; ok {
1790
+ protoDeposits = make ([]* looprpc.Deposit , 0 , len (ds ))
1791
+ for _ , d := range ds {
1792
+ state := toClientDepositState (d .GetState ())
1793
+ blocksUntilExpiry := d .ConfirmationHeight +
1794
+ int64 (addrParams .Expiry ) -
1795
+ int64 (lndInfo .BlockHeight )
1796
+
1797
+ pd := & looprpc.Deposit {
1798
+ Id : d .ID [:],
1799
+ State : state ,
1800
+ Outpoint : d .OutPoint .String (),
1801
+ Value : int64 (d .Value ),
1802
+ ConfirmationHeight : d .ConfirmationHeight ,
1803
+ SwapHash : d .SwapHash ,
1804
+ BlocksUntilExpiry : blocksUntilExpiry ,
1805
+ }
1806
+ protoDeposits = append (protoDeposits , pd )
1807
+ }
1757
1808
}
1809
+
1810
+ state := toClientStaticAddressLoopInState (swp .GetState ())
1811
+ swapAmount := int64 (swp .TotalDepositAmount ())
1812
+ payReqAmount := int64 (swapPayReq .MilliSat .ToSatoshis ())
1758
1813
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
- ),
1814
+ SwapHash : swp .SwapHash [:],
1815
+ DepositOutpoints : swp .DepositOutpoints ,
1816
+ State : state ,
1817
+ SwapAmountSatoshis : swapAmount ,
1818
+ PaymentRequestAmountSatoshis : payReqAmount ,
1819
+ Deposits : protoDeposits ,
1768
1820
}
1769
1821
1770
1822
clientSwaps = append (clientSwaps , swap )
0 commit comments