Skip to content

Commit e90fa16

Browse files
authored
Merge branch 'main' into julien/authtx
2 parents 194e401 + 2151427 commit e90fa16

File tree

38 files changed

+9238
-6960
lines changed

38 files changed

+9238
-6960
lines changed

cosmovisor/upgrade.go

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -33,8 +33,15 @@ func UpgradeBinary(logger *zerolog.Logger, cfg *Config, info upgradetypes.Plan)
3333
}
3434

3535
// if the dir is there already, don't download either
36-
if _, err := os.Stat(cfg.UpgradeDir(info.Name)); !os.IsNotExist(err) {
36+
switch fi, err := os.Stat(cfg.UpgradeDir(info.Name)); {
37+
case fi != nil: // The directory exists, do not overwrite.
3738
return errors.New("upgrade dir already exists, won't overwrite")
39+
40+
case os.IsNotExist(err): // In this case the directory doesn't exist, continue below.
41+
// Do nothing and we shall download the binary down below.
42+
43+
default: // Otherwise an unexpected error
44+
return fmt.Errorf("unhandled error: %w", err)
3845
}
3946

4047
// If not there, then we try to download it... maybe

docs/architecture/adr-050-sign-mode-textual-annex1.md

Lines changed: 30 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -218,12 +218,37 @@ as `2006-01-02T15:04:05.7Z`.
218218
The timestamp with 1136214245 seconds and zero nanoseconds is rendered
219219
as `2006-01-02T15:04:05Z`.
220220

221-
### `google.protobuf.Duration` (TODO)
221+
### `google.protobuf.Duration`
222222

223-
- 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)
224-
- total seconds values included at the end so users have both pieces of information
225-
- Ex:
226-
- `1483530 seconds` -> `2 weeks, 3 days, 4 hours, 5 minutes, 30 seconds (1483530 seconds total)`
223+
The duration proto expresses a raw number of seconds and nanoseconds.
224+
This will be rendered as longer time units of days, hours, and minutes,
225+
plus any remaining seconds, in that order.
226+
Leading and trailing zero-quantity units will be omitted, but all
227+
units in between nonzero units will be shown, e.g. ` 3 days, 0 hours, 0 minutes, 5 seconds`.
228+
229+
Even longer time units such as months or years are imprecise.
230+
Weeks are precise, but not commonly used - `91 days` is more immediately
231+
legible than `13 weeks`. Although `days` can be problematic,
232+
e.g. noon to noon on subsequent days can be 23 or 25 hours depending on
233+
daylight savings transitions, there is significant advantage in using
234+
strict 24-hour days over using only hours (e.g. `91 days` vs `2184 hours`).
235+
236+
When nanoseconds are nonzero, they will be shown as fractional seconds,
237+
with only the minimum number of digits, e.g `0.5 seconds`.
238+
239+
A duration of exactly zero is shown as `0 seconds`.
240+
241+
Units will be given as singular (no trailing `s`) when the quantity is exactly one,
242+
and will be shown in plural otherwise.
243+
244+
Negative durations will be indicated with a leading minus sign (`-`).
245+
246+
Examples:
247+
248+
- `1 day`
249+
- `30 days`
250+
- `-1 day, 12 hours`
251+
- `3 hours, 0 minutes, 53.025 seconds`
227252

228253
### bytes
229254

orm/Makefile

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,7 @@
11
codegen:
22
go install ./cmd/protoc-gen-go-cosmos-orm
3+
go install ./cmd/protoc-gen-go-cosmos-orm-proto
4+
# generate .proto files first
5+
(cd internal; buf generate --template buf.proto.gen.yaml)
6+
# generate go code
37
(cd internal; buf generate)
Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
package main
2+
3+
import (
4+
"google.golang.org/protobuf/compiler/protogen"
5+
6+
"github.com/cosmos/cosmos-sdk/orm/internal/codegen"
7+
)
8+
9+
func main() {
10+
protogen.Options{}.Run(codegen.QueryProtoPluginRunner)
11+
}

orm/cmd/protoc-gen-go-cosmos-orm/main.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,5 +7,5 @@ import (
77
)
88

99
func main() {
10-
protogen.Options{}.Run(codegen.PluginRunner)
10+
protogen.Options{}.Run(codegen.ORMPluginRunner)
1111
}

orm/internal/buf.gen.yaml

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,10 @@ managed:
66
override:
77
buf.build/cosmos/cosmos-sdk: cosmossdk.io/api
88
plugins:
9-
- name: go-pulsar
9+
- name: go
10+
out: .
11+
opt: paths=source_relative
12+
- name: go-grpc
1013
out: .
1114
opt: paths=source_relative
1215
- name: go-cosmos-orm

orm/internal/buf.proto.gen.yaml

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
version: v1
2+
managed:
3+
enabled: true
4+
go_package_prefix:
5+
default: github.com/cosmos/cosmos-sdk/orm/internal
6+
override:
7+
buf.build/cosmos/cosmos-sdk: cosmossdk.io/api
8+
plugins:
9+
- name: go-cosmos-orm-proto
10+
out: .
11+
opt: paths=source_relative

orm/internal/codegen/codegen.go

Lines changed: 36 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2,9 +2,11 @@ package codegen
22

33
import (
44
"fmt"
5+
"os"
56

67
"google.golang.org/protobuf/compiler/protogen"
78
"google.golang.org/protobuf/proto"
9+
"google.golang.org/protobuf/types/pluginpb"
810

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

20-
func PluginRunner(p *protogen.Plugin) error {
22+
func ORMPluginRunner(p *protogen.Plugin) error {
23+
p.SupportedFeatures = uint64(pluginpb.CodeGeneratorResponse_FEATURE_PROTO3_OPTIONAL)
2124
for _, f := range p.Files {
2225
if !f.Generate {
2326
continue
@@ -32,12 +35,42 @@ func PluginRunner(p *protogen.Plugin) error {
3235
GeneratedFile: gen,
3336
LocalPackages: map[string]bool{},
3437
}
35-
f := fileGen{GeneratedFile: cgen, file: f}
36-
err := f.gen()
38+
fgen := fileGen{GeneratedFile: cgen, file: f}
39+
err := fgen.gen()
40+
if err != nil {
41+
return err
42+
}
43+
}
44+
45+
return nil
46+
}
47+
48+
func QueryProtoPluginRunner(p *protogen.Plugin) error {
49+
p.SupportedFeatures = uint64(pluginpb.CodeGeneratorResponse_FEATURE_PROTO3_OPTIONAL)
50+
for _, f := range p.Files {
51+
if !f.Generate {
52+
continue
53+
}
54+
55+
if !hasTables(f) {
56+
continue
57+
}
58+
59+
out, err := os.OpenFile(fmt.Sprintf("%s_query.proto", f.GeneratedFilenamePrefix), os.O_RDWR|os.O_TRUNC|os.O_CREATE, 0644)
3760
if err != nil {
3861
return err
3962
}
4063

64+
err = queryProtoGen{
65+
File: f,
66+
svc: newWriter(),
67+
msgs: newWriter(),
68+
outFile: out,
69+
imports: map[string]bool{},
70+
}.gen()
71+
if err != nil {
72+
return err
73+
}
4174
}
4275

4376
return nil

orm/internal/codegen/file.go

Lines changed: 15 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -87,7 +87,11 @@ func (f fileGen) storeStructName() string {
8787
}
8888

8989
func (f fileGen) fileShortName() string {
90-
filename := f.file.Proto.GetName()
90+
return fileShortName(f.file)
91+
}
92+
93+
func fileShortName(file *protogen.File) string {
94+
filename := file.Proto.GetName()
9195
shortName := filepath.Base(filename)
9296
i := strings.Index(shortName, ".")
9397
if i > 0 {
@@ -155,11 +159,20 @@ func (f fileGen) genStoreConstructor(stores []*protogen.Message) {
155159
f.P("}")
156160
}
157161

158-
func (f fileGen) fieldsToCamelCase(fields string) string {
162+
func fieldsToCamelCase(fields string) string {
159163
splitFields := strings.Split(fields, ",")
160164
camelFields := make([]string, len(splitFields))
161165
for i, field := range splitFields {
162166
camelFields[i] = strcase.ToCamel(field)
163167
}
164168
return strings.Join(camelFields, "")
165169
}
170+
171+
func fieldsToSnakeCase(fields string) string {
172+
splitFields := strings.Split(fields, ",")
173+
camelFields := make([]string, len(splitFields))
174+
for i, field := range splitFields {
175+
camelFields[i] = strcase.ToSnake(field)
176+
}
177+
return strings.Join(camelFields, "_")
178+
}

0 commit comments

Comments
 (0)