Skip to content

Commit

Permalink
Protobufs changes (#208)
Browse files Browse the repository at this point in the history
* first steps

* protocgen2

* more proto related changes

* more proto related changes

* Update docker.yml

* Update docker.yml

* mint folder

* mint folder

* add fix for proto-fix-protos.sh (#3)

* does not tidy

* add proto generation to makefile

* remove unintended change

* remove unintended change

* tidy

Co-authored-by: nghuyenthevinh2000 <[email protected]>
  • Loading branch information
faddat and nghuyenthevinh2000 authored Jun 7, 2022
1 parent 51c0fe0 commit abc6318
Show file tree
Hide file tree
Showing 14 changed files with 223 additions and 117 deletions.
13 changes: 13 additions & 0 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -96,3 +96,16 @@ install: go.sum

build:
go build $(BUILD_FLAGS) -o bin/junod ./cmd/junod

###############################################################################
### Proto ###
###############################################################################

protoVer=v0.7
protoImageName=tendermintdev/sdk-proto-gen:$(protoVer)
containerProtoGen=juno-proto-gen-$(protoVer)

proto-gen:
@echo "Generating Protobuf files"
@if docker ps -a --format '{{.Names}}' | grep -Eq "^${containerProtoGen}$$"; then docker start -a $(containerProtoGen); else docker run --name $(containerProtoGen) -v $(CURDIR):/workspace --workdir /workspace $(protoImageName) \
sh ./scripts/protocgen.sh; fi
8 changes: 8 additions & 0 deletions buf.gen.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
version: v1
plugins:
- name: gocosmos
out: .
opt: plugins=interfacetype+grpc,Mgoogle/protobuf/any.proto=github.com/cosmos/cosmos-sdk/codec/types
- name: grpc-gateway
out: .
opt: logtostderr=true,allow_colon_final_segments=true
3 changes: 3 additions & 0 deletions buf.work.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
version: v1
directories:
- proto
11 changes: 11 additions & 0 deletions proto/buf.lock
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
# Generated by buf. DO NOT EDIT.
version: v1
deps:
- remote: buf.build
owner: gogo
repository: protobuf
commit: 4df00b267f944190a229ce3695781e99
- remote: buf.build
owner: googleapis
repository: googleapis
commit: cf209eca30404c41a80fec3caba9903f
19 changes: 19 additions & 0 deletions proto/buf.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
version: v1
name: buf.build/CosmosContracts/juno
deps:
- buf.build/gogo/protobuf
- buf.build/googleapis/googleapis
breaking:
use:
- FILE
lint:
use:
- DEFAULT
- COMMENTS
- FILE_LOWER_SNAKE_CASE
except:
- UNARY_RPC
- COMMENT_FIELD
- SERVICE_SUFFIX
- PACKAGE_VERSION_SUFFIX
- RPC_REQUEST_STANDARD_NAME
4 changes: 2 additions & 2 deletions proto/mint/genesis.proto → proto/juno/mint/genesis.proto
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
syntax = "proto3";
package CosmosContracts.juno.mint;
package juno.mint;

import "gogoproto/gogo.proto";
import "mint/mint.proto";
import "juno/mint/mint.proto";

option go_package = "github.com/CosmosContracts/juno/x/mint/types";

Expand Down
2 changes: 1 addition & 1 deletion proto/mint/mint.proto → proto/juno/mint/mint.proto
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
syntax = "proto3";
package CosmosContracts.juno.mint;
package juno.mint;

option go_package = "github.com/CosmosContracts/juno/x/mint/types";

Expand Down
4 changes: 2 additions & 2 deletions proto/mint/query.proto → proto/juno/mint/query.proto
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
syntax = "proto3";
package CosmosContracts.juno.mint;
package juno.mint;

import "gogoproto/gogo.proto";
import "google/api/annotations.proto";
import "mint/mint.proto";
import "juno/mint/mint.proto";

option go_package = "github.com/CosmosContracts/juno/x/mint/types";

Expand Down
34 changes: 34 additions & 0 deletions scripts/protocgen.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
#!/usr/bin/env bash

#== Requirements ==
#
## 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/[email protected]
# 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/[email protected]

set -eo pipefail

echo "Generating gogo proto code"
cd proto
buf mod update
cd ..
buf generate

# move proto files to the right places
cp -r ./github.com/CosmosContracts/juno/x/* x/
rm -rf ./github.com

go mod tidy -compat=1.17

# ./scripts/protocgen2.sh
19 changes: 19 additions & 0 deletions scripts/protocgen2.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
# this script is for generating protobuf files for the new google.golang.org/protobuf API

set -eo pipefail

protoc_install_gopulsar() {
go install github.com/cosmos/cosmos-proto/cmd/protoc-gen-go-pulsar@latest
go install google.golang.org/grpc/cmd/protoc-gen-go-grpc@latest
}

protoc_install_gopulsar

echo "Cleaning API directory"
(cd api; find ./ -type f \( -iname \*.pulsar.go -o -iname \*.pb.go -o -iname \*.cosmos_orm.go -o -iname \*.pb.gw.go \) -delete; find . -empty -type d -delete; cd ..)

echo "Generating API module"
(cd proto; buf generate --template buf.gen.pulsar.yaml)

echo "Generate Pulsar Test Data"
(cd testutil/testdata; buf generate --template buf.gen.pulsar.yaml)
40 changes: 20 additions & 20 deletions x/mint/types/genesis.pb.go

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

64 changes: 32 additions & 32 deletions x/mint/types/mint.pb.go

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

Loading

0 comments on commit abc6318

Please sign in to comment.