Fix endpoint last-txs to fit portal explorer requirements (#286)

This commit is contained in:
walker-16 2023-05-03 14:01:55 -03:00 committed by GitHub
parent c0a3ed2ea9
commit fd51f0a819
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
5 changed files with 61 additions and 27 deletions

View File

@ -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": {

View File

@ -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": {

View File

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

View File

@ -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 <sampleRate> 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) {

View File

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