diff --git a/lnrpc/routerrpc/router_server.go b/lnrpc/routerrpc/router_server.go index c7d1496df..e9233716e 100644 --- a/lnrpc/routerrpc/router_server.go +++ b/lnrpc/routerrpc/router_server.go @@ -10,6 +10,7 @@ import ( "sync/atomic" "time" + "github.com/btcsuite/btcd/wire" "github.com/btcsuite/btcutil" "github.com/grpc-ecosystem/grpc-gateway/runtime" "github.com/lightningnetwork/lnd/channeldb" @@ -115,6 +116,10 @@ var ( Entity: "offchain", Action: "write", }}, + "/routerrpc.Router/UpdateChanStatus": {{ + Entity: "offchain", + Action: "write", + }}, } // DefaultRouterMacFilename is the default name of the router macaroon @@ -698,9 +703,43 @@ func (s *Server) HtlcInterceptor(stream Router_HtlcInterceptorServer) error { return newForwardInterceptor(s, stream).run() } +func extractOutPoint(req *UpdateChanStatusRequest) (*wire.OutPoint, error) { + chanPoint := req.GetChanPoint() + txid, err := lnrpc.GetChanPointFundingTxid(chanPoint) + if err != nil { + return nil, err + } + index := chanPoint.OutputIndex + return wire.NewOutPoint(txid, index), nil +} + // UpdateChanStatus allows channel state to be set manually. func (s *Server) UpdateChanStatus(ctx context.Context, req *UpdateChanStatusRequest) (*UpdateChanStatusResponse, error) { - return nil, fmt.Errorf("unimplemented") + outPoint, err := extractOutPoint(req) + if err != nil { + return nil, err + } + + action := req.GetAction() + + log.Debugf("UpdateChanStatus called for channel(%v) with "+ + "action %v", outPoint, action) + + switch action { + case ChanStatusAction_ENABLE: + err = s.cfg.RouterBackend.SetChannelEnabled(*outPoint) + case ChanStatusAction_DISABLE: + err = s.cfg.RouterBackend.SetChannelDisabled(*outPoint) + case ChanStatusAction_AUTO: + err = s.cfg.RouterBackend.SetChannelAuto(*outPoint) + default: + err = fmt.Errorf("unrecognized ChannelStatusAction %v", action) + } + + if err != nil { + return nil, err + } + return &UpdateChanStatusResponse{}, nil }