rpcserver+lnrpc: register REST subservers with root server

This commit is contained in:
Oliver Gugger
2020-04-02 15:12:28 +02:00
parent fe16be5bb8
commit 558d63718b
11 changed files with 224 additions and 4 deletions

View File

@@ -13,6 +13,7 @@ import (
"github.com/btcsuite/btcd/chaincfg/chainhash"
"github.com/btcsuite/btcd/wire"
"github.com/grpc-ecosystem/grpc-gateway/runtime"
"github.com/lightningnetwork/lnd/chainntnfs"
"github.com/lightningnetwork/lnd/lnrpc"
"google.golang.org/grpc"
@@ -189,6 +190,28 @@ func (s *Server) RegisterWithRootServer(grpcServer *grpc.Server) error {
return nil
}
// RegisterWithRestServer will be called by the root REST mux to direct a sub
// RPC server to register itself with the main REST mux server. Until this is
// called, each sub-server won't be able to have requests routed towards it.
//
// NOTE: This is part of the lnrpc.SubServer interface.
func (s *Server) RegisterWithRestServer(ctx context.Context,
mux *runtime.ServeMux, dest string, opts []grpc.DialOption) error {
// We make sure that we register it with the main REST server to ensure
// all our methods are routed properly.
err := RegisterChainNotifierHandlerFromEndpoint(ctx, mux, dest, opts)
if err != nil {
log.Errorf("Could not register ChainNotifier REST server "+
"with root REST server: %v", err)
return err
}
log.Debugf("ChainNotifier REST server successfully registered with " +
"root REST server")
return nil
}
// RegisterConfirmationsNtfn is a synchronous response-streaming RPC that
// registers an intent for a client to be notified once a confirmation request
// has reached its required number of confirmations on-chain.