Skip to content

Commit

Permalink
feat(SPV-930): AdminGetWebhooks method (#262)
Browse files Browse the repository at this point in the history
  • Loading branch information
chris-4chain authored Aug 27, 2024
1 parent b2cf4f7 commit d347070
Show file tree
Hide file tree
Showing 7 changed files with 31 additions and 9 deletions.
2 changes: 1 addition & 1 deletion examples/Taskfile.yml
Original file line number Diff line number Diff line change
Expand Up @@ -70,4 +70,4 @@ tasks:
desc: "running webhooks..."
cmds:
- echo "running webhooks..."
- go run ./webhooks/webhooks.go
- go run ./webhooks/webhooks.go || true
2 changes: 1 addition & 1 deletion examples/go.mod

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

8 changes: 4 additions & 4 deletions examples/go.sum

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

10 changes: 10 additions & 0 deletions examples/webhooks/webhooks.go
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,16 @@ func main() {

http.Handle("/notification", wh.HTTPHandler())

// show all subscribed webhooks (including the current one)
allWebhooks, err := client.AdminGetWebhooks(context.Background())
if err != nil {
panic(err)
}
fmt.Println("Subscribed webhooks list")
for _, item := range allWebhooks {
fmt.Printf("URL: %s, banned: %v\n", item.URL, item.Banned)
}

if err = notifications.RegisterHandler(wh, func(gpe *models.StringEvent) {
time.Sleep(50 * time.Millisecond) // simulate processing time
fmt.Printf("Processing event-string: %s\n", gpe.Value)
Expand Down
2 changes: 1 addition & 1 deletion go.mod

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

6 changes: 4 additions & 2 deletions go.sum

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

10 changes: 10 additions & 0 deletions http.go
Original file line number Diff line number Diff line change
Expand Up @@ -1159,3 +1159,13 @@ func (wc *WalletClient) AdminUnsubscribeWebhook(ctx context.Context, webhookURL
err = wc.doHTTPRequest(ctx, http.MethodDelete, "/admin/webhooks/subscriptions", rawJSON, wc.adminXPriv, true, nil)
return err
}

// AdminGetWebhooks gets all webhooks
func (wc *WalletClient) AdminGetWebhooks(ctx context.Context) ([]*models.Webhook, error) {
var webhooks []*models.Webhook
err := wc.doHTTPRequest(ctx, http.MethodGet, "/admin/webhooks/subscriptions", nil, wc.adminXPriv, true, &webhooks)
if err != nil {
return nil, WrapError(err)
}
return webhooks, nil
}

0 comments on commit d347070

Please sign in to comment.