diff --git a/README.md b/README.md index 1fca386..26f7254 100644 --- a/README.md +++ b/README.md @@ -38,13 +38,10 @@ | GET
`text/plain` | `/health` | Checks database connection | | GET
`text/plain` | `/metrics` | [Prometheus](https://prometheus.io/) metrics | -## GraphQL - -Go to `/graphql` for a GraphIQL interface. - ### `X-Api-Key` Use the `Variables` tab at the bottom to add your API key: + ```json { "X-Api-Key": "changeme" @@ -60,7 +57,7 @@ Use the `Variables` tab at the bottom to add your API key: ## Requirements - [ClickHouse](clickhouse.com/), databases should follow a `{chain}_tokens_{version}` naming scheme. Database tables can be setup using the [`schema.sql`](./schema.sql) definitions created by the [`create_schema.sh`](./create_schema.sh) script. -- A [Substream sink](https://substreams.streamingfast.io/reference-and-specs/glossary#sink) for loading data into ClickHouse. We recommend [Substreams Sink ClickHouse](https://github.com/pinax-network/substreams-sink-clickhouse/) or [Substreams Sink SQL](https://github.com/pinax-network/substreams-sink-sql). You should use the generated [`protobuf` files](static/@typespec/protobuf) to build your substream. This Token API makes use of the [`substreams-antelope-tokens`](https://github.com/pinax-network/substreams-antelope-tokens/) substream. +- A [Substream sink](https://substreams.streamingfast.io/reference-and-specs/glossary#sink) for loading data into ClickHouse. We recommend [Substreams Sink ClickHouse](https://github.com/pinax-network/substreams-sink-clickhouse/) or [Substreams Sink SQL](https://github.com/pinax-network/substreams-sink-sql). This Token API makes use of the [`substreams-antelope-tokens`](https://github.com/pinax-network/substreams-antelope-tokens/) substream. ### API stack architecture @@ -129,7 +126,6 @@ echo "CREATE DATABASE eos_tokens_v1 ON CLUSTER " | clickhouse client -h ./create_schema.sh -o /tmp/schema.sql -c ``` - ## [`Bun` Binary Releases](https://github.com/pinax-network/antelope-token-api/releases) > [!WARNING] @@ -179,21 +175,25 @@ VERBOSE=true - Pull from GitHub Container registry **For latest tagged release** + ```bash docker pull ghcr.io/pinax-network/antelope-token-api:latest ``` **For head of `main` branch** + ```bash docker pull ghcr.io/pinax-network/antelope-token-api:develop ``` - Build from source + ```bash docker build -t antelope-token-api . ``` - Run with `.env` file + ```bash docker run -it --rm --env-file .env ghcr.io/pinax-network/antelope-token-api ``` @@ -207,12 +207,13 @@ See [`CONTRIBUTING.md`](CONTRIBUTING.md). Install [Bun](https://bun.sh/) ```console -$ bun install -$ bun dev +bun install +bun dev ``` **Tests** + ```console -$ bun lint -$ bun test +bun lint +bun test ``` diff --git a/package.json b/package.json index 62019cf..d7d9c76 100644 --- a/package.json +++ b/package.json @@ -48,7 +48,6 @@ "@typespec/compiler": "latest", "@typespec/openapi": "latest", "@typespec/openapi3": "latest", - "@typespec/protobuf": "latest", "bun-types": "latest", "openapi-to-graphql-cli": "^3.0.7", "typescript": "latest" diff --git a/src/types/zod.gen.ts b/src/types/zod.gen.ts index f6aaac7..e40c155 100644 --- a/src/types/zod.gen.ts +++ b/src/types/zod.gen.ts @@ -106,23 +106,23 @@ export const usageTransfersAccountQueryResponseSchema = z.object({ "data": z.arr export type UsageTransfersAccountQueryResponseSchema = z.infer; -export const usageHeadQueryParamsSchema = z.object({ "limit": z.coerce.number().int().default(10).optional(), "page": z.coerce.number().int().default(1).optional() }).optional(); -export type UsageHeadQueryParamsSchema = z.infer; +export const monitoringHeadQueryParamsSchema = z.object({ "limit": z.coerce.number().int().default(10).optional(), "page": z.coerce.number().int().default(1).optional() }).optional(); +export type MonitoringHeadQueryParamsSchema = z.infer; /** * @description Head block information. */ -export const usageHead200Schema = z.object({ "data": z.array(z.object({ "block_num": z.coerce.number().int(), "block_id": z.coerce.string() })), "meta": z.lazy(() => responseMetadataSchema) }); -export type UsageHead200Schema = z.infer; +export const monitoringHead200Schema = z.object({ "data": z.array(z.object({ "block_num": z.coerce.number().int(), "block_id": z.coerce.string() })), "meta": z.lazy(() => responseMetadataSchema) }); +export type MonitoringHead200Schema = z.infer; /** * @description An unexpected error response. */ -export const usageHeadErrorSchema = z.lazy(() => apiErrorSchema); -export type UsageHeadErrorSchema = z.infer; +export const monitoringHeadErrorSchema = z.lazy(() => apiErrorSchema); +export type MonitoringHeadErrorSchema = z.infer; /** * @description Head block information. */ -export const usageHeadQueryResponseSchema = z.object({ "data": z.array(z.object({ "block_num": z.coerce.number().int(), "block_id": z.coerce.string() })), "meta": z.lazy(() => responseMetadataSchema) }); -export type UsageHeadQueryResponseSchema = z.infer; +export const monitoringHeadQueryResponseSchema = z.object({ "data": z.array(z.object({ "block_num": z.coerce.number().int(), "block_id": z.coerce.string() })), "meta": z.lazy(() => responseMetadataSchema) }); +export type MonitoringHeadQueryResponseSchema = z.infer; /** * @description OK or ApiError. @@ -317,16 +317,16 @@ export type DocsVersionQueryResponseSchema = z.infer) @@ -117,7 +113,8 @@ interface Usage { Historical token balances of an account. @returns Array of balances. */ - @summary("Historical token balances") + @tag("Account") + @summary("Account historical token balances") @route("/account/balances/historical") @get @useAuth(ApiKeyAuth) @@ -130,21 +127,29 @@ interface Usage { ): ApiResponse>; /** - Current head block for which data is available (can be lower than head block of the chain). - @returns Head block information. + All transfers related to an account. + @returns Array of transfers. */ - @summary("Head block information") - @route("/head") + @tag("Account") + @summary("Account token transfers") + @route("/account/transfers") @get - head(...PaginationQueryParams): ApiResponse>; + @useAuth(ApiKeyAuth) + transfersAccount( + @query account: BalanceChange.account, + @query(#{ explode: false }) block_range?: BlockRange, + @query from?: Transfer.from, + @query to?: Transfer.to, + @query contract?: TokenIdentifier.contract, + @query symcode?: TokenIdentifier.symcode, + ...PaginationQueryParams, + ): ApiResponse>; /** List of holders of a token. @returns Array of accounts. */ + @tag("Tokens") @summary("Token holders") @route("/tokens/holders") @get @@ -159,6 +164,7 @@ interface Usage { Total supply for a token. @returns Array of supplies. */ + @tag("Tokens") @summary("Token supply") @route("/tokens/supplies") @get @@ -175,6 +181,7 @@ interface Usage { List of available tokens. @returns Array of token identifier. */ + @tag("Tokens") @summary("Tokens") @route("/tokens") @get @@ -187,6 +194,7 @@ interface Usage { All transfers related to a token. @returns Array of transfers. */ + @tag("Transfers") @summary("Token transfers") @route("/transfers") @get @@ -198,28 +206,11 @@ interface Usage { ...PaginationQueryParams, ): ApiResponse>; - /** - All transfers related to an account. - @returns Array of transfers. - */ - @summary("Token transfers from and to an account") - @route("/account/transfers") - @get - @useAuth(ApiKeyAuth) - transfersAccount( - @query account: BalanceChange.account, - @query(#{ explode: false }) block_range?: BlockRange, - @query from?: Transfer.from, - @query to?: Transfer.to, - @query contract?: TokenIdentifier.contract, - @query symcode?: TokenIdentifier.symcode, - ...PaginationQueryParams, - ): ApiResponse>; - /** Specific transfer related to a token. @returns Array of transfers. */ + @tag("Transfers") @summary("Token transfer") @route("/transfers/id") @get @@ -278,4 +269,16 @@ interface Monitoring { @route("/metrics") @get metrics(): ApiResponse; + + /** + Current head block for which data is available (can be lower than head block of the chain). + @returns Head block information. + */ + @summary("Head block information") + @route("/head") + @get + head(...PaginationQueryParams): ApiResponse>; } diff --git a/src/typespec/protobuf.tsp b/src/typespec/protobuf.tsp deleted file mode 100644 index 9bfc8bd..0000000 --- a/src/typespec/protobuf.tsp +++ /dev/null @@ -1,43 +0,0 @@ -import "@typespec/protobuf"; -import "./models.tsp"; - -using TypeSpec.Protobuf; - -@package({ - name: "antelope.eosio.token.v1", -}) -namespace AntelopeTokensV1; - -// `is` or `extends` syntax doesn't work here, see https://github.com/microsoft/typespec/issues/3266 -model Transfer { - ...Models.Transfer; -} -@@field(Transfer.trx_id, 1); -@@field(Transfer.action_index, 2); -@@field(Transfer.contract, 3); -@@field(Transfer.symcode, 4); -@@field(Transfer.from, 5); -@@field(Transfer.to, 6); -@@field(Transfer.quantity, 7); -@@field(Transfer.memo, 8); -@@field(Transfer.precision, 9); -@@field(Transfer.amount, 10); -@@field(Transfer.value, 11); -@@field(Transfer.block_num, 12); -@@field(Transfer.timestamp, 13); - -model BalanceChange { - ...Models.BalanceChange; -} -@@field(BalanceChange.trx_id, 1); -@@field(BalanceChange.action_index, 2); -@@field(BalanceChange.contract, 3); -@@field(BalanceChange.symcode, 4); -@@field(BalanceChange.account, 5); -@@field(BalanceChange.balance, 6); -@@field(BalanceChange.balance_delta, 7); -@@field(BalanceChange.precision, 8); -@@field(BalanceChange.amount, 9); -@@field(BalanceChange.value, 10); -@@field(BalanceChange.block_num, 11); -@@field(BalanceChange.timestamp, 12); diff --git a/static/@typespec/openapi3/openapi.json b/static/@typespec/openapi3/openapi.json index 460757a..885b9f4 100644 --- a/static/@typespec/openapi3/openapi.json +++ b/static/@typespec/openapi3/openapi.json @@ -2,16 +2,18 @@ "openapi": "3.0.0", "info": { "title": "Antelope Token Api", - "summary": "Tokens information from the Antelope blockchains, powered by Substreams", - "license": { - "name": "MIT", - "url": "https://github.com/pinax-network/antelope-token-api/blob/4f4bf36341b794c0ccf5b7a14fdf810be06462d2/LICENSE" - }, + "description": "Tokens information from the Antelope blockchains, powered by Substreams", "version": "6.1.0" }, "tags": [ { - "name": "Usage" + "name": "Account" + }, + { + "name": "Tokens" + }, + { + "name": "Transfers" }, { "name": "Docs" @@ -24,7 +26,7 @@ "/account/balances": { "get": { "operationId": "Usage_balance", - "summary": "Token balances", + "summary": "Account token balances", "description": "Token balances of an account.", "parameters": [ { @@ -115,7 +117,7 @@ } }, "tags": [ - "Usage" + "Account" ], "security": [ { @@ -127,7 +129,7 @@ "/account/balances/historical": { "get": { "operationId": "Usage_balanceHistorical", - "summary": "Historical token balances", + "summary": "Account historical token balances", "description": "Historical token balances of an account.", "parameters": [ { @@ -228,7 +230,7 @@ } }, "tags": [ - "Usage" + "Account" ], "security": [ { @@ -240,7 +242,7 @@ "/account/transfers": { "get": { "operationId": "Usage_transfersAccount", - "summary": "Token transfers from and to an account", + "summary": "Account token transfers", "description": "All transfers related to an account.", "parameters": [ { @@ -358,7 +360,7 @@ } }, "tags": [ - "Usage" + "Account" ], "security": [ { @@ -369,7 +371,7 @@ }, "/head": { "get": { - "operationId": "Usage_head", + "operationId": "Monitoring_head", "summary": "Head block information", "description": "Current head block for which data is available (can be lower than head block of the chain).", "parameters": [ @@ -447,7 +449,7 @@ } }, "tags": [ - "Usage" + "Monitoring" ] } }, @@ -610,7 +612,7 @@ } }, "tags": [ - "Usage" + "Tokens" ], "security": [ { @@ -704,7 +706,7 @@ } }, "tags": [ - "Usage" + "Tokens" ], "security": [ { @@ -817,7 +819,7 @@ } }, "tags": [ - "Usage" + "Tokens" ], "security": [ { @@ -920,7 +922,7 @@ } }, "tags": [ - "Usage" + "Transfers" ], "security": [ { @@ -1005,7 +1007,7 @@ } }, "tags": [ - "Usage" + "Transfers" ], "security": [ { diff --git a/swagger/index.html b/swagger/index.html index 9267022..1779a0d 100644 --- a/swagger/index.html +++ b/swagger/index.html @@ -1,33 +1,18 @@ - - - - - Substreams Antelope Token API - SwaggerUI - - - - -
- - - - + + + + + + Substreams Antelope Transactions API - SwaggerUI + + + + + + + + + \ No newline at end of file diff --git a/tspconfig.yaml b/tspconfig.yaml index bf6f357..c669899 100644 --- a/tspconfig.yaml +++ b/tspconfig.yaml @@ -19,7 +19,6 @@ # output-dir: "{project-root}/_generated" # Configure the base output directory for all emitters warn-as-error: true emit: - - "@typespec/protobuf" - "@typespec/openapi3" options: "@typespec/openapi3":