Skip to content

Commit fa90690

Browse files
authored
Merge pull request #476 from ellemouton/addJsonRegistrations
multi: add some litd client helpers
2 parents a261564 + bee2d62 commit fa90690

File tree

4 files changed

+57
-6
lines changed

4 files changed

+57
-6
lines changed

itest/litd_mode_integrated_test.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -974,7 +974,7 @@ func bakeSuperMacaroon(cfg *LitNodeConfig, readOnly bool) (string, error) {
974974
lndAdminCtx := macaroonContext(ctxt, lndAdminMacBytes)
975975
lndConn := lnrpc.NewLightningClient(rawConn)
976976

977-
permsMgr, err := perms.NewManager()
977+
permsMgr, err := perms.NewManager(false)
978978
if err != nil {
979979
return "", err
980980
}

litclient/jsoncallbacks.go

Lines changed: 44 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,44 @@
1+
package litclient
2+
3+
import (
4+
"context"
5+
6+
"github.com/lightninglabs/faraday/frdrpc"
7+
"github.com/lightninglabs/loop/looprpc"
8+
"github.com/lightninglabs/pool/poolrpc"
9+
"github.com/lightningnetwork/lnd/lnrpc"
10+
"github.com/lightningnetwork/lnd/lnrpc/autopilotrpc"
11+
"github.com/lightningnetwork/lnd/lnrpc/chainrpc"
12+
"github.com/lightningnetwork/lnd/lnrpc/invoicesrpc"
13+
"github.com/lightningnetwork/lnd/lnrpc/routerrpc"
14+
"github.com/lightningnetwork/lnd/lnrpc/signrpc"
15+
"github.com/lightningnetwork/lnd/lnrpc/verrpc"
16+
"github.com/lightningnetwork/lnd/lnrpc/walletrpc"
17+
"github.com/lightningnetwork/lnd/lnrpc/watchtowerrpc"
18+
"github.com/lightningnetwork/lnd/lnrpc/wtclientrpc"
19+
"google.golang.org/grpc"
20+
)
21+
22+
// StubPackageRegistration defines the signature of a function that maps JSON
23+
// method URIs to the function that should be called to handle the method.
24+
type StubPackageRegistration func(map[string]func(context.Context,
25+
*grpc.ClientConn, string, func(string, error)))
26+
27+
// Registrations defines a list of StubPackageRegistrations that a lit client
28+
// will have access to when using Lit.
29+
var Registrations = []StubPackageRegistration{
30+
lnrpc.RegisterLightningJSONCallbacks,
31+
lnrpc.RegisterStateJSONCallbacks,
32+
autopilotrpc.RegisterAutopilotJSONCallbacks,
33+
chainrpc.RegisterChainNotifierJSONCallbacks,
34+
invoicesrpc.RegisterInvoicesJSONCallbacks,
35+
routerrpc.RegisterRouterJSONCallbacks,
36+
signrpc.RegisterSignerJSONCallbacks,
37+
verrpc.RegisterVersionerJSONCallbacks,
38+
walletrpc.RegisterWalletKitJSONCallbacks,
39+
watchtowerrpc.RegisterWatchtowerJSONCallbacks,
40+
wtclientrpc.RegisterWatchtowerClientJSONCallbacks,
41+
looprpc.RegisterSwapClientJSONCallbacks,
42+
poolrpc.RegisterTraderJSONCallbacks,
43+
frdrpc.RegisterFaradayServerJSONCallbacks,
44+
}

perms/permissions.go

Lines changed: 11 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -135,8 +135,12 @@ type Manager struct {
135135
}
136136

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

167171
// If this sub-server is one that we know is
168172
// automatically compiled in LND then we add it to our
169-
// map of active permissions.
170-
if lndAutoCompiledSubServers[name] {
173+
// map of active permissions. We also add the permission
174+
// if withAllSubServers is true.
175+
if withAllSubServers ||
176+
lndAutoCompiledSubServers[name] {
177+
171178
permissions[lndPerms][key] = value
172179
}
173180
}

terminal.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -212,7 +212,7 @@ func (g *LightningTerminal) Run() error {
212212
defer g.errQueue.Stop()
213213

214214
// Construct a new Manager.
215-
g.permsMgr, err = perms.NewManager()
215+
g.permsMgr, err = perms.NewManager(false)
216216
if err != nil {
217217
return fmt.Errorf("could not create permissions manager")
218218
}

0 commit comments

Comments
 (0)