Skip to content

Commit 4694721

Browse files
authored
Merge pull request #56 from KiraCore/bugfix/41
Closes #41 Spawned issues: #59, #60
2 parents 0222ffe + 36a29a0 commit 4694721

File tree

4 files changed

+78
-50
lines changed

4 files changed

+78
-50
lines changed

manager/gateway/cosmos.go

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,9 @@ import (
2727
kiraUbi "github.com/KiraCore/sai-interx-manager/proto-gen/kira/ubi"
2828
kiraUpgrades "github.com/KiraCore/sai-interx-manager/proto-gen/kira/upgrade"
2929

30+
"github.com/KiraCore/sai-interx-manager/logger"
31+
"github.com/KiraCore/sai-interx-manager/types"
32+
"github.com/KiraCore/sai-service/service"
3033
sekaitypes "github.com/KiraCore/sekai/types"
3134
"github.com/cosmos/cosmos-sdk/client"
3235
"github.com/cosmos/cosmos-sdk/codec"
@@ -41,9 +44,6 @@ import (
4144
"github.com/cosmos/go-bip39"
4245
"github.com/google/uuid"
4346
"github.com/grpc-ecosystem/grpc-gateway/v2/runtime"
44-
"github.com/KiraCore/sai-interx-manager/logger"
45-
"github.com/KiraCore/sai-interx-manager/types"
46-
"github.com/KiraCore/sai-service/service"
4747
"go.uber.org/zap"
4848
"google.golang.org/grpc"
4949
"google.golang.org/grpc/credentials/insecure"
@@ -277,7 +277,7 @@ func (g *CosmosGateway) Handle(data []byte) (interface{}, error) {
277277
var req types.InboundRequest
278278

279279
if err := json.Unmarshal(data, &req); err != nil {
280-
logger.Logger.Error("CosmosGateway - Handle - Unmarshal request failed", zap.Error(err))
280+
logger.Logger.Error("CosmosGateway - Handle - Unmarshal request failed", zap.Error(err), zap.Any("req", req))
281281
return nil, err
282282
}
283283

manager/gateway/cosmos_agregated3.go

Lines changed: 52 additions & 33 deletions
Original file line numberDiff line numberDiff line change
@@ -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
}

manager/types/cosmos.go

Lines changed: 11 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -175,17 +175,17 @@ type TransactionResultResponse struct {
175175
}
176176

177177
type QueryTxsParams struct {
178-
Hash string `json:"hash,omitempty"`
179-
Height string `json:"height,omitempty"`
180-
Address string `json:"address,omitempty"`
181-
StartDate int64 `json:"start_date,string,omitempty"`
182-
EndDate int64 `json:"end_date,string,omitempty"`
183-
Directions []string `json:"directions,omitempty"`
184-
Statuses []string `json:"statuses,omitempty"`
185-
Types []string `json:"types,omitempty"`
186-
Offset int `json:"offset,string,omitempty"`
187-
Limit int `json:"limit,string,omitempty"`
188-
Sort map[string]interface{} `json:"sort,omitempty"`
178+
Hash string `json:"hash,omitempty"`
179+
Height string `json:"height,omitempty"`
180+
Address string `json:"address,omitempty"`
181+
StartDate string `json:"start_date,omitempty"`
182+
EndDate string `json:"end_date,omitempty"`
183+
Directions []string `json:"directions,omitempty"`
184+
Statuses []string `json:"statuses,omitempty"`
185+
Types []string `json:"types,omitempty"`
186+
Offset int `json:"offset,string,omitempty"`
187+
Limit int `json:"limit,string,omitempty"`
188+
Sort string `json:"sort,omitempty"`
189189
}
190190

191191
type TxResponse struct {

proxy/internal/service.go

Lines changed: 11 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -51,10 +51,19 @@ func (is *InternalService) handleHttpConnections(w http.ResponseWriter, r *http.
5151

5252
if r.Method == "GET" {
5353
queryParams := r.URL.Query()
54-
paramMap := make(map[string]string)
54+
paramMap := make(map[string]interface{})
5555
for key, values := range queryParams {
5656
if len(values) > 0 {
57-
paramMap[key] = values[0]
57+
normalizedKey := strings.TrimSuffix(key, "[]")
58+
isArray := strings.HasSuffix(key, "[]")
59+
60+
if len(values) == 1 && strings.Contains(values[0], ",") {
61+
paramMap[normalizedKey] = strings.Split(values[0], ",")
62+
} else if isArray || len(values) > 1 {
63+
paramMap[normalizedKey] = values
64+
} else {
65+
paramMap[normalizedKey] = values[0]
66+
}
5867
}
5968
}
6069
requestData = paramMap

0 commit comments

Comments
 (0)