7 "github.com/gin-gonic/gin"
9 "github.com/vapor/errors"
10 "github.com/vapor/federation/common"
11 "github.com/vapor/federation/database/orm"
14 type listCrosschainTxsReq struct{ Display }
16 func (s *Server) ListCrosschainTxs(c *gin.Context, listTxsReq *listCrosschainTxsReq, query *PaginationQuery) ([]*orm.CrossTransaction, error) {
17 var ormTxs []*orm.CrossTransaction
18 txFilter := &orm.CrossTransaction{}
21 if status, err := listTxsReq.GetFilterString("status"); err == nil && status != "" {
24 txFilter.Status = common.CrossTxPendingStatus
26 txFilter.Status = common.CrossTxCompletedStatus
31 if txHash, err := listTxsReq.GetFilterString("source_tx_hash"); err == nil && txHash != "" {
32 txFilter.SourceTxHash = txHash
34 if txHash, err := listTxsReq.GetFilterString("dest_tx_hash"); err == nil && txHash != "" {
35 txFilter.DestTxHash = sql.NullString{txHash, true}
38 txQuery := s.db.Preload("Chain").Preload("Reqs").Preload("Reqs.Asset").Where(txFilter)
40 if fromChainName, err := listTxsReq.GetFilterString("from"); err == nil && fromChainName != "" {
41 txQuery = txQuery.Joins("join chains on chains.id = cross_transactions.chain_id").Where("chains.name = ?", fromChainName)
43 txQuery = txQuery.Order(fmt.Sprintf("cross_transactions.source_block_height %s", listTxsReq.Sorter.Order))
44 txQuery = txQuery.Order(fmt.Sprintf("cross_transactions.source_tx_index %s", listTxsReq.Sorter.Order))
45 if err := txQuery.Offset(query.Start).Limit(query.Limit).Find(&ormTxs).Error; err != nil {
46 return nil, errors.Wrap(err, "query txs")