@@ -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,17 @@ 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" )
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 )
97
99
}
98
100
99
- acct , err := s .Account (ctx , * acctID )
101
+ acct , err := s .Account (ctx , accountID )
100
102
if err != nil {
101
103
return mid .RPCErrString (
102
- req , "error getting account %x: %v" , acctID [:], err ,
104
+ req , "error getting account %x: %v" , accountID [:], err ,
103
105
)
104
106
}
105
107
@@ -208,27 +210,6 @@ func parseRPCMessage(msg *lnrpc.RPCMessage) (proto.Message, error) {
208
210
return parsedMsg , nil
209
211
}
210
212
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
213
// CaveatFromID creates a custom caveat that can be used to bind a macaroon to
233
214
// a certain account.
234
215
func CaveatFromID (id AccountID ) macaroon.Caveat {
0 commit comments