8 "github.com/gin-gonic/gin"
10 "github.com/vapor/errors"
11 "github.com/vapor/toolbar/federation/common"
12 "github.com/vapor/toolbar/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 sourceChainName, err := listTxsReq.GetFilterString("source_chain_name"); err == nil && sourceChainName != "" {
42 txQuery = txQuery.Joins("join chains on chains.id = cross_transactions.chain_id").Where("chains.name = ?", sourceChainName)
46 if address, err := listTxsReq.GetFilterString("address"); err == nil && address != "" {
47 txQuery = txQuery.Joins("join cross_transaction_reqs on cross_transaction_reqs.cross_transaction_id = cross_transactions.id").
48 Where("cross_transaction_reqs.from_address = ? or cross_transaction_reqs.to_address = ?", address, address)
52 txQuery = txQuery.Order(fmt.Sprintf("cross_transactions.source_block_height %s", listTxsReq.Sorter.Order))
53 txQuery = txQuery.Order(fmt.Sprintf("cross_transactions.source_tx_index %s", listTxsReq.Sorter.Order))
54 if err := txQuery.Offset(query.Start).Limit(query.Limit).Find(&ormTxs).Error; err != nil {
55 return nil, errors.Wrap(err, "query txs")
61 func (s *Server) ListChains(c *gin.Context) ([]*orm.Chain, error) {
62 var chains []*orm.Chain
63 if err := s.db.Find(&chains).Error; err != nil {