mirror of
https://github.com/scroll-tech/scroll.git
synced 2026-01-15 00:48:01 -05:00
Co-authored-by: colinlyguo <colinlyguo@users.noreply.github.com> Co-authored-by: zzq0826 <770166635@qq.com>
95 lines
2.9 KiB
Go
95 lines
2.9 KiB
Go
package api
|
|
|
|
import (
|
|
"github.com/gin-gonic/gin"
|
|
"github.com/go-redis/redis/v8"
|
|
"gorm.io/gorm"
|
|
|
|
"scroll-tech/bridge-history-api/internal/logic"
|
|
"scroll-tech/bridge-history-api/internal/types"
|
|
)
|
|
|
|
// HistoryController contains the query claimable txs service
|
|
type HistoryController struct {
|
|
historyLogic *logic.HistoryLogic
|
|
}
|
|
|
|
// NewHistoryController return HistoryController instance
|
|
func NewHistoryController(db *gorm.DB, redis *redis.Client) *HistoryController {
|
|
return &HistoryController{
|
|
historyLogic: logic.NewHistoryLogic(db, redis),
|
|
}
|
|
}
|
|
|
|
// GetL2UnclaimedWithdrawalsByAddress defines the http get method behavior
|
|
func (c *HistoryController) GetL2UnclaimedWithdrawalsByAddress(ctx *gin.Context) {
|
|
var req types.QueryByAddressRequest
|
|
if err := ctx.ShouldBind(&req); err != nil {
|
|
types.RenderFailure(ctx, types.ErrParameterInvalidNo, err)
|
|
return
|
|
}
|
|
|
|
pagedTxs, total, err := c.historyLogic.GetL2UnclaimedWithdrawalsByAddress(ctx, req.Address, req.Page, req.PageSize)
|
|
if err != nil {
|
|
types.RenderFailure(ctx, types.ErrGetL2ClaimableWithdrawalsError, err)
|
|
return
|
|
}
|
|
|
|
resultData := &types.ResultData{Results: pagedTxs, Total: total}
|
|
types.RenderSuccess(ctx, resultData)
|
|
}
|
|
|
|
// GetL2WithdrawalsByAddress defines the http get method behavior
|
|
func (c *HistoryController) GetL2WithdrawalsByAddress(ctx *gin.Context) {
|
|
var req types.QueryByAddressRequest
|
|
if err := ctx.ShouldBind(&req); err != nil {
|
|
types.RenderFailure(ctx, types.ErrParameterInvalidNo, err)
|
|
return
|
|
}
|
|
|
|
pagedTxs, total, err := c.historyLogic.GetL2WithdrawalsByAddress(ctx, req.Address, req.Page, req.PageSize)
|
|
if err != nil {
|
|
types.RenderFailure(ctx, types.ErrGetL2WithdrawalsError, err)
|
|
return
|
|
}
|
|
|
|
resultData := &types.ResultData{Results: pagedTxs, Total: total}
|
|
types.RenderSuccess(ctx, resultData)
|
|
}
|
|
|
|
// GetTxsByAddress defines the http get method behavior
|
|
func (c *HistoryController) GetTxsByAddress(ctx *gin.Context) {
|
|
var req types.QueryByAddressRequest
|
|
if err := ctx.ShouldBind(&req); err != nil {
|
|
types.RenderFailure(ctx, types.ErrParameterInvalidNo, err)
|
|
return
|
|
}
|
|
|
|
pagedTxs, total, err := c.historyLogic.GetTxsByAddress(ctx, req.Address, req.Page, req.PageSize)
|
|
if err != nil {
|
|
types.RenderFailure(ctx, types.ErrGetTxsError, err)
|
|
return
|
|
}
|
|
|
|
resultData := &types.ResultData{Results: pagedTxs, Total: total}
|
|
types.RenderSuccess(ctx, resultData)
|
|
}
|
|
|
|
// PostQueryTxsByHashes defines the http post method behavior
|
|
func (c *HistoryController) PostQueryTxsByHashes(ctx *gin.Context) {
|
|
var req types.QueryByHashRequest
|
|
if err := ctx.ShouldBindJSON(&req); err != nil {
|
|
types.RenderFailure(ctx, types.ErrParameterInvalidNo, err)
|
|
return
|
|
}
|
|
|
|
results, err := c.historyLogic.GetTxsByHashes(ctx, req.Txs)
|
|
if err != nil {
|
|
types.RenderFailure(ctx, types.ErrGetTxsByHashError, err)
|
|
return
|
|
}
|
|
|
|
resultData := &types.ResultData{Results: results, Total: uint64(len(results))}
|
|
types.RenderSuccess(ctx, resultData)
|
|
}
|