wallet/pkg/rest/eth_v1_transaction.go
Anton Nesterov f1bc53ce2a
[init]
2024-08-31 17:00:14 +02:00

63 lines
1.3 KiB
Go

package rest
import (
"net/http"
eth "custodial/pkg/eth"
gin "github.com/gin-gonic/gin"
)
type EthTransactionInfoRequest struct {
TxID string `json:"tx_id"`
}
type EthTransactionInfoResponse struct {
Id string `json:"id"`
Status string `json:"status"`
}
// @BasePath /api/v1
//
// AddressBalance godoc
//
// @Summary Get transaction info
// @Schemes
// @Description Get transaction info
// @Tags Ethereum
// @Accept json
// @Produce json
// @Security ApiKeyAuth
// @Param message body EthTransactionInfoRequest true "Tx Info"
// @Success 200 {object} EthTransactionInfoResponse
// @Failure 400 {object} ErrorResponse
// @Router /eth/tx-info [post]
func EthTransactionInfoV1(c *gin.Context) {
var req EthTransactionInfoRequest
if err := c.ShouldBindJSON(&req); err != nil {
c.JSON(http.StatusBadRequest, gin.H{"error": err.Error()})
return
}
tx, err := eth.GetTransactionByHash(req.TxID)
if err != nil {
c.JSON(http.StatusBadRequest, gin.H{"error": err.Error()})
return
}
status := "pending"
if tx == nil {
status = "pending"
} else if tx.Status == 1 {
status = "success"
} else if tx.Status == 0 {
status = "failed"
}
res := EthTransactionInfoResponse{
Id: req.TxID,
Status: status,
}
c.JSON(http.StatusOK, res)
}