start logic webhook and added model for webhook payload
This commit is contained in:
parent
732a898a11
commit
ca24a9c1f2
39
internal/models/alchemy/webhook.go
Normal file
39
internal/models/alchemy/webhook.go
Normal file
@ -0,0 +1,39 @@
|
|||||||
|
package alchemy
|
||||||
|
|
||||||
|
type AlchemyAddressActivityWebhook struct {
|
||||||
|
CreatedAt string `json:"createdAt"`
|
||||||
|
Event struct {
|
||||||
|
Activity []struct {
|
||||||
|
Asset string `json:"asset"`
|
||||||
|
BlockNum string `json:"blockNum"`
|
||||||
|
Category string `json:"category"`
|
||||||
|
//Erc1155Metadata interface{} `json:"erc1155Metadata"`
|
||||||
|
//Erc721TokenId interface{} `json:"erc721TokenId"`
|
||||||
|
FromAddress string `json:"fromAddress"`
|
||||||
|
Hash string `json:"hash"`
|
||||||
|
Log struct {
|
||||||
|
Address string `json:"address"`
|
||||||
|
BlockHash string `json:"blockHash"`
|
||||||
|
BlockNumber string `json:"blockNumber"`
|
||||||
|
Data string `json:"data"`
|
||||||
|
LogIndex string `json:"logIndex"`
|
||||||
|
Removed bool `json:"removed"`
|
||||||
|
Topics []string `json:"topics"`
|
||||||
|
TransactionHash string `json:"transactionHash"`
|
||||||
|
TransactionIndex string `json:"transactionIndex"`
|
||||||
|
} `json:"log"`
|
||||||
|
RawContract struct {
|
||||||
|
Address string `json:"address"`
|
||||||
|
Decimals int `json:"decimals"`
|
||||||
|
RawValue string `json:"rawValue"`
|
||||||
|
} `json:"rawContract"`
|
||||||
|
ToAddress string `json:"toAddress"`
|
||||||
|
//TypeTraceAddress interface{} `json:"typeTraceAddress"`
|
||||||
|
Value float64 `json:"value"`
|
||||||
|
} `json:"activity"`
|
||||||
|
Network string `json:"network"`
|
||||||
|
} `json:"event"`
|
||||||
|
ID string `json:"id"`
|
||||||
|
Type string `json:"type"`
|
||||||
|
WebhookId string `json:"webhookId"`
|
||||||
|
}
|
@ -2,8 +2,10 @@ package alchemy
|
|||||||
|
|
||||||
import (
|
import (
|
||||||
"context"
|
"context"
|
||||||
|
"fmt"
|
||||||
"gitea.pena/PenaSide/treasurer/internal/errors"
|
"gitea.pena/PenaSide/treasurer/internal/errors"
|
||||||
"gitea.pena/PenaSide/treasurer/internal/models"
|
"gitea.pena/PenaSide/treasurer/internal/models"
|
||||||
|
"gitea.pena/PenaSide/treasurer/internal/models/alchemy"
|
||||||
"github.com/gofiber/fiber/v2"
|
"github.com/gofiber/fiber/v2"
|
||||||
"go.uber.org/zap"
|
"go.uber.org/zap"
|
||||||
)
|
)
|
||||||
@ -11,6 +13,7 @@ import (
|
|||||||
const ProviderName = "alchemy"
|
const ProviderName = "alchemy"
|
||||||
|
|
||||||
type Config struct {
|
type Config struct {
|
||||||
|
WalletAddress string `json:"walletAddress"`
|
||||||
}
|
}
|
||||||
|
|
||||||
type Provider struct {
|
type Provider struct {
|
||||||
@ -47,5 +50,16 @@ func (p *Provider) RegisterWebhookHandlers(router fiber.Router) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
func (p *Provider) handleWebhook(ctx *fiber.Ctx) error {
|
func (p *Provider) handleWebhook(ctx *fiber.Ctx) error {
|
||||||
return nil
|
var payload alchemy.AlchemyAddressActivityWebhook
|
||||||
|
if err := ctx.BodyParser(&payload); err != nil {
|
||||||
|
return ctx.Status(fiber.StatusBadRequest).SendString(fmt.Sprintf("failed to parse Alchemy webhook: %s", err.Error()))
|
||||||
|
}
|
||||||
|
|
||||||
|
for _, act := range payload.Event.Activity {
|
||||||
|
if act.ToAddress != p.config.WalletAddress {
|
||||||
|
continue
|
||||||
|
}
|
||||||
|
//TODO: найти инвойс по act.Value и act.FromAddress
|
||||||
|
}
|
||||||
|
return ctx.SendStatus(fiber.StatusOK)
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user