Skip to content

Commit

Permalink
updates
Browse files Browse the repository at this point in the history
  • Loading branch information
hard-nett committed Mar 29, 2024
1 parent 3b10918 commit 7f2b967
Show file tree
Hide file tree
Showing 24 changed files with 526 additions and 752 deletions.
2 changes: 1 addition & 1 deletion app/app.go
Original file line number Diff line number Diff line change
Expand Up @@ -66,7 +66,7 @@ import (
v2 "github.com/terpnetwork/terp-core/v4/app/upgrades/v2"
v3 "github.com/terpnetwork/terp-core/v4/app/upgrades/v3"
"github.com/terpnetwork/terp-core/v4/app/upgrades/v4_1"
"github.com/terpnetwork/terp-core/v4/docs"
"github.com/terpnetwork/terp-core/v4/client/docs"

"github.com/CosmWasm/wasmd/x/wasm"
wasmkeeper "github.com/CosmWasm/wasmd/x/wasm/keeper"
Expand Down
9 changes: 9 additions & 0 deletions client/docs/config.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
{
"swagger": "2.0",
"info": {
"title": "Terp Network - gRPC Gateway docs",
"description": "A REST interface for state queries, legacy transactions",
"version": "1.0.0"
},
"apis": []
}
File renamed without changes.
16 changes: 16 additions & 0 deletions client/docs/package.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
{
"name": "docs",
"version": "1.0.0",
"main": "index.js",
"license": "MIT",
"scripts": {
"combine": "swagger-combine ./config.json -o static/swagger/swagger.yaml -f yaml --continueOnConflictingPaths --includeDefinitions",
"convert": "swagger2openapi static/swagger/swagger.yaml --outfile static/openapi/openapi.yaml --yaml",
"build": "redoc-cli bundle static/openapi/openapi.yaml --output ./static/openapi/index.html"
},
"dependencies": {
"redoc-cli": "^0.9.12",
"swagger-combine": "^1.4.0",
"swagger2openapi": "^7.0.3"
}
}
5 changes: 5 additions & 0 deletions client/docs/static/swagger/swagger.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
swagger: '2.0'
info:
title: Terp Network - gRPC Gateway docs
description: A REST interface for state queries, legacy transactions
version: 1.0.0
19 changes: 14 additions & 5 deletions contrib/devtools/Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -49,25 +49,34 @@ BUF_VERSION ?= 0.11.0
TOOLS_DESTDIR ?= $(GOPATH)/bin
STATIK = $(TOOLS_DESTDIR)/statik
RUNSIM = $(TOOLS_DESTDIR)/runsim
GOLANGCI_LINT = $(TOOLS_DESTDIR)/golangci-lint

tools: tools-stamp
tools-stamp: statik runsim
tools-stamp: statik runsim golangci-lint
# Create dummy file to satisfy dependency and avoid
# rebuilding when this Makefile target is hit twice
# in a row.
touch $@

# Install the runsim binary
statik: $(STATIK)
$(STATIK):
@echo "Installing statik..."
@go install github.com/rakyll/statik@v0.1.6
@(cd /tmp && go install github.com/rakyll/statik@v0.1.6)

# Install the runsim binary
# Install the runsim binary with a temporary workaround of entering an outside
# directory as the "go get" command ignores the -mod option and will polute the
# go.{mod, sum} files.
#
# ref: https://github.com/golang/go/issues/30515
runsim: $(RUNSIM)
$(RUNSIM):
@echo "Installing runsim..."
@go install github.com/cosmos/tools/cmd/runsim@v1.0.0
@(cd /tmp && go install github.com/cosmos/tools/cmd/runsim@v1.0.0)

golangci-lint: $(GOLANGCI_LINT)
$(GOLANGCI_LINT):
@echo "Installing golangci-lint..."
@(cd /tmp && go install github.com/golangci/golangci-lint/cmd/golangci-lint@v1.47.0)

tools-clean:
rm -f $(STATIK) $(GOLANGCI_LINT) $(RUNSIM)
Expand Down
3 changes: 0 additions & 3 deletions docs/README.md

This file was deleted.

2 changes: 1 addition & 1 deletion proto/buf.gen.gogo.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ version: v1
plugins:
- name: gocosmos
out: ..
opt: plugins=grpc,Mgoogle/protobuf/any.proto=github.com/cosmos/cosmos-sdk/codec/types
opt: plugins=grpc,Mgoogle/protobuf/any.proto=github.com/cosmos/cosmos-sdk/codec/types,Mcosmos/orm/v1/orm.proto=cosmossdk.io/orm
- name: grpc-gateway
out: ..
opt: logtostderr=true,allow_colon_final_segments=true
8 changes: 8 additions & 0 deletions proto/buf.gen.pulsar.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
version: v1
plugins:
- name: gocosmos
out: ..
opt: plugins=grpc,Mgoogle/protobuf/any.proto=github.com/cosmos/cosmos-sdk/codec/types,Mcosmos/orm/v1/orm.proto=cosmossdk.io/orm
- name: grpc-gateway
out: ..
opt: logtostderr=true,allow_colon_final_segments=true
12 changes: 11 additions & 1 deletion scripts/makefiles/proto.mk
Original file line number Diff line number Diff line change
Expand Up @@ -25,13 +25,23 @@ proto-all: proto-format proto-gen

proto-gen:
@echo "Generating Protobuf files"
@$(DOCKER) run --rm -u 0 -v $(CURDIR):/workspace --workdir /workspace $(PROTO_BUILDER_IMAGE) sh ./scripts/protocgen.sh
@$(protoImage) sh ./scripts/protocgen.sh
# generate the stubs for the proto files from the proto directory
spawn stub-gen

proto-swagger-gen:
@$(protoImage) sh ./scripts/protoc_swagger_openapi_gen.sh

proto-lint:
@$(protoImage) buf lint --error-format=json

proto-format:
@echo "Formatting Protobuf files"
@$(DOCKER) run --rm -v $(CURDIR):/workspace --workdir /workspace tendermintdev/docker-build-proto \
find ./proto -name "*.proto" -exec clang-format -i {} \;

proto-check-breaking:
@$(CURDIR) $(protoImage) buf breaking --against $(HTTPS_GIT)#branch=main

SWAGGER_DIR=./swagger-proto
THIRD_PARTY_DIR=$(SWAGGER_DIR)/third_party
Expand Down
69 changes: 41 additions & 28 deletions scripts/protocgen.sh
Original file line number Diff line number Diff line change
@@ -1,37 +1,50 @@
#!/usr/bin/env bash

#== Legacy Requirements (<= SDK v45) ==
#
## make sure your `go env GOPATH` is in the `$PATH`
## Install:
## + latest buf (v1.0.0-rc11 or later)
## + protobuf v3
#
## All protoc dependencies must be installed not in the module scope
## currently we must use grpc-gateway v1
# cd ~
# go install google.golang.org/protobuf/cmd/protoc-gen-go@latest
# go install google.golang.org/grpc/cmd/protoc-gen-go-grpc@latest
# go install github.com/grpc-ecosystem/grpc-gateway/protoc-gen-grpc-gateway@v1.16.0
# go install github.com/cosmos/cosmos-proto/cmd/protoc-gen-go-pulsar@latest
# go get github.com/regen-network/cosmos-proto@latest # doesn't work in install mode
# go get github.com/regen-network/cosmos-proto/protoc-gen-gocosmos@v0.3.1

# Updated - How to run manually:
# docker build --pull --rm -f "contrib/devtools/Dockerfile" -t cosmossdk-proto:latest "contrib/devtools"
# docker run --rm -v $(pwd):/workspace --workdir /workspace cosmossdk-proto sh ./scripts/protocgen.sh

set -eo pipefail
set -e

GO_MOD_PACKAGE="github.com/terpnetwork/terp-core"

echo "Generating gogo proto code"
cd proto
buf mod update
proto_dirs=$(find . -path -prune -o -name '*.proto' -print0 | xargs -0 -n1 dirname | sort | uniq)
for dir in $proto_dirs; do
for file in $(find "${dir}" -maxdepth 1 -name '*.proto'); do
# this regex checks if a proto file has its go_package set to github.com/strangelove-ventures/poa/...
# gogo proto files SHOULD ONLY be generated if this is false
# we don't want gogo proto to run for proto files which are natively built for google.golang.org/protobuf
if grep -q "option go_package" "$file" && grep -H -o -c "option go_package.*$GO_MOD_PACKAGE/api" "$file" | grep -q ':0$'; then
buf generate --template buf.gen.gogo.yaml $file
fi
done
done

echo "Generating pulsar proto code"
buf generate --template buf.gen.pulsar.yaml

cd ..
buf generate

# move proto files to the right places
cp -r ./github.com/terpnetwork/terp-core/x/* x/
cp -r ./github.com/cosmos/gaia/x/* x/
cp -r $GO_MOD_PACKAGE/* ./
rm -rf github.com

# Copy files over for dep injection
rm -rf api && mkdir api
custom_modules=$(find . -name 'module' -type d -not -path "./proto/*")

# get the 1 up directory (so ./cosmos/mint/module becomes ./cosmos/mint)
# remove the relative path starter from base namespaces. so ./cosmos/mint becomes cosmos/mint
base_namespace=$(echo $custom_modules | sed -e 's|/module||g' | sed -e 's|\./||g')

# echo "Base namespace: $base_namespace"
for module in $base_namespace; do
echo " [+] Moving: ./$module to ./api/$module"

mkdir -p api/$module

mv $module/* ./api/$module/

# # incorrect reference to the module for coins
find api/$module -type f -name '*.go' -exec sed -i -e 's|types "github.com/cosmos/cosmos-sdk/types"|types "cosmossdk.io/api/cosmos/base/v1beta1"|g' {} \;
find api/$module -type f -name '*.go' -exec sed -i -e 's|types1 "github.com/cosmos/cosmos-sdk/x/bank/types"|types1 "cosmossdk.io/api/cosmos/bank/v1beta1"|g' {} \;

rm -rf ./github.com
rm -rf $module
done
19 changes: 0 additions & 19 deletions scripts/protocgen2.sh

This file was deleted.

32 changes: 10 additions & 22 deletions x/feeshare/types/feeshare.pb.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Loading

0 comments on commit 7f2b967

Please sign in to comment.