@@ -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,14 @@ 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" )
97- 	}
94+ 	accountID , err  :=  acctID .UnwrapOrErr (
95+ 		fmt .Errorf ("expected account ID in macaroon caveat" ),
96+ 	)
9897
99- 	acct , err  :=  s .Account (ctx , * acctID )
98+ 	acct , err  :=  s .Account (ctx , accountID )
10099	if  err  !=  nil  {
101100		return  mid .RPCErrString (
102- 			req , "error getting account %x: %v" , acctID [:], err ,
101+ 			req , "error getting account %x: %v" , accountID [:], err ,
103102		)
104103	}
105104
@@ -208,27 +207,6 @@ func parseRPCMessage(msg *lnrpc.RPCMessage) (proto.Message, error) {
208207	return  parsedMsg , nil 
209208}
210209
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- 
232210// CaveatFromID creates a custom caveat that can be used to bind a macaroon to 
233211// a certain account. 
234212func  CaveatFromID (id  AccountID ) macaroon.Caveat  {
0 commit comments