Add last-tx filter for valid configuration and fix doc (#319)

This commit is contained in:
walker-16 2023-05-15 16:59:54 -03:00 committed by GitHub
parent c2b94f6448
commit 9d7484e97b
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
5 changed files with 47 additions and 13 deletions

View File

@ -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"
}
}
},

View File

@ -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"
}
}
},

View File

@ -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

View File

@ -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 <timeSpan>, <sampleRate> QUERY PARAMETERS.", nil)
}
case "1w":
if sampleRate != "1d" {
return "", "", response.NewInvalidQueryParamError(c, "INVALID CONFIGURATION <timeSpan>, <sampleRate> QUERY PARAMETERS", nil)
}
case "1mo":
if sampleRate != "1d" {
return "", "", response.NewInvalidQueryParamError(c, "INVALID CONFIGURATION <timeSpan>, <sampleRate> 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, "")

View File

@ -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
}