@@ -81,7 +81,7 @@ func (s *InterceptorService) Intercept(ctx context.Context,
81
81
return mid .RPCErrString (req , "error parsing macaroon: %v" , err )
82
82
}
83
83
84
- acctID , err := accountFromMacaroon (mac )
84
+ acctID , err := IDFromCaveats (mac . Caveats () )
85
85
if err != nil {
86
86
return mid .RPCErrString (
87
87
req , "error parsing account from macaroon: %v" , err ,
@@ -91,15 +91,14 @@ func (s *InterceptorService) Intercept(ctx context.Context,
91
91
// No account lock in the macaroon, something's weird. The interceptor
92
92
// wouldn't have been triggered if there was no caveat, so we do expect
93
93
// 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
+ )
98
97
99
- acct , err := s .Account (ctx , * acctID )
98
+ acct , err := s .Account (ctx , accountID )
100
99
if err != nil {
101
100
return mid .RPCErrString (
102
- req , "error getting account %x: %v" , acctID [:], err ,
101
+ req , "error getting account %x: %v" , accountID [:], err ,
103
102
)
104
103
}
105
104
@@ -208,27 +207,6 @@ func parseRPCMessage(msg *lnrpc.RPCMessage) (proto.Message, error) {
208
207
return parsedMsg , nil
209
208
}
210
209
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
-
232
210
// CaveatFromID creates a custom caveat that can be used to bind a macaroon to
233
211
// a certain account.
234
212
func CaveatFromID (id AccountID ) macaroon.Caveat {
0 commit comments