86 lines
2 KiB
Go
86 lines
2 KiB
Go
|
package rest
|
||
|
|
||
|
import (
|
||
|
"net/http"
|
||
|
|
||
|
store "custodial/pkg/store"
|
||
|
trc "custodial/pkg/tron"
|
||
|
|
||
|
gin "github.com/gin-gonic/gin"
|
||
|
)
|
||
|
|
||
|
type TronAddressBalanceRequest struct {
|
||
|
Address string `json:"address"`
|
||
|
}
|
||
|
|
||
|
type TronAccountBalanceRequest struct {
|
||
|
AccountID string `json:"account_id"`
|
||
|
}
|
||
|
|
||
|
// @BasePath /api/v1
|
||
|
//
|
||
|
// AddressBalance godoc
|
||
|
//
|
||
|
// @Summary Get address balance
|
||
|
// @Schemes
|
||
|
// @Description Get address balance
|
||
|
// @Tags Tron
|
||
|
// @Accept json
|
||
|
// @Produce json
|
||
|
// @Security ApiKeyAuth
|
||
|
// @Param message body TronAddressBalanceRequest true "Account Info"
|
||
|
// @Success 200 {object} trc.TronAccountBalance
|
||
|
// @Failure 400 {object} ErrorResponse
|
||
|
// @Router /tron/address-balance [post]
|
||
|
func TronAddressBalanceV1(c *gin.Context) {
|
||
|
var req TronAddressBalanceRequest
|
||
|
if err := c.ShouldBindJSON(&req); err != nil {
|
||
|
c.JSON(http.StatusBadRequest, gin.H{"error": err.Error()})
|
||
|
return
|
||
|
}
|
||
|
|
||
|
balance, err := trc.TronBalance(req.Address)
|
||
|
if err != nil {
|
||
|
c.JSON(http.StatusBadRequest, gin.H{"error": err.Error()})
|
||
|
return
|
||
|
}
|
||
|
|
||
|
c.JSON(http.StatusOK, balance)
|
||
|
}
|
||
|
|
||
|
// @BasePath /api/v1
|
||
|
//
|
||
|
// AddressBalance godoc
|
||
|
//
|
||
|
// @Summary Get address balance
|
||
|
// @Schemes
|
||
|
// @Description Get address balance
|
||
|
// @Tags Tron
|
||
|
// @Accept json
|
||
|
// @Produce json
|
||
|
// @Security ApiKeyAuth
|
||
|
// @Param message body TronAccountBalanceRequest true "Account Info"
|
||
|
// @Success 200 {object} trc.TronAccountBalance
|
||
|
// @Failure 400 {object} ErrorResponse
|
||
|
// @Router /tron/account-balance [post]
|
||
|
func TronAccountBalanceV1(c *gin.Context) {
|
||
|
var req TronAccountBalanceRequest
|
||
|
if err := c.ShouldBindJSON(&req); err != nil {
|
||
|
c.JSON(http.StatusBadRequest, gin.H{"error": err.Error()})
|
||
|
return
|
||
|
}
|
||
|
|
||
|
storedAccount, err := store.GetAccount(req.AccountID, store.Tron)
|
||
|
if err != nil {
|
||
|
c.JSON(http.StatusBadRequest, gin.H{"error": err.Error()})
|
||
|
return
|
||
|
}
|
||
|
|
||
|
balance, err := trc.TronBalance(storedAccount.GetAddress())
|
||
|
if err != nil {
|
||
|
c.JSON(http.StatusBadRequest, gin.H{"error": err.Error()})
|
||
|
return
|
||
|
}
|
||
|
c.JSON(http.StatusOK, balance)
|
||
|
}
|