mirror of
https://github.com/aljazceru/lspd.git
synced 2025-12-24 01:04:21 +01:00
feat: remove webhook subcription by url (#194)
* feat: added webhook unsubscription * test: adding unsubscribe tests
This commit is contained in:
@@ -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
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user