@@ -10,9 +10,9 @@ import (
1010 "strconv"
1111 "strings"
1212
13+ "github.com/KiraCore/sai-storage-mongo/external/adapter"
1314 sekaitypes "github.com/KiraCore/sekai/types"
1415 sdk "github.com/cosmos/cosmos-sdk/types"
15- "github.com/KiraCore/sai-storage-mongo/external/adapter"
1616 "go.uber.org/zap"
1717
1818 "github.com/KiraCore/sai-interx-manager/logger"
@@ -361,6 +361,8 @@ func (g *CosmosGateway) transactions(req types.InboundRequest) (interface{}, err
361361 Limit : sekaitypes .PageIterationLimit - 1 ,
362362 }
363363
364+ logger .Logger .Debug ("[query-transactions] request" , zap .Any ("req" , req ))
365+
364366 jsonData , err := json .Marshal (req .Payload )
365367 if err != nil {
366368 logger .Logger .Error ("[query-transactions] Invalid request format" , zap .Error (err ))
@@ -374,32 +376,27 @@ func (g *CosmosGateway) transactions(req types.InboundRequest) (interface{}, err
374376 }
375377
376378 sortMap := make (map [string ]interface {})
377- if request .Sort != nil {
378- sortMap = request .Sort
379- } else if req .Payload ["sort" ] != nil {
380- sortStr , ok := req .Payload ["sort" ].(string )
381- if ok && sortStr != "" {
382- parts := strings .Split (sortStr , ":" )
383- var field string
384- var direction string
385-
386- if len (parts ) == 2 {
387- field = strings .TrimSpace (parts [0 ])
388- direction = strings .TrimSpace (parts [1 ])
389- } else if len (parts ) == 1 {
390- field = "cr_time"
391- direction = strings .TrimSpace (parts [0 ])
392- }
379+ if request .Sort != "" {
380+ parts := strings .Split (request .Sort , ":" )
381+ var field string
382+ var direction string
383+
384+ if len (parts ) == 2 {
385+ field = strings .TrimSpace (parts [0 ])
386+ direction = strings .TrimSpace (parts [1 ])
387+ } else if len (parts ) == 1 {
388+ field = "cr_time"
389+ direction = strings .TrimSpace (parts [0 ])
390+ }
393391
394- if field != "" {
395- var dirValue int
396- if direction == "desc" || direction == "-1" {
397- dirValue = - 1
398- } else {
399- dirValue = 1
400- }
401- sortMap [field ] = dirValue
392+ if field != "" {
393+ var dirValue int
394+ if direction == "desc" || direction == "-1" {
395+ dirValue = - 1
396+ } else {
397+ dirValue = 1
402398 }
399+ sortMap [field ] = dirValue
403400 }
404401 }
405402
@@ -426,20 +423,20 @@ func (g *CosmosGateway) transactions(req types.InboundRequest) (interface{}, err
426423 }
427424 }
428425
429- if request .StartDate > 0 {
426+ if request .StartDate != "" {
430427 criteria ["timestamp" ] = map [string ]interface {}{
431- "$gt " : request .StartDate ,
428+ "$gte " : request .StartDate ,
432429 }
433430
434- if request .EndDate > 0 {
431+ if request .EndDate != "" {
435432 criteria ["timestamp" ] = map [string ]interface {}{
436- "$gt " : request .StartDate ,
437- "$lt " : request .EndDate ,
433+ "$gte " : request .StartDate ,
434+ "$lte " : request .EndDate ,
438435 }
439436 }
440- } else if request .EndDate > 0 {
437+ } else if request .EndDate != "" {
441438 criteria ["timestamp" ] = map [string ]interface {}{
442- "$lt " : request .EndDate ,
439+ "$lte " : request .EndDate ,
443440 }
444441 }
445442
@@ -467,21 +464,43 @@ func (g *CosmosGateway) transactions(req types.InboundRequest) (interface{}, err
467464 return nil , fmt .Errorf ("directions filter requires address to be specified" )
468465 }
469466
467+ logger .Logger .Debug ("[query-transactions] request" ,
468+ zap .Any ("request.Directions" , request .Directions ),
469+ zap .Any ("request.Address" , request .Address ),
470+ )
471+
470472 if request .Address != "" {
471473 orConditions := []map [string ]interface {}{}
472474
473475 if len (request .Directions ) == 0 {
474476 orConditions = []map [string ]interface {}{
475477 {"messages.from_address" : request .Address },
476- {"messages.to_address" : request .Address },
478+ {"pf" : request .Address },
479+ {"tx_result.events.attributes.value" : request .Address },
477480 }
478481 } else {
479482 for _ , direction := range request .Directions {
480483 switch direction {
481484 case "inbound" :
482485 orConditions = append (orConditions , map [string ]interface {}{"messages.to_address" : request .Address })
486+ orConditions = append (orConditions , map [string ]interface {}{
487+ "tx_result.events.attributes" : map [string ]interface {}{
488+ "$elemMatch" : map [string ]interface {}{
489+ "key" : "recipient" ,
490+ "value" : request .Address ,
491+ },
492+ },
493+ })
483494 case "outbound" :
484495 orConditions = append (orConditions , map [string ]interface {}{"messages.from_address" : request .Address })
496+ orConditions = append (orConditions , map [string ]interface {}{
497+ "tx_result.events.attributes" : map [string ]interface {}{
498+ "$elemMatch" : map [string ]interface {}{
499+ "key" : "sender" ,
500+ "value" : request .Address ,
501+ },
502+ },
503+ })
485504 }
486505 }
487506 }
0 commit comments