Skip to content

Commit

Permalink
Merge branch 'main' into julien/authtx
Browse files Browse the repository at this point in the history
  • Loading branch information
julienrbrt authored Oct 7, 2022
2 parents 194e401 + 2151427 commit e90fa16
Show file tree
Hide file tree
Showing 38 changed files with 9,238 additions and 6,960 deletions.
9 changes: 8 additions & 1 deletion cosmovisor/upgrade.go
Original file line number Diff line number Diff line change
Expand Up @@ -33,8 +33,15 @@ func UpgradeBinary(logger *zerolog.Logger, cfg *Config, info upgradetypes.Plan)
}

// if the dir is there already, don't download either
if _, err := os.Stat(cfg.UpgradeDir(info.Name)); !os.IsNotExist(err) {
switch fi, err := os.Stat(cfg.UpgradeDir(info.Name)); {
case fi != nil: // The directory exists, do not overwrite.
return errors.New("upgrade dir already exists, won't overwrite")

case os.IsNotExist(err): // In this case the directory doesn't exist, continue below.
// Do nothing and we shall download the binary down below.

default: // Otherwise an unexpected error
return fmt.Errorf("unhandled error: %w", err)
}

// If not there, then we try to download it... maybe
Expand Down
35 changes: 30 additions & 5 deletions docs/architecture/adr-050-sign-mode-textual-annex1.md
Original file line number Diff line number Diff line change
Expand Up @@ -218,12 +218,37 @@ as `2006-01-02T15:04:05.7Z`.
The timestamp with 1136214245 seconds and zero nanoseconds is rendered
as `2006-01-02T15:04:05Z`.

### `google.protobuf.Duration` (TODO)
### `google.protobuf.Duration`

- rendered in terms of weeks, days, hours, minutes and seconds as these time units can be measured independently of any calendar and duration values are in seconds (so months and years can't be used precisely)
- total seconds values included at the end so users have both pieces of information
- Ex:
- `1483530 seconds` -> `2 weeks, 3 days, 4 hours, 5 minutes, 30 seconds (1483530 seconds total)`
The duration proto expresses a raw number of seconds and nanoseconds.
This will be rendered as longer time units of days, hours, and minutes,
plus any remaining seconds, in that order.
Leading and trailing zero-quantity units will be omitted, but all
units in between nonzero units will be shown, e.g. ` 3 days, 0 hours, 0 minutes, 5 seconds`.

Even longer time units such as months or years are imprecise.
Weeks are precise, but not commonly used - `91 days` is more immediately
legible than `13 weeks`. Although `days` can be problematic,
e.g. noon to noon on subsequent days can be 23 or 25 hours depending on
daylight savings transitions, there is significant advantage in using
strict 24-hour days over using only hours (e.g. `91 days` vs `2184 hours`).

When nanoseconds are nonzero, they will be shown as fractional seconds,
with only the minimum number of digits, e.g `0.5 seconds`.

A duration of exactly zero is shown as `0 seconds`.

Units will be given as singular (no trailing `s`) when the quantity is exactly one,
and will be shown in plural otherwise.

Negative durations will be indicated with a leading minus sign (`-`).

Examples:

- `1 day`
- `30 days`
- `-1 day, 12 hours`
- `3 hours, 0 minutes, 53.025 seconds`

### bytes

Expand Down
4 changes: 4 additions & 0 deletions orm/Makefile
Original file line number Diff line number Diff line change
@@ -1,3 +1,7 @@
codegen:
go install ./cmd/protoc-gen-go-cosmos-orm
go install ./cmd/protoc-gen-go-cosmos-orm-proto
# generate .proto files first
(cd internal; buf generate --template buf.proto.gen.yaml)
# generate go code
(cd internal; buf generate)
11 changes: 11 additions & 0 deletions orm/cmd/protoc-gen-go-cosmos-orm-proto/main.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
package main

import (
"google.golang.org/protobuf/compiler/protogen"

"github.com/cosmos/cosmos-sdk/orm/internal/codegen"
)

func main() {
protogen.Options{}.Run(codegen.QueryProtoPluginRunner)
}
2 changes: 1 addition & 1 deletion orm/cmd/protoc-gen-go-cosmos-orm/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,5 +7,5 @@ import (
)

func main() {
protogen.Options{}.Run(codegen.PluginRunner)
protogen.Options{}.Run(codegen.ORMPluginRunner)
}
5 changes: 4 additions & 1 deletion orm/internal/buf.gen.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,10 @@ managed:
override:
buf.build/cosmos/cosmos-sdk: cosmossdk.io/api
plugins:
- name: go-pulsar
- name: go
out: .
opt: paths=source_relative
- name: go-grpc
out: .
opt: paths=source_relative
- name: go-cosmos-orm
Expand Down
11 changes: 11 additions & 0 deletions orm/internal/buf.proto.gen.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
version: v1
managed:
enabled: true
go_package_prefix:
default: github.com/cosmos/cosmos-sdk/orm/internal
override:
buf.build/cosmos/cosmos-sdk: cosmossdk.io/api
plugins:
- name: go-cosmos-orm-proto
out: .
opt: paths=source_relative
39 changes: 36 additions & 3 deletions orm/internal/codegen/codegen.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,11 @@ package codegen

import (
"fmt"
"os"

"google.golang.org/protobuf/compiler/protogen"
"google.golang.org/protobuf/proto"
"google.golang.org/protobuf/types/pluginpb"

ormv1 "cosmossdk.io/api/cosmos/orm/v1"
"github.com/cosmos/cosmos-proto/generator"
Expand All @@ -17,7 +19,8 @@ const (
ormTablePkg = protogen.GoImportPath("github.com/cosmos/cosmos-sdk/orm/model/ormtable")
)

func PluginRunner(p *protogen.Plugin) error {
func ORMPluginRunner(p *protogen.Plugin) error {
p.SupportedFeatures = uint64(pluginpb.CodeGeneratorResponse_FEATURE_PROTO3_OPTIONAL)
for _, f := range p.Files {
if !f.Generate {
continue
Expand All @@ -32,12 +35,42 @@ func PluginRunner(p *protogen.Plugin) error {
GeneratedFile: gen,
LocalPackages: map[string]bool{},
}
f := fileGen{GeneratedFile: cgen, file: f}
err := f.gen()
fgen := fileGen{GeneratedFile: cgen, file: f}
err := fgen.gen()
if err != nil {
return err
}
}

return nil
}

func QueryProtoPluginRunner(p *protogen.Plugin) error {
p.SupportedFeatures = uint64(pluginpb.CodeGeneratorResponse_FEATURE_PROTO3_OPTIONAL)
for _, f := range p.Files {
if !f.Generate {
continue
}

if !hasTables(f) {
continue
}

out, err := os.OpenFile(fmt.Sprintf("%s_query.proto", f.GeneratedFilenamePrefix), os.O_RDWR|os.O_TRUNC|os.O_CREATE, 0644)
if err != nil {
return err
}

err = queryProtoGen{
File: f,
svc: newWriter(),
msgs: newWriter(),
outFile: out,
imports: map[string]bool{},
}.gen()
if err != nil {
return err
}
}

return nil
Expand Down
17 changes: 15 additions & 2 deletions orm/internal/codegen/file.go
Original file line number Diff line number Diff line change
Expand Up @@ -87,7 +87,11 @@ func (f fileGen) storeStructName() string {
}

func (f fileGen) fileShortName() string {
filename := f.file.Proto.GetName()
return fileShortName(f.file)
}

func fileShortName(file *protogen.File) string {
filename := file.Proto.GetName()
shortName := filepath.Base(filename)
i := strings.Index(shortName, ".")
if i > 0 {
Expand Down Expand Up @@ -155,11 +159,20 @@ func (f fileGen) genStoreConstructor(stores []*protogen.Message) {
f.P("}")
}

func (f fileGen) fieldsToCamelCase(fields string) string {
func fieldsToCamelCase(fields string) string {
splitFields := strings.Split(fields, ",")
camelFields := make([]string, len(splitFields))
for i, field := range splitFields {
camelFields[i] = strcase.ToCamel(field)
}
return strings.Join(camelFields, "")
}

func fieldsToSnakeCase(fields string) string {
splitFields := strings.Split(fields, ",")
camelFields := make([]string, len(splitFields))
for i, field := range splitFields {
camelFields[i] = strcase.ToSnake(field)
}
return strings.Join(camelFields, "_")
}
Loading

0 comments on commit e90fa16

Please sign in to comment.