Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
15 changes: 15 additions & 0 deletions loopd/swapclient_server.go
Original file line number Diff line number Diff line change
Expand Up @@ -1490,6 +1490,11 @@ func (s *swapClientServer) InstantOut(ctx context.Context,
req *looprpc.InstantOutRequest) (*looprpc.InstantOutResponse,
error) {

if s.instantOutManager == nil {
return nil, status.Error(codes.Unimplemented,
"Restart loop with --experimental")
}
Comment on lines +1493 to +1496

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

medium

This check is duplicated in InstantOutQuote (line 1537) and ListInstantOuts (line 1561). To improve maintainability and reduce code duplication, consider extracting this logic into a private helper method on swapClientServer.

For example:

func (s *swapClientServer) requireInstantOutManager() error {
	if s.instantOutManager == nil {
		return status.Error(codes.Unimplemented, "Restart loop with --experimental")
	}
	return nil
}

You could then call this helper at the beginning of InstantOut, InstantOutQuote, and ListInstantOuts:

if err := s.requireInstantOutManager(); err != nil {
	return nil, err
}

This would also make the code more consistent, as ListReservations has a similar check for reservationManager.


reservationIds := make([]reservation.ID, len(req.ReservationIds))
for i, id := range req.ReservationIds {
if len(id) != reservation.IdLength {
Expand Down Expand Up @@ -1529,6 +1534,11 @@ func (s *swapClientServer) InstantOutQuote(ctx context.Context,
req *looprpc.InstantOutQuoteRequest) (
*looprpc.InstantOutQuoteResponse, error) {

if s.instantOutManager == nil {
return nil, status.Error(codes.Unimplemented,
"Restart loop with --experimental")
}

quote, err := s.instantOutManager.GetInstantOutQuote(
ctx, btcutil.Amount(req.Amt), req.ReservationIds,
)
Expand All @@ -1548,6 +1558,11 @@ func (s *swapClientServer) ListInstantOuts(ctx context.Context,
_ *looprpc.ListInstantOutsRequest) (
*looprpc.ListInstantOutsResponse, error) {

if s.instantOutManager == nil {
return nil, status.Error(codes.Unimplemented,
"Restart loop with --experimental")
}

instantOuts, err := s.instantOutManager.ListInstantOuts(ctx)
if err != nil {
return nil, err
Expand Down
Loading