8 "github.com/gin-gonic/gin"
10 "github.com/bytom/vapor/errors"
11 "github.com/bytom/vapor/toolbar/federation/common"
12 "github.com/bytom/vapor/toolbar/federation/database/orm"
13 serverCommon "github.com/bytom/vapor/toolbar/server"
16 type listCrosschainTxsReq struct{ serverCommon.Display }
18 func (s *Server) ListCrosschainTxs(c *gin.Context, listTxsReq *listCrosschainTxsReq, query *serverCommon.PaginationQuery) ([]*orm.CrossTransaction, error) {
19 var ormTxs []*orm.CrossTransaction
20 txFilter := &orm.CrossTransaction{}
23 if status, err := listTxsReq.GetFilterString("status"); err == nil && status != "" {
24 switch strings.ToLower(status) {
25 case common.CrossTxPendingStatusLabel:
26 txFilter.Status = common.CrossTxPendingStatus
27 case common.CrossTxCompletedStatusLabel:
28 txFilter.Status = common.CrossTxCompletedStatus
33 if txHash, err := listTxsReq.GetFilterString("source_tx_hash"); err == nil && txHash != "" {
34 txFilter.SourceTxHash = txHash
36 if txHash, err := listTxsReq.GetFilterString("dest_tx_hash"); err == nil && txHash != "" {
37 txFilter.DestTxHash = sql.NullString{txHash, true}
40 txQuery := s.db.Preload("Chain").Preload("Reqs").Preload("Reqs.Asset").Where(txFilter)
42 if sourceChainName, err := listTxsReq.GetFilterString("source_chain_name"); err == nil && sourceChainName != "" {
43 txQuery = txQuery.Joins("join chains on chains.id = cross_transactions.chain_id").Where("chains.name = ?", sourceChainName)
47 if address, err := listTxsReq.GetFilterString("address"); err == nil && address != "" {
48 txQuery = txQuery.Joins("join cross_transaction_reqs on cross_transaction_reqs.cross_transaction_id = cross_transactions.id").
49 Where("cross_transaction_reqs.from_address = ? or cross_transaction_reqs.to_address = ?", address, address)
53 txQuery = txQuery.Order(fmt.Sprintf("cross_transactions.source_block_height %s", listTxsReq.Sorter.Order))
54 txQuery = txQuery.Order(fmt.Sprintf("cross_transactions.source_tx_index %s", listTxsReq.Sorter.Order))
55 if err := txQuery.Offset(query.Start).Limit(query.Limit).Find(&ormTxs).Error; err != nil {
56 return nil, errors.Wrap(err, "query txs")
62 func (s *Server) ListChains(c *gin.Context) ([]*orm.Chain, error) {
63 var chains []*orm.Chain
64 if err := s.db.Find(&chains).Error; err != nil {