2
0
mirror of https://github.com/lightninglabs/loop synced 2024-11-08 01:10:29 +00:00
loop/loopd/swapclient_server_debug.go
carla 87b02b7715
multi: add force tick endpoint behind debug server
To itest our autolooper, we need to be able to trigger dispatch on
demand. This functionality is included in a separate rpc server behind
a dev flag. Since it is unlikely that we need to split loop into
multiple rpc servers, this commit simply adds an additional debug server
rather than opting for a full subserver setup.
2020-10-15 13:53:27 +02:00

49 lines
1.1 KiB
Go

// +build dev
package loopd
import (
"context"
"fmt"
"gopkg.in/macaroon-bakery.v2/bakery"
"github.com/lightninglabs/lndclient"
"github.com/lightninglabs/loop/looprpc"
)
var (
debugRequiredPermissions = map[string][]bakery.Op{
"/looprpc.Debug/ForceAutoLoop": {{
Entity: "debug",
Action: "write",
}},
}
debugPermissions = []bakery.Op{
{
Entity: "debug",
Action: "write",
},
}
)
// registerDebugServer registers the debug server.
func (d *Daemon) registerDebugServer() {
looprpc.RegisterDebugServer(d.grpcServer, d)
}
// ForceAutoLoop triggers our liquidity manager to dispatch an automated swap,
// if one is suggested. This endpoint is only for testing purposes and cannot be
// used on mainnet.
func (s *swapClientServer) ForceAutoLoop(ctx context.Context,
_ *looprpc.ForceAutoLoopRequest) (*looprpc.ForceAutoLoopResponse, error) {
if s.network == lndclient.NetworkMainnet {
return nil, fmt.Errorf("force autoloop not allowed on mainnet")
}
err := s.liquidityMgr.ForceAutoLoop(ctx)
return &looprpc.ForceAutoLoopResponse{}, err
}