package rest import ( "net/http" store "custodial/pkg/store" trc "custodial/pkg/tron" gin "github.com/gin-gonic/gin" ) type RechargeTronRequest struct { AccountID string `json:"account_id"` Amount string `json:"amount"` } type RechargeTronResponse struct { Status string `json:"status"` TXID string `json:"txid"` } // @BasePath /api/v1 // // TronRechargeTrxBySpenderV1 godoc // // @Summary Add TRX from spender account // @Schemes // @Description Add TRX funds from the spender account // @Tags Tron // @Accept json // @Produce json // @Security ApiKeyAuth // @Param message body RechargeTronRequest true "Account Info" // @Success 200 {object} RechargeTronResponse // @Failure 400 {object} ErrorResponse // @Router /tron/recharge-trx-by-spender [post] func TronRechargeTrxBySpenderV1(c *gin.Context) { var req RechargeTronRequest 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 } spender, err := trc.GetSpender() if err != nil { c.JSON(http.StatusBadRequest, gin.H{"error": err.Error()}) return } txid, err := spender.WithdrawTRX(storedAccount.GetAddress(), req.Amount) if err != nil { c.JSON(http.StatusBadRequest, gin.H{"error": err.Error()}) return } c.JSON(http.StatusOK, gin.H{"txid": txid, "status": "ok"}) }