Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Ref(SPV-1373)update go client to match adapter interface #314

Merged
merged 2 commits into from
Jan 16, 2025
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
17 changes: 13 additions & 4 deletions notifications/webhook.go
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ import (
"runtime"
"time"

"github.com/bitcoin-sv/spv-wallet-go-client/commands"
"github.com/bitcoin-sv/spv-wallet/models"
)

Expand Down Expand Up @@ -66,8 +67,8 @@ func WithProcessors(count int) WebhookOpts {

// WebhookSubscriber - interface for subscribing and unsubscribing to webhooks
type WebhookSubscriber interface {
AdminSubscribeWebhook(ctx context.Context, webhookURL, tokenHeader, tokenValue string) error
AdminUnsubscribeWebhook(ctx context.Context, webhookURL string) error
AdminSubscribeWebhook(ctx context.Context, cmd *commands.CreateWebhookSubscription) error
AdminUnsubscribeWebhook(ctx context.Context, cmd *commands.CancelWebhookSubscription) error
}

// Webhook - the webhook event receiver
Expand Down Expand Up @@ -101,7 +102,12 @@ func NewWebhook(subscriber WebhookSubscriber, url string, opts ...WebhookOpts) *

// Subscribe - sends a subscription request to the spv-wallet
func (w *Webhook) Subscribe(ctx context.Context) error {
err := w.subscriber.AdminSubscribeWebhook(ctx, w.URL, w.options.TokenHeader, w.options.TokenValue)
cmd := &commands.CreateWebhookSubscription{
URL: w.URL,
TokenHeader: w.options.TokenHeader,
TokenValue: w.options.TokenValue,
}
err := w.subscriber.AdminSubscribeWebhook(ctx, cmd)
if err != nil {
return fmt.Errorf("failed to subscribe webhook: %w", err)
}
Expand All @@ -110,7 +116,10 @@ func (w *Webhook) Subscribe(ctx context.Context) error {

// Unsubscribe - sends an unsubscription request to the spv-wallet
func (w *Webhook) Unsubscribe(ctx context.Context) error {
err := w.subscriber.AdminUnsubscribeWebhook(ctx, w.URL)
cmd := &commands.CancelWebhookSubscription{
URL: w.URL,
}
err := w.subscriber.AdminUnsubscribeWebhook(ctx, cmd)
if err != nil {
return fmt.Errorf("failed to unsubscribe webhook: %w", err)
}
Expand Down
Loading