Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

change: move types and msgs to protobuf #361

Draft
wants to merge 4 commits into
base: master
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
21 changes: 21 additions & 0 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -65,6 +65,11 @@ build: go.sum
GOARCH=amd64 CGO_ENABLED=0 GOOS=linux go build -o ./build/iovnsd -mod=readonly $(BUILD_FLAGS) ./cmd/iovnsd
GOARCH=amd64 CGO_ENABLED=0 GOOS=linux go build -o ./build/iovnscli -mod=readonly $(BUILD_FLAGS) ./cmd/iovnscli

# dev-container makes you join the dev-container which contains all the tools required to build iovns and proto related files
dev-container:
docker build -t dev-container:local -f ./runtimes/protobuild.dockerfile .
docker run -v="${CURDIR}:/src" -w="/src" -it dev-container:local

go.sum: go.mod
@echo "--> Ensure dependencies have not been modified"
GO111MODULE=on go mod verify
Expand All @@ -75,6 +80,22 @@ lint:
@golangci-lint run
@go mod verify

# proto builds protobuf files, each newly added .proto should be
# added here, and in case paths are changed they should be updated
proto:
protoc -I=. \
-I=${GOPATH}/src/github.com/gogo/protobuf \
-I=${GOPATH}/src/github.com/gogo/protobuf/protobuf \
--gofast_out=Mgoogle/protobuf/any.proto=github.com/gogo/protobuf/types,Mgoogle/protobuf/duration.proto=github.com/gogo/protobuf/types,Mgoogle/protobuf/struct.proto=github.com/gogo/protobuf/types,Mgoogle/protobuf/timestamp.proto=github.com/gogo/protobuf/types,Mgoogle/protobuf/wrappers.proto=github.com/gogo/protobuf/types,paths=source_relative:. \
x/starname/types/msgs.proto x/starname/types/types.proto

protoc -I=. \
-I=${GOPATH}/src/github.com/gogo/protobuf \
-I=${GOPATH}/src/github.com/gogo/protobuf/protobuf \
-I=/proto_includes \
--gofast_out=Mgoogle/protobuf/any.proto=github.com/gogo/protobuf/types,Mgoogle/protobuf/duration.proto=github.com/gogo/protobuf/types,Mgoogle/protobuf/struct.proto=github.com/gogo/protobuf/types,Mgoogle/protobuf/timestamp.proto=github.com/gogo/protobuf/types,Mgoogle/protobuf/wrappers.proto=github.com/gogo/protobuf/types,paths=source_relative:. \
x/configuration/types/msgs.proto x/configuration/types/types.proto

test:
@# iovnscli binary is required for it tests
go install -mod=readonly $(BUILD_FLAGS) ./cmd/iovnscli
Expand Down
2 changes: 2 additions & 0 deletions go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,9 @@ go 1.14
require (
github.com/cosmos/cosmos-sdk v0.39.1
github.com/fatih/structs v1.1.0
github.com/gogo/protobuf v1.3.1
github.com/golang/mock v1.3.1 // indirect
github.com/golang/protobuf v1.4.0
github.com/gorilla/mux v1.7.4
github.com/gorilla/websocket v1.4.2
github.com/iov-one/cosmos-sdk-crud v0.0.0-20200804183153-2b7470a92e52
Expand Down
8 changes: 8 additions & 0 deletions runtimes/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
# Runtimes

Contains a series of dockerfiles that can be used to build images that can be used a runtimes to run certain pieces of softwares.

## protobuild.dockerfile
It's the docker image used to build the .proto files, this is because we need to leverage gogoproto which is not currently
supported by latest protobuf versions of protobuf. And also it exists so you do not have to download the whole protobuf,
protoc-gen-go executable. The image will build everything for you.
41 changes: 41 additions & 0 deletions runtimes/protobuild.dockerfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
FROM alpine as protoc

ARG PROTOC_VERSION="3.13.0"
ARG PROTOC_ZIP=protoc-${PROTOC_VERSION}-linux-aarch_64.zip
ARG COSMOS_VERSION=master

RUN apk --no-cache add curl
WORKDIR /protoc
RUN curl -OL https://github.com/protocolbuffers/protobuf/releases/download/v${PROTOC_VERSION}/${PROTOC_ZIP}
RUN unzip -o $PROTOC_ZIP

FROM golang:1.15-alpine
# add g++ required for ledger
RUN apk add g++
# add make
RUN apk add make
# install protobuf
RUN apk add protobuf
# copy protobuf includes
COPY --from=protoc /protoc/include /protobuf/include
# include protobuf in path
ENV PATH=$PATH:/protobuf:/go/bin
# INSTALL GIT
RUN apk --no-cache add git
# INSTALL gogoproto
RUN go get github.com/gogo/protobuf/protoc-gen-gofast
# install cosmos dependencies
WORKDIR /tmp
RUN git clone https://github.com/cosmos/cosmos-sdk.git
WORKDIR /tmp/cosmos-sdk
# checkout to pinned version
RUN git checkout ${COSMOS_VERSION}
# save proto includes from cosmos-sdk
WORKDIR /proto_includes
RUN mv /tmp/cosmos-sdk/proto/cosmos /proto_includes/cosmos
RUN mv /tmp/cosmos-sdk/proto/ibc /proto_includes/ibc
# remove cosmos repository
RUN rm -rf /tmp/cosmos-sdk
# switch to default dir
WORKDIR /src
CMD ["sh"]
2 changes: 1 addition & 1 deletion x/configuration/handler.go
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ func handleUpdateConfig(ctx sdk.Context, msg types.MsgUpdateConfig, k Keeper) (*
return nil, sdkerrors.Wrapf(sdkerrors.ErrUnauthorized, "%s is not allowed to update configuration", msg.Signer)
}
// if allowed update configuration
k.SetConfig(ctx, msg.NewConfiguration)
k.SetConfig(ctx, *msg.NewConfiguration)
// TODO emit event
return &sdk.Result{}, nil
}
52 changes: 0 additions & 52 deletions x/configuration/types/fees.go
Original file line number Diff line number Diff line change
Expand Up @@ -11,58 +11,6 @@ func NewFees() *Fees {
return &Fees{}
}

// Fees contains different type of fees
// to calculate coins to detract when
// processing different messages
type Fees struct {
// FeeCoinDenom defines the denominator of the coin used to process fees
FeeCoinDenom string `json:"fee_coin_denom"`
// FeeCoinPrice defines the price of the coin
FeeCoinPrice sdk.Dec `json:"fee_coin_price"`
// FeeDefault is the parameter defining the default fee
FeeDefault sdk.Dec `json:"fee_default"`
// account fees
// RegisterAccountClosed is the fee to be paid to register an account in a closed domain
RegisterAccountClosed sdk.Dec `json:"register_account_closed"`
// RegisterAccountOpen is the fee to be paid to register an account in an open domain
RegisterAccountOpen sdk.Dec `json:"register_account_open"`
// TransferAccountClosed is the fee to be paid to register an account in a closed domain
TransferAccountClosed sdk.Dec `json:"transfer_account_closed"`
// TransferAccountOpen is the fee to be paid to register an account in an open domain
TransferAccountOpen sdk.Dec `json:"transfer_account_open"`
// ReplaceAccountResources is the fee to be paid to replace account's resources
ReplaceAccountResources sdk.Dec `json:"replace_account_resources"`
// AddAccountCertificate is the fee to be paid to add a certificate to an account
AddAccountCertificate sdk.Dec `json:"add_account_certificate"`
// DelAccountCertificate is the feed to be paid to delete a certificate in an account
DelAccountCertificate sdk.Dec `json:"del_account_certificate"`
// SetAccountMetadata is the fee to be paid to set account's metadata
SetAccountMetadata sdk.Dec `json:"set_account_metadata"`
// domain fees
// Register domain
// RegisterDomain1 is the fee to be paid to register a domain with one character
RegisterDomain1 sdk.Dec `json:"register_domain_1"`
// RegisterDomain2 is the fee to be paid to register a domain with two characters
RegisterDomain2 sdk.Dec `json:"register_domain_2"`
// RegisterDomain3 is the fee to be paid to register a domain with three characters
RegisterDomain3 sdk.Dec `json:"register_domain_3"`
// RegisterDomain4 is the fee to be paid to register a domain with four characters
RegisterDomain4 sdk.Dec `json:"register_domain_4"`
// RegisterDomain5 is the fee to be paid to register a domain with five characters
RegisterDomain5 sdk.Dec `json:"register_domain_5"`
// RegisterDomainDefault is the fee to be paid to register a domain with more than five characters
RegisterDomainDefault sdk.Dec `json:"register_domain_default"`
// RegisterDomainMultiplier is the multiplication applied to fees in register domain operations if they're of open type
RegisterOpenDomainMultiplier sdk.Dec `json:"register_open_domain_multiplier"`
// TransferDomain
// TransferDomainClosed is the fee to be paid to transfer a closed domain
TransferDomainClosed sdk.Dec `json:"transfer_domain_closed"`
// TransferDomainOpen is the fee to be paid to transfer open domains
TransferDomainOpen sdk.Dec `json:"transfer_domain_open"`
// RenewDomainOpen is the fee to be paid to renew an open domain
RenewDomainOpen sdk.Dec `json:"renew_domain_open"`
}

// Validate validates the fee object
func (f *Fees) Validate() error {
if f == nil {
Expand Down
19 changes: 3 additions & 16 deletions x/configuration/types/msgs.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,15 +5,6 @@ import (
sdkerrors "github.com/cosmos/cosmos-sdk/types/errors"
)

// MsgUpdateConfig is used to update
// configuration using a multisig strategy
type MsgUpdateConfig struct {
// Signer is the address of the entity who is doing the transaction
Signer sdk.AccAddress
// NewConfiguration contains the new configuration data
NewConfiguration Config
}

var _ sdk.Msg = (*MsgUpdateConfig)(nil)

// Route implements sdk.Msg
Expand All @@ -24,6 +15,9 @@ func (m MsgUpdateConfig) Type() string { return "update_config" }

// ValidateBasic implements sdk.Msg
func (m MsgUpdateConfig) ValidateBasic() error {
if m.NewConfiguration == nil {
return sdkerrors.Wrap(sdkerrors.ErrInvalidRequest, "missing configuration")
}
if m.Signer.Empty() {
return sdkerrors.Wrapf(sdkerrors.ErrInvalidRequest, "no signer specified")
}
Expand All @@ -36,13 +30,6 @@ func (m MsgUpdateConfig) GetSignBytes() []byte { return sdk.MustSortJSON(ModuleC
// GetSigners implements sdk.Msg
func (m MsgUpdateConfig) GetSigners() []sdk.AccAddress { return []sdk.AccAddress{m.Signer} }

type MsgUpdateFees struct {
// Fees represent the new fees to apply
Fees *Fees
// Configurer is the address that is singing the message
Configurer sdk.AccAddress
}

// Route implements sdk.Msg
func (m MsgUpdateFees) Route() string {
return RouterKey
Expand Down
Loading