From b4d7e3284e0881a9241d57ad0285a99729e398cf Mon Sep 17 00:00:00 2001 From: Mariano <9205080+marianososto@users.noreply.github.com> Date: Thu, 25 Apr 2024 17:46:09 -0300 Subject: [PATCH 1/4] refactor to accept multiple sourceChains,targetChains and appIds --- api/handlers/operations/repository.go | 61 ++++++++++++-------- api/handlers/operations/service.go | 12 ++-- api/middleware/extract_parameters.go | 59 +++++++++++++++++++ api/routes/wormscan/operations/controller.go | 13 +++-- 4 files changed, 111 insertions(+), 34 deletions(-) diff --git a/api/handlers/operations/repository.go b/api/handlers/operations/repository.go index 0a87c419..5c4f4498 100644 --- a/api/handlers/operations/repository.go +++ b/api/handlers/operations/repository.go @@ -111,51 +111,66 @@ type OperationQuery struct { Pagination pagination.Pagination TxHash string Address string - SourceChainID *vaa.ChainID - TargetChainID *vaa.ChainID - AppID string + SourceChainIDs []vaa.ChainID + TargetChainIDs []vaa.ChainID + AppID []string ExclusiveAppId bool } -func buildQueryOperationsByChain(sourceChainID, targetChainID *vaa.ChainID) bson.D { +func buildQueryOperationsByChain(sourceChainIDs, targetChainIDs []vaa.ChainID) bson.D { var allMatch bson.A - if sourceChainID != nil { - matchSourceChain := bson.M{"rawStandardizedProperties.fromChain": *sourceChainID} + if len(sourceChainIDs) > 0 { + matchSourceChain := bson.M{"rawStandardizedProperties.fromChain": bson.M{"$in": sourceChainIDs}} allMatch = append(allMatch, matchSourceChain) } - if targetChainID != nil { - matchTargetChain := bson.M{"rawStandardizedProperties.toChain": *targetChainID} + if len(targetChainIDs) > 0 { + matchTargetChain := bson.M{"rawStandardizedProperties.toChain": bson.M{"$in": targetChainIDs}} allMatch = append(allMatch, matchTargetChain) } - if (sourceChainID != nil && targetChainID != nil) && (*sourceChainID == *targetChainID) { + if (len(sourceChainIDs) == 1 && len(targetChainIDs) == 1) && (sourceChainIDs[0] == targetChainIDs[0]) { return bson.D{{Key: "$match", Value: bson.M{"$or": allMatch}}} } return bson.D{{Key: "$match", Value: bson.M{"$and": allMatch}}} } -func buildQueryOperationsByAppID(appID string, exclusive bool) []bson.D { +func buildQueryOperationsByAppID(appIDs []string, exclusive bool) []bson.D { var result []bson.D - if appID == "" { - result = append(result, bson.D{{Key: "$match", Value: bson.M{}}}) - return result - } + /* + if appID == "" { + result = append(result, bson.D{{Key: "$match", Value: bson.M{}}}) + return result + } + */ if exclusive { - result = append(result, bson.D{{Key: "$match", Value: bson.M{ - "$and": bson.A{ - bson.M{"rawStandardizedProperties.appIds": bson.M{"$eq": []string{appID}}}, - bson.M{"rawStandardizedProperties.appIds": bson.M{"$size": 1}}, - }}}}) - return result + if len(appIDs) == 1 { + result = append(result, bson.D{{Key: "$match", Value: bson.M{ + "$and": bson.A{ + bson.M{"rawStandardizedProperties.appIds": bson.M{"$eq": appIDs}}, + bson.M{"rawStandardizedProperties.appIds": bson.M{"$size": 1}}, + }}}}) + } else { + a := bson.A{} + for _, appID := range appIDs { + cond := bson.M{ + "$and": bson.A{ + bson.M{"rawStandardizedProperties.appIds": bson.M{"$eq": appID}}, + bson.M{"rawStandardizedProperties.appIds": bson.M{"$size": 1}}, + }} + a = append(a, cond) + } + result = append(result, bson.D{{Key: "$match", Value: bson.M{ + "$or": a}}}) + } } else { - result = append(result, bson.D{{Key: "$match", Value: bson.M{"rawStandardizedProperties.appIds": bson.M{"$in": []string{appID}}}}}) + result = append(result, bson.D{{Key: "$match", Value: bson.M{"rawStandardizedProperties.appIds": bson.M{"$in": appIDs}}}}) } return result } @@ -238,8 +253,8 @@ func (r *Repository) FindByChainAndAppId(ctx context.Context, query OperationQue var pipeline mongo.Pipeline - if query.SourceChainID != nil || query.TargetChainID != nil { - matchBySourceTargetChain := buildQueryOperationsByChain(query.SourceChainID, query.TargetChainID) + if len(query.SourceChainIDs) != 0 || len(query.TargetChainIDs) != 0 { + matchBySourceTargetChain := buildQueryOperationsByChain(query.SourceChainIDs, query.TargetChainIDs) pipeline = append(pipeline, matchBySourceTargetChain) } diff --git a/api/handlers/operations/service.go b/api/handlers/operations/service.go index 340a2efa..77f49b8d 100644 --- a/api/handlers/operations/service.go +++ b/api/handlers/operations/service.go @@ -34,9 +34,9 @@ func (s *Service) FindById(ctx context.Context, chainID vaa.ChainID, type OperationFilter struct { TxHash *types.TxHash Address string - SourceChainID *vaa.ChainID - TargetChainID *vaa.ChainID - AppID string + SourceChainIDs []vaa.ChainID + TargetChainIDs []vaa.ChainID + AppID []string ExclusiveAppId bool Pagination pagination.Pagination } @@ -52,13 +52,13 @@ func (s *Service) FindAll(ctx context.Context, filter OperationFilter) ([]*Opera TxHash: txHash, Address: filter.Address, Pagination: filter.Pagination, - SourceChainID: filter.SourceChainID, - TargetChainID: filter.TargetChainID, + SourceChainIDs: filter.SourceChainIDs, + TargetChainIDs: filter.TargetChainIDs, AppID: filter.AppID, ExclusiveAppId: filter.ExclusiveAppId, } - if operationQuery.AppID != "" || operationQuery.SourceChainID != nil || operationQuery.TargetChainID != nil { + if len(operationQuery.AppID) != 0 || len(operationQuery.SourceChainIDs) > 0 || len(operationQuery.TargetChainIDs) > 0 { return s.repo.FindByChainAndAppId(ctx, operationQuery) } diff --git a/api/middleware/extract_parameters.go b/api/middleware/extract_parameters.go index 0ba910a1..45ff7231 100644 --- a/api/middleware/extract_parameters.go +++ b/api/middleware/extract_parameters.go @@ -61,14 +61,73 @@ func ExtractToChain(c *fiber.Ctx, l *zap.Logger) (*sdk.ChainID, error) { return &result, nil } +func ExtractChain(c *fiber.Ctx, l *zap.Logger) (*sdk.ChainID, error) { + return extractChainQueryParam(c, l, "chain") +} + +/* func ExtractSourceChain(c *fiber.Ctx, l *zap.Logger) (*sdk.ChainID, error) { return extractChainQueryParam(c, l, "sourceChain") } + + func ExtractTargetChain(c *fiber.Ctx, l *zap.Logger) (*sdk.ChainID, error) { return extractChainQueryParam(c, l, "targetChain") } +*/ + +func ExtractSourceChain(c *fiber.Ctx, l *zap.Logger) ([]sdk.ChainID, error) { + param := c.Query("sourceChain") + if param == "" { + return nil, nil + } + result := make([]sdk.ChainID, 0, len(param)) + for _, val := range strings.Split(param, ",") { + chain, err := parseChainIDParam(val) + if err != nil { + requestID := fmt.Sprintf("%v", c.Locals("requestid")) + l.Error("failed to parse sourceChain parameter", + zap.Error(err), + zap.String("requestID", requestID), + ) + return nil, response.NewInvalidParamError(c, "INVALID SOURCE_CHAIN VALUE", errors.WithStack(err)) + } + result = append(result, chain) + } + return result, nil +} + +func ExtractTargetChain(c *fiber.Ctx, l *zap.Logger) ([]sdk.ChainID, error) { + param := c.Query("targetChain") + if param == "" { + return nil, nil + } + result := make([]sdk.ChainID, 0, len(param)) + for _, val := range strings.Split(param, ",") { + chain, err := parseChainIDParam(val) + if err != nil { + requestID := fmt.Sprintf("%v", c.Locals("requestid")) + l.Error("failed to parse targetChain parameter", + zap.Error(err), + zap.String("requestID", requestID), + ) + return nil, response.NewInvalidParamError(c, "INVALID TARGET_CHAIN VALUE", errors.WithStack(err)) + } + result = append(result, chain) + } + return result, nil +} + +func parseChainIDParam(param string) (sdk.ChainID, error) { + chain, err := strconv.ParseInt(param, 10, 16) + if err != nil { + return sdk.ChainIDUnset, err + } + return sdk.ChainID(chain), nil +} + func extractChainQueryParam(c *fiber.Ctx, l *zap.Logger, queryParam string) (*sdk.ChainID, error) { param := c.Query(queryParam) if param == "" { diff --git a/api/routes/wormscan/operations/controller.go b/api/routes/wormscan/operations/controller.go index af2a8d41..7062c48e 100644 --- a/api/routes/wormscan/operations/controller.go +++ b/api/routes/wormscan/operations/controller.go @@ -2,6 +2,7 @@ package operations import ( "strconv" + "strings" "github.com/gofiber/fiber/v2" "github.com/wormhole-foundation/wormhole-explorer/api/handlers/operations" @@ -75,14 +76,16 @@ func (c *Controller) FindAll(ctx *fiber.Ctx) error { return err } - appID := middleware.ExtractAppId(ctx, c.logger) + //appID := middleware.ExtractAppId(ctx, c.logger) + appID := strings.Split(ctx.Query("appId"), ",") + exclusiveAppId, err := middleware.ExtractExclusiveAppId(ctx) if err != nil { return err } - searchBySourceTargetChain := sourceChain != nil || targetChain != nil - searchByAppId := appID != "" + searchBySourceTargetChain := len(sourceChain) != 0 || targetChain != nil + searchByAppId := len(appID) != 0 if (searchByAddress || searchByTxHash) && (searchBySourceTargetChain || searchByAppId) { return response.NewInvalidParamError(ctx, "address/txHash cannot be combined with sourceChain/targetChain/appId query filter", nil) @@ -91,8 +94,8 @@ func (c *Controller) FindAll(ctx *fiber.Ctx) error { filter := operations.OperationFilter{ TxHash: txHash, Address: address, - SourceChainID: sourceChain, - TargetChainID: targetChain, + SourceChainIDs: sourceChain, + TargetChainIDs: targetChain, AppID: appID, ExclusiveAppId: exclusiveAppId, Pagination: *pagination, From 92b432a9064dd4c16e23aa98d90de269d42eb824 Mon Sep 17 00:00:00 2001 From: Mariano <9205080+marianososto@users.noreply.github.com> Date: Fri, 26 Apr 2024 15:00:09 -0300 Subject: [PATCH 2/4] support multiple appIds --- api/handlers/operations/repository.go | 54 ++++++-------------- api/handlers/operations/service.go | 6 +-- api/routes/wormscan/operations/controller.go | 16 +++--- 3 files changed, 28 insertions(+), 48 deletions(-) diff --git a/api/handlers/operations/repository.go b/api/handlers/operations/repository.go index 5c4f4498..28c24970 100644 --- a/api/handlers/operations/repository.go +++ b/api/handlers/operations/repository.go @@ -113,7 +113,7 @@ type OperationQuery struct { Address string SourceChainIDs []vaa.ChainID TargetChainIDs []vaa.ChainID - AppID []string + AppIDs []string ExclusiveAppId bool } @@ -138,41 +138,19 @@ func buildQueryOperationsByChain(sourceChainIDs, targetChainIDs []vaa.ChainID) b return bson.D{{Key: "$match", Value: bson.M{"$and": allMatch}}} } -func buildQueryOperationsByAppID(appIDs []string, exclusive bool) []bson.D { - var result []bson.D - - /* - if appID == "" { - result = append(result, bson.D{{Key: "$match", Value: bson.M{}}}) - return result - } - */ - - if exclusive { - if len(appIDs) == 1 { - result = append(result, bson.D{{Key: "$match", Value: bson.M{ - "$and": bson.A{ - bson.M{"rawStandardizedProperties.appIds": bson.M{"$eq": appIDs}}, - bson.M{"rawStandardizedProperties.appIds": bson.M{"$size": 1}}, - }}}}) - } else { - a := bson.A{} - for _, appID := range appIDs { - cond := bson.M{ - "$and": bson.A{ - bson.M{"rawStandardizedProperties.appIds": bson.M{"$eq": appID}}, - bson.M{"rawStandardizedProperties.appIds": bson.M{"$size": 1}}, - }} - a = append(a, cond) - } - result = append(result, bson.D{{Key: "$match", Value: bson.M{ - "$or": a}}}) - } - - } else { - result = append(result, bson.D{{Key: "$match", Value: bson.M{"rawStandardizedProperties.appIds": bson.M{"$in": appIDs}}}}) +func buildQueryOperationsByAppID(appIDs []string, exclusive bool) bson.D { + if !exclusive { + return bson.D{{Key: "$match", Value: bson.M{"rawStandardizedProperties.appIds": bson.M{"$in": appIDs}}}} } - return result + matchAppID := bson.A{} + for _, appID := range appIDs { + cond := bson.M{"$and": bson.A{ + bson.M{"rawStandardizedProperties.appIds": bson.M{"$eq": appID}}, + bson.M{"rawStandardizedProperties.appIds": bson.M{"$size": 1}}, + }} + matchAppID = append(matchAppID, cond) + } + return bson.D{{Key: "$match", Value: bson.M{"$or": matchAppID}}} } // findOperationsIdByAddress returns all operations filtered by address. @@ -258,9 +236,9 @@ func (r *Repository) FindByChainAndAppId(ctx context.Context, query OperationQue pipeline = append(pipeline, matchBySourceTargetChain) } - if len(query.AppID) > 0 { - matchByAppId := buildQueryOperationsByAppID(query.AppID, query.ExclusiveAppId) - pipeline = append(pipeline, matchByAppId...) + if len(query.AppIDs) > 0 { + matchByAppId := buildQueryOperationsByAppID(query.AppIDs, query.ExclusiveAppId) + pipeline = append(pipeline, matchByAppId) } pipeline = append(pipeline, bson.D{{Key: "$sort", Value: bson.D{ diff --git a/api/handlers/operations/service.go b/api/handlers/operations/service.go index 77f49b8d..28f811a7 100644 --- a/api/handlers/operations/service.go +++ b/api/handlers/operations/service.go @@ -36,7 +36,7 @@ type OperationFilter struct { Address string SourceChainIDs []vaa.ChainID TargetChainIDs []vaa.ChainID - AppID []string + AppIDs []string ExclusiveAppId bool Pagination pagination.Pagination } @@ -54,11 +54,11 @@ func (s *Service) FindAll(ctx context.Context, filter OperationFilter) ([]*Opera Pagination: filter.Pagination, SourceChainIDs: filter.SourceChainIDs, TargetChainIDs: filter.TargetChainIDs, - AppID: filter.AppID, + AppIDs: filter.AppIDs, ExclusiveAppId: filter.ExclusiveAppId, } - if len(operationQuery.AppID) != 0 || len(operationQuery.SourceChainIDs) > 0 || len(operationQuery.TargetChainIDs) > 0 { + if len(operationQuery.AppIDs) != 0 || len(operationQuery.SourceChainIDs) > 0 || len(operationQuery.TargetChainIDs) > 0 { return s.repo.FindByChainAndAppId(ctx, operationQuery) } diff --git a/api/routes/wormscan/operations/controller.go b/api/routes/wormscan/operations/controller.go index 7062c48e..dd52bcee 100644 --- a/api/routes/wormscan/operations/controller.go +++ b/api/routes/wormscan/operations/controller.go @@ -1,14 +1,13 @@ package operations import ( - "strconv" - "strings" - "github.com/gofiber/fiber/v2" "github.com/wormhole-foundation/wormhole-explorer/api/handlers/operations" "github.com/wormhole-foundation/wormhole-explorer/api/middleware" "github.com/wormhole-foundation/wormhole-explorer/api/response" "go.uber.org/zap" + "strconv" + "strings" ) // Controller is the controller for the operation resource. @@ -76,8 +75,11 @@ func (c *Controller) FindAll(ctx *fiber.Ctx) error { return err } - //appID := middleware.ExtractAppId(ctx, c.logger) - appID := strings.Split(ctx.Query("appId"), ",") + var appIDs []string + appIDQueryParam := ctx.Query("appId") + if appIDQueryParam != "" { + appIDs = strings.Split(appIDQueryParam, ",") + } exclusiveAppId, err := middleware.ExtractExclusiveAppId(ctx) if err != nil { @@ -85,7 +87,7 @@ func (c *Controller) FindAll(ctx *fiber.Ctx) error { } searchBySourceTargetChain := len(sourceChain) != 0 || targetChain != nil - searchByAppId := len(appID) != 0 + searchByAppId := len(appIDs) != 0 if (searchByAddress || searchByTxHash) && (searchBySourceTargetChain || searchByAppId) { return response.NewInvalidParamError(ctx, "address/txHash cannot be combined with sourceChain/targetChain/appId query filter", nil) @@ -96,7 +98,7 @@ func (c *Controller) FindAll(ctx *fiber.Ctx) error { Address: address, SourceChainIDs: sourceChain, TargetChainIDs: targetChain, - AppID: appID, + AppIDs: appIDs, ExclusiveAppId: exclusiveAppId, Pagination: *pagination, } From 4051ad491f7aa886179ed6688a4b6896d50886c0 Mon Sep 17 00:00:00 2001 From: Mariano <9205080+marianososto@users.noreply.github.com> Date: Fri, 26 Apr 2024 16:43:20 -0300 Subject: [PATCH 3/4] adjust x-chain-activity/tops to also support multiple sourceChains and targetChains --- api/handlers/transactions/model.go | 12 ++++++------ api/handlers/transactions/repository.go | 18 ++++++++++++++---- 2 files changed, 20 insertions(+), 10 deletions(-) diff --git a/api/handlers/transactions/model.go b/api/handlers/transactions/model.go index adc3beee..8f1083b1 100644 --- a/api/handlers/transactions/model.go +++ b/api/handlers/transactions/model.go @@ -215,12 +215,12 @@ type TransactionDto struct { } type ChainActivityTopsQuery struct { - SourceChain *sdk.ChainID `json:"source_chain"` - TargetChain *sdk.ChainID `json:"target_chain"` - AppId string `json:"app_id"` - From time.Time `json:"from"` - To time.Time `json:"to"` - Timespan Timespan `json:"timespan"` + SourceChain []sdk.ChainID `json:"source_chain"` + TargetChain []sdk.ChainID `json:"target_chain"` + AppId string `json:"app_id"` + From time.Time `json:"from"` + To time.Time `json:"to"` + Timespan Timespan `json:"timespan"` } type Timespan string diff --git a/api/handlers/transactions/repository.go b/api/handlers/transactions/repository.go index fffb7201..74fa2afd 100644 --- a/api/handlers/transactions/repository.go +++ b/api/handlers/transactions/repository.go @@ -1095,13 +1095,23 @@ func (r *Repository) buildChainActivityQueryTops(q ChainActivityTopsQuery) strin } filterTargetChain := "" - if q.TargetChain != nil { - filterTargetChain = "|> filter(fn: (r) => r.destination_chain == \"" + strconv.Itoa(int(*q.TargetChain)) + "\")" + if len(q.TargetChain) > 0 { + val := fmt.Sprintf("r.destination_chain == \"%d\"", q.TargetChain[0]) + buff := "" + for _, tc := range q.TargetChain[1:] { + buff += fmt.Sprintf("or r.destination_chain == \"%d\" ", tc) + } + filterTargetChain = fmt.Sprintf("|> filter(fn: (r) => %s %s)", val, buff) } filterSourceChain := "" - if q.SourceChain != nil { - filterSourceChain = "|> filter(fn: (r) => r.emitter_chain == \"" + strconv.Itoa(int(*q.SourceChain)) + "\")" + if len(q.SourceChain) > 0 { + val := fmt.Sprintf("r.emitter_chain == \"%d\"", q.SourceChain[0]) + buff := "" + for _, tc := range q.SourceChain[1:] { + buff += fmt.Sprintf("or r.emitter_chain == \"%d\" ", tc) + } + filterSourceChain = fmt.Sprintf("|> filter(fn: (r) => %s %s)", val, buff) } filterAppId := "" From 7c85ebf0165becdf10b16b6d1fdc068f5edf8d41 Mon Sep 17 00:00:00 2001 From: Mariano <9205080+marianososto@users.noreply.github.com> Date: Fri, 26 Apr 2024 17:13:38 -0300 Subject: [PATCH 4/4] readapt to multiple sourceChains and targetChains --- api/docs/docs.go | 8 ++++---- api/handlers/operations/repository.go | 2 +- api/handlers/transactions/model.go | 12 ++++++------ api/handlers/transactions/repository.go | 14 +++++++------- api/middleware/extract_parameters.go | 17 ----------------- api/routes/wormscan/transactions/controller.go | 16 ++++++++-------- 6 files changed, 26 insertions(+), 43 deletions(-) diff --git a/api/docs/docs.go b/api/docs/docs.go index d8c0ff52..bdb85963 100644 --- a/api/docs/docs.go +++ b/api/docs/docs.go @@ -2741,17 +2741,17 @@ const docTemplate = `{ "type": "string" }, "sourceChain": { - "$ref": "#/definitions/operations.SourceChain" + "$ref": "#/definitions/operations.SourceChains" }, "targetChain": { - "$ref": "#/definitions/operations.TargetChain" + "$ref": "#/definitions/operations.TargetChains" }, "vaa": { "$ref": "#/definitions/operations.Vaa" } } }, - "operations.SourceChain": { + "operations.SourceChains": { "type": "object", "properties": { "attribute": { @@ -2815,7 +2815,7 @@ const docTemplate = `{ } } }, - "operations.TargetChain": { + "operations.TargetChains": { "type": "object", "properties": { "chainId": { diff --git a/api/handlers/operations/repository.go b/api/handlers/operations/repository.go index 28c24970..c68495a6 100644 --- a/api/handlers/operations/repository.go +++ b/api/handlers/operations/repository.go @@ -231,7 +231,7 @@ func (r *Repository) FindByChainAndAppId(ctx context.Context, query OperationQue var pipeline mongo.Pipeline - if len(query.SourceChainIDs) != 0 || len(query.TargetChainIDs) != 0 { + if len(query.SourceChainIDs) > 0 || len(query.TargetChainIDs) > 0 { matchBySourceTargetChain := buildQueryOperationsByChain(query.SourceChainIDs, query.TargetChainIDs) pipeline = append(pipeline, matchBySourceTargetChain) } diff --git a/api/handlers/transactions/model.go b/api/handlers/transactions/model.go index 8f1083b1..620e2102 100644 --- a/api/handlers/transactions/model.go +++ b/api/handlers/transactions/model.go @@ -215,12 +215,12 @@ type TransactionDto struct { } type ChainActivityTopsQuery struct { - SourceChain []sdk.ChainID `json:"source_chain"` - TargetChain []sdk.ChainID `json:"target_chain"` - AppId string `json:"app_id"` - From time.Time `json:"from"` - To time.Time `json:"to"` - Timespan Timespan `json:"timespan"` + SourceChains []sdk.ChainID `json:"source_chain"` + TargetChains []sdk.ChainID `json:"target_chain"` + AppId string `json:"app_id"` + From time.Time `json:"from"` + To time.Time `json:"to"` + Timespan Timespan `json:"timespan"` } type Timespan string diff --git a/api/handlers/transactions/repository.go b/api/handlers/transactions/repository.go index 74fa2afd..7e01ad69 100644 --- a/api/handlers/transactions/repository.go +++ b/api/handlers/transactions/repository.go @@ -1095,20 +1095,20 @@ func (r *Repository) buildChainActivityQueryTops(q ChainActivityTopsQuery) strin } filterTargetChain := "" - if len(q.TargetChain) > 0 { - val := fmt.Sprintf("r.destination_chain == \"%d\"", q.TargetChain[0]) + if len(q.TargetChains) > 0 { + val := fmt.Sprintf("r.destination_chain == \"%d\"", q.TargetChains[0]) buff := "" - for _, tc := range q.TargetChain[1:] { + for _, tc := range q.TargetChains[1:] { buff += fmt.Sprintf("or r.destination_chain == \"%d\" ", tc) } filterTargetChain = fmt.Sprintf("|> filter(fn: (r) => %s %s)", val, buff) } filterSourceChain := "" - if len(q.SourceChain) > 0 { - val := fmt.Sprintf("r.emitter_chain == \"%d\"", q.SourceChain[0]) + if len(q.SourceChains) > 0 { + val := fmt.Sprintf("r.emitter_chain == \"%d\"", q.SourceChains[0]) buff := "" - for _, tc := range q.SourceChain[1:] { + for _, tc := range q.SourceChains[1:] { buff += fmt.Sprintf("or r.emitter_chain == \"%d\" ", tc) } filterSourceChain = fmt.Sprintf("|> filter(fn: (r) => %s %s)", val, buff) @@ -1119,7 +1119,7 @@ func (r *Repository) buildChainActivityQueryTops(q ChainActivityTopsQuery) strin filterAppId = "|> filter(fn: (r) => r.app_id == \"" + q.AppId + "\")" } - if q.TargetChain == nil && q.AppId == "" { + if len(q.TargetChains) == 0 && q.AppId == "" { return r.buildQueryChainActivityTopsByEmitter(q, start, stop, filterSourceChain) } diff --git a/api/middleware/extract_parameters.go b/api/middleware/extract_parameters.go index 45ff7231..c95edb20 100644 --- a/api/middleware/extract_parameters.go +++ b/api/middleware/extract_parameters.go @@ -61,23 +61,6 @@ func ExtractToChain(c *fiber.Ctx, l *zap.Logger) (*sdk.ChainID, error) { return &result, nil } -func ExtractChain(c *fiber.Ctx, l *zap.Logger) (*sdk.ChainID, error) { - return extractChainQueryParam(c, l, "chain") -} - -/* -func ExtractSourceChain(c *fiber.Ctx, l *zap.Logger) (*sdk.ChainID, error) { - return extractChainQueryParam(c, l, "sourceChain") -} - - - -func ExtractTargetChain(c *fiber.Ctx, l *zap.Logger) (*sdk.ChainID, error) { - return extractChainQueryParam(c, l, "targetChain") -} - -*/ - func ExtractSourceChain(c *fiber.Ctx, l *zap.Logger) ([]sdk.ChainID, error) { param := c.Query("sourceChain") if param == "" { diff --git a/api/routes/wormscan/transactions/controller.go b/api/routes/wormscan/transactions/controller.go index 22b7a51f..f9763313 100644 --- a/api/routes/wormscan/transactions/controller.go +++ b/api/routes/wormscan/transactions/controller.go @@ -200,11 +200,11 @@ func (c *Controller) GetTopAssets(ctx *fiber.Ctx) error { // @Router /api/v1/x-chain-activity/tops [get] func (c *Controller) GetChainActivityTops(ctx *fiber.Ctx) error { - sourceChain, err := middleware.ExtractSourceChain(ctx, c.logger) + sourceChains, err := middleware.ExtractSourceChain(ctx, c.logger) if err != nil { return err } - targetChain, err := middleware.ExtractTargetChain(ctx, c.logger) + targetChains, err := middleware.ExtractTargetChain(ctx, c.logger) if err != nil { return err } @@ -221,12 +221,12 @@ func (c *Controller) GetChainActivityTops(ctx *fiber.Ctx) error { } payload := transactions.ChainActivityTopsQuery{ - SourceChain: sourceChain, - TargetChain: targetChain, - From: *from, - To: *to, - AppId: middleware.ExtractAppId(ctx, c.logger), - Timespan: transactions.Timespan(ctx.Query("timespan")), + SourceChains: sourceChains, + TargetChains: targetChains, + From: *from, + To: *to, + AppId: middleware.ExtractAppId(ctx, c.logger), + Timespan: transactions.Timespan(ctx.Query("timespan")), } if !payload.Timespan.IsValid() {