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