Skip to content

Commit

Permalink
feat(SPV-848): use actual models for subscribe & unsubscribe
Browse files Browse the repository at this point in the history
  • Loading branch information
chris-4chain committed Jul 4, 2024
1 parent 042514b commit 87c454e
Showing 1 changed file with 6 additions and 10 deletions.
16 changes: 6 additions & 10 deletions http.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down

0 comments on commit 87c454e

Please sign in to comment.