mirror of
https://github.com/lightningnetwork/lnd.git
synced 2025-10-04 18:13:33 +02:00
lnrpc/routerrpc: add config, implement full RouterServer
In this commit, we implement the full RouterServer as specified by the newly added sub-service as defined in router.proto. This new sub-server has its own macaroon state (but overlapping permissions which can be combined with the current admin.macaroon), and gives users a simplified interface for a gRPC service that is able to simply send payment. Much of the error reporting atm, is a place holder, and a follow up commit will put up the infrastructure for a proper set of errors.
This commit is contained in:
62
lnrpc/routerrpc/driver.go
Normal file
62
lnrpc/routerrpc/driver.go
Normal file
@@ -0,0 +1,62 @@
|
||||
// +build routerrpc
|
||||
|
||||
package routerrpc
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
|
||||
"github.com/lightningnetwork/lnd/lnrpc"
|
||||
)
|
||||
|
||||
// createNewSubServer is a helper method that will create the new router sub
|
||||
// server given the main config dispatcher method. If we're unable to find the
|
||||
// config that is meant for us in the config dispatcher, then we'll exit with
|
||||
// an error.
|
||||
func createNewSubServer(configRegistry lnrpc.SubServerConfigDispatcher) (
|
||||
lnrpc.SubServer, lnrpc.MacaroonPerms, error) {
|
||||
|
||||
// We'll attempt to look up the config that we expect, according to our
|
||||
// subServerName name. If we can't find this, then we'll exit with an
|
||||
// error, as we're unable to properly initialize ourselves without this
|
||||
// config.
|
||||
routeServerConf, ok := configRegistry.FetchConfig(subServerName)
|
||||
if !ok {
|
||||
return nil, nil, fmt.Errorf("unable to find config for "+
|
||||
"subserver type %s", subServerName)
|
||||
}
|
||||
|
||||
// Now that we've found an object mapping to our service name, we'll
|
||||
// ensure that it's the type we need.
|
||||
config, ok := routeServerConf.(*Config)
|
||||
if !ok {
|
||||
return nil, nil, fmt.Errorf("wrong type of config for "+
|
||||
"subserver %s, expected %T got %T", subServerName,
|
||||
&Config{}, routeServerConf)
|
||||
}
|
||||
|
||||
// Before we try to make the new router service instance, we'll perform
|
||||
// some sanity checks on the arguments to ensure that they're useable.
|
||||
switch {
|
||||
case config.Router == nil:
|
||||
return nil, nil, fmt.Errorf("Router must be set to create " +
|
||||
"Routerpc")
|
||||
}
|
||||
|
||||
return New(config)
|
||||
}
|
||||
|
||||
func init() {
|
||||
subServer := &lnrpc.SubServerDriver{
|
||||
SubServerName: subServerName,
|
||||
New: func(c lnrpc.SubServerConfigDispatcher) (lnrpc.SubServer, lnrpc.MacaroonPerms, error) {
|
||||
return createNewSubServer(c)
|
||||
},
|
||||
}
|
||||
|
||||
// If the build tag is active, then we'll register ourselves as a
|
||||
// sub-RPC server within the global lnrpc package namespace.
|
||||
if err := lnrpc.RegisterSubServer(subServer); err != nil {
|
||||
panic(fmt.Sprintf("failed to register sub server driver '%s': %v",
|
||||
subServerName, err))
|
||||
}
|
||||
}
|
Reference in New Issue
Block a user