From 87c454e43686b882ac90143e8e0298e55a4edd9c Mon Sep 17 00:00:00 2001 From: Krzysztof Tomecki <152964795+chris-4chain@users.noreply.github.com> Date: Thu, 4 Jul 2024 15:30:55 +0200 Subject: [PATCH] feat(SPV-848): use actual models for subscribe & unsubscribe --- http.go | 16 ++++++---------- 1 file changed, 6 insertions(+), 10 deletions(-) diff --git a/http.go b/http.go index a107f65..a66add4 100644 --- a/http.go +++ b/http.go @@ -1133,33 +1133,29 @@ func (wc *WalletClient) SendToRecipients(ctx context.Context, recipients []*Reci return wc.RecordTransaction(ctx, hex, draft.ID, metadata) } +// AdminSubscribeWebhook subscribes to a webhook to receive notifications from spv-wallet func (wc *WalletClient) AdminSubscribeWebhook(ctx context.Context, webhookURL, tokenHeader, tokenValue string) error { - requestModel := struct { - URL string `json:"url"` - TokenHeader string `json:"tokenHeader"` - TokenValue string `json:"tokenValue"` - }{ + requestModel := models.SubscribeRequestBody{ URL: webhookURL, TokenHeader: tokenHeader, TokenValue: tokenValue, } rawJSON, err := json.Marshal(requestModel) if err != nil { - return WrapError(nil) + return WrapError(err) } err = wc.doHTTPRequest(ctx, http.MethodPost, "/admin/webhooks/subscribe", rawJSON, wc.adminXPriv, true, nil) return WrapError(err) } +// AdminUnsubscribeWebhook unsubscribes from a webhook func (wc *WalletClient) AdminUnsubscribeWebhook(ctx context.Context, webhookURL string) error { - requestModel := struct { - URL string `json:"url"` - }{ + requestModel := models.UnsubscribeRequestBody{ URL: webhookURL, } rawJSON, err := json.Marshal(requestModel) if err != nil { - return WrapError(nil) + return WrapError(err) } err = wc.doHTTPRequest(ctx, http.MethodPost, "/admin/webhooks/unsubscribe", rawJSON, wc.adminXPriv, true, nil) return err