From 1156e57005790fd39a48e4d70be1a26516560e3f Mon Sep 17 00:00:00 2001 From: Dheeraj Dubey Date: Thu, 2 Mar 2023 17:54:48 +0530 Subject: [PATCH] update swagger and docker --- .dockerignore | 1 + Dockerfile | 53 +++ Makefile | 10 + docker-compose.yml | 17 + docker/run_comdex.sh | 9 + docker/setup_and_run.sh | 4 + docker/setup_comdex.sh | 70 ++++ docker/test-user.env | 2 + docs/docs.go | 66 ---- docs/swagger.json | 620 ---------------------------------- docs/swagger.yaml | 404 ---------------------- go.mod | 10 - go.sum | 17 - scripts/merge_protoc.py | 62 ++++ scripts/protoc_swagger_gen.sh | 88 +++++ 15 files changed, 316 insertions(+), 1117 deletions(-) create mode 100644 .dockerignore create mode 100644 Dockerfile create mode 100644 docker-compose.yml create mode 100755 docker/run_comdex.sh create mode 100644 docker/setup_and_run.sh create mode 100755 docker/setup_comdex.sh create mode 100644 docker/test-user.env delete mode 100644 docs/docs.go delete mode 100644 docs/swagger.json delete mode 100644 docs/swagger.yaml create mode 100644 scripts/merge_protoc.py create mode 100644 scripts/protoc_swagger_gen.sh diff --git a/.dockerignore b/.dockerignore new file mode 100644 index 000000000..d16386367 --- /dev/null +++ b/.dockerignore @@ -0,0 +1 @@ +build/ \ No newline at end of file diff --git a/Dockerfile b/Dockerfile new file mode 100644 index 000000000..fee973993 --- /dev/null +++ b/Dockerfile @@ -0,0 +1,53 @@ +# docker build . -t cosmoscontracts/comdex:latest +# docker run --rm -it cosmoscontracts/comdex:latest /bin/sh +FROM golang:1.20-alpine AS go-builder + +# this comes from standard alpine nightly file +# https://github.com/rust-lang/docker-rust-nightly/blob/master/alpine3.12/Dockerfile +# with some changes to support our toolchain, etc +SHELL ["/bin/sh", "-ecuxo", "pipefail"] +# we probably want to default to latest and error +# since this is predominantly for dev use +# hadolint ignore=DL3018 +RUN apk add --no-cache ca-certificates build-base git +# NOTE: add these to run with LEDGER_ENABLED=true +# RUN apk add libusb-dev linux-headers + +WORKDIR /code +COPY . /code/ + +# See https://github.com/CosmWasm/wasmvm/releases +ADD https://github.com/CosmWasm/wasmvm/releases/download/v1.1.1/libwasmvm_muslc.aarch64.a /lib/libwasmvm_muslc.aarch64.a +ADD https://github.com/CosmWasm/wasmvm/releases/download/v1.1.1/libwasmvm_muslc.x86_64.a /lib/libwasmvm_muslc.x86_64.a +RUN sha256sum /lib/libwasmvm_muslc.aarch64.a | grep 9ecb037336bd56076573dc18c26631a9d2099a7f2b40dc04b6cae31ffb4c8f9a +RUN sha256sum /lib/libwasmvm_muslc.x86_64.a | grep 6e4de7ba9bad4ae9679c7f9ecf7e283dd0160e71567c6a7be6ae47c81ebe7f32 + +# Copy the library you want to the final location that will be found by the linker flag `-lwasmvm_muslc` +RUN cp "/lib/libwasmvm_muslc.$(uname -m).a" /lib/libwasmvm_muslc.a + +# force it to use static lib (from above) not standard libgo_cosmwasm.so file +# then log output of file /code/bin/comdex +# then ensure static linking +RUN LEDGER_ENABLED=false BUILD_TAGS=muslc LINK_STATICALLY=true make build \ + && file /code/bin/comdex \ + && echo "Ensuring binary is statically linked ..." \ + && (file /code/bin/comdex | grep "statically linked") + +# -------------------------------------------------------- +FROM alpine:3.16 + +COPY --from=go-builder /code/bin/comdex /usr/bin/comdex + +COPY docker/* /opt/ +RUN chmod +x /opt/*.sh + +WORKDIR /opt + +# rest server +EXPOSE 1317 +# tendermint p2p +EXPOSE 26656 +# tendermint rpc +EXPOSE 26657 + +CMD ["/usr/bin/comdex", "version"] diff --git a/Makefile b/Makefile index 697057274..28872142d 100644 --- a/Makefile +++ b/Makefile @@ -17,6 +17,8 @@ PACKAGES_SIMTEST=$(shell go list ./... | grep '/simulation') LEDGER_ENABLED ?= true SDK_PACK := $(shell go list -m github.com/cosmos/cosmos-sdk | sed 's/ /\@/g') TM_VERSION := $(shell go list -m github.com/tendermint/tendermint | sed 's:.* ::') # grab everything after the space in "github.com/tendermint/tendermint v0.34.7" +DOCKER := $(shell which docker) +DOCKER_BUF := $(DOCKER) run --rm -v $(CURDIR):/workspace --workdir /workspace bufbuild/buf:1.0.0-rc8 BUILDDIR ?= $(CURDIR)/build GOBIN = $(shell go env GOPATH)/bin GOARCH = $(shell go env GOARCH) @@ -176,6 +178,14 @@ endif .PHONY: run-tests test test-all $(TEST_TARGETS) +protoVer=v0.1 +containerProtoGenSwagger=comdex-proto-gen-swagger-$(protoVer) + +proto-swagger-gen: + @echo "Generating Protobuf Swagger" + @if docker ps -a --format '{{.Names}}' | grep -Eq "^${containerProtoGenSwagger}$$"; then docker start -a $(containerProtoGenSwagger); else docker run --name $(containerProtoGenSwagger) -v $(CURDIR):/workspace --workdir /workspace $(protoImageName) \ + sh ./scripts/protoc-swagger-gen.sh; fi + test-sim-nondeterminism: @echo "Running non-determinism test..." @go test -mod=readonly $(SIMAPP) -run TestAppStateDeterminism -Enabled=true \ diff --git a/docker-compose.yml b/docker-compose.yml new file mode 100644 index 000000000..af8e68ac0 --- /dev/null +++ b/docker-compose.yml @@ -0,0 +1,17 @@ +--- +version: "3" +services: + node: + build: + context: . + args: + - arch=${ARCH:-x86_64} + command: ./setup_and_run.sh comdex1pkkayn066msg6kn33wnl5srhdt3tnu2v9jjqu0 + ports: + - 1317:1317 # rest + - 26656:26656 # p2p + - 26657:26657 # rpc + environment: + - GAS_LIMIT=${GAS_LIMIT:-10000000} + - STAKE_TOKEN=${STAKE_TOKEN:-ucmdx} + - TIMEOUT_COMMIT=${TIMEOUT_COMMIT:-5s} diff --git a/docker/run_comdex.sh b/docker/run_comdex.sh new file mode 100755 index 000000000..f405b8eff --- /dev/null +++ b/docker/run_comdex.sh @@ -0,0 +1,9 @@ +#!/bin/sh + +if test -n "$1"; then + # need -R not -r to copy hidden files + cp -R "$1/.comdex" /root +fi + +mkdir -p /root/log +comdex start --rpc.laddr tcp://0.0.0.0:26657 --trace \ No newline at end of file diff --git a/docker/setup_and_run.sh b/docker/setup_and_run.sh new file mode 100644 index 000000000..f86a2e5e6 --- /dev/null +++ b/docker/setup_and_run.sh @@ -0,0 +1,4 @@ +#!/bin/sh + +./setup_comdex.sh "$@" +./run_comdex.sh \ No newline at end of file diff --git a/docker/setup_comdex.sh b/docker/setup_comdex.sh new file mode 100755 index 000000000..d99817834 --- /dev/null +++ b/docker/setup_comdex.sh @@ -0,0 +1,70 @@ +#!/bin/sh +#set -o errexit -o nounset -o pipefail + +PASSWORD=${PASSWORD:-1234567890} +STAKE=${STAKE_TOKEN:-ustake} +FEE=${FEE_TOKEN:-ucosm} +CHAIN_ID=${CHAIN_ID:-testing} +MONIKER=${MONIKER:-node001} +KEYRING="--keyring-backend test" +TIMEOUT_COMMIT=${TIMEOUT_COMMIT:-5s} +BLOCK_GAS_LIMIT=${GAS_LIMIT:-10000000} # should mirror mainnet + +echo "Configured Block Gas Limit: $BLOCK_GAS_LIMIT" + +# check the genesis file +GENESIS_FILE="$HOME"/.comdex/config/genesis.json +GENESIS_FILE="$HOME"/.comdex/config/genesis.json +if [ -f "$GENESIS_FILE" ]; then + echo "$GENESIS_FILE exists..." +else + echo "$GENESIS_FILE does not exist. Generating..." + + comdex init --chain-id "$CHAIN_ID" "$MONIKER" + comdex add-ica-config + # staking/governance token is hardcoded in config, change this + sed -i "s/\"stake\"/\"$STAKE\"/" "$GENESIS_FILE" + # this is essential for sub-1s block times (or header times go crazy) + sed -i 's/"time_iota_ms": "1000"/"time_iota_ms": "10"/' "$GENESIS_FILE" + # change gas limit to mainnet value + sed -i 's/"max_gas": "-1"/"max_gas": "'"$BLOCK_GAS_LIMIT"'"/' "$GENESIS_FILE" + # change default keyring-backend to test + sed -i 's/keyring-backend = "os"/keyring-backend = "test"/' "$HOME"/.comdex/config/client.toml +fi + +APP_TOML_CONFIG="$HOME"/.comdex/config/app.toml +APP_TOML_CONFIG_NEW="$HOME"/.comdex/config/app_new.toml +CONFIG_TOML_CONFIG="$HOME"/.comdex/config/config.toml +if [ -n "$UNSAFE_CORS" ]; then + echo "Unsafe CORS set... updating app.toml and config.toml" + # sorry about this bit, but toml is rubbish for structural editing + sed -n '1h;1!H;${g;s/# Enable defines if the API server should be enabled.\nenable = false/enable = true/;p;}' "$APP_TOML_CONFIG" > "$APP_TOML_CONFIG_NEW" + mv "$APP_TOML_CONFIG_NEW" "$APP_TOML_CONFIG" + # ...and breathe + sed -i "s/enabled-unsafe-cors = false/enabled-unsafe-cors = true/" "$APP_TOML_CONFIG" + sed -i "s/cors_allowed_origins = \[\]/cors_allowed_origins = \[\"\*\"\]/" "$CONFIG_TOML_CONFIG" +fi + +# speed up block times for testing environments +sed -i "s/timeout_commit = \"5s\"/timeout_commit = \"$TIMEOUT_COMMIT\"/" "$CONFIG_TOML_CONFIG" + +# are we running for the first time? +if ! comdex keys show validator $KEYRING; then + (echo "$PASSWORD"; echo "$PASSWORD") | comdex keys add validator $KEYRING + + # hardcode the validator account for this instance + echo "$PASSWORD" | comdex add-genesis-account validator "1000000000$STAKE,1000000000$FEE" $KEYRING + + # (optionally) add a few more genesis accounts + for addr in "$@"; do + echo $addr + comdex add-genesis-account "$addr" "1000000000$STAKE,1000000000$FEE" + done + + # submit a genesis validator tx + ## Workraround for https://github.com/cosmos/cosmos-sdk/issues/8251 + (echo "$PASSWORD"; echo "$PASSWORD"; echo "$PASSWORD") | comdex gentx validator "250000000$STAKE" --chain-id="$CHAIN_ID" --amount="250000000$STAKE" $KEYRING + ## should be: + # (echo "$PASSWORD"; echo "$PASSWORD"; echo "$PASSWORD") | comdex gentx validator "250000000$STAKE" --chain-id="$CHAIN_ID" + comdex collect-gentxs +fi diff --git a/docker/test-user.env b/docker/test-user.env new file mode 100644 index 000000000..d8d59bb42 --- /dev/null +++ b/docker/test-user.env @@ -0,0 +1,2 @@ +TEST_ADDR=comdex1pkkayn066msg6kn33wnl5srhdt3tnu2v9jjqu0 +TEST_MNEMONIC="wage thunder live sense resemble foil apple course spin horse glass mansion midnight laundry acoustic rhythm loan scale talent push green direct brick please" \ No newline at end of file diff --git a/docs/docs.go b/docs/docs.go deleted file mode 100644 index dd6b82f78..000000000 --- a/docs/docs.go +++ /dev/null @@ -1,66 +0,0 @@ -package docs - -import ( - "bytes" - "encoding/json" - "strings" - "text/template" - - "github.com/swaggo/swag" -) - -var doc = `` - -type swaggerInfo struct { - Version string - Host string - BasePath string - Schemes []string - Title string - Description string -} - -// SwaggerInfo holds exported Swagger Info so clients can modify it. -var SwaggerInfo = swaggerInfo{ - Version: "0.1.0", - Host: "localhost:1317", - BasePath: "", - Schemes: []string{}, - Title: "Comdex Swagger Documentation", - Description: "API Documentation of Comdex custom modules", -} - -type s struct{} - -func (s *s) ReadDoc() string { - sInfo := SwaggerInfo - sInfo.Description = strings.Replace(sInfo.Description, "\n", "\\n", -1) - - t, err := template.New("swagger_info").Funcs(template.FuncMap{ - "marshal": func(v interface{}) string { - a, _ := json.Marshal(v) - return string(a) - }, - "escape": func(v interface{}) string { - // escape tabs - str := strings.Replace(v.(string), "\t", "\\t", -1) //nolint:forcetypeassert - // replace " with \", and if that results in \\", replace that with \\\" - str = strings.Replace(str, "\"", "\\\"", -1) - return strings.Replace(str, "\\\\\"", "\\\\\\\"", -1) - }, - }).Parse(doc) - if err != nil { - return doc - } - - var tpl bytes.Buffer - if err := t.Execute(&tpl, sInfo); err != nil { - return doc - } - - return tpl.String() -} - -func init() { - swag.Register(swag.Name, &s{}) -} diff --git a/docs/swagger.json b/docs/swagger.json deleted file mode 100644 index 26b5d82a3..000000000 --- a/docs/swagger.json +++ /dev/null @@ -1,620 +0,0 @@ -{ - "swagger": "2.0", - "info": { - "description": "API Documentation of Comdex custom modules", - "title": "Comdex Swagger Documentation", - "contact": {}, - "license": { - "name": "Apache 2.0", - "url": "http://www.apache.org/licenses/LICENSE-2.0.html" - }, - "version": "0.1.0" - }, - "host": "localhost:1317", - "schemes": [ - "http", - "https" - ], - "tags": [ - { - "name": "Asset", - "description": "Everything about Assets", - "externalDocs": { - "description": "Find out more", - "url": "http://comdex.one" - } - }, - { - "name": "Oracle", - "description": "Everything about Oracle", - "externalDocs": { - "description": "Find out more", - "url": "http://comdex.one" - } - }, - { - "name": "Vault", - "description": "Everything about Vault", - "externalDocs": { - "description": "Find out more", - "url": "http://comdex.one" - } - } - ], - "paths": { - "/comdex/asset/v1beta1/assets": { - "get": { - "description": "Get list of all available Assets", - "consumes": [ - "text/plain" - ], - "produces": [ - "application/json" - ], - "tags": [ - "Asset" - ], - "summary": "Available Assets", - "parameters": [], - "responses": { - "200": { - "description": "Message for a successful request.", - "schema": { - "$ref": "#/definitions/assets.asset.queryResponse.all" - } - }, - "default": { - "description": "Message for an unexpected error.", - "schema": { - "$ref": "#/definitions/helpers.errorObject" - } - } - } - } - }, - "/comdex/asset/v1beta1/assets/{assetId}": { - "get": { - "description": "Search for any assets by using assetId", - "consumes": [ - "text/plain" - ], - "produces": [ - "application/json" - ], - "tags": [ - "Asset" - ], - "summary": "Search for an asset by Asset ID", - "parameters": [ - { - "type": "string", - "description": "Asset ID", - "name": "assetId", - "in": "path", - "required": true - } - ], - "responses": { - "200": { - "description": "Message for a successful search.", - "schema": { - "$ref": "#/definitions/assets.asset.queryResponse.one.success" - } - }, - "default": { - "description": "Message for an unexpected error.", - "schema": { - "$ref": "#/definitions/helpers.errorObject" - } - } - } - } - }, - "/comdex/asset/v1beta1/pairs": { - "get": { - "description": "Get list of all available Pairs", - "consumes": [ - "text/plain" - ], - "produces": [ - "application/json" - ], - "tags": [ - "Asset" - ], - "summary": "Available Pairs", - "parameters": [], - "responses": { - "200": { - "description": "Message for a successful request.", - "schema": { - "$ref": "#/definitions/assets.pair.queryResponse.all" - } - }, - "default": { - "description": "Message for an unexpected error.", - "schema": { - "$ref": "#/definitions/helpers.errorObject" - } - } - } - } - }, - "/comdex/asset/v1beta1/pairs/{pairId}": { - "get": { - "description": "Search for any assets by using assetId", - "consumes": [ - "text/plain" - ], - "produces": [ - "application/json" - ], - "tags": [ - "Asset" - ], - "summary": "Search for pair by pair ID", - "parameters": [ - { - "type": "string", - "description": "Pair ID", - "name": "pairId", - "in": "path", - "required": true - } - ], - "responses": { - "200": { - "description": "Message for a successful search.", - "schema": { - "$ref": "#/definitions/assets.pair.queryResponse.one.success" - } - }, - "default": { - "description": "Message for an unexpected error.", - "schema": { - "$ref": "#/definitions/helpers.errorObject" - } - } - } - } - }, - "/comdex/asset/v1beta1/params": { - "get": { - "description": "Params", - "consumes": [ - "text/plain" - ], - "produces": [ - "application/json" - ], - "tags": [ - "Asset" - ], - "summary": "Params", - "parameters": [], - "responses": { - "200": { - "description": "Message for a successful request.", - "schema": { - "type": "object", - "properties": { - "params": { - "type": "object", - "properties": { - "admin": { - "type": "string" - } - } - } - } - } - }, - "default": { - "description": "Message for an unexpected error.", - "schema": { - "$ref": "#/definitions/helpers.errorObject" - } - } - } - } - }, - "/comdex/oracle/v1beta1/markets": { - "get": { - "description": "Get list of all available Markets", - "consumes": [ - "text/plain" - ], - "produces": [ - "application/json" - ], - "tags": [ - "Oracle" - ], - "summary": "Available Markets", - "parameters": [], - "responses": { - "200": { - "description": "Message for a successful request.", - "schema": { - "$ref": "#/definitions/oracle.markets.queryResponse.all" - } - }, - "default": { - "description": "Message for an unexpected error.", - "schema": { - "$ref": "#/definitions/helpers.errorObject" - } - } - } - } - }, - "/comdex/oracle/v1beta1/markets/{marketSymbol}": { - "get": { - "description": "Search for any market by using market symbol", - "consumes": [ - "text/plain" - ], - "produces": [ - "application/json" - ], - "tags": [ - "Oracle" - ], - "summary": "Search for market by market symbol", - "parameters": [ - { - "type": "string", - "description": "Symbol", - "name": "marketSymbol", - "in": "path", - "required": true - } - ], - "responses": { - "200": { - "description": "Message for a successful search.", - "schema": { - "$ref": "#/definitions/oracle.market.queryResponse.one.success" - } - }, - "default": { - "description": "Message for an unexpected error.", - "schema": { - "$ref": "#/definitions/helpers.errorObject" - } - } - } - } - }, - "/comdex/oracle/v1beta1/params": { - "get": { - "description": "Params", - "consumes": [ - "text/plain" - ], - "produces": [ - "application/json" - ], - "tags": [ - "Oracle" - ], - "summary": "Params", - "parameters": [], - "responses": { - "200": { - "description": "Message for a successful request.", - "schema": { - "type": "object" - } - }, - "default": { - "description": "Message for an unexpected error.", - "schema": { - "$ref": "#/definitions/helpers.errorObject" - } - } - } - } - }, - "/comdex/vault/v1beta1/vaults": { - "get": { - "description": "Get list of all available vaults", - "consumes": [ - "text/plain" - ], - "produces": [ - "application/json" - ], - "tags": [ - "Vault" - ], - "summary": "Available Vaults", - "parameters": [], - "responses": { - "200": { - "description": "Message for a successful request.", - "schema": { - "$ref": "#/definitions/vault.vaults.queryResponse.all" - } - }, - "default": { - "description": "Message for an unexpected error.", - "schema": { - "$ref": "#/definitions/helpers.errorObject" - } - } - } - } - }, - "/comdex/vault/v1beta1/vaults/{vaultId}": { - "get": { - "description": "Search for any vault by using vaultId", - "consumes": [ - "text/plain" - ], - "produces": [ - "application/json" - ], - "tags": [ - "Vault" - ], - "summary": "Search for an vault by Vault ID", - "parameters": [ - { - "type": "string", - "description": "Vault ID", - "name": "vaultId", - "in": "path", - "required": true - } - ], - "responses": { - "200": { - "description": "Message for a successful search.", - "schema": { - "$ref": "#/definitions/vault.vaults.queryResponse.one.success" - } - }, - "default": { - "description": "Message for an unexpected error.", - "schema": { - "$ref": "#/definitions/helpers.errorObject" - } - } - } - } - } - }, - "definitions": { - "assets.asset.queryResponse.all": { - "type": "object", - "properties": { - "assets": { - "type": "array", - "items": { - "$ref": "#/definitions/helpers.assetObject" - } - }, - "pagination": { - "type": "object", - "properties": { - "next_key": { - "type": "string" - }, - "total": { - "type": "integer" - } - } - } - } - }, - "assets.asset.queryResponse.one.success": { - "type": "object", - "properties": { - "asset": { - "$ref": "#/definitions/helpers.assetObject" - } - } - }, - "assets.pair.queryResponse.all": { - "type": "object", - "properties": { - "pairInfo": { - "type": "array", - "items": { - "$ref": "#/definitions/helpers.pairObject" - } - }, - "pagination": { - "type": "object", - "properties": { - "next_key": { - "type": "string" - }, - "total": { - "type": "integer" - } - } - } - } - }, - "assets.pair.queryResponse.one.success": { - "type": "object", - "properties": { - "pairInfo": { - "$ref": "#/definitions/helpers.pairObject" - } - } - }, - "oracle.markets.queryResponse.all": { - "type": "object", - "properties": { - "markets": { - "type": "array", - "items": { - "$ref": "#/definitions/helpers.marketObject" - } - }, - "pagination": { - "type": "object", - "properties": { - "next_key": { - "type": "string" - }, - "total": { - "type": "integer" - } - } - } - } - }, - "oracle.market.queryResponse.one.success": { - "type": "object", - "properties": { - "market": { - "$ref": "#/definitions/helpers.marketObject" - } - } - }, - "vault.vaults.queryResponse.all": { - "type": "object", - "properties": { - "vaultsInfo": { - "type": "array", - "items": { - "$ref": "#/definitions/helpers.vaultObject" - } - }, - "pagination": { - "type": "object", - "properties": { - "next_key": { - "type": "string" - }, - "total": { - "type": "integer" - } - } - } - } - }, - "vault.vaults.queryResponse.one.success": { - "type": "object", - "properties": { - "vaultInfo": { - "$ref": "#/definitions/helpers.vaultObject" - } - } - }, - "helpers.assetObject": { - "type": "object", - "properties": { - "id": { - "type": "string" - }, - "name": { - "type": "string" - }, - "denom": { - "type": "string" - }, - "decimals": { - "type": "string" - } - } - }, - "helpers.pairObject": { - "type": "object", - "properties": { - "id": { - "type": "string" - }, - "asset_in": { - "type": "string" - }, - "denom_in": { - "type": "string" - }, - "asset_out": { - "type": "string" - }, - "denom_out": { - "type": "string" - }, - "liquidation_ratio": { - "type": "string" - } - } - }, - "helpers.marketObject": { - "type": "object", - "properties": { - "symbol": { - "type": "string" - }, - "script_id": { - "type": "string" - } - } - }, - "helpers.vaultObject": { - "type": "object", - "properties": { - "id": { - "type": "string" - }, - "pair_id": { - "type": "string" - }, - "owner": { - "type": "string" - }, - "collateral": { - "type": "object", - "properties": { - "denom": { - "type": "string" - }, - "amount": { - "type": "string" - } - } - }, - "debt": { - "type": "object", - "properties": { - "denom": { - "type": "string" - }, - "amount": { - "type": "string" - } - } - }, - "collateralization_ratio": { - "type": "string" - } - } - }, - "helpers.errorObject": { - "type": "object", - "properties": { - "code": { - "type": "integer" - }, - "message": { - "type": "string" - }, - "details": { - "type": "array", - "items": { - "$ref": "#/definitions/helpers.Mappable" - } - } - } - }, - "helpers.Mappable": { - "type": "object" - } - } -} \ No newline at end of file diff --git a/docs/swagger.yaml b/docs/swagger.yaml deleted file mode 100644 index ff7ce7a78..000000000 --- a/docs/swagger.yaml +++ /dev/null @@ -1,404 +0,0 @@ -swagger: '2.0' -info: - description: API Documentation of Comdex custom modules - title: Comdex Swagger Documentation - contact: {} - license: - name: Apache 2.0 - url: http://www.apache.org/licenses/LICENSE-2.0.html - version: 0.1.0 -host: localhost:1317 -schemes: - - http - - https -tags: - - name: Asset - description: Everything about Assets - externalDocs: - description: Find out more - url: http://comdex.one - - name: Oracle - description: Everything about Oracle - externalDocs: - description: Find out more - url: http://comdex.one - - name: Vault - description: Everything about Vault - externalDocs: - description: Find out more - url: http://comdex.one -paths: - /comdex/asset/v1beta1/assets: - get: - description: Get list of all available Assets - consumes: - - text/plain - produces: - - application/json - tags: - - Asset - summary: Available Assets - parameters: [] - responses: - '200': - description: Message for a successful request. - schema: - $ref: '#/definitions/assets.asset.queryResponse.all' - default: - description: Message for an unexpected error. - schema: - $ref: '#/definitions/helpers.errorObject' - /comdex/asset/v1beta1/assets/{assetId}: - get: - description: Search for any assets by using assetId - consumes: - - text/plain - produces: - - application/json - tags: - - Asset - summary: Search for an asset by Asset ID - parameters: - - type: string - description: Asset ID - name: assetId - in: path - required: true - responses: - '200': - description: Message for a successful search. - schema: - $ref: '#/definitions/assets.asset.queryResponse.one.success' - default: - description: Message for an unexpected error. - schema: - $ref: '#/definitions/helpers.errorObject' - /comdex/asset/v1beta1/pairs: - get: - description: Get list of all available Pairs - consumes: - - text/plain - produces: - - application/json - tags: - - Asset - summary: Available Pairs - parameters: [] - responses: - '200': - description: Message for a successful request. - schema: - $ref: '#/definitions/assets.pair.queryResponse.all' - default: - description: Message for an unexpected error. - schema: - $ref: '#/definitions/helpers.errorObject' - /comdex/asset/v1beta1/pairs/{pairId}: - get: - description: Search for any assets by using assetId - consumes: - - text/plain - produces: - - application/json - tags: - - Asset - summary: Search for pair by pair ID - parameters: - - type: string - description: Pair ID - name: pairId - in: path - required: true - responses: - '200': - description: Message for a successful search. - schema: - $ref: '#/definitions/assets.pair.queryResponse.one.success' - default: - description: Message for an unexpected error. - schema: - $ref: '#/definitions/helpers.errorObject' - /comdex/asset/v1beta1/params: - get: - description: Params - consumes: - - text/plain - produces: - - application/json - tags: - - Asset - summary: Params - parameters: [] - responses: - '200': - description: Message for a successful request. - schema: - type: object - properties: - params: - type: object - properties: - admin: - type: string - default: - description: Message for an unexpected error. - schema: - $ref: '#/definitions/helpers.errorObject' - /comdex/oracle/v1beta1/markets: - get: - description: Get list of all available Markets - consumes: - - text/plain - produces: - - application/json - tags: - - Oracle - summary: Available Markets - parameters: [] - responses: - '200': - description: Message for a successful request. - schema: - $ref: '#/definitions/oracle.markets.queryResponse.all' - default: - description: Message for an unexpected error. - schema: - $ref: '#/definitions/helpers.errorObject' - /comdex/oracle/v1beta1/markets/{marketSymbol}: - get: - description: Search for any market by using market symbol - consumes: - - text/plain - produces: - - application/json - tags: - - Oracle - summary: Search for market by market symbol - parameters: - - type: string - description: Symbol - name: marketSymbol - in: path - required: true - responses: - '200': - description: Message for a successful search. - schema: - $ref: '#/definitions/oracle.market.queryResponse.one.success' - default: - description: Message for an unexpected error. - schema: - $ref: '#/definitions/helpers.errorObject' - /comdex/oracle/v1beta1/params: - get: - description: Params - consumes: - - text/plain - produces: - - application/json - tags: - - Oracle - summary: Params - parameters: [] - responses: - '200': - description: Message for a successful request. - schema: - type: object - default: - description: Message for an unexpected error. - schema: - $ref: '#/definitions/helpers.errorObject' - /comdex/vault/v1beta1/vaults: - get: - description: Get list of all available vaults - consumes: - - text/plain - produces: - - application/json - tags: - - Vault - summary: Available Vaults - parameters: [] - responses: - '200': - description: Message for a successful request. - schema: - $ref: '#/definitions/vault.vaults.queryResponse.all' - default: - description: Message for an unexpected error. - schema: - $ref: '#/definitions/helpers.errorObject' - /comdex/vault/v1beta1/vaults/{vaultId}: - get: - description: Search for any vault by using vaultId - consumes: - - text/plain - produces: - - application/json - tags: - - Vault - summary: Search for an vault by Vault ID - parameters: - - type: string - description: Vault ID - name: vaultId - in: path - required: true - responses: - '200': - description: Message for a successful search. - schema: - $ref: '#/definitions/vault.vaults.queryResponse.one.success' - default: - description: Message for an unexpected error. - schema: - $ref: '#/definitions/helpers.errorObject' -definitions: - assets.asset.queryResponse.all: - type: object - properties: - assets: - type: array - items: - $ref: '#/definitions/helpers.assetObject' - pagination: - type: object - properties: - next_key: - type: string - total: - type: integer - assets.asset.queryResponse.one.success: - type: object - properties: - asset: - $ref: '#/definitions/helpers.assetObject' - assets.pair.queryResponse.all: - type: object - properties: - pairInfo: - type: array - items: - $ref: '#/definitions/helpers.pairObject' - pagination: - type: object - properties: - next_key: - type: string - total: - type: integer - assets.pair.queryResponse.one.success: - type: object - properties: - pairInfo: - $ref: '#/definitions/helpers.pairObject' - oracle.markets.queryResponse.all: - type: object - properties: - markets: - type: array - items: - $ref: '#/definitions/helpers.marketObject' - pagination: - type: object - properties: - next_key: - type: string - total: - type: integer - oracle.market.queryResponse.one.success: - type: object - properties: - market: - $ref: '#/definitions/helpers.marketObject' - vault.vaults.queryResponse.all: - type: object - properties: - vaultsInfo: - type: array - items: - $ref: '#/definitions/helpers.vaultObject' - pagination: - type: object - properties: - next_key: - type: string - total: - type: integer - vault.vaults.queryResponse.one.success: - type: object - properties: - vaultInfo: - $ref: '#/definitions/helpers.vaultObject' - helpers.assetObject: - type: object - properties: - id: - type: string - name: - type: string - denom: - type: string - decimals: - type: string - helpers.pairObject: - type: object - properties: - id: - type: string - asset_in: - type: string - denom_in: - type: string - asset_out: - type: string - denom_out: - type: string - liquidation_ratio: - type: string - helpers.marketObject: - type: object - properties: - symbol: - type: string - script_id: - type: string - helpers.vaultObject: - type: object - properties: - id: - type: string - pair_id: - type: string - owner: - type: string - collateral: - type: object - properties: - denom: - type: string - amount: - type: string - debt: - type: object - properties: - denom: - type: string - amount: - type: string - collateralization_ratio: - type: string - helpers.errorObject: - type: object - properties: - code: - type: integer - message: - type: string - details: - type: array - items: - $ref: '#/definitions/helpers.Mappable' - helpers.Mappable: - type: object diff --git a/go.mod b/go.mod index ae146361c..5880909e9 100644 --- a/go.mod +++ b/go.mod @@ -16,7 +16,6 @@ require ( github.com/spf13/cast v1.5.0 github.com/spf13/cobra v1.6.1 github.com/stretchr/testify v1.8.1 - github.com/swaggo/swag v1.8.10 github.com/tendermint/tendermint v0.34.24 github.com/tendermint/tm-db v0.6.7 google.golang.org/genproto v0.0.0-20221024183307-1bc688fe9f3e @@ -46,11 +45,8 @@ require ( github.com/ChainSafe/go-schnorrkel v0.0.0-20200405005733-88cbf1b4c40d // indirect github.com/Djarvur/go-err113 v0.1.0 // indirect github.com/GaijinEntertainment/go-exhaustruct/v2 v2.3.0 // indirect - github.com/KyleBanks/depth v1.2.1 // indirect github.com/Masterminds/semver v1.5.0 // indirect github.com/OpenPeeDeeP/depguard v1.1.1 // indirect - github.com/PuerkitoBio/purell v1.1.1 // indirect - github.com/PuerkitoBio/urlesc v0.0.0-20170810143723-de5bf2ad4578 // indirect github.com/Workiva/go-datastructures v1.0.53 // indirect github.com/alexkohler/prealloc v1.0.0 // indirect github.com/alingse/asasalint v0.0.11 // indirect @@ -104,10 +100,6 @@ require ( github.com/go-kit/kit v0.12.0 // indirect github.com/go-kit/log v0.2.1 // indirect github.com/go-logfmt/logfmt v0.5.1 // indirect - github.com/go-openapi/jsonpointer v0.19.5 // indirect - github.com/go-openapi/jsonreference v0.19.6 // indirect - github.com/go-openapi/spec v0.20.4 // indirect - github.com/go-openapi/swag v0.19.15 // indirect github.com/go-toolsmith/astcast v1.1.0 // indirect github.com/go-toolsmith/astcopy v1.0.3 // indirect github.com/go-toolsmith/astequal v1.1.0 // indirect @@ -160,7 +152,6 @@ require ( github.com/jingyugao/rowserrcheck v1.1.1 // indirect github.com/jirfag/go-printf-func-name v0.0.0-20200119135958-7558a9eaa5af // indirect github.com/jmhodges/levigo v1.0.0 // indirect - github.com/josharian/intern v1.0.0 // indirect github.com/julz/importas v0.1.0 // indirect github.com/junk1tm/musttag v0.4.5 // indirect github.com/kisielk/errcheck v1.6.3 // indirect @@ -177,7 +168,6 @@ require ( github.com/libp2p/go-buffer-pool v0.1.0 // indirect github.com/lufeee/execinquery v1.2.1 // indirect github.com/magiconair/properties v1.8.6 // indirect - github.com/mailru/easyjson v0.7.6 // indirect github.com/maratori/testableexamples v1.0.0 // indirect github.com/maratori/testpackage v1.1.0 // indirect github.com/matoous/godox v0.0.0-20210227103229-6504466cf951 // indirect diff --git a/go.sum b/go.sum index df5f25eaa..9eaca470a 100644 --- a/go.sum +++ b/go.sum @@ -301,8 +301,6 @@ github.com/GoogleCloudPlatform/k8s-cloud-provider v0.0.0-20190822182118-27a4ced3 github.com/HdrHistogram/hdrhistogram-go v1.1.0/go.mod h1:yDgFjdqOqDEKOvasDdhWNXYg9BVp4O+o5f6V/ehm6Oo= github.com/HdrHistogram/hdrhistogram-go v1.1.2/go.mod h1:yDgFjdqOqDEKOvasDdhWNXYg9BVp4O+o5f6V/ehm6Oo= github.com/Knetic/govaluate v3.0.1-0.20171022003610-9aa49832a739+incompatible/go.mod h1:r7JcOSlj0wfOMncg0iLm8Leh48TZaKVeNIfJntJ2wa0= -github.com/KyleBanks/depth v1.2.1 h1:5h8fQADFrWtarTdtDudMmGsC7GPbOAu6RVB3ffsVFHc= -github.com/KyleBanks/depth v1.2.1/go.mod h1:jzSb9d0L43HxTQfT+oSA1EEp2q+ne2uh6XgeJcm8brE= github.com/Masterminds/goutils v1.1.0/go.mod h1:8cTjp+g8YejhMuvIA5y2vz3BpJxksy863GQaJW2MFNU= github.com/Masterminds/semver v1.4.2/go.mod h1:MB6lktGJrhw8PrUyiEoblNEGEQ+RzHPF078ddwwvV3Y= github.com/Masterminds/semver v1.5.0 h1:H65muMkzWKEuNDnfl9d70GUjFniHKHRbFPGBuZ3QEww= @@ -351,10 +349,8 @@ github.com/OpenPeeDeeP/depguard v1.0.1/go.mod h1:xsIw86fROiiwelg+jB2uM9PiKihMMmU github.com/OpenPeeDeeP/depguard v1.1.1 h1:TSUznLjvp/4IUP+OQ0t/4jF4QUyxIcVX8YnghZdunyA= github.com/OpenPeeDeeP/depguard v1.1.1/go.mod h1:JtAMzWkmFEzDPyAd+W0NHl1lvpQKTvT9jnRVsohBKpc= github.com/PuerkitoBio/purell v1.0.0/go.mod h1:c11w/QuzBsJSee3cPx9rAFu61PvFxuPbtSwDGJws/X0= -github.com/PuerkitoBio/purell v1.1.1 h1:WEQqlqaGbrPkxLJWfBwQmfEAE1Z7ONdDLqrN38tNFfI= github.com/PuerkitoBio/purell v1.1.1/go.mod h1:c11w/QuzBsJSee3cPx9rAFu61PvFxuPbtSwDGJws/X0= github.com/PuerkitoBio/urlesc v0.0.0-20160726150825-5bd2802263f2/go.mod h1:uGdkoq3SwY9Y+13GIhn11/XLaGBb4BfwItxLd5jeuXE= -github.com/PuerkitoBio/urlesc v0.0.0-20170810143723-de5bf2ad4578 h1:d+Bc7a5rLufV/sSk/8dngufqelfh6jnri85riMAaF/M= github.com/PuerkitoBio/urlesc v0.0.0-20170810143723-de5bf2ad4578/go.mod h1:uGdkoq3SwY9Y+13GIhn11/XLaGBb4BfwItxLd5jeuXE= github.com/Shopify/logrus-bugsnag v0.0.0-20171204204709-577dee27f20d/go.mod h1:HI8ITrYtUY+O+ZhtlqUnD8+KwNPOyugEhfP9fdUIaEQ= github.com/Shopify/sarama v1.19.0/go.mod h1:FVkBWblsNy7DGZRfXLU0O9RCGt5g3g3yEuWXgklEdEo= @@ -973,24 +969,17 @@ github.com/go-ole/go-ole v1.2.6/go.mod h1:pprOEPIfldk/42T2oK7lQ4v4JSDwmV0As9GaiU github.com/go-openapi/jsonpointer v0.0.0-20160704185906-46af16f9f7b1/go.mod h1:+35s3my2LFTysnkMfxsJBAMHj/DoqoB9knIWoYG/Vk0= github.com/go-openapi/jsonpointer v0.19.2/go.mod h1:3akKfEdA7DF1sugOqz1dVQHBcuDBPKZGEoHC/NkiQRg= github.com/go-openapi/jsonpointer v0.19.3/go.mod h1:Pl9vOtqEWErmShwVjC8pYs9cog34VGT37dQOVbmoatg= -github.com/go-openapi/jsonpointer v0.19.5 h1:gZr+CIYByUqjcgeLXnQu2gHYQC9o73G2XUeOFYEICuY= github.com/go-openapi/jsonpointer v0.19.5/go.mod h1:Pl9vOtqEWErmShwVjC8pYs9cog34VGT37dQOVbmoatg= github.com/go-openapi/jsonreference v0.0.0-20160704190145-13c6e3589ad9/go.mod h1:W3Z9FmVs9qj+KR4zFKmDPGiLdk1D9Rlm7cyMvf57TTg= github.com/go-openapi/jsonreference v0.19.2/go.mod h1:jMjeRr2HHw6nAVajTXJ4eiUwohSTlpa0o73RUL1owJc= github.com/go-openapi/jsonreference v0.19.3/go.mod h1:rjx6GuL8TTa9VaixXglHmQmIL98+wF9xc8zWvFonSJ8= github.com/go-openapi/jsonreference v0.19.5/go.mod h1:RdybgQwPxbL4UEjuAruzK1x3nE69AqPYEJeo/TWfEeg= -github.com/go-openapi/jsonreference v0.19.6 h1:UBIxjkht+AWIgYzCDSv2GN+E/togfwXUJFRTWhl2Jjs= -github.com/go-openapi/jsonreference v0.19.6/go.mod h1:diGHMEHg2IqXZGKxqyvWdfWU/aim5Dprw5bqpKkTvns= github.com/go-openapi/spec v0.0.0-20160808142527-6aced65f8501/go.mod h1:J8+jY1nAiCcj+friV/PDoE1/3eeccG9LYBs0tYvLOWc= github.com/go-openapi/spec v0.19.3/go.mod h1:FpwSN1ksY1eteniUU7X0N/BgJ7a4WvBFVA8Lj9mJglo= -github.com/go-openapi/spec v0.20.4 h1:O8hJrt0UMnhHcluhIdUgCLRWyM2x7QkBXRvOs7m+O1M= -github.com/go-openapi/spec v0.20.4/go.mod h1:faYFR1CvsJZ0mNsmsphTMSoRrNV3TEDoAM7FOEWeq8I= github.com/go-openapi/swag v0.0.0-20160704191624-1d0bd113de87/go.mod h1:DXUve3Dpr1UfpPtxFw+EFuQ41HhCWZfha5jSVRG7C7I= github.com/go-openapi/swag v0.19.2/go.mod h1:POnQmlKehdgb5mhVOsnJFsivZCEZ/vjK9gh66Z9tfKk= github.com/go-openapi/swag v0.19.5/go.mod h1:POnQmlKehdgb5mhVOsnJFsivZCEZ/vjK9gh66Z9tfKk= github.com/go-openapi/swag v0.19.14/go.mod h1:QYRuS/SOXUCsnplDa677K7+DxSOj6IPNl/eQntq43wQ= -github.com/go-openapi/swag v0.19.15 h1:D2NRCBzS9/pEY3gP9Nl8aDqGUcPFrwG2p+CNFrLyrCM= -github.com/go-openapi/swag v0.19.15/go.mod h1:QYRuS/SOXUCsnplDa677K7+DxSOj6IPNl/eQntq43wQ= github.com/go-pdf/fpdf v0.5.0/go.mod h1:HzcnA+A23uwogo0tp9yU+l3V+KXhiESpt1PMayhOh5M= github.com/go-pdf/fpdf v0.6.0/go.mod h1:HzcnA+A23uwogo0tp9yU+l3V+KXhiESpt1PMayhOh5M= github.com/go-playground/assert/v2 v2.0.1/go.mod h1:VDjEfimB/XKnb+ZQfWdccd7VUvScMdVu0Titje2rxJ4= @@ -1470,7 +1459,6 @@ github.com/joho/godotenv v1.3.0/go.mod h1:7hK45KPybAkOC6peb+G5yklZfMxEjkZhHbwpqx github.com/jonboulle/clockwork v0.1.0/go.mod h1:Ii8DK3G1RaLaWxj9trq07+26W01tbo22gdxWY5EU2bo= github.com/jonboulle/clockwork v0.2.0/go.mod h1:Pkfl5aHPm1nk2H9h0bjmnJD/BcgbGXUBGnn1kMkgxc8= github.com/jonboulle/clockwork v0.2.2/go.mod h1:Pkfl5aHPm1nk2H9h0bjmnJD/BcgbGXUBGnn1kMkgxc8= -github.com/josharian/intern v1.0.0 h1:vlS4z54oSdjm0bgjRigI+G1HpF+tI+9rE5LLzOg8HmY= github.com/josharian/intern v1.0.0/go.mod h1:5DoeVV0s6jJacbCEi61lwdGj/aVlrQvzHFFd8Hwg//Y= github.com/josharian/txtarfs v0.0.0-20210218200122-0702f000015a/go.mod h1:izVPOvVRsHiKkeGCT6tYBNWyDVuzj9wAaBb5R9qamfw= github.com/jpillora/backoff v0.0.0-20180909062703-3050d21c67d7/go.mod h1:2iMrUgbbvHEiQClaW2NsSzMyGHqN+rDFqY705q49KG0= @@ -1596,7 +1584,6 @@ github.com/mailru/easyjson v0.0.0-20160728113105-d5b7844b561a/go.mod h1:C1wdFJiN github.com/mailru/easyjson v0.0.0-20190614124828-94de47d64c63/go.mod h1:C1wdFJiN94OJF2b5HbByQZoLdCWB1Yqtg26g4irojpc= github.com/mailru/easyjson v0.0.0-20190626092158-b2ccc519800e/go.mod h1:C1wdFJiN94OJF2b5HbByQZoLdCWB1Yqtg26g4irojpc= github.com/mailru/easyjson v0.7.0/go.mod h1:KAzv3t3aY1NaHWoQz1+4F1ccyAH66Jk7yos7ldAVICs= -github.com/mailru/easyjson v0.7.6 h1:8yTIVnZgCoiM1TgqoeTl+LfU5Jg6/xL3QhGQnimLYnA= github.com/mailru/easyjson v0.7.6/go.mod h1:xzfreul335JAWq5oZzymOObrkdz5UnU4kGfJJLY9Nlc= github.com/maratori/testableexamples v1.0.0 h1:dU5alXRrD8WKSjOUnmJZuzdxWOEQ57+7s93SLMxb2vI= github.com/maratori/testableexamples v1.0.0/go.mod h1:4rhjL1n20TUTT4vdh3RDqSizKLyXp7K2u6HgraZCGzE= @@ -2247,8 +2234,6 @@ github.com/subosito/gotenv v1.3.0/go.mod h1:YzJjq/33h7nrwdY+iHMhEOEEbW0ovIz0tB6t github.com/subosito/gotenv v1.4.0/go.mod h1:mZd6rFysKEcUhUHXJk0C/08wAgyDBFuwEYL7vWWGaGo= github.com/subosito/gotenv v1.4.1 h1:jyEFiXpy21Wm81FBN71l9VoMMV8H8jG+qIK3GCpY6Qs= github.com/subosito/gotenv v1.4.1/go.mod h1:ayKnFf/c6rvx/2iiLrJUk1e6plDbT3edrFNGqEflhK0= -github.com/swaggo/swag v1.8.10 h1:eExW4bFa52WOjqRzRD58bgWsWfdFJso50lpbeTcmTfo= -github.com/swaggo/swag v1.8.10/go.mod h1:ezQVUUhly8dludpVk+/PuwJWvLLanB13ygV5Pr9enSk= github.com/syndtr/gocapability v0.0.0-20170704070218-db04d3cc01c8/go.mod h1:hkRG7XYTFWNJGYcbNJQlaLq0fg1yr4J4t/NcTQtrfww= github.com/syndtr/gocapability v0.0.0-20180916011248-d98352740cb2/go.mod h1:hkRG7XYTFWNJGYcbNJQlaLq0fg1yr4J4t/NcTQtrfww= github.com/syndtr/gocapability v0.0.0-20200815063812-42c35b437635/go.mod h1:hkRG7XYTFWNJGYcbNJQlaLq0fg1yr4J4t/NcTQtrfww= @@ -2701,7 +2686,6 @@ golang.org/x/net v0.0.0-20210226172049-e18ecbb05110/go.mod h1:m0MpNAwzfU5UDzcl9v golang.org/x/net v0.0.0-20210316092652-d523dce5a7f4/go.mod h1:RBQZq4jEuRlivfhVLdyRGr576XBO4/greRjx4P4O3yc= golang.org/x/net v0.0.0-20210405180319-a5a99cb37ef4/go.mod h1:p54w0d4576C0XHj96bSt6lcn1PtDYWL6XObtHCRCNQM= golang.org/x/net v0.0.0-20210410081132-afb366fc7cd1/go.mod h1:9tjilg8BloeKEkVJvy7fQ90B1CfIiPueXVOjqfkSzI8= -golang.org/x/net v0.0.0-20210421230115-4e50805a0758/go.mod h1:72T/g9IO56b78aLF+1Kcs5dz7/ng1VjMUvfKvpfy+jM= golang.org/x/net v0.0.0-20210428140749-89ef3d95e781/go.mod h1:OJAsFXCWl8Ukc7SiCT/9KSuxbyM7479/AVlXFRxuMCk= golang.org/x/net v0.0.0-20210503060351-7fd8e65b6420/go.mod h1:9nx3DQGgdP8bBQD5qxJ1jj9UTztislL4KSBs9R2vV5Y= golang.org/x/net v0.0.0-20210510120150-4163338589ed/go.mod h1:9nx3DQGgdP8bBQD5qxJ1jj9UTztislL4KSBs9R2vV5Y= @@ -2895,7 +2879,6 @@ golang.org/x/sys v0.0.0-20210320140829-1e4c9ba3b0c4/go.mod h1:h1NjWce9XRLGQEsW7w golang.org/x/sys v0.0.0-20210324051608-47abb6519492/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs= golang.org/x/sys v0.0.0-20210330210617-4fbd30eecc44/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs= golang.org/x/sys v0.0.0-20210403161142-5e06dd20ab57/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs= -golang.org/x/sys v0.0.0-20210420072515-93ed5bcd2bfe/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs= golang.org/x/sys v0.0.0-20210423082822-04245dca01da/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs= golang.org/x/sys v0.0.0-20210423185535-09eb48e85fd7/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs= golang.org/x/sys v0.0.0-20210426230700-d19ff857e887/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs= diff --git a/scripts/merge_protoc.py b/scripts/merge_protoc.py new file mode 100644 index 000000000..6506501ff --- /dev/null +++ b/scripts/merge_protoc.py @@ -0,0 +1,62 @@ +#!/usr/bin/env python3 + +# Call this from the ./scripts/protoc_swagger_gen.sh script + +# merged protoc definitions together into 1 JSON file without duplicate keys +# this is done AFTER swagger-merger has been run, merging the multiple name-#.json files into 1. + +import json +import os +import random +import string + +current_dir = os.path.dirname(os.path.realpath(__file__)) +project_root = os.path.dirname(current_dir) + +all_dir = os.path.join(project_root, "tmp-swagger-gen", "_all") + +# What we will save when all combined +output: dict +output = { + "swagger": "2.0", + "info": {"title": "Comdex network", "version": "v9"}, + "consumes": ["application/json"], + "produces": ["application/json"], + "paths": {}, + "definitions": {}, +} + +# Combine all individual files calls into 1 massive file. +for file in os.listdir(all_dir): + if not file.endswith(".json"): + continue + + # read file all_dir / file + with open(os.path.join(all_dir, file), "r") as f: + data = json.load(f) + + for key in data["paths"]: + output["paths"][key] = data["paths"][key] + + for key in data["definitions"]: + output["definitions"][key] = data["definitions"][key] + + +# loop through all paths, then alter any keys which are "operationId" to be a random string of 20 characters +# this is done to avoid duplicate keys in the final output (which opens 2 tabs in swagger-ui) +# current-random +for path in output["paths"]: + for method in output["paths"][path]: + if "operationId" in output["paths"][path][method]: + output["paths"][path][method][ + "operationId" + ] = f'{output["paths"][path][method]["operationId"]}_' + "".join( + random.choices(string.ascii_uppercase + string.digits, k=5) + ) + + +# save output into 1 big json file +with open( + os.path.join(project_root, "tmp-swagger-gen", "_all", "FINAL.json"), "w" +) as f: + json.dump(output, f, indent=2) diff --git a/scripts/protoc_swagger_gen.sh b/scripts/protoc_swagger_gen.sh new file mode 100644 index 000000000..12d1b8ec7 --- /dev/null +++ b/scripts/protoc_swagger_gen.sh @@ -0,0 +1,88 @@ +#!/usr/bin/env bash + +# Run from the project root directory +# This script generates the swagger & openapi.yaml documentation for the rest API on port 1317 + +# change to the scripts folder +cd "$(dirname `realpath "$0"`)" +# change to the root folder +cd ../ + +mkdir -p ./tmp-swagger-gen + +# Get the paths used repos from go/pkg/mod +cosmos_sdk_dir=$(go list -f '{{ .Dir }}' -m github.com/cosmos/cosmos-sdk) +wasmd=$(go list -f '{{ .Dir }}' -m github.com/CosmWasm/wasmd) +ica=$(go list -f '{{ .Dir }}' -m github.com/cosmos/interchain-accounts) + +proto_dirs=$(find ./proto "$cosmos_sdk_dir"/proto "$wasmd"/proto "$ica"/proto -path -prune -o -name '*.proto' -print0 | xargs -0 -n1 dirname | sort | uniq) +for dir in $proto_dirs; do + + # generate swagger files (filter query files) + query_file=$(find "${dir}" -maxdepth 1 \( -name 'query.proto' -o -name 'service.proto' \)) + if [[ ! -z "$query_file" ]]; then + # Get swagger protoc plugin with `go install github.com/grpc-ecosystem/grpc-gateway/protoc-gen-swagger@v1.16.0` + protoc \ + -I "proto" \ + -I "$cosmos_sdk_dir/third_party/proto" \ + -I "$cosmos_sdk_dir/proto" \ + -I "$wasmd/proto" \ + -I "$ica/proto" \ + "$query_file" \ + --swagger_out ./tmp-swagger-gen \ + --swagger_opt logtostderr=true \ + --swagger_opt fqn_for_swagger_name=true \ + --swagger_opt simple_operation_ids=true + fi +done + +# delete cosmos/mint path since comdex uses its own module +rm -rf ./tmp-swagger-gen/cosmos/mint + +# Fix circular definition in cosmos/tx/v1beta1/service.swagger.json +jq 'del(.definitions["cosmos.tx.v1beta1.ModeInfo.Multi"].properties.mode_infos.items["$ref"])' ./tmp-swagger-gen/cosmos/tx/v1beta1/service.swagger.json > ./tmp-swagger-gen/cosmos/tx/v1beta1/fixed-service.swagger.json + +# Tag everything as "gRPC Gateway API" +perl -i -pe 's/"(Query|Service)"/"gRPC Gateway API"/' $(find ./tmp-swagger-gen -name '*.swagger.json' -print0 | xargs -0) + +# Convert all *.swagger.json files into a single folder _all +files=$(find ./tmp-swagger-gen -name '*.swagger.json' -print0 | xargs -0) +mkdir -p ./tmp-swagger-gen/_all +counter=0 +for f in $files; do + echo "[+] $f" + + # check gaia first before cosmos + # if [[ "$f" =~ "gaia" ]]; then + # cp $f ./tmp-swagger-gen/_all/gaia-$counter.json + if [[ "$f" =~ "router" ]]; then + cp $f ./tmp-swagger-gen/_all/pfm-$counter.json + elif [[ "$f" =~ "cosmwasm" ]]; then + cp $f ./tmp-swagger-gen/_all/cosmwasm-$counter.json + elif [[ "$f" =~ "comdex" ]]; then + cp $f ./tmp-swagger-gen/_all/comdex-$counter.json + elif [[ "$f" =~ "cosmos" ]]; then + cp $f ./tmp-swagger-gen/_all/cosmos-$counter.json + elif [[ "$f" =~ "intertx" ]]; then + cp $f ./tmp-swagger-gen/_all/intertx-$counter.json + else + cp $f ./tmp-swagger-gen/_all/other-$counter.json + fi + ((counter++)) +done + +# merges all the above into FINAL.json +python3 ./scripts/merge_protoc.py + +# Makes a swagger temp file with reference pointers +swagger-combine ./tmp-swagger-gen/_all/FINAL.json -o ./docs/_tmp_swagger.yaml -f yaml --continueOnConflictingPaths --includeDefinitions + +# extends out the *ref instances to their full value +swagger-merger --input ./docs/_tmp_swagger.yaml -o ./docs/swagger.yaml + +# Derive openapi from swagger docs +swagger2openapi --patch ./docs/swagger.yaml --outfile ./docs/static/openapi.yml --yaml + +# clean swagger tmp files +rm ./docs/_tmp_swagger.yaml +rm -rf ./tmp-swagger-gen \ No newline at end of file