Skip to content

multi: add some litd client helpers #476

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 2 commits into from
Jan 11, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion itest/litd_mode_integrated_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -974,7 +974,7 @@ func bakeSuperMacaroon(cfg *LitNodeConfig, readOnly bool) (string, error) {
lndAdminCtx := macaroonContext(ctxt, lndAdminMacBytes)
lndConn := lnrpc.NewLightningClient(rawConn)

permsMgr, err := perms.NewManager()
permsMgr, err := perms.NewManager(false)
if err != nil {
return "", err
}
Expand Down
44 changes: 44 additions & 0 deletions litclient/jsoncallbacks.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
package litclient

import (
"context"

"github.com/lightninglabs/faraday/frdrpc"
"github.com/lightninglabs/loop/looprpc"
"github.com/lightninglabs/pool/poolrpc"
"github.com/lightningnetwork/lnd/lnrpc"
"github.com/lightningnetwork/lnd/lnrpc/autopilotrpc"
"github.com/lightningnetwork/lnd/lnrpc/chainrpc"
"github.com/lightningnetwork/lnd/lnrpc/invoicesrpc"
"github.com/lightningnetwork/lnd/lnrpc/routerrpc"
"github.com/lightningnetwork/lnd/lnrpc/signrpc"
"github.com/lightningnetwork/lnd/lnrpc/verrpc"
"github.com/lightningnetwork/lnd/lnrpc/walletrpc"
"github.com/lightningnetwork/lnd/lnrpc/watchtowerrpc"
"github.com/lightningnetwork/lnd/lnrpc/wtclientrpc"
"google.golang.org/grpc"
)

// StubPackageRegistration defines the signature of a function that maps JSON
// method URIs to the function that should be called to handle the method.
type StubPackageRegistration func(map[string]func(context.Context,
*grpc.ClientConn, string, func(string, error)))

// Registrations defines a list of StubPackageRegistrations that a lit client
// will have access to when using Lit.
var Registrations = []StubPackageRegistration{
lnrpc.RegisterLightningJSONCallbacks,
lnrpc.RegisterStateJSONCallbacks,
autopilotrpc.RegisterAutopilotJSONCallbacks,
chainrpc.RegisterChainNotifierJSONCallbacks,
invoicesrpc.RegisterInvoicesJSONCallbacks,
routerrpc.RegisterRouterJSONCallbacks,
signrpc.RegisterSignerJSONCallbacks,
verrpc.RegisterVersionerJSONCallbacks,
walletrpc.RegisterWalletKitJSONCallbacks,
watchtowerrpc.RegisterWatchtowerJSONCallbacks,
wtclientrpc.RegisterWatchtowerClientJSONCallbacks,
looprpc.RegisterSwapClientJSONCallbacks,
poolrpc.RegisterTraderJSONCallbacks,
frdrpc.RegisterFaradayServerJSONCallbacks,
}
15 changes: 11 additions & 4 deletions perms/permissions.go
Original file line number Diff line number Diff line change
Expand Up @@ -135,8 +135,12 @@ type Manager struct {
}

// NewManager constructs a new Manager instance and collects any of the fixed
// permissions.
func NewManager() (*Manager, error) {
// permissions. If withAllSubServers is true, then all the LND sub-server
// permissions will be added to the available permissions set regardless of
// whether LND was compiled with those sub-servers. If it is not set, however,
// then OnLNDBuildTags can be used to specify the exact sub-servers that LND
// was compiled with and then only the corresponding permissions will be added.
func NewManager(withAllSubServers bool) (*Manager, error) {
permissions := make(map[subServerName]map[string][]bakery.Op)
permissions[faradayPerms] = faraday.RequiredPermissions
permissions[loopPerms] = loop.RequiredPermissions
Expand Down Expand Up @@ -166,8 +170,11 @@ func NewManager() (*Manager, error) {

// If this sub-server is one that we know is
// automatically compiled in LND then we add it to our
// map of active permissions.
if lndAutoCompiledSubServers[name] {
// map of active permissions. We also add the permission
// if withAllSubServers is true.
if withAllSubServers ||
lndAutoCompiledSubServers[name] {

permissions[lndPerms][key] = value
}
}
Expand Down
2 changes: 1 addition & 1 deletion terminal.go
Original file line number Diff line number Diff line change
Expand Up @@ -212,7 +212,7 @@ func (g *LightningTerminal) Run() error {
defer g.errQueue.Stop()

// Construct a new Manager.
g.permsMgr, err = perms.NewManager()
g.permsMgr, err = perms.NewManager(false)
if err != nil {
return fmt.Errorf("could not create permissions manager")
}
Expand Down