diff --git a/Makefile b/Makefile index 0873758..6f6661b 100644 --- a/Makefile +++ b/Makefile @@ -31,4 +31,7 @@ ga: license-header: update-license -path=./ -license=./HEADER -.PHONY: indexer api generate test lint cover api-docs ga license-header \ No newline at end of file +build: + docker-compose up -d --build + +.PHONY: indexer api generate test lint cover api-docs ga license-header build \ No newline at end of file diff --git a/README.md b/README.md index 687c90e..f840de1 100644 --- a/README.md +++ b/README.md @@ -1 +1,22 @@ -# Astria Indexer \ No newline at end of file +# Astria Indexer + +## Standalone + +To run indexer clone repository, open directory containing project and run build command. Example: + +```bash +git clone git@github.com:celenium-io/astria-indexer.git +cd astria-indexer +make build +``` + +or by docker compose + + +```bash +git clone git@github.com:celenium-io/astria-indexer.git +cd astria-indexer +docker-compose up -d --build +``` + +You can set environment variables for customizing instances and indexing logic. Example of environment file can be found [here](.env.example). \ No newline at end of file diff --git a/cmd/api/docs/docs.go b/cmd/api/docs/docs.go index 3c838fa..4adcfe9 100644 --- a/cmd/api/docs/docs.go +++ b/cmd/api/docs/docs.go @@ -2011,7 +2011,7 @@ const docTemplate = `{ }, "/v1/ws": { "get": { - "description": "## Documentation for websocket API\n\n### Subscribe\n\nTo receive updates from websocket API send ` + "`" + `subscribe` + "`" + ` request to server.\n\n` + "`" + `` + "`" + `` + "`" + `json\n{\n \"method\": \"subscribe\",\n \"body\": {\n \"channel\": \"\u003cCHANNEL_NAME\u003e\",\n \"filters\": {\n // pass channel filters\n }\n }\n}\n` + "`" + `` + "`" + `` + "`" + `\n\nNow 2 channels are supported:\n\n* ` + "`" + `head` + "`" + ` - receive information about indexer state update. Channel does not have any filters. Subscribe message should looks like:\n\n` + "`" + `` + "`" + `` + "`" + `json\n{\n \"method\": \"subscribe\",\n \"body\": {\n \"channel\": \"head\"\n }\n}\n` + "`" + `` + "`" + `` + "`" + `\n\nIn that channel messages of ` + "`" + `responses.State` + "`" + ` type will be sent.\n\n* ` + "`" + `blocks` + "`" + ` - receive information about new blocks. Channel does not have any filters. Subscribe message should looks like:\n\n` + "`" + `` + "`" + `` + "`" + `json\n{\n \"method\": \"subscribe\",\n \"body\": {\n \"channel\": \"blocks\"\n }\n}\n` + "`" + `` + "`" + `` + "`" + `\n\nIn that channel messages of ` + "`" + `responses.Block` + "`" + ` type will be sent.\n\n\n### Unsubscribe\n\nTo unsubscribe send ` + "`" + `unsubscribe` + "`" + ` message containing one of channel name describing above.\n\n\n` + "`" + `` + "`" + `` + "`" + `json\n{\n \"method\": \"unsubscribe\",\n \"body\": {\n \"channel\": \"\u003cCHANNEL_NAME\u003e\",\n }\n}\n` + "`" + `` + "`" + `` + "`" + `\n", + "description": "## Documentation for websocket API\n\n### Notification\n\nThe structure of notification is following in all channels:\n\n` + "`" + `` + "`" + `` + "`" + `json\n{\n \"channel\": \"channel_name\",\n \"body\": \"\u003cobject or array\u003e\" // depends on channel\n}\n` + "`" + `` + "`" + `` + "`" + `\n\n### Subscribe\n\nTo receive updates from websocket API send ` + "`" + `subscribe` + "`" + ` request to server.\n\n` + "`" + `` + "`" + `` + "`" + `json\n{\n \"method\": \"subscribe\",\n \"body\": {\n \"channel\": \"\u003cCHANNEL_NAME\u003e\",\n \"filters\": {\n // pass channel filters\n }\n }\n}\n` + "`" + `` + "`" + `` + "`" + `\n\nNow 2 channels are supported:\n\n* ` + "`" + `head` + "`" + ` - receive information about indexer state update. Channel does not have any filters. Subscribe message should looks like:\n\n` + "`" + `` + "`" + `` + "`" + `json\n{\n \"method\": \"subscribe\",\n \"body\": {\n \"channel\": \"head\"\n }\n}\n` + "`" + `` + "`" + `` + "`" + `\n\nNotification body of ` + "`" + `responses.State` + "`" + ` type will be sent to the channel.\n\n* ` + "`" + `blocks` + "`" + ` - receive information about new blocks. Channel does not have any filters. Subscribe message should looks like:\n\n` + "`" + `` + "`" + `` + "`" + `json\n{\n \"method\": \"subscribe\",\n \"body\": {\n \"channel\": \"blocks\"\n }\n}\n` + "`" + `` + "`" + `` + "`" + `\n\nNotification body of ` + "`" + `responses.Block` + "`" + ` type will be sent to the channel.\n\n\n### Unsubscribe\n\nTo unsubscribe send ` + "`" + `unsubscribe` + "`" + ` message containing one of channel name describing above.\n\n\n` + "`" + `` + "`" + `` + "`" + `json\n{\n \"method\": \"unsubscribe\",\n \"body\": {\n \"channel\": \"\u003cCHANNEL_NAME\u003e\",\n }\n}\n` + "`" + `` + "`" + `` + "`" + `\n", "produces": [ "application/json" ], diff --git a/cmd/api/docs/swagger.json b/cmd/api/docs/swagger.json index fb3fca6..37d437e 100644 --- a/cmd/api/docs/swagger.json +++ b/cmd/api/docs/swagger.json @@ -2001,7 +2001,7 @@ }, "/v1/ws": { "get": { - "description": "## Documentation for websocket API\n\n### Subscribe\n\nTo receive updates from websocket API send `subscribe` request to server.\n\n```json\n{\n \"method\": \"subscribe\",\n \"body\": {\n \"channel\": \"\u003cCHANNEL_NAME\u003e\",\n \"filters\": {\n // pass channel filters\n }\n }\n}\n```\n\nNow 2 channels are supported:\n\n* `head` - receive information about indexer state update. Channel does not have any filters. Subscribe message should looks like:\n\n```json\n{\n \"method\": \"subscribe\",\n \"body\": {\n \"channel\": \"head\"\n }\n}\n```\n\nIn that channel messages of `responses.State` type will be sent.\n\n* `blocks` - receive information about new blocks. Channel does not have any filters. Subscribe message should looks like:\n\n```json\n{\n \"method\": \"subscribe\",\n \"body\": {\n \"channel\": \"blocks\"\n }\n}\n```\n\nIn that channel messages of `responses.Block` type will be sent.\n\n\n### Unsubscribe\n\nTo unsubscribe send `unsubscribe` message containing one of channel name describing above.\n\n\n```json\n{\n \"method\": \"unsubscribe\",\n \"body\": {\n \"channel\": \"\u003cCHANNEL_NAME\u003e\",\n }\n}\n```\n", + "description": "## Documentation for websocket API\n\n### Notification\n\nThe structure of notification is following in all channels:\n\n```json\n{\n \"channel\": \"channel_name\",\n \"body\": \"\u003cobject or array\u003e\" // depends on channel\n}\n```\n\n### Subscribe\n\nTo receive updates from websocket API send `subscribe` request to server.\n\n```json\n{\n \"method\": \"subscribe\",\n \"body\": {\n \"channel\": \"\u003cCHANNEL_NAME\u003e\",\n \"filters\": {\n // pass channel filters\n }\n }\n}\n```\n\nNow 2 channels are supported:\n\n* `head` - receive information about indexer state update. Channel does not have any filters. Subscribe message should looks like:\n\n```json\n{\n \"method\": \"subscribe\",\n \"body\": {\n \"channel\": \"head\"\n }\n}\n```\n\nNotification body of `responses.State` type will be sent to the channel.\n\n* `blocks` - receive information about new blocks. Channel does not have any filters. Subscribe message should looks like:\n\n```json\n{\n \"method\": \"subscribe\",\n \"body\": {\n \"channel\": \"blocks\"\n }\n}\n```\n\nNotification body of `responses.Block` type will be sent to the channel.\n\n\n### Unsubscribe\n\nTo unsubscribe send `unsubscribe` message containing one of channel name describing above.\n\n\n```json\n{\n \"method\": \"unsubscribe\",\n \"body\": {\n \"channel\": \"\u003cCHANNEL_NAME\u003e\",\n }\n}\n```\n", "produces": [ "application/json" ], diff --git a/cmd/api/docs/swagger.yaml b/cmd/api/docs/swagger.yaml index edf764a..ac61adc 100644 --- a/cmd/api/docs/swagger.yaml +++ b/cmd/api/docs/swagger.yaml @@ -1823,6 +1823,17 @@ paths: description: | ## Documentation for websocket API + ### Notification + + The structure of notification is following in all channels: + + ```json + { + "channel": "channel_name", + "body": "" // depends on channel + } + ``` + ### Subscribe To receive updates from websocket API send `subscribe` request to server. @@ -1852,7 +1863,7 @@ paths: } ``` - In that channel messages of `responses.State` type will be sent. + Notification body of `responses.State` type will be sent to the channel. * `blocks` - receive information about new blocks. Channel does not have any filters. Subscribe message should looks like: @@ -1865,7 +1876,7 @@ paths: } ``` - In that channel messages of `responses.Block` type will be sent. + Notification body of `responses.Block` type will be sent to the channel. ### Unsubscribe diff --git a/cmd/api/handler/ws_test.go b/cmd/api/handler/ws_test.go index fb648a3..7999de8 100644 --- a/cmd/api/handler/ws_test.go +++ b/cmd/api/handler/ws_test.go @@ -1,3 +1,6 @@ +// SPDX-FileCopyrightText: 2024 PK Lab AG +// SPDX-License-Identifier: MIT + package handler import (