From fd51f0a819df7bad7e70bfa12d777a9ca1497294 Mon Sep 17 00:00:00 2001 From: walker-16 Date: Wed, 3 May 2023 14:01:55 -0300 Subject: [PATCH] Fix endpoint last-txs to fit portal explorer requirements (#286) --- api/docs/docs.go | 24 +++++++++++++++---- api/docs/swagger.json | 24 +++++++++++++++---- api/docs/swagger.yaml | 19 +++++++++++---- api/middleware/extract_parameters.go | 17 +++++-------- .../wormscan/transactions/controller.go | 4 ++-- 5 files changed, 61 insertions(+), 27 deletions(-) diff --git a/api/docs/docs.go b/api/docs/docs.go index 0f877d8c..59ac6328 100644 --- a/api/docs/docs.go +++ b/api/docs/docs.go @@ -608,13 +608,13 @@ const docTemplate = `{ "parameters": [ { "type": "string", - "description": "Time Span, default: 1h, examples: 30m, 1h, 1d, 2w, 3mo, 1y, all.", + "description": "Time Span, default: 1d, supported values: [1d, 1w, 1mo]", "name": "timeSpan", "in": "query" }, { "type": "string", - "description": "Sample Rate, default: 1m, examples: 30s, 1m, 1h, 1d, 2w, 3mo, 1y.", + "description": "Sample Rate, default: 1h, supported values: [1h, 1d]", "name": "sampleRate", "in": "query" } @@ -2327,7 +2327,17 @@ const docTemplate = `{ } }, "transactions.ScorecardsResponse": { - "type": "object" + "type": "object", + "properties": { + "24h_tx_count": { + "description": "Number of VAAs emitted in the last 24 hours (does not include Pyth messages).", + "type": "string" + }, + "total_tx_count": { + "description": "Number of VAAs emitted since the creation of the network (does not include Pyth messages)", + "type": "string" + } + } }, "transactions.TransactionCountResult": { "type": "object", @@ -2391,7 +2401,9 @@ const docTemplate = `{ 28, 29, 30, - 3104 + 32, + 3104, + 10002 ], "x-enum-varnames": [ "ChainIDUnset", @@ -2422,7 +2434,9 @@ const docTemplate = `{ "ChainIDXpla", "ChainIDBtc", "ChainIDBase", - "ChainIDWormchain" + "ChainIDSei", + "ChainIDWormchain", + "ChainIDSepolia" ] }, "vaa.VaaDoc": { diff --git a/api/docs/swagger.json b/api/docs/swagger.json index 809a9c3e..42b97127 100644 --- a/api/docs/swagger.json +++ b/api/docs/swagger.json @@ -601,13 +601,13 @@ "parameters": [ { "type": "string", - "description": "Time Span, default: 1h, examples: 30m, 1h, 1d, 2w, 3mo, 1y, all.", + "description": "Time Span, default: 1d, supported values: [1d, 1w, 1mo]", "name": "timeSpan", "in": "query" }, { "type": "string", - "description": "Sample Rate, default: 1m, examples: 30s, 1m, 1h, 1d, 2w, 3mo, 1y.", + "description": "Sample Rate, default: 1h, supported values: [1h, 1d]", "name": "sampleRate", "in": "query" } @@ -2320,7 +2320,17 @@ } }, "transactions.ScorecardsResponse": { - "type": "object" + "type": "object", + "properties": { + "24h_tx_count": { + "description": "Number of VAAs emitted in the last 24 hours (does not include Pyth messages).", + "type": "string" + }, + "total_tx_count": { + "description": "Number of VAAs emitted since the creation of the network (does not include Pyth messages)", + "type": "string" + } + } }, "transactions.TransactionCountResult": { "type": "object", @@ -2384,7 +2394,9 @@ 28, 29, 30, - 3104 + 32, + 3104, + 10002 ], "x-enum-varnames": [ "ChainIDUnset", @@ -2415,7 +2427,9 @@ "ChainIDXpla", "ChainIDBtc", "ChainIDBase", - "ChainIDWormchain" + "ChainIDSei", + "ChainIDWormchain", + "ChainIDSepolia" ] }, "vaa.VaaDoc": { diff --git a/api/docs/swagger.yaml b/api/docs/swagger.yaml index bbf78b91..7d1c5f07 100644 --- a/api/docs/swagger.yaml +++ b/api/docs/swagger.yaml @@ -483,6 +483,15 @@ definitions: type: number type: object transactions.ScorecardsResponse: + properties: + 24h_tx_count: + description: Number of VAAs emitted in the last 24 hours (does not include + Pyth messages). + type: string + total_tx_count: + description: Number of VAAs emitted since the creation of the network (does + not include Pyth messages) + type: string type: object transactions.TransactionCountResult: properties: @@ -534,7 +543,9 @@ definitions: - 28 - 29 - 30 + - 32 - 3104 + - 10002 type: integer x-enum-varnames: - ChainIDUnset @@ -565,7 +576,9 @@ definitions: - ChainIDXpla - ChainIDBtc - ChainIDBase + - ChainIDSei - ChainIDWormchain + - ChainIDSepolia vaa.VaaDoc: properties: appId: @@ -1009,13 +1022,11 @@ paths: and sample rate. operationId: get-last-transactions parameters: - - description: 'Time Span, default: 1h, examples: 30m, 1h, 1d, 2w, 3mo, 1y, - all.' + - description: 'Time Span, default: 1d, supported values: [1d, 1w, 1mo]' in: query name: timeSpan type: string - - description: 'Sample Rate, default: 1m, examples: 30s, 1m, 1h, 1d, 2w, 3mo, - 1y.' + - description: 'Sample Rate, default: 1h, supported values: [1h, 1d]' in: query name: sampleRate type: string diff --git a/api/middleware/extract_parameters.go b/api/middleware/extract_parameters.go index 0c7c186f..f8e50844 100644 --- a/api/middleware/extract_parameters.go +++ b/api/middleware/extract_parameters.go @@ -233,10 +233,7 @@ func ExtractAppId(c *fiber.Ctx, l *zap.Logger) string { func ExtractTimeSpan(c *fiber.Ctx, l *zap.Logger) (string, error) { // get the timeSpan from query params - timeSpanStr := c.Query("timeSpan", "1h") - if timeSpanStr == "all" { - return timeSpanStr, nil - } + timeSpanStr := c.Query("timeSpan", "1d") // validate the timeSpan if !isValidTimeSpan(timeSpanStr) { @@ -245,17 +242,15 @@ func ExtractTimeSpan(c *fiber.Ctx, l *zap.Logger) (string, error) { return timeSpanStr, nil } -// isValidTimeSpan check if the timeSpan is valid +// isValidTimeSpan check that the timeSpan is valid. func isValidTimeSpan(timeSpan string) bool { - return regexp.MustCompile(`^all$|^\d+[mhdwy]$|^\dmo$`).MatchString(timeSpan) + return regexp.MustCompile(`^1d$|^1w$|^1mo$`).MatchString(timeSpan) } func ExtractSampleRate(c *fiber.Ctx, l *zap.Logger) (string, error) { // get the sampleRate from query params - sampleRateStr := c.Query("sampleRate", "1m") - if sampleRateStr == "1y" { - return sampleRateStr, nil - } + sampleRateStr := c.Query("sampleRate", "1h") + // validate the sampleRate if !isValidSampleRate(sampleRateStr) { return "", response.NewInvalidQueryParamError(c, "INVALID QUERY PARAMETER", nil) @@ -264,7 +259,7 @@ func ExtractSampleRate(c *fiber.Ctx, l *zap.Logger) (string, error) { } func isValidSampleRate(sampleRate string) bool { - return regexp.MustCompile(`^\d+[smhdwy]$|^\dmo$`).MatchString(sampleRate) + return regexp.MustCompile(`^1h$|^1d$`).MatchString(sampleRate) } func ExtractTime(c *fiber.Ctx, queryParam string) (*time.Time, error) { diff --git a/api/routes/wormscan/transactions/controller.go b/api/routes/wormscan/transactions/controller.go index 235e668f..538b69ea 100644 --- a/api/routes/wormscan/transactions/controller.go +++ b/api/routes/wormscan/transactions/controller.go @@ -28,8 +28,8 @@ 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: 1h, examples: 30m, 1h, 1d, 2w, 3mo, 1y, all." -// @Param sampleRate query string false "Sample Rate, default: 1m, examples: 30s, 1m, 1h, 1d, 2w, 3mo, 1y." +// @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]" // @Success 200 {object} []transactions.TransactionCountResult // @Failure 400 // @Failure 500