8 "github.com/gin-gonic/gin"
10 "github.com/vapor/errors"
11 "github.com/vapor/federation/common"
12 "github.com/vapor/federation/database/orm"
15 type listCrosschainTxsReq struct{ Display }
17 func (s *Server) ListCrosschainTxs(c *gin.Context, listTxsReq *listCrosschainTxsReq, query *PaginationQuery) ([]*orm.CrossTransaction, error) {
18 var ormTxs []*orm.CrossTransaction
19 txFilter := &orm.CrossTransaction{}
22 if status, err := listTxsReq.GetFilterString("status"); err == nil && status != "" {
23 switch strings.ToLower(status) {
24 case common.CrossTxPendingStatusLabel:
25 txFilter.Status = common.CrossTxPendingStatus
26 case common.CrossTxCompletedStatusLabel:
27 txFilter.Status = common.CrossTxCompletedStatus
32 if txHash, err := listTxsReq.GetFilterString("source_tx_hash"); err == nil && txHash != "" {
33 txFilter.SourceTxHash = txHash
35 if txHash, err := listTxsReq.GetFilterString("dest_tx_hash"); err == nil && txHash != "" {
36 txFilter.DestTxHash = sql.NullString{txHash, true}
39 txQuery := s.db.Preload("Chain").Preload("Reqs").Preload("Reqs.Asset").Where(txFilter)
41 if fromChainName, err := listTxsReq.GetFilterString("from_chain"); err == nil && fromChainName != "" {
42 txQuery = txQuery.Joins("join chains on chains.id = cross_transactions.chain_id").Where("chains.name = ?", fromChainName)
44 txQuery = txQuery.Order(fmt.Sprintf("cross_transactions.source_block_height %s", listTxsReq.Sorter.Order))
45 txQuery = txQuery.Order(fmt.Sprintf("cross_transactions.source_tx_index %s", listTxsReq.Sorter.Order))
46 if err := txQuery.Offset(query.Start).Limit(query.Limit).Find(&ormTxs).Error; err != nil {
47 return nil, errors.Wrap(err, "query txs")