mirror of
https://github.com/scroll-tech/scroll.git
synced 2026-01-14 16:37:56 -05:00
Co-authored-by: zimpha <zimpha@gmail.com> Co-authored-by: georgehao <georgehao@users.noreply.github.com> Co-authored-by: colin <102356659+colinlyguo@users.noreply.github.com> Co-authored-by: colinlyguo <colinlyguo@users.noreply.github.com> Co-authored-by: colinlyguo <colinlyguo@scroll.io>
41 lines
1.1 KiB
Go
41 lines
1.1 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"
|
|
)
|
|
|
|
// TxsByAddressController the controller of GetTxsByAddress
|
|
type TxsByAddressController struct {
|
|
historyLogic *logic.HistoryLogic
|
|
}
|
|
|
|
// NewTxsByAddressController create new TxsByAddressController
|
|
func NewTxsByAddressController(db *gorm.DB, redisClient *redis.Client) *TxsByAddressController {
|
|
return &TxsByAddressController{
|
|
historyLogic: logic.NewHistoryLogic(db, redisClient),
|
|
}
|
|
}
|
|
|
|
// GetTxsByAddress defines the http get method behavior
|
|
func (c *TxsByAddressController) 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)
|
|
}
|