mirror of
https://github.com/lightningnetwork/lnd.git
synced 2024-11-19 09:53:54 +01:00
1a8f094503
This commits adds the devrpc package which implements a subserver that adds clean separation for RPC calls useful for development and debugging. This subserver is only compiled in if the dev tag is set. Furthermore the commit adds the devrpc.ImportGraph call which can import a graph dump obtained from another node by calling DescribeGraph. Since the graph dump does not include the auth proofs, the imported channels will be considered private.
68 lines
2.0 KiB
Go
68 lines
2.0 KiB
Go
//go:build dev
|
|
// +build dev
|
|
|
|
package devrpc
|
|
|
|
import (
|
|
"fmt"
|
|
|
|
"github.com/lightningnetwork/lnd/lnrpc"
|
|
)
|
|
|
|
// createNewSubServer is a helper method that will create the new 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) (
|
|
*Server, 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.
|
|
subServerConf, 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 := subServerConf.(*Config)
|
|
if !ok {
|
|
return nil, nil, fmt.Errorf("wrong type of config for "+
|
|
"subserver %s, expected %T got %T", subServerName,
|
|
&Config{}, subServerConf)
|
|
}
|
|
|
|
// Before we try to make the new service instance, we'll perform
|
|
// some sanity checks on the arguments to ensure that they're useable.
|
|
if config.ActiveNetParams == nil {
|
|
return nil, nil, fmt.Errorf("ActiveNetParams must be set to " +
|
|
"create DevRPC")
|
|
}
|
|
|
|
if config.GraphDB == nil {
|
|
return nil, nil, fmt.Errorf("GraphDB must be set to create " +
|
|
"DevRPC")
|
|
}
|
|
|
|
return New(config)
|
|
}
|
|
|
|
func init() {
|
|
subServer := &lnrpc.SubServerDriver{
|
|
SubServerName: subServerName,
|
|
NewGrpcHandler: func() lnrpc.GrpcHandler {
|
|
return &ServerShell{}
|
|
},
|
|
}
|
|
|
|
// 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))
|
|
}
|
|
}
|