diff --git a/examples/webhooks/webhooks.go b/examples/webhooks/webhooks.go index aee9dab..7f12df8 100644 --- a/examples/webhooks/webhooks.go +++ b/examples/webhooks/webhooks.go @@ -17,7 +17,7 @@ import ( func main() { defer examples.HandlePanic() - client := walletclient.NewWithAdminKey("http://localhost:3003/v1", examples.ExampleAdminKey) + client := walletclient.NewWithAdminKey("http://localhost:3003/v1", "xprv9s21ZrQH143K2pmNeAHBzU4JHNDaFaPTbzKbBCw55ErhMDLsxDwKqcaDVV3PwmEmRZa9qUaU261iJaUx8eBiBF77zrPxTH8JGXC7LZQnsgA") //"Authorization", "this-is-the-token", 3 wh := notifications.NewWebhook( context.Background(), @@ -33,16 +33,16 @@ func main() { http.Handle("/notification", wh.HTTPHandler()) - if err = notifications.RegisterHandler(wh, func(gpe *notifications.NumericEvent) { + if err = notifications.RegisterHandler(wh, func(gpe *notifications.StringEvent) { time.Sleep(50 * time.Millisecond) // simulate processing time - fmt.Printf("Processing event-numeric: %d\n", gpe.Numeric) + fmt.Printf("Processing event-string: %s\n", gpe.Value) }); err != nil { panic(err) } - if err = notifications.RegisterHandler(wh, func(gpe *notifications.StringEvent) { + if err = notifications.RegisterHandler(wh, func(gpe *notifications.TransactionEvent) { time.Sleep(50 * time.Millisecond) // simulate processing time - fmt.Printf("Processing event-string: %s\n", gpe.Value) + fmt.Printf("Processing event-transaction: XPubID: %s, TxID: %s\n", gpe.XPubID, gpe.TransactionID) }); err != nil { panic(err) } diff --git a/notifications/webhook.go b/notifications/webhook.go index 85cc38b..3574b07 100644 --- a/notifications/webhook.go +++ b/notifications/webhook.go @@ -90,19 +90,28 @@ func (nd *Webhook) process() { ////////////////////// BELOW it should be imported from spv-wallet models +// RawEvent - the base event type type RawEvent struct { Type string `json:"type"` Content json.RawMessage `json:"content"` } +// StringEvent - event with string value; can be used for generic messages and it's used for testing type StringEvent struct { - Value string + Value string `json:"value"` } -type NumericEvent struct { - Numeric int +type UserEvent struct { + XPubID string `json:"xpubId"` } +type TransactionEvent struct { + UserEvent `json:",inline"` + + TransactionID string `json:"transactionId"` +} + +// Events - interface for all supported events type Events interface { - StringEvent | NumericEvent + StringEvent | TransactionEvent }