Skip to content

Commit

Permalink
Merge pull request #13 from breez/savage-swap-updated
Browse files Browse the repository at this point in the history
Add Boltz webhook handling
  • Loading branch information
dangeross authored Aug 27, 2024
2 parents f3cad7a + 262421f commit 3062a1d
Show file tree
Hide file tree
Showing 2 changed files with 32 additions and 5 deletions.
28 changes: 27 additions & 1 deletion http/router.go
Original file line number Diff line number Diff line change
Expand Up @@ -121,6 +121,25 @@ func (p *AddressTxsConfirmedPayload) ToNotification(query *MobilePushWebHookQuer
}
}

type SwapUpdatedPayload struct {
Event string `json:"event" binding:"required,eq=swap.update"`
Data struct {
Id string `json:"id" binding:"required"`
Status string `json:"status" binding:"required"`
} `json:"data"`
}

func (p *SwapUpdatedPayload) ToNotification(query *MobilePushWebHookQuery) *notify.Notification {
return &notify.Notification{
Template: notify.NOTIFICATION_SWAP_UPDATED,
DisplayMessage: "Swap updated",
Type: query.Platform,
TargetIdentifier: query.Token,
AppData: query.AppData,
Data: map[string]interface{}{"id": p.Data.Id, "status": p.Data.Status},
}
}

func Run(notifier *notify.Notifier, config *config.HTTPConfig) error {
r := setupRouter(notifier)
r.SetTrustedProxies(nil)
Expand Down Expand Up @@ -148,7 +167,14 @@ func addWebHookRouter(r *gin.RouterGroup, notifier *notify.Notifier) {
}

// Find a matching notification payload
payloads := []NotificationConvertible{&PaymentReceivedPayload{}, &TxConfirmedPayload{}, &AddressTxsConfirmedPayload{}, &LnurlPayInfoPayload{}, &LnurlPayInvoicePayload{}}
payloads := []NotificationConvertible{
&PaymentReceivedPayload{},
&TxConfirmedPayload{},
&AddressTxsConfirmedPayload{},
&LnurlPayInfoPayload{},
&LnurlPayInvoicePayload{},
&SwapUpdatedPayload{},
}
var validPayload NotificationConvertible
for _, p := range payloads {
if err := c.ShouldBindBodyWith(p, binding.JSON); err != nil {
Expand Down
9 changes: 5 additions & 4 deletions notify/notify.go
Original file line number Diff line number Diff line change
Expand Up @@ -10,11 +10,12 @@ import (
)

const (
NOTIFICATION_PAYMENT_RECEIVED = "payment_received"
NOTIFICATION_TX_CONFIRMED = "tx_confirmed"
NOTIFICATION_PAYMENT_RECEIVED = "payment_received"
NOTIFICATION_TX_CONFIRMED = "tx_confirmed"
NOTIFICATION_ADDRESS_TXS_CONFIRMED = "address_txs_confirmed"
NOTIFICATION_LNURLPAY_INFO = "lnurlpay_info"
NOTIFICATION_LNURLPAY_INVOICE = "lnurlpay_invoice"
NOTIFICATION_LNURLPAY_INFO = "lnurlpay_info"
NOTIFICATION_LNURLPAY_INVOICE = "lnurlpay_invoice"
NOTIFICATION_SWAP_UPDATED = "swap_updated"
)

var (
Expand Down

0 comments on commit 3062a1d

Please sign in to comment.