@@ -113,14 +113,61 @@ func NewClient(dbDir string, serverAddress string, insecure bool,
113113 return client , cleanup , nil
114114}
115115
116- // FetchLoopOutSwaps returns a list of all swaps currently in the database.
117- func (s * Client ) FetchLoopOutSwaps () ([]* loopdb.LoopOut , error ) {
118- return s .Store .FetchLoopOutSwaps ()
119- }
116+ // FetchSwaps returns all loop in and out swaps currently in the database.
117+ func (s * Client ) FetchSwaps () ([]* SwapInfo , error ) {
118+ loopOutSwaps , err := s .Store .FetchLoopOutSwaps ()
119+ if err != nil {
120+ return nil , err
121+ }
122+
123+ loopInSwaps , err := s .Store .FetchLoopInSwaps ()
124+ if err != nil {
125+ return nil , err
126+ }
127+
128+ swaps := make ([]* SwapInfo , 0 , len (loopInSwaps )+ len (loopOutSwaps ))
129+
130+ for _ , swp := range loopOutSwaps {
131+ htlc , err := swap .NewHtlc (
132+ swp .Contract .CltvExpiry , swp .Contract .SenderKey ,
133+ swp .Contract .ReceiverKey , swp .Hash , swap .HtlcP2WSH ,
134+ s .lndServices .ChainParams ,
135+ )
136+ if err != nil {
137+ return nil , err
138+ }
139+
140+ swaps = append (swaps , & SwapInfo {
141+ SwapType : TypeOut ,
142+ SwapContract : swp .Contract .SwapContract ,
143+ State : swp .State (),
144+ SwapHash : swp .Hash ,
145+ LastUpdate : swp .LastUpdateTime (),
146+ HtlcAddress : htlc .Address ,
147+ })
148+ }
149+
150+ for _ , swp := range loopInSwaps {
151+ htlc , err := swap .NewHtlc (
152+ swp .Contract .CltvExpiry , swp .Contract .SenderKey ,
153+ swp .Contract .ReceiverKey , swp .Hash , swap .HtlcNP2WSH ,
154+ s .lndServices .ChainParams ,
155+ )
156+ if err != nil {
157+ return nil , err
158+ }
159+
160+ swaps = append (swaps , & SwapInfo {
161+ SwapType : TypeIn ,
162+ SwapContract : swp .Contract .SwapContract ,
163+ State : swp .State (),
164+ SwapHash : swp .Hash ,
165+ LastUpdate : swp .LastUpdateTime (),
166+ HtlcAddress : htlc .Address ,
167+ })
168+ }
120169
121- // FetchLoopInSwaps returns a list of all swaps currently in the database.
122- func (s * Client ) FetchLoopInSwaps () ([]* loopdb.LoopIn , error ) {
123- return s .Store .FetchLoopInSwaps ()
170+ return swaps , nil
124171}
125172
126173// Run is a blocking call that executes all swaps. Any pending swaps are
0 commit comments