Skip to content

Commit

Permalink
Ref(SPV-1373)update go client to match adapter interface (#314)
Browse files Browse the repository at this point in the history
  • Loading branch information
ac4ch authored Jan 16, 2025
1 parent 3ae60c5 commit 23c450a
Showing 1 changed file with 13 additions and 4 deletions.
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

0 comments on commit 23c450a

Please sign in to comment.