mirror of
https://github.com/alexgo-io/gaze-indexer.git
synced 2026-01-12 08:34:28 +08:00
* feat: recover nodesale module. * fix: refactored. * fix: fix table type. * fix: add entity * fix: bug UTC time. * ci: try to tidy before testing * ci: touch result file * ci: use echo to create new file * fix: try to skip test in ci * fix: remove os.Exit * fix: handle error * feat: add todo note * fix: Cannot run nodesale test because qtx is not initiated. * fix: 50% chance public key compare incorrectly. * fix: more consistent SQL * fix: sanity refactor. * fix: remove unused code. * fix: move last_block_default to config file. * fix: minor mistakes. * fix: * fix: refactor * fix: refactor * fix: delegate tx hash not record into db. * refactor: prepare for moving integration tests. * refactor: convert to unit tests. * fix: change to using input values since output values deducted fee. * feat: add extra unit test. * fix: wrong timestamp format. * fix: handle block timeout = 0 --------- Co-authored-by: Gaze <gazenw@users.noreply.github.com>
57 lines
1.6 KiB
Go
57 lines
1.6 KiB
Go
package httphandler
|
|
|
|
import (
|
|
"encoding/json"
|
|
"time"
|
|
|
|
"github.com/cockroachdb/errors"
|
|
"github.com/gaze-network/indexer-network/modules/nodesale/protobuf"
|
|
"github.com/gofiber/fiber/v2"
|
|
)
|
|
|
|
type eventRequest struct {
|
|
WalletAddress string `query:"walletAddress"`
|
|
}
|
|
|
|
type eventResposne struct {
|
|
TxHash string `json:"txHash"`
|
|
BlockHeight int64 `json:"blockHeight"`
|
|
TxIndex int32 `json:"txIndex"`
|
|
WalletAddress string `json:"walletAddress"`
|
|
Action string `json:"action"`
|
|
ParsedMessage json.RawMessage `json:"parsedMessage"`
|
|
BlockTimestamp time.Time `json:"blockTimestamp"`
|
|
BlockHash string `json:"blockHash"`
|
|
}
|
|
|
|
func (h *handler) eventsHandler(ctx *fiber.Ctx) error {
|
|
var request eventRequest
|
|
err := ctx.QueryParser(&request)
|
|
if err != nil {
|
|
return errors.Wrap(err, "cannot parse query")
|
|
}
|
|
|
|
events, err := h.nodeSaleDg.GetEventsByWallet(ctx.UserContext(), request.WalletAddress)
|
|
if err != nil {
|
|
return errors.Wrap(err, "Can't get events from db")
|
|
}
|
|
|
|
responses := make([]eventResposne, len(events))
|
|
for i, event := range events {
|
|
responses[i].TxHash = event.TxHash
|
|
responses[i].BlockHeight = event.BlockHeight
|
|
responses[i].TxIndex = event.TxIndex
|
|
responses[i].WalletAddress = event.WalletAddress
|
|
responses[i].Action = protobuf.Action_name[event.Action]
|
|
responses[i].ParsedMessage = event.ParsedMessage
|
|
responses[i].BlockTimestamp = event.BlockTimestamp
|
|
responses[i].BlockHash = event.BlockHash
|
|
}
|
|
|
|
err = ctx.JSON(responses)
|
|
if err != nil {
|
|
return errors.Wrap(err, "Go fiber cannot parse JSON")
|
|
}
|
|
return nil
|
|
}
|