routerrpc: implement UpdateChanStatus RPC in router server
Update UpdateChanStatus stub implementation to call into exposed ChanStatusManager methods in RouterBackend.
This commit is contained in:
parent
ce2796257e
commit
6d01f140d9
@ -10,6 +10,7 @@ import (
|
|||||||
"sync/atomic"
|
"sync/atomic"
|
||||||
"time"
|
"time"
|
||||||
|
|
||||||
|
"github.com/btcsuite/btcd/wire"
|
||||||
"github.com/btcsuite/btcutil"
|
"github.com/btcsuite/btcutil"
|
||||||
"github.com/grpc-ecosystem/grpc-gateway/runtime"
|
"github.com/grpc-ecosystem/grpc-gateway/runtime"
|
||||||
"github.com/lightningnetwork/lnd/channeldb"
|
"github.com/lightningnetwork/lnd/channeldb"
|
||||||
@ -115,6 +116,10 @@ var (
|
|||||||
Entity: "offchain",
|
Entity: "offchain",
|
||||||
Action: "write",
|
Action: "write",
|
||||||
}},
|
}},
|
||||||
|
"/routerrpc.Router/UpdateChanStatus": {{
|
||||||
|
Entity: "offchain",
|
||||||
|
Action: "write",
|
||||||
|
}},
|
||||||
}
|
}
|
||||||
|
|
||||||
// DefaultRouterMacFilename is the default name of the router macaroon
|
// 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()
|
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.
|
// UpdateChanStatus allows channel state to be set manually.
|
||||||
func (s *Server) UpdateChanStatus(ctx context.Context,
|
func (s *Server) UpdateChanStatus(ctx context.Context,
|
||||||
req *UpdateChanStatusRequest) (*UpdateChanStatusResponse, error) {
|
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
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user