Skip to content

Commit 3e25bc3

Browse files
committed
loopd+looprpc: add REST compatible status calls
1 parent 403b409 commit 3e25bc3

File tree

5 files changed

+575
-96
lines changed

5 files changed

+575
-96
lines changed

loopd/swapclient_server.go

Lines changed: 44 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -241,6 +241,50 @@ func (s *swapClientServer) Monitor(in *looprpc.MonitorRequest,
241241
}
242242
}
243243

244+
// ListSwaps returns a list of all currently known swaps and their current
245+
// status.
246+
func (s *swapClientServer) ListSwaps(_ context.Context,
247+
_ *looprpc.ListSwapsRequest) (*looprpc.ListSwapsResponse, error) {
248+
249+
var (
250+
rpcSwaps = make([]*looprpc.SwapStatus, len(s.swaps))
251+
idx = 0
252+
err error
253+
)
254+
255+
// We can just use the server's in-memory cache as that contains the
256+
// most up-to-date state including temporary failures which aren't
257+
// persisted to disk. The swaps field is a map, that's why we need an
258+
// additional index.
259+
for _, swp := range s.swaps {
260+
swp := swp
261+
rpcSwaps[idx], err = s.marshallSwap(&swp)
262+
if err != nil {
263+
return nil, err
264+
}
265+
idx++
266+
}
267+
return &looprpc.ListSwapsResponse{Swaps: rpcSwaps}, nil
268+
}
269+
270+
// SwapInfo returns all known details about a single swap.
271+
func (s *swapClientServer) SwapInfo(_ context.Context,
272+
req *looprpc.SwapInfoRequest) (*looprpc.SwapStatus, error) {
273+
274+
swapHash, err := lntypes.MakeHash(req.Id)
275+
if err != nil {
276+
return nil, fmt.Errorf("error parsing swap hash: %v", err)
277+
}
278+
279+
// Just return the server's in-memory cache here too as we also want to
280+
// return temporary failures to the client.
281+
swp, ok := s.swaps[swapHash]
282+
if !ok {
283+
return nil, fmt.Errorf("swap with hash %s not found", req.Id)
284+
}
285+
return s.marshallSwap(&swp)
286+
}
287+
244288
// LoopOutTerms returns the terms that the server enforces for loop out swaps.
245289
func (s *swapClientServer) LoopOutTerms(ctx context.Context,
246290
req *looprpc.TermsRequest) (*looprpc.TermsResponse, error) {

0 commit comments

Comments
 (0)