diff --git a/cmd/api/docs/docs.go b/cmd/api/docs/docs.go index dc7166b8..549baa8b 100644 --- a/cmd/api/docs/docs.go +++ b/cmd/api/docs/docs.go @@ -1252,6 +1252,7 @@ const docTemplate = `{ { "enum": [ "block", + "block_stats", "tx", "event", "message" @@ -1336,7 +1337,7 @@ const docTemplate = `{ }, "/v1/stats/summary/{table}/{function}": { "get": { - "description": "Returns string value by passed table and function.\n\n### Availiable tables\n* ` + "`" + `block` + "`" + `\n* ` + "`" + `tx` + "`" + `\n* ` + "`" + `message` + "`" + `\n* ` + "`" + `event` + "`" + `\n\n\n### Availiable functions\n* ` + "`" + `sum` + "`" + `\n* ` + "`" + `min` + "`" + `\n* ` + "`" + `max` + "`" + `\n* ` + "`" + `avg` + "`" + `\n* ` + "`" + `count` + "`" + `\n\n\n` + "`" + `Column` + "`" + ` query parameter is required for functions ` + "`" + `sum` + "`" + `, ` + "`" + `min` + "`" + `, ` + "`" + `max` + "`" + ` and ` + "`" + `avg` + "`" + ` and should not pass for ` + "`" + `count` + "`" + `.\n\n\n### Availiable columns and functions for tables:\n\n#### Block\n* ` + "`" + `height` + "`" + ` -- min max\n* ` + "`" + `time` + "`" + ` -- min max\n* ` + "`" + `tx_count` + "`" + ` -- min max sum avg\n* ` + "`" + `events_count` + "`" + ` -- min max sum avg\n* ` + "`" + `blobs_size` + "`" + ` -- min max sum avg\n* ` + "`" + `fee` + "`" + ` -- min max sum avg\n\n#### Tx\n* ` + "`" + `height` + "`" + ` -- min max\n* ` + "`" + `time` + "`" + ` -- min max\n* ` + "`" + `gas_wanted` + "`" + ` -- min max sum avg\n* ` + "`" + `gas_used` + "`" + ` -- min max sum avg\n* ` + "`" + `timeout_height` + "`" + ` -- min max avg\n* ` + "`" + `events_count` + "`" + ` -- min max sum avg\n* ` + "`" + `messages_count` + "`" + ` -- min max sum avg\n* ` + "`" + `fee` + "`" + ` -- min max sum avg\n\n#### Event\n* ` + "`" + `height` + "`" + ` -- min max\n* ` + "`" + `time` + "`" + ` -- min max\n\n#### Message\n* ` + "`" + `height` + "`" + ` -- min max\n* ` + "`" + `time` + "`" + ` -- min max", + "description": "Returns string value by passed table and function.\n\n### Availiable tables\n* ` + "`" + `block` + "`" + `\n* ` + "`" + `block_stats` + "`" + `\n* ` + "`" + `tx` + "`" + `\n* ` + "`" + `message` + "`" + `\n* ` + "`" + `event` + "`" + `\n\n\n### Availiable functions\n* ` + "`" + `sum` + "`" + `\n* ` + "`" + `min` + "`" + `\n* ` + "`" + `max` + "`" + `\n* ` + "`" + `avg` + "`" + `\n* ` + "`" + `count` + "`" + `\n\n\n` + "`" + `Column` + "`" + ` query parameter is required for functions ` + "`" + `sum` + "`" + `, ` + "`" + `min` + "`" + `, ` + "`" + `max` + "`" + ` and ` + "`" + `avg` + "`" + ` and should not pass for ` + "`" + `count` + "`" + `.\n\n\n### Availiable columns and functions for tables:\n\n#### Block\n* ` + "`" + `height` + "`" + ` -- min max\n* ` + "`" + `time` + "`" + ` -- min max\n\n#### Block stats\n* ` + "`" + `height` + "`" + ` -- min max\n* ` + "`" + `time` + "`" + ` -- min max\n* ` + "`" + `tx_count` + "`" + ` -- min max sum avg\n* ` + "`" + `events_count` + "`" + ` -- min max sum avg\n* ` + "`" + `blobs_size` + "`" + ` -- min max sum avg\n* ` + "`" + `block_time` + "`" + ` -- min max sum avg\n* ` + "`" + `supply_chnge` + "`" + ` -- min max sum avg\n* ` + "`" + `inflation_rate` + "`" + ` -- min max avg\n* ` + "`" + `fee` + "`" + ` -- min max sum avg\n\n#### Tx\n* ` + "`" + `height` + "`" + ` -- min max\n* ` + "`" + `time` + "`" + ` -- min max\n* ` + "`" + `gas_wanted` + "`" + ` -- min max sum avg\n* ` + "`" + `gas_used` + "`" + ` -- min max sum avg\n* ` + "`" + `timeout_height` + "`" + ` -- min max avg\n* ` + "`" + `events_count` + "`" + ` -- min max sum avg\n* ` + "`" + `messages_count` + "`" + ` -- min max sum avg\n* ` + "`" + `fee` + "`" + ` -- min max sum avg\n\n#### Event\n* ` + "`" + `height` + "`" + ` -- min max\n* ` + "`" + `time` + "`" + ` -- min max\n\n#### Message\n* ` + "`" + `height` + "`" + ` -- min max\n* ` + "`" + `time` + "`" + ` -- min max", "produces": [ "application/json" ], diff --git a/cmd/api/docs/swagger.json b/cmd/api/docs/swagger.json index cdc2f883..16a308c0 100644 --- a/cmd/api/docs/swagger.json +++ b/cmd/api/docs/swagger.json @@ -1246,6 +1246,7 @@ { "enum": [ "block", + "block_stats", "tx", "event", "message" @@ -1330,7 +1331,7 @@ }, "/v1/stats/summary/{table}/{function}": { "get": { - "description": "Returns string value by passed table and function.\n\n### Availiable tables\n* `block`\n* `tx`\n* `message`\n* `event`\n\n\n### Availiable functions\n* `sum`\n* `min`\n* `max`\n* `avg`\n* `count`\n\n\n`Column` query parameter is required for functions `sum`, `min`, `max` and `avg` and should not pass for `count`.\n\n\n### Availiable columns and functions for tables:\n\n#### Block\n* `height` -- min max\n* `time` -- min max\n* `tx_count` -- min max sum avg\n* `events_count` -- min max sum avg\n* `blobs_size` -- min max sum avg\n* `fee` -- min max sum avg\n\n#### Tx\n* `height` -- min max\n* `time` -- min max\n* `gas_wanted` -- min max sum avg\n* `gas_used` -- min max sum avg\n* `timeout_height` -- min max avg\n* `events_count` -- min max sum avg\n* `messages_count` -- min max sum avg\n* `fee` -- min max sum avg\n\n#### Event\n* `height` -- min max\n* `time` -- min max\n\n#### Message\n* `height` -- min max\n* `time` -- min max", + "description": "Returns string value by passed table and function.\n\n### Availiable tables\n* `block`\n* `block_stats`\n* `tx`\n* `message`\n* `event`\n\n\n### Availiable functions\n* `sum`\n* `min`\n* `max`\n* `avg`\n* `count`\n\n\n`Column` query parameter is required for functions `sum`, `min`, `max` and `avg` and should not pass for `count`.\n\n\n### Availiable columns and functions for tables:\n\n#### Block\n* `height` -- min max\n* `time` -- min max\n\n#### Block stats\n* `height` -- min max\n* `time` -- min max\n* `tx_count` -- min max sum avg\n* `events_count` -- min max sum avg\n* `blobs_size` -- min max sum avg\n* `block_time` -- min max sum avg\n* `supply_chnge` -- min max sum avg\n* `inflation_rate` -- min max avg\n* `fee` -- min max sum avg\n\n#### Tx\n* `height` -- min max\n* `time` -- min max\n* `gas_wanted` -- min max sum avg\n* `gas_used` -- min max sum avg\n* `timeout_height` -- min max avg\n* `events_count` -- min max sum avg\n* `messages_count` -- min max sum avg\n* `fee` -- min max sum avg\n\n#### Event\n* `height` -- min max\n* `time` -- min max\n\n#### Message\n* `height` -- min max\n* `time` -- min max", "produces": [ "application/json" ], diff --git a/cmd/api/docs/swagger.yaml b/cmd/api/docs/swagger.yaml index 9ccc3255..7a2bfc53 100644 --- a/cmd/api/docs/swagger.yaml +++ b/cmd/api/docs/swagger.yaml @@ -1521,6 +1521,7 @@ paths: - description: Table name enum: - block + - block_stats - tx - event - message @@ -1590,6 +1591,7 @@ paths: ### Availiable tables * `block` + * `block_stats` * `tx` * `message` * `event` @@ -1611,9 +1613,16 @@ paths: #### Block * `height` -- min max * `time` -- min max + + #### Block stats + * `height` -- min max + * `time` -- min max * `tx_count` -- min max sum avg * `events_count` -- min max sum avg * `blobs_size` -- min max sum avg + * `block_time` -- min max sum avg + * `supply_chnge` -- min max sum avg + * `inflation_rate` -- min max avg * `fee` -- min max sum avg #### Tx diff --git a/cmd/api/handler/stats.go b/cmd/api/handler/stats.go index 3b3570e9..f9bf7082 100644 --- a/cmd/api/handler/stats.go +++ b/cmd/api/handler/stats.go @@ -76,7 +76,7 @@ func (sh StatsHandler) Summary(c echo.Context) error { } type histogramRequest struct { - Table string `example:"block" param:"table" swaggertype:"string" validate:"required,oneof=block tx event message"` + Table string `example:"block" param:"table" swaggertype:"string" validate:"required,oneof=block block_stats tx event message"` Function string `example:"count" param:"function" swaggertype:"string" validate:"required,oneof=avg sum min max count"` Timeframe string `example:"hour" param:"timeframe" swaggertype:"string" validate:"required,oneof=hour day week month year"` Column string `example:"fee" query:"column" swaggertype:"string" validate:"omitempty"` @@ -90,7 +90,7 @@ type histogramRequest struct { // @Description.markdown histogram // @Tags stats // @ID stats-histogram -// @Param table path string true "Table name" Enums(block, tx, event, message) +// @Param table path string true "Table name" Enums(block, block_stats, tx, event, message) // @Param function path string true "Function name" Enums(min, max, avg, sum, count) // @Param timeframe path string true "Timeframe" Enums(hour, day, week, month, year) // @Param column query string false "Column name which will be used for computation. Optional for count" diff --git a/cmd/api/markdown/summary.md b/cmd/api/markdown/summary.md index 6d5e3b9b..c5d26592 100644 --- a/cmd/api/markdown/summary.md +++ b/cmd/api/markdown/summary.md @@ -2,6 +2,7 @@ Returns string value by passed table and function. ### Availiable tables * `block` +* `block_stats` * `tx` * `message` * `event` @@ -23,9 +24,16 @@ Returns string value by passed table and function. #### Block * `height` -- min max * `time` -- min max + +#### Block stats +* `height` -- min max +* `time` -- min max * `tx_count` -- min max sum avg * `events_count` -- min max sum avg * `blobs_size` -- min max sum avg +* `block_time` -- min max sum avg +* `supply_chnge` -- min max sum avg +* `inflation_rate` -- min max avg * `fee` -- min max sum avg #### Tx diff --git a/internal/storage/block_stats.go b/internal/storage/block_stats.go index cc89b2f9..ba3b6e1f 100644 --- a/internal/storage/block_stats.go +++ b/internal/storage/block_stats.go @@ -5,9 +5,10 @@ package storage import ( "context" - "github.com/celenium-io/celestia-indexer/internal/storage/types" "time" + "github.com/celenium-io/celestia-indexer/internal/storage/types" + pkgTypes "github.com/celenium-io/celestia-indexer/pkg/types" "github.com/shopspring/decimal" "github.com/uptrace/bun" @@ -28,7 +29,7 @@ type BlockStats struct { TxCount int64 `bun:"tx_count" comment:"Count of transactions in block" stats:"func:min max sum avg"` EventsCount int64 `bun:"events_count" comment:"Count of events in begin and end of block" stats:"func:min max sum avg"` BlobsSize int64 `bun:"blobs_size" comment:"Summary blocks size from pay for blob" stats:"func:min max sum avg"` - BlockTime uint64 `bun:"block_time" comment:"Time in milliseconds between current and previous block" stats:"func:min max avg sum"` + BlockTime uint64 `bun:"block_time" comment:"Time in milliseconds between current and previous block" stats:"func:min max sum avg"` SupplyChange decimal.Decimal `bun:",type:numeric" comment:"Change of total supply in the block" stats:"func:min max sum avg"` InflationRate decimal.Decimal `bun:",type:numeric" comment:"Inflation rate" stats:"func:min max avg"` Fee decimal.Decimal `bun:"fee,type:numeric" comment:"Summary block fee" stats:"func:min max sum avg"`