From d3470706d0de31dba5f2e2b54ea6ac473264164b Mon Sep 17 00:00:00 2001 From: chris-4chain <152964795+chris-4chain@users.noreply.github.com> Date: Tue, 27 Aug 2024 08:36:42 +0200 Subject: [PATCH] feat(SPV-930): AdminGetWebhooks method (#262) --- examples/Taskfile.yml | 2 +- examples/go.mod | 2 +- examples/go.sum | 8 ++++---- examples/webhooks/webhooks.go | 10 ++++++++++ go.mod | 2 +- go.sum | 6 ++++-- http.go | 10 ++++++++++ 7 files changed, 31 insertions(+), 9 deletions(-) diff --git a/examples/Taskfile.yml b/examples/Taskfile.yml index f6116bd2..81d7cbe9 100644 --- a/examples/Taskfile.yml +++ b/examples/Taskfile.yml @@ -70,4 +70,4 @@ tasks: desc: "running webhooks..." cmds: - echo "running webhooks..." - - go run ./webhooks/webhooks.go + - go run ./webhooks/webhooks.go || true diff --git a/examples/go.mod b/examples/go.mod index 2da659d8..9e17759f 100644 --- a/examples/go.mod +++ b/examples/go.mod @@ -6,7 +6,7 @@ replace github.com/bitcoin-sv/spv-wallet-go-client => ../ require ( github.com/bitcoin-sv/spv-wallet-go-client v0.0.0-00010101000000-000000000000 - github.com/bitcoin-sv/spv-wallet/models v1.0.0-beta.23 + github.com/bitcoin-sv/spv-wallet/models v1.0.0-beta.24 ) require ( diff --git a/examples/go.sum b/examples/go.sum index 6482c5ac..ae2fa9f1 100644 --- a/examples/go.sum +++ b/examples/go.sum @@ -1,7 +1,7 @@ -github.com/bitcoin-sv/spv-wallet/models v1.0.0-beta.22 h1:iMVrWwiUBNLLZFhulUHZtwM1aW4usnguP4XQbtnK9Ws= -github.com/bitcoin-sv/spv-wallet/models v1.0.0-beta.22/go.mod h1:PEJdH9ZWKOiKHyOZkzYsRbKuZjzlRaEJy3GsM75Icdo= -github.com/bitcoin-sv/spv-wallet/models v1.0.0-beta.23 h1:rM4w5H9INUQlUbSGQKN24eKKglvnk3yXuNVf1tahi0A= -github.com/bitcoin-sv/spv-wallet/models v1.0.0-beta.23/go.mod h1:PEJdH9ZWKOiKHyOZkzYsRbKuZjzlRaEJy3GsM75Icdo= +github.com/bitcoin-sv/spv-wallet/models v1.0.0-beta.23.0.20240823064107-bcc29881132b h1:NCjFanr8Z0Xvdbof6gHwGnfW4Anf5tL3XDqwdB6S7NY= +github.com/bitcoin-sv/spv-wallet/models v1.0.0-beta.23.0.20240823064107-bcc29881132b/go.mod h1:PEJdH9ZWKOiKHyOZkzYsRbKuZjzlRaEJy3GsM75Icdo= +github.com/bitcoin-sv/spv-wallet/models v1.0.0-beta.24 h1:A5uhGBRo5eC1Nu30inL9X0QsFOd0wXUruLuwV9+HyLo= +github.com/bitcoin-sv/spv-wallet/models v1.0.0-beta.24/go.mod h1:PEJdH9ZWKOiKHyOZkzYsRbKuZjzlRaEJy3GsM75Icdo= github.com/bitcoinschema/go-bitcoin/v2 v2.0.5 h1:Sgh5Eb746Zck/46rFDrZZEXZWyO53fMuWYhNoZa1tck= github.com/bitcoinschema/go-bitcoin/v2 v2.0.5/go.mod h1:JjO1ivfZv6vhK0uAXzyH08AAHlzNMAfnyK1Fiv9r4ZA= github.com/bitcoinsv/bsvd v0.0.0-20190609155523-4c29707f7173 h1:2yTIV9u7H0BhRDGXH5xrAwAz7XibWJtX2dNezMeNsUo= diff --git a/examples/webhooks/webhooks.go b/examples/webhooks/webhooks.go index b71e7b12..e1cb70d2 100644 --- a/examples/webhooks/webhooks.go +++ b/examples/webhooks/webhooks.go @@ -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) diff --git a/go.mod b/go.mod index 103d4262..439a3636 100644 --- a/go.mod +++ b/go.mod @@ -3,7 +3,7 @@ module github.com/bitcoin-sv/spv-wallet-go-client go 1.22.5 require ( - github.com/bitcoin-sv/spv-wallet/models v1.0.0-beta.23 + github.com/bitcoin-sv/spv-wallet/models v1.0.0-beta.24 github.com/bitcoinschema/go-bitcoin/v2 v2.0.5 github.com/libsv/go-bk v0.1.6 github.com/libsv/go-bt/v2 v2.2.5 diff --git a/go.sum b/go.sum index 11a17c03..ca9ebaff 100644 --- a/go.sum +++ b/go.sum @@ -1,7 +1,9 @@ -github.com/bitcoin-sv/spv-wallet/models v1.0.0-beta.22 h1:iMVrWwiUBNLLZFhulUHZtwM1aW4usnguP4XQbtnK9Ws= -github.com/bitcoin-sv/spv-wallet/models v1.0.0-beta.22/go.mod h1:PEJdH9ZWKOiKHyOZkzYsRbKuZjzlRaEJy3GsM75Icdo= github.com/bitcoin-sv/spv-wallet/models v1.0.0-beta.23 h1:rM4w5H9INUQlUbSGQKN24eKKglvnk3yXuNVf1tahi0A= github.com/bitcoin-sv/spv-wallet/models v1.0.0-beta.23/go.mod h1:PEJdH9ZWKOiKHyOZkzYsRbKuZjzlRaEJy3GsM75Icdo= +github.com/bitcoin-sv/spv-wallet/models v1.0.0-beta.23.0.20240823064107-bcc29881132b h1:NCjFanr8Z0Xvdbof6gHwGnfW4Anf5tL3XDqwdB6S7NY= +github.com/bitcoin-sv/spv-wallet/models v1.0.0-beta.23.0.20240823064107-bcc29881132b/go.mod h1:PEJdH9ZWKOiKHyOZkzYsRbKuZjzlRaEJy3GsM75Icdo= +github.com/bitcoin-sv/spv-wallet/models v1.0.0-beta.24 h1:A5uhGBRo5eC1Nu30inL9X0QsFOd0wXUruLuwV9+HyLo= +github.com/bitcoin-sv/spv-wallet/models v1.0.0-beta.24/go.mod h1:PEJdH9ZWKOiKHyOZkzYsRbKuZjzlRaEJy3GsM75Icdo= github.com/bitcoinschema/go-bitcoin/v2 v2.0.5 h1:Sgh5Eb746Zck/46rFDrZZEXZWyO53fMuWYhNoZa1tck= github.com/bitcoinschema/go-bitcoin/v2 v2.0.5/go.mod h1:JjO1ivfZv6vhK0uAXzyH08AAHlzNMAfnyK1Fiv9r4ZA= github.com/bitcoinsv/bsvd v0.0.0-20190609155523-4c29707f7173 h1:2yTIV9u7H0BhRDGXH5xrAwAz7XibWJtX2dNezMeNsUo= diff --git a/http.go b/http.go index 6f49f7c5..0999c59a 100644 --- a/http.go +++ b/http.go @@ -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 +}