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