rpcperms+lnd: use macaroon service from interceptor chain

We'll refactor the wallet creation and unlock process in a following
commit and want to make it possible to not need a direct reference to
the macaroon service in our main function. Since we store it in the
interceptor chain anyway (if we're using macaroons in the first place),
we might as well use the instance there directly.
This commit is contained in:
Oliver Gugger 2021-09-23 16:54:33 +02:00
parent d12154154a
commit b22f51098a
No known key found for this signature in database
GPG Key ID: 8E4256593F177720
2 changed files with 11 additions and 2 deletions

4
lnd.go
View File

@ -917,8 +917,8 @@ func Main(cfg *Config, lisCfg ListenerCfg, interceptor signal.Interceptor) error
// Now we have created all dependencies necessary to populate and
// start the RPC server.
err = rpcServer.addDeps(
server, macaroonService, cfg.SubRPCServers, atplManager,
server.invoices, tower, chainedAcceptor,
server, interceptorChain.MacaroonService(), cfg.SubRPCServers,
atplManager, server.invoices, tower, chainedAcceptor,
)
if err != nil {
err := fmt.Errorf("unable to add deps to RPC server: %v", err)

View File

@ -386,6 +386,15 @@ func (r *InterceptorChain) AddMacaroonService(svc *macaroons.Service) {
r.svc = svc
}
// MacaroonService returns the currently registered macaroon service. This might
// be nil if none was registered (yet).
func (r *InterceptorChain) MacaroonService() *macaroons.Service {
r.RLock()
defer r.RUnlock()
return r.svc
}
// AddPermission adds a new macaroon rule for the given method.
func (r *InterceptorChain) AddPermission(method string, ops []bakery.Op) error {
r.Lock()