walletrpc: export wallet kit sub server name

We'll want to re-use the PSBT funding functionality from the wallet kit
sub server in the main RPC server. To be able to dynamically obtain an
instance of the wallet kit server we need to know its name under which
it registers itself in the list of sub server. We export the name so we
don't have to hard code it in the main server.
This commit is contained in:
Oliver Gugger 2021-08-24 11:21:53 +02:00
parent 84035f1fb2
commit ae2e9541a4
No known key found for this signature in database
GPG Key ID: 8E4256593F177720
4 changed files with 21 additions and 14 deletions

View File

@ -11,6 +11,13 @@ import (
"github.com/lightningnetwork/lnd/sweep"
)
const (
// SubServerName is the name of the sub rpc server. We'll use this name
// to register ourselves, and we also require that the main
// SubServerConfigDispatcher instance recognize as the name of our
SubServerName = "WalletKitRPC"
)
// Config is the primary configuration struct for the WalletKit RPC server. It
// contains all the items required for the signer rpc server to carry out its
// duties. The fields with struct tags are meant to be parsed as normal

View File

@ -2,6 +2,13 @@
package walletrpc
const (
// SubServerName is the name of the sub rpc server. We'll use this name
// to register ourselves, and we also require that the main
// SubServerConfigDispatcher instance recognize as the name of our
SubServerName = "WalletKitRPC"
)
// Config is the primary configuration struct for the WalletKit RPC server.
// When the server isn't active (via the build flag), callers outside this
// package will see this shell of a config file.

View File

@ -16,13 +16,13 @@ func createNewSubServer(configRegistry lnrpc.SubServerConfigDispatcher) (
*WalletKit, 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
// 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.
walletKitServerConf, ok := configRegistry.FetchConfig(subServerName)
walletKitServerConf, ok := configRegistry.FetchConfig(SubServerName)
if !ok {
return nil, nil, fmt.Errorf("unable to find config for "+
"subserver type %s", subServerName)
"subserver type %s", SubServerName)
}
// Now that we've found an object mapping to our service name, we'll
@ -30,7 +30,7 @@ func createNewSubServer(configRegistry lnrpc.SubServerConfigDispatcher) (
config, ok := walletKitServerConf.(*Config)
if !ok {
return nil, nil, fmt.Errorf("wrong type of config for "+
"subserver %s, expected %T got %T", subServerName,
"subserver %s, expected %T got %T", SubServerName,
&Config{}, walletKitServerConf)
}
@ -68,7 +68,7 @@ func createNewSubServer(configRegistry lnrpc.SubServerConfigDispatcher) (
func init() {
subServer := &lnrpc.SubServerDriver{
SubServerName: subServerName,
SubServerName: SubServerName,
NewGrpcHandler: func() lnrpc.GrpcHandler {
return &ServerShell{}
},
@ -78,6 +78,6 @@ func init() {
// 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))
SubServerName, err))
}
}

View File

@ -37,13 +37,6 @@ import (
"gopkg.in/macaroon-bakery.v2/bakery"
)
const (
// subServerName is the name of the sub rpc server. We'll use this name
// to register ourselves, and we also require that the main
// SubServerConfigDispatcher instance recognize as the name of our
subServerName = "WalletKitRPC"
)
var (
// macaroonOps are the set of capabilities that our minted macaroon (if
// it doesn't already exist) will have.
@ -256,7 +249,7 @@ func (w *WalletKit) Stop() error {
//
// NOTE: This is part of the lnrpc.SubServer interface.
func (w *WalletKit) Name() string {
return subServerName
return SubServerName
}
// RegisterWithRootServer will be called by the root gRPC server to direct a