From 9d7484e97b7c4427eddc8c80950457f52ef8e2e1 Mon Sep 17 00:00:00 2001 From: walker-16 Date: Mon, 15 May 2023 16:59:54 -0300 Subject: [PATCH] Add last-tx filter for valid configuration and fix doc (#319) --- api/docs/docs.go | 7 +++-- api/docs/swagger.json | 7 +++-- api/docs/swagger.yaml | 8 ++++-- api/middleware/extract_parameters.go | 28 +++++++++++++++++++ .../wormscan/transactions/controller.go | 10 ++----- 5 files changed, 47 insertions(+), 13 deletions(-) diff --git a/api/docs/docs.go b/api/docs/docs.go index 2619c4c5..7b69abb8 100644 --- a/api/docs/docs.go +++ b/api/docs/docs.go @@ -608,13 +608,13 @@ const docTemplate = `{ "parameters": [ { "type": "string", - "description": "Time Span, default: 1d, supported values: [1d, 1w, 1mo]", + "description": "Time Span, default: 1d, supported values: [1d, 1w, 1mo]. 1mo ​​is 30 days.", "name": "timeSpan", "in": "query" }, { "type": "string", - "description": "Sample Rate, default: 1h, supported values: [1h, 1d]", + "description": "Sample Rate, default: 1h, supported values: [1h, 1d]. Valid configurations with timeSpan: 1d/1h, 1w/1d, 1mo/1d", "name": "sampleRate", "in": "query" } @@ -2426,6 +2426,9 @@ const docTemplate = `{ "total_tx_count": { "description": "Number of VAAs emitted since the creation of the network (does not include Pyth messages)", "type": "string" + }, + "total_volume": { + "type": "string" } } }, diff --git a/api/docs/swagger.json b/api/docs/swagger.json index 43c948b6..4b5b928b 100644 --- a/api/docs/swagger.json +++ b/api/docs/swagger.json @@ -601,13 +601,13 @@ "parameters": [ { "type": "string", - "description": "Time Span, default: 1d, supported values: [1d, 1w, 1mo]", + "description": "Time Span, default: 1d, supported values: [1d, 1w, 1mo]. 1mo ​​is 30 days.", "name": "timeSpan", "in": "query" }, { "type": "string", - "description": "Sample Rate, default: 1h, supported values: [1h, 1d]", + "description": "Sample Rate, default: 1h, supported values: [1h, 1d]. Valid configurations with timeSpan: 1d/1h, 1w/1d, 1mo/1d", "name": "sampleRate", "in": "query" } @@ -2419,6 +2419,9 @@ "total_tx_count": { "description": "Number of VAAs emitted since the creation of the network (does not include Pyth messages)", "type": "string" + }, + "total_volume": { + "type": "string" } } }, diff --git a/api/docs/swagger.yaml b/api/docs/swagger.yaml index 56a41901..d2a67ef5 100644 --- a/api/docs/swagger.yaml +++ b/api/docs/swagger.yaml @@ -514,6 +514,8 @@ definitions: description: Number of VAAs emitted since the creation of the network (does not include Pyth messages) type: string + total_volume: + type: string type: object transactions.TopAssetsResponse: properties: @@ -1058,11 +1060,13 @@ paths: and sample rate. operationId: get-last-transactions parameters: - - description: 'Time Span, default: 1d, supported values: [1d, 1w, 1mo]' + - description: 'Time Span, default: 1d, supported values: [1d, 1w, 1mo]. 1mo + ​​is 30 days.' in: query name: timeSpan type: string - - description: 'Sample Rate, default: 1h, supported values: [1h, 1d]' + - description: 'Sample Rate, default: 1h, supported values: [1h, 1d]. Valid + configurations with timeSpan: 1d/1h, 1w/1d, 1mo/1d' in: query name: sampleRate type: string diff --git a/api/middleware/extract_parameters.go b/api/middleware/extract_parameters.go index 98d92035..6db64993 100644 --- a/api/middleware/extract_parameters.go +++ b/api/middleware/extract_parameters.go @@ -263,6 +263,34 @@ func isValidSampleRate(sampleRate string) bool { return regexp.MustCompile(`^1h$|^1d$`).MatchString(sampleRate) } +func ExtractTimeSpanAndSampleRate(c *fiber.Ctx, l *zap.Logger) (string, string, error) { + timeSpan, err := ExtractTimeSpan(c, l) + if err != nil { + return "", "", err + } + sampleRate, err := ExtractSampleRate(c, l) + if err != nil { + return "", "", err + } + + switch timeSpan { + case "1d": + if sampleRate != "1h" { + return "", "", response.NewInvalidQueryParamError(c, "INVALID CONFIGURATION , QUERY PARAMETERS.", nil) + } + case "1w": + if sampleRate != "1d" { + return "", "", response.NewInvalidQueryParamError(c, "INVALID CONFIGURATION , QUERY PARAMETERS", nil) + } + case "1mo": + if sampleRate != "1d" { + return "", "", response.NewInvalidQueryParamError(c, "INVALID CONFIGURATION , QUERY PARAMETERS", nil) + } + } + + return timeSpan, sampleRate, nil +} + func ExtractTime(c *fiber.Ctx, queryParam string) (*time.Time, error) { // get the start_time from query params date := c.Query(queryParam, "") diff --git a/api/routes/wormscan/transactions/controller.go b/api/routes/wormscan/transactions/controller.go index 71d5beb1..725d5cda 100644 --- a/api/routes/wormscan/transactions/controller.go +++ b/api/routes/wormscan/transactions/controller.go @@ -29,18 +29,14 @@ func NewController(transactionsService *transactions.Service, logger *zap.Logger // @Description Returns the number of transactions [vaa] by a defined time span and sample rate. // @Tags Wormscan // @ID get-last-transactions -// @Param timeSpan query string false "Time Span, default: 1d, supported values: [1d, 1w, 1mo]" -// @Param sampleRate query string false "Sample Rate, default: 1h, supported values: [1h, 1d]" +// @Param timeSpan query string false "Time Span, default: 1d, supported values: [1d, 1w, 1mo]. 1mo ​​is 30 days." +// @Param sampleRate query string false "Sample Rate, default: 1h, supported values: [1h, 1d]. Valid configurations with timeSpan: 1d/1h, 1w/1d, 1mo/1d" // @Success 200 {object} []transactions.TransactionCountResult // @Failure 400 // @Failure 500 // @Router /api/v1/last-txs [get] func (c *Controller) GetLastTransactions(ctx *fiber.Ctx) error { - timeSpan, err := middleware.ExtractTimeSpan(ctx, c.logger) - if err != nil { - return err - } - sampleRate, err := middleware.ExtractSampleRate(ctx, c.logger) + timeSpan, sampleRate, err := middleware.ExtractTimeSpanAndSampleRate(ctx, c.logger) if err != nil { return err }