diff --git a/README.md b/README.md index a370dd2e3..5e9ba6eca 100644 --- a/README.md +++ b/README.md @@ -190,13 +190,13 @@ GET /v3/aex141/:contract_id/templates - nft templates GET /v3/aex141/:contract_id/templates/:id/tokens - nft supply from a template GET /v3/aex141/transfers - nft transfers that can be filtered by sender/recipient -GET /v3/deltastats - statistics for generations from tip of the chain -GET /v3/totalstats - aggregated statistics for generations from tip of the chain -GET /v3/minerstats - total rewards for each miner +GET /v3/stats/delta - statistics for generations from tip of the chain +GET /v3/stats/total - aggregated statistics for generations from tip of the chain +GET /v3/stats/miners - total rewards for each miner -GET /v3/statistics/transactions - statistics over time of transactions count -GET /v3/statistics/blocks - statistics over time of blocks count -GET /v3/statistics/names - statistics over time of names count +GET /v3/stats/transactions - statistics over time of transactions count +GET /v3/stats/blocks - statistics over time of blocks count +GET /v3/stats/names - statistics over time of names count GET /v3/status - middleware status ``` @@ -3247,14 +3247,14 @@ $ curl -s 'https://testnet.aeternity.io/mdw/v3/aex141/transfers?to=ak_QVSUoGrJ31 --- -## Statistics +## Stats -### `/v3/deltastats` +### `/v3/stats/delta` To show a statistics for a given height, we can use "stats" endpoint: ``` -$ curl -s "https://mainnet.aeternity.io/mdw/v3/deltastats?limit=1" | jq '.' +$ curl -s "https://mainnet.aeternity.io/mdw/v3/stats/delta?limit=1" | jq '.' { "data": [ { @@ -3276,16 +3276,16 @@ $ curl -s "https://mainnet.aeternity.io/mdw/v3/deltastats?limit=1" | jq '.' "oracles_registered": 0 } ], - "next": "/v3/deltastats?limit=1&cursor=419208" + "next": "/v3/stats/delta?limit=1&cursor=419208" } ``` -### `/v3/totalstats` +### `/v3/stats/total` Aggregated (summarized) statistics are also available, showing the total sum of rewards and the token supply: ``` -$ curl -s "https://mainnet.aeternity.io/mdw/v3/totalstats?scope=gen:421454-0&limit=1" | jq '.' +$ curl -s "https://mainnet.aeternity.io/mdw/v3/stats/total?scope=gen:421454-0&limit=1" | jq '.' { "data": [ { @@ -3306,18 +3306,18 @@ $ curl -s "https://mainnet.aeternity.io/mdw/v3/totalstats?scope=gen:421454-0&lim "total_token_supply": 8.945137682239798e+25 } ], - "next": "/v3/totalstats?scope=gen:421454-0&limit=1&cursor=42152" + "next": "/v3/stats/total?scope=gen:421454-0&limit=1&cursor=42152" } ``` These endpoints allow pagination, with typical `forward/backward` direction or scope denoted by `gen/from-to`. -### `/v3/minerstats` +### `/v3/stats/miners` Total reward given to each chain miner. ``` -$ curl -s "https://mainnet.aeternity.io/mdw/v3/minerstats?limit=1" | jq '.' +$ curl -s "https://mainnet.aeternity.io/mdw/v3/stats/miners?limit=1" | jq '.' { "data": [ { @@ -3325,7 +3325,7 @@ $ curl -s "https://mainnet.aeternity.io/mdw/v3/minerstats?limit=1" | jq '.' "total_reward": 76626041292504000000 } ], - "next": "/v3/totalminers?cursor=ak_2wk52gAYRWAMi7gWP7A1oMvHEP9kpmp471VJFpvVzWMHnRc47a", + "next": "/v3/stats/miners?cursor=ak_2wk52gAYRWAMi7gWP7A1oMvHEP9kpmp471VJFpvVzWMHnRc47a", "prev": null } ``` diff --git a/docs/swagger_v3/stats.spec.yaml b/docs/swagger_v3/stats.spec.yaml index bc1c14af3..83039cbd7 100644 --- a/docs/swagger_v3/stats.spec.yaml +++ b/docs/swagger_v3/stats.spec.yaml @@ -166,9 +166,9 @@ schemas: sum_dev_reward: 33027000000000000000 total_token_supply: 10000000000000000000000000000 last_tx_hash: th_2FHxDzpQMRTiRfpYRV3eCcsheHr1sjf9waxk7z6JDTVcgqZRXR - Statistic: + Stat: type: object - description: Statistic + description: Stat required: - count - start_date @@ -329,14 +329,14 @@ paths: application/json: schema: $ref: '#/components/schemas/ErrorResponse' - /statistics/blocks: + /stats/blocks: get: deprecated: false - description: Get total blocks count statistics. - operationId: GetBlocksStatistics + description: Get total blocks count stats. + operationId: GetBlocksStats parameters: - name: interval_by - description: The interval in which to return the statistics. + description: The interval in which to return the stats. in: query required: false schema: @@ -386,7 +386,7 @@ paths: data: type: array items: - $ref: '#/components/schemas/Statistic' + $ref: '#/components/schemas/Stat' - $ref: '#/components/schemas/PaginatedResponse' '400': description: Bad request @@ -394,14 +394,14 @@ paths: application/json: schema: $ref: '#/components/schemas/ErrorResponse' - /statistics/transactions: + /stats/transactions: get: deprecated: false - description: Get total transactions count statistics. - operationId: GetTransactionsStatistics + description: Get total transactions count stats. + operationId: GetTransactionsStats parameters: - name: interval_by - description: The interval in which to return the statistics. + description: The interval in which to return the stats. in: query required: false schema: @@ -448,7 +448,7 @@ paths: data: type: array items: - $ref: '#/components/schemas/Statistic' + $ref: '#/components/schemas/Stat' - $ref: '#/components/schemas/PaginatedResponse' '400': description: Bad request @@ -456,14 +456,14 @@ paths: application/json: schema: $ref: '#/components/schemas/ErrorResponse' - /statistics/names: + /stats/names: get: deprecated: false - description: Get total names count statistics. - operationId: GetNamesStatistics + description: Get total names count stats. + operationId: GetNamesStats parameters: - name: interval_by - description: The interval in which to return the statistics. + description: The interval in which to return the stats. in: query required: false schema: @@ -503,7 +503,7 @@ paths: data: type: array items: - $ref: '#/components/schemas/Statistic' + $ref: '#/components/schemas/Stats' - $ref: '#/components/schemas/PaginatedResponse' '400': description: Bad request diff --git a/lib/ae_mdw/stats.ex b/lib/ae_mdw/stats.ex index 2b60e7f97..378bca70e 100644 --- a/lib/ae_mdw/stats.ex +++ b/lib/ae_mdw/stats.ex @@ -218,9 +218,9 @@ defmodule AeMdw.Stats do end end - @spec fetch_transactions_statistics(State.t(), pagination(), query(), range(), cursor()) :: + @spec fetch_transactions_stats(State.t(), pagination(), query(), range(), cursor()) :: {:ok, {pagination_cursor(), [statistic()], pagination_cursor()}} - def fetch_transactions_statistics(state, pagination, query, range, cursor) do + def fetch_transactions_stats(state, pagination, query, range, cursor) do with {:ok, filters} <- Util.convert_params(query, &convert_transactions_param/1) do tx_tag = Map.get(filters, :tx_type, :all) @@ -228,9 +228,9 @@ defmodule AeMdw.Stats do end end - @spec fetch_blocks_statistics(State.t(), pagination(), query(), range(), cursor()) :: + @spec fetch_blocks_stats(State.t(), pagination(), query(), range(), cursor()) :: {:ok, {pagination_cursor(), [statistic()], pagination_cursor()}} | {:error, reason()} - def fetch_blocks_statistics(state, pagination, query, range, cursor) do + def fetch_blocks_stats(state, pagination, query, range, cursor) do with {:ok, filters} <- Util.convert_params(query, &convert_blocks_param/1) do type_tag = Map.get(filters, :block_type, :all) @@ -238,9 +238,9 @@ defmodule AeMdw.Stats do end end - @spec fetch_names_statistics(State.t(), pagination(), query(), range(), cursor()) :: + @spec fetch_names_stats(State.t(), pagination(), query(), range(), cursor()) :: {:ok, {pagination_cursor(), [statistic()], pagination_cursor()}} | {:error, reason()} - def fetch_names_statistics(state, pagination, query, range, cursor) do + def fetch_names_stats(state, pagination, query, range, cursor) do with {:ok, filters} <- Util.convert_params(query, &convert_param/1) do fetch_statistics(state, pagination, filters, range, cursor, :names_activated) end diff --git a/lib/ae_mdw_web/controllers/stats_controller.ex b/lib/ae_mdw_web/controllers/stats_controller.ex index df1adbd9e..894215a09 100644 --- a/lib/ae_mdw_web/controllers/stats_controller.ex +++ b/lib/ae_mdw_web/controllers/stats_controller.ex @@ -8,13 +8,13 @@ defmodule AeMdwWeb.StatsController do alias AeMdwWeb.Util alias Plug.Conn - @statistics_limit 1_000 + @stats_limit 1_000 - plug PaginatedPlug when action not in ~w(transactions_statistics blocks_statistics)a + plug PaginatedPlug when action not in ~w(transactions_stats blocks_stats names_stats)a plug PaginatedPlug, - [max_limit: @statistics_limit] - when action in ~w(transactions_statistics blocks_statistics)a + [max_limit: @stats_limit] + when action in ~w(transactions_stats blocks_stats names_stats)a action_fallback(FallbackController) @@ -71,8 +71,8 @@ defmodule AeMdwWeb.StatsController do end end - @spec miners(Conn.t(), map()) :: Conn.t() - def miners(%Conn{assigns: assigns} = conn, _params) do + @spec miners_stats(Conn.t(), map()) :: Conn.t() + def miners_stats(%Conn{assigns: assigns} = conn, _params) do %{state: state, pagination: pagination, cursor: cursor} = assigns {prev_cursor, miners, next_cursor} = Miners.fetch_miners(state, pagination, cursor) @@ -80,33 +80,33 @@ defmodule AeMdwWeb.StatsController do Util.render(conn, prev_cursor, miners, next_cursor) end - @spec transactions_statistics(Conn.t(), map()) :: Conn.t() - def transactions_statistics(%Conn{assigns: assigns} = conn, _params) do + @spec transactions_stats(Conn.t(), map()) :: Conn.t() + def transactions_stats(%Conn{assigns: assigns} = conn, _params) do %{state: state, pagination: pagination, query: query, scope: scope, cursor: cursor} = assigns - with {:ok, paginated_statistics} <- - Stats.fetch_transactions_statistics(state, pagination, query, scope, cursor) do - Util.render(conn, paginated_statistics) + with {:ok, paginated_stats} <- + Stats.fetch_transactions_stats(state, pagination, query, scope, cursor) do + Util.render(conn, paginated_stats) end end - @spec blocks_statistics(Conn.t(), map()) :: Conn.t() - def blocks_statistics(%Conn{assigns: assigns} = conn, _params) do + @spec blocks_stats(Conn.t(), map()) :: Conn.t() + def blocks_stats(%Conn{assigns: assigns} = conn, _params) do %{state: state, pagination: pagination, query: query, scope: scope, cursor: cursor} = assigns - with {:ok, paginated_statistics} <- - Stats.fetch_blocks_statistics(state, pagination, query, scope, cursor) do - Util.render(conn, paginated_statistics) + with {:ok, paginated_stats} <- + Stats.fetch_blocks_stats(state, pagination, query, scope, cursor) do + Util.render(conn, paginated_stats) end end - @spec names_statistics(Conn.t(), map()) :: Conn.t() - def names_statistics(%Conn{assigns: assigns} = conn, _params) do + @spec names_stats(Conn.t(), map()) :: Conn.t() + def names_stats(%Conn{assigns: assigns} = conn, _params) do %{state: state, pagination: pagination, query: query, scope: scope, cursor: cursor} = assigns - with {:ok, paginated_statistics} <- - Stats.fetch_names_statistics(state, pagination, query, scope, cursor) do - Util.render(conn, paginated_statistics) + with {:ok, paginated_stats} <- + Stats.fetch_names_stats(state, pagination, query, scope, cursor) do + Util.render(conn, paginated_stats) end end end diff --git a/lib/ae_mdw_web/router.ex b/lib/ae_mdw_web/router.ex index bd50c2a58..745334e0e 100644 --- a/lib/ae_mdw_web/router.ex +++ b/lib/ae_mdw_web/router.ex @@ -86,9 +86,13 @@ defmodule AeMdwWeb.Router do get "/accounts/:account_id/dex/swaps", DexController, :account_swaps get "/accounts/:id/transactions/count", TxController, :count_id - get "/deltastats", StatsController, :delta_stats + get "/stats/transactions", StatsController, :transactions_stats + get "/stats/blocks", StatsController, :blocks_stats + get "/stats/names", StatsController, :names_stats + get "/stats/total", StatsController, :total_stats + get "/stats/delta", StatsController, :delta_stats + get "/stats/miners", StatsController, :miners_stats get "/stats", StatsController, :stats - get "/minerstats", StatsController, :miners get "/names", NameController, :names get "/names/count", NameController, :names_count @@ -101,12 +105,7 @@ defmodule AeMdwWeb.Router do get "/names/:id/transfers", NameController, :name_transfers get "/names/:id/history", NameController, :name_history - get "/statistics/transactions", StatsController, :transactions_statistics - get "/statistics/blocks", StatsController, :blocks_statistics - get "/statistics/names", StatsController, :names_statistics - get "/transfers", TransferController, :transfers - get "/totalstats/", StatsController, :total_stats get "/status", UtilController, :status get "/aex9", AexnTokenController, :aex9_contracts @@ -216,7 +215,7 @@ defmodule AeMdwWeb.Router do get "/deltastats", StatsController, :delta_stats get "/stats", StatsController, :stats - get "/minerstats", StatsController, :miners + get "/minerstats", StatsController, :miners_stats get "/wealth", WealthController, :wealth get "/api", UtilController, :static_file, diff --git a/test/ae_mdw_web/controllers/stats_controller_test.exs b/test/ae_mdw_web/controllers/stats_controller_test.exs index 751fb3686..2c1a1bb97 100644 --- a/test/ae_mdw_web/controllers/stats_controller_test.exs +++ b/test/ae_mdw_web/controllers/stats_controller_test.exs @@ -56,7 +56,7 @@ defmodule AeMdwWeb.StatsControllerTest do assert %{"prev" => nil, "data" => [stat1], "next" => nil} = conn |> with_store(store) - |> get("/v2/deltastats") + |> get("/v3/stats/delta") |> json_response(200) assert %{ @@ -68,12 +68,12 @@ defmodule AeMdwWeb.StatsControllerTest do assert %{"prev" => nil, "data" => [], "next" => nil} = conn |> with_store(store) - |> get("/v2/deltastats") + |> get("/v3/stats/delta") |> json_response(200) end end - describe "transactions_statistics" do + describe "transactions_stats" do test "it returns the count of transactions for the latest daily periods", %{ conn: conn, store: store @@ -95,7 +95,7 @@ defmodule AeMdwWeb.StatsControllerTest do assert %{"prev" => nil, "data" => [st1, st2] = statistics, "next" => next_url} = conn - |> get("/v3/statistics/transactions", limit: 2) + |> get("/v3/stats/transactions", limit: 2) |> json_response(200) assert %{"start_date" => "1970-02-01", "count" => 3} = st1 @@ -137,7 +137,7 @@ defmodule AeMdwWeb.StatsControllerTest do assert %{"prev" => nil, "data" => [st1, st2] = statistics, "next" => next_url} = conn - |> get("/v3/statistics/transactions", + |> get("/v3/stats/transactions", limit: 2, tx_type: "spend", direction: "forward" @@ -183,7 +183,7 @@ defmodule AeMdwWeb.StatsControllerTest do assert %{"prev" => nil, "data" => [st1, st2] = statistics, "next" => next_url} = conn - |> get("/v3/statistics/transactions", limit: 2, interval_by: "week") + |> get("/v3/stats/transactions", limit: 2, interval_by: "week") |> json_response(200) assert %{"start_date" => "1970-01-29", "count" => 3} = st1 @@ -228,7 +228,7 @@ defmodule AeMdwWeb.StatsControllerTest do assert %{"prev" => nil, "data" => [st1, st2] = statistics, "next" => next_url} = conn - |> get("/v3/statistics/transactions", limit: 2, interval_by: "month") + |> get("/v3/stats/transactions", limit: 2, interval_by: "month") |> json_response(200) assert %{"start_date" => "1970-05-01", "count" => 8} = st1 @@ -265,7 +265,7 @@ defmodule AeMdwWeb.StatsControllerTest do assert %{"prev" => nil, "data" => [st1, st2] = statistics, "next" => next_url} = conn - |> get("/v3/statistics/transactions", limit: 2, interval_by: "month") + |> get("/v3/stats/transactions", limit: 2, interval_by: "month") |> json_response(200) assert %{"start_date" => "1970-05-01", "count" => 0} = st1 @@ -286,7 +286,7 @@ defmodule AeMdwWeb.StatsControllerTest do end end - describe "blocks_statistics" do + describe "blocks_stats" do test "it returns the count of blocks for the latest daily periods", %{ conn: conn, store: store @@ -310,7 +310,7 @@ defmodule AeMdwWeb.StatsControllerTest do assert %{"prev" => nil, "data" => [st1, st2] = statistics, "next" => next_url} = conn - |> get("/v3/statistics/blocks", limit: 2) + |> get("/v3/stats/blocks", limit: 2) |> json_response(200) assert %{"start_date" => "1970-02-01", "count" => 0} = st1 @@ -352,7 +352,7 @@ defmodule AeMdwWeb.StatsControllerTest do assert %{"prev" => nil, "data" => [st1, st2] = statistics, "next" => next_url} = conn - |> get("/v3/statistics/blocks", + |> get("/v3/stats/blocks", limit: 2, type: "micro", direction: "forward" @@ -393,7 +393,7 @@ defmodule AeMdwWeb.StatsControllerTest do assert %{"prev" => nil, "data" => [st1, st2], "next" => nil} = conn - |> get("/v3/statistics/blocks", + |> get("/v3/stats/blocks", limit: 2, min_start_date: "1970-01-02", max_start_date: "1970-01-03", @@ -427,7 +427,7 @@ defmodule AeMdwWeb.StatsControllerTest do assert %{"prev" => nil, "data" => [st1, st2] = statistics, "next" => next_url} = conn - |> get("/v3/statistics/blocks", limit: 2, interval_by: "week") + |> get("/v3/stats/blocks", limit: 2, interval_by: "week") |> json_response(200) assert %{"start_date" => "1970-01-29", "count" => 0} = st1 @@ -453,24 +453,24 @@ defmodule AeMdwWeb.StatsControllerTest do assert %{"error" => ^error_msg} = conn - |> get("/v3/statistics/blocks", type: block_type) + |> get("/v3/stats/blocks", type: block_type) |> json_response(400) end test "when limit is less than 1000, it doesn't return an error", %{conn: conn} do assert %{"data" => _data} = conn - |> get("/v3/statistics/blocks", limit: 1000) + |> get("/v3/stats/blocks", limit: 1000) |> json_response(200) assert %{"data" => _data} = conn - |> get("/v3/statistics/blocks", limit: 301) + |> get("/v3/stats/blocks", limit: 301) |> json_response(200) assert %{"error" => "limit too large: 1001"} = conn - |> get("/v3/statistics/blocks", limit: 1001) + |> get("/v3/stats/blocks", limit: 1001) |> json_response(400) end end