mirror of
https://github.com/lightninglabs/lightning-terminal.git
synced 2026-08-13 12:33:36 +02:00
multi: add AddActionReq MacaroonId helper func
Add helper method to `AddActionReq` returns the 4 byte macaroon ID that is derived from the MacaroonRootKeyID. Using the helper removes some code repetition at call sites, and makes the intended usage clearer.
This commit is contained in:
parent
01bc36ca41
commit
bd59605516
4 changed files with 15 additions and 13 deletions
|
|
@ -84,6 +84,18 @@ type AddActionReq struct {
|
|||
RPCParamsJson []byte
|
||||
}
|
||||
|
||||
// MacaroonId returns the 4 byte macaroon ID that is derived from the
|
||||
// MacaroonRootKeyID. If the MacaroonRootKeyID is not set, then this will return
|
||||
// an empty 4 byte array.
|
||||
func (a *AddActionReq) MacaroonId() [4]byte {
|
||||
var macID [4]byte
|
||||
a.MacaroonRootKeyID.WhenSome(func(rootID uint64) {
|
||||
macID = session.IDFromMacRootKeyID(rootID)
|
||||
})
|
||||
|
||||
return macID
|
||||
}
|
||||
|
||||
// Action represents an RPC call made through the firewall.
|
||||
type Action struct {
|
||||
AddActionReq
|
||||
|
|
|
|||
|
|
@ -61,10 +61,7 @@ func (db *BoltDB) AddAction(ctx context.Context,
|
|||
// If no macaroon is provided, then an empty 4-byte array is used as the
|
||||
// macaroon ID. Note that the kvdb implementation only stores the last
|
||||
// 4 bytes of the macaroon root key ID.
|
||||
var macaroonID [4]byte
|
||||
req.MacaroonRootKeyID.WhenSome(func(rootID uint64) {
|
||||
macaroonID = session.IDFromMacRootKeyID(rootID)
|
||||
})
|
||||
macaroonID := req.MacaroonId()
|
||||
|
||||
// If the new action links to a session, the session must exist.
|
||||
// For the bbolt impl of the store, this is our best effort attempt
|
||||
|
|
|
|||
|
|
@ -243,12 +243,8 @@ func TestListActions(t *testing.T) {
|
|||
assertActions := func(dbActions []*Action, al []*action) {
|
||||
require.Len(t, dbActions, len(al))
|
||||
for i, a := range al {
|
||||
rID, err := dbActions[i].MacaroonRootKeyID.UnwrapOrErr(
|
||||
fmt.Errorf("macaroon root key is none"),
|
||||
)
|
||||
require.NoError(t, err)
|
||||
require.EqualValues(
|
||||
t, a.sessionID, session.IDFromMacRootKeyID(rID),
|
||||
t, a.sessionID, dbActions[i].MacaroonId(),
|
||||
)
|
||||
require.Equal(t, a.actionID, dbActions[i].FeatureName)
|
||||
}
|
||||
|
|
|
|||
|
|
@ -817,10 +817,7 @@ func (s *sessionRpcServer) ListActions(ctx context.Context,
|
|||
sessionID = id
|
||||
})
|
||||
|
||||
var macID [4]byte
|
||||
a.MacaroonRootKeyID.WhenSome(func(rootID uint64) {
|
||||
macID = session.IDFromMacRootKeyID(rootID)
|
||||
})
|
||||
macID := a.MacaroonId()
|
||||
|
||||
resp[i] = &litrpc.Action{
|
||||
SessionId: sessionID[:],
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue