feat: remove webhook subcription by url (#194)

* feat: added webhook unsubscription
* test: adding unsubscribe tests
This commit is contained in:
yse
2024-02-29 09:59:09 +01:00
committed by GitHub
parent ed6fd76b31
commit 11f35cbab1
9 changed files with 356 additions and 21 deletions

View File

@@ -82,3 +82,59 @@ func (s *server) SubscribeNotifications(
log.Printf("%v was successfully registered for notifications on url %s", pubkey, request.Url)
return &SubscribeNotificationsReply{}, nil
}
func (s *server) UnsubscribeNotifications(
ctx context.Context,
in *EncryptedNotificationRequest,
) (*UnsubscribeNotificationsReply, error) {
node, _, err := lspdrpc.GetNode(ctx)
if err != nil {
return nil, err
}
data, err := ecies.Decrypt(node.EciesPrivateKey, in.Blob)
if err != nil {
log.Printf(
"failed to unsubscribe: ecies.Decrypt error: %v",
err,
)
return nil, fmt.Errorf("ecies.Decrypt(%x) error: %w", in.Blob, err)
}
var request UnsubscribeNotificationsRequest
err = proto.Unmarshal(data, &request)
if err != nil {
log.Printf(
"failed to unsubscribe: proto.Unmarshal(%x) error: %v",
data,
err,
)
return nil, fmt.Errorf("proto.Unmarshal(%x) error: %w", data, err)
}
pubkey, err := lightning.VerifyMessage([]byte(request.Url), request.Signature)
if err != nil {
log.Printf(
"failed to unsubscribe on url %s: lightning.VerifyMessage error: %v",
request.Url,
err,
)
return nil, err
}
err = s.store.Unsubscribe(ctx, hex.EncodeToString(pubkey.SerializeCompressed()), request.Url)
if err != nil {
log.Printf(
"failed to unsubscribe %x on url %s: %v",
pubkey.SerializeCompressed(),
request.Url,
err,
)
return nil, ErrInternal
}
return &UnsubscribeNotificationsReply{}, nil
}