@@ -81,7 +81,7 @@ func (s *InterceptorService) Intercept(ctx context.Context,
8181 return mid .RPCErrString (req , "error parsing macaroon: %v" , err )
8282 }
8383
84- acctID , err := accountFromMacaroon (mac )
84+ acctID , err := IDFromCaveats (mac . Caveats () )
8585 if err != nil {
8686 return mid .RPCErrString (
8787 req , "error parsing account from macaroon: %v" , err ,
@@ -91,15 +91,17 @@ func (s *InterceptorService) Intercept(ctx context.Context,
9191 // No account lock in the macaroon, something's weird. The interceptor
9292 // wouldn't have been triggered if there was no caveat, so we do expect
9393 // a macaroon here.
94- if acctID == nil {
95- return mid .RPCErrString (req , "expected account ID in " +
96- "macaroon caveat" )
94+ accountID , err := acctID .UnwrapOrErr (
95+ fmt .Errorf ("expected account ID in macaroon caveat" ),
96+ )
97+ if err != nil {
98+ return mid .RPCErr (req , err )
9799 }
98100
99- acct , err := s .Account (ctx , * acctID )
101+ acct , err := s .Account (ctx , accountID )
100102 if err != nil {
101103 return mid .RPCErrString (
102- req , "error getting account %x: %v" , acctID [:], err ,
104+ req , "error getting account %x: %v" , accountID [:], err ,
103105 )
104106 }
105107
@@ -208,27 +210,6 @@ func parseRPCMessage(msg *lnrpc.RPCMessage) (proto.Message, error) {
208210 return parsedMsg , nil
209211}
210212
211- // accountFromMacaroon attempts to extract an account ID from the custom account
212- // caveat in the macaroon.
213- func accountFromMacaroon (mac * macaroon.Macaroon ) (* AccountID , error ) {
214- if mac == nil {
215- return nil , nil
216- }
217-
218- // Extract the account caveat from the macaroon.
219- accountID , err := IDFromCaveats (mac .Caveats ())
220- if err != nil {
221- return nil , err
222- }
223-
224- var id * AccountID
225- accountID .WhenSome (func (aID AccountID ) {
226- id = & aID
227- })
228-
229- return id , nil
230- }
231-
232213// CaveatFromID creates a custom caveat that can be used to bind a macaroon to
233214// a certain account.
234215func CaveatFromID (id AccountID ) macaroon.Caveat {
0 commit comments