From f6150bd4afa5cb752d33807e5ec064cf82fcda5e Mon Sep 17 00:00:00 2001 From: Tyler <48813565+technicallyty@users.noreply.github.com> Date: Fri, 13 May 2022 14:47:55 -0700 Subject: [PATCH 1/5] refactor(ORM)!: InsertReturningID -> InsertReturning (#11659) ## Description - changes the generated function signature for InsertReturningID to InsertReturning[AutoIncrement Field Name] Closes: #11655 --- ### Author Checklist *All items are required. Please add a note to the item if the item is not applicable and please add links to any relevant follow up issues.* I have... - [ ] included the correct [type prefix](https://github.com/commitizen/conventional-commit-types/blob/v3.0.0/index.json) in the PR title - [ ] added `!` to the type prefix if API or client breaking change - [ ] targeted the correct branch (see [PR Targeting](https://github.com/cosmos/cosmos-sdk/blob/master/CONTRIBUTING.md#pr-targeting)) - [ ] provided a link to the relevant issue or specification - [ ] followed the guidelines for [building modules](https://github.com/cosmos/cosmos-sdk/blob/master/docs/building-modules) - [ ] included the necessary unit and integration [tests](https://github.com/cosmos/cosmos-sdk/blob/master/CONTRIBUTING.md#testing) - [ ] added a changelog entry to `CHANGELOG.md` - [ ] included comments for [documenting Go code](https://blog.golang.org/godoc) - [ ] updated the relevant documentation or specification - [ ] reviewed "Files changed" and left comments if necessary - [ ] confirmed all CI checks have passed ### Reviewers Checklist *All items are required. Please add a note if the item is not applicable and please add your handle next to the items reviewed if you only reviewed selected items.* I have... - [ ] confirmed the correct [type prefix](https://github.com/commitizen/conventional-commit-types/blob/v3.0.0/index.json) in the PR title - [ ] confirmed `!` in the type prefix if API or client breaking change - [ ] confirmed all author checklist items have been addressed - [ ] reviewed state machine logic - [ ] reviewed API design and naming - [ ] reviewed documentation is accurate - [ ] reviewed tests and test coverage - [ ] manually tested (if applicable) --- orm/internal/codegen/table.go | 6 +- orm/internal/testpb/test_schema.cosmos_orm.go | 143 ++++- orm/internal/testpb/test_schema.proto | 10 + orm/internal/testpb/test_schema.pulsar.go | 588 ++++++++++++++++-- orm/model/ormtable/auto_increment.go | 38 +- orm/model/ormtable/auto_increment_test.go | 6 +- orm/model/ormtable/table.go | 6 +- orm/model/ormtable/table_test.go | 16 + 8 files changed, 743 insertions(+), 70 deletions(-) diff --git a/orm/internal/codegen/table.go b/orm/internal/codegen/table.go index ae50ce702be5..ed03ac5eb55a 100644 --- a/orm/internal/codegen/table.go +++ b/orm/internal/codegen/table.go @@ -61,7 +61,7 @@ func (t tableGen) getTableInterface() { t.P("type ", t.messageTableInterfaceName(t.msg), " interface {") t.P("Insert(ctx ", contextPkg.Ident("Context"), ", ", t.param(t.msg.GoIdent.GoName), " *", t.QualifiedGoIdent(t.msg.GoIdent), ") error") if t.table.PrimaryKey.AutoIncrement { - t.P("InsertReturningID(ctx ", contextPkg.Ident("Context"), ", ", t.param(t.msg.GoIdent.GoName), " *", t.QualifiedGoIdent(t.msg.GoIdent), ") (uint64, error)") + t.P("InsertReturning", t.fieldsToCamelCase(t.table.PrimaryKey.Fields), "(ctx ", contextPkg.Ident("Context"), ", ", t.param(t.msg.GoIdent.GoName), " *", t.QualifiedGoIdent(t.msg.GoIdent), ") (uint64, error)") } t.P("Update(ctx ", contextPkg.Ident("Context"), ", ", t.param(t.msg.GoIdent.GoName), " *", t.QualifiedGoIdent(t.msg.GoIdent), ") error") t.P("Save(ctx ", contextPkg.Ident("Context"), ", ", t.param(t.msg.GoIdent.GoName), " *", t.QualifiedGoIdent(t.msg.GoIdent), ") error") @@ -180,8 +180,8 @@ func (t tableGen) genTableImpl() { } if t.table.PrimaryKey.AutoIncrement { - t.P(receiver, "InsertReturningID(ctx ", contextPkg.Ident("Context"), ", ", varName, " *", varTypeName, ") (uint64, error) {") - t.P("return ", receiverVar, ".table.InsertReturningID(ctx, ", varName, ")") + t.P(receiver, "InsertReturning", t.fieldsToCamelCase(t.table.PrimaryKey.Fields), "(ctx ", contextPkg.Ident("Context"), ", ", varName, " *", varTypeName, ") (uint64, error) {") + t.P("return ", receiverVar, ".table.InsertReturningPKey(ctx, ", varName, ")") t.P("}") t.P() } diff --git a/orm/internal/testpb/test_schema.cosmos_orm.go b/orm/internal/testpb/test_schema.cosmos_orm.go index 5f62658a0778..a5cf2a6fbd11 100644 --- a/orm/internal/testpb/test_schema.cosmos_orm.go +++ b/orm/internal/testpb/test_schema.cosmos_orm.go @@ -215,7 +215,7 @@ func NewExampleTableTable(db ormtable.Schema) (ExampleTableTable, error) { type ExampleAutoIncrementTableTable interface { Insert(ctx context.Context, exampleAutoIncrementTable *ExampleAutoIncrementTable) error - InsertReturningID(ctx context.Context, exampleAutoIncrementTable *ExampleAutoIncrementTable) (uint64, error) + InsertReturningId(ctx context.Context, exampleAutoIncrementTable *ExampleAutoIncrementTable) (uint64, error) Update(ctx context.Context, exampleAutoIncrementTable *ExampleAutoIncrementTable) error Save(ctx context.Context, exampleAutoIncrementTable *ExampleAutoIncrementTable) error Delete(ctx context.Context, exampleAutoIncrementTable *ExampleAutoIncrementTable) error @@ -298,8 +298,8 @@ func (this exampleAutoIncrementTableTable) Delete(ctx context.Context, exampleAu return this.table.Delete(ctx, exampleAutoIncrementTable) } -func (this exampleAutoIncrementTableTable) InsertReturningID(ctx context.Context, exampleAutoIncrementTable *ExampleAutoIncrementTable) (uint64, error) { - return this.table.InsertReturningID(ctx, exampleAutoIncrementTable) +func (this exampleAutoIncrementTableTable) InsertReturningId(ctx context.Context, exampleAutoIncrementTable *ExampleAutoIncrementTable) (uint64, error) { + return this.table.InsertReturningPKey(ctx, exampleAutoIncrementTable) } func (this exampleAutoIncrementTableTable) Has(ctx context.Context, id uint64) (found bool, err error) { @@ -400,7 +400,7 @@ func NewExampleSingletonTable(db ormtable.Schema) (ExampleSingletonTable, error) type ExampleTimestampTable interface { Insert(ctx context.Context, exampleTimestamp *ExampleTimestamp) error - InsertReturningID(ctx context.Context, exampleTimestamp *ExampleTimestamp) (uint64, error) + InsertReturningId(ctx context.Context, exampleTimestamp *ExampleTimestamp) (uint64, error) Update(ctx context.Context, exampleTimestamp *ExampleTimestamp) error Save(ctx context.Context, exampleTimestamp *ExampleTimestamp) error Delete(ctx context.Context, exampleTimestamp *ExampleTimestamp) error @@ -480,8 +480,8 @@ func (this exampleTimestampTable) Delete(ctx context.Context, exampleTimestamp * return this.table.Delete(ctx, exampleTimestamp) } -func (this exampleTimestampTable) InsertReturningID(ctx context.Context, exampleTimestamp *ExampleTimestamp) (uint64, error) { - return this.table.InsertReturningID(ctx, exampleTimestamp) +func (this exampleTimestampTable) InsertReturningId(ctx context.Context, exampleTimestamp *ExampleTimestamp) (uint64, error) { + return this.table.InsertReturningPKey(ctx, exampleTimestamp) } func (this exampleTimestampTable) Has(ctx context.Context, id uint64) (found bool, err error) { @@ -680,12 +680,132 @@ func NewSimpleExampleTable(db ormtable.Schema) (SimpleExampleTable, error) { return simpleExampleTable{table}, nil } +type ExampleAutoIncFieldNameTable interface { + Insert(ctx context.Context, exampleAutoIncFieldName *ExampleAutoIncFieldName) error + InsertReturningFoo(ctx context.Context, exampleAutoIncFieldName *ExampleAutoIncFieldName) (uint64, error) + Update(ctx context.Context, exampleAutoIncFieldName *ExampleAutoIncFieldName) error + Save(ctx context.Context, exampleAutoIncFieldName *ExampleAutoIncFieldName) error + Delete(ctx context.Context, exampleAutoIncFieldName *ExampleAutoIncFieldName) error + Has(ctx context.Context, foo uint64) (found bool, err error) + // Get returns nil and an error which responds true to ormerrors.IsNotFound() if the record was not found. + Get(ctx context.Context, foo uint64) (*ExampleAutoIncFieldName, error) + List(ctx context.Context, prefixKey ExampleAutoIncFieldNameIndexKey, opts ...ormlist.Option) (ExampleAutoIncFieldNameIterator, error) + ListRange(ctx context.Context, from, to ExampleAutoIncFieldNameIndexKey, opts ...ormlist.Option) (ExampleAutoIncFieldNameIterator, error) + DeleteBy(ctx context.Context, prefixKey ExampleAutoIncFieldNameIndexKey) error + DeleteRange(ctx context.Context, from, to ExampleAutoIncFieldNameIndexKey) error + + doNotImplement() +} + +type ExampleAutoIncFieldNameIterator struct { + ormtable.Iterator +} + +func (i ExampleAutoIncFieldNameIterator) Value() (*ExampleAutoIncFieldName, error) { + var exampleAutoIncFieldName ExampleAutoIncFieldName + err := i.UnmarshalMessage(&exampleAutoIncFieldName) + return &exampleAutoIncFieldName, err +} + +type ExampleAutoIncFieldNameIndexKey interface { + id() uint32 + values() []interface{} + exampleAutoIncFieldNameIndexKey() +} + +// primary key starting index.. +type ExampleAutoIncFieldNamePrimaryKey = ExampleAutoIncFieldNameFooIndexKey + +type ExampleAutoIncFieldNameFooIndexKey struct { + vs []interface{} +} + +func (x ExampleAutoIncFieldNameFooIndexKey) id() uint32 { return 0 } +func (x ExampleAutoIncFieldNameFooIndexKey) values() []interface{} { return x.vs } +func (x ExampleAutoIncFieldNameFooIndexKey) exampleAutoIncFieldNameIndexKey() {} + +func (this ExampleAutoIncFieldNameFooIndexKey) WithFoo(foo uint64) ExampleAutoIncFieldNameFooIndexKey { + this.vs = []interface{}{foo} + return this +} + +type exampleAutoIncFieldNameTable struct { + table ormtable.AutoIncrementTable +} + +func (this exampleAutoIncFieldNameTable) Insert(ctx context.Context, exampleAutoIncFieldName *ExampleAutoIncFieldName) error { + return this.table.Insert(ctx, exampleAutoIncFieldName) +} + +func (this exampleAutoIncFieldNameTable) Update(ctx context.Context, exampleAutoIncFieldName *ExampleAutoIncFieldName) error { + return this.table.Update(ctx, exampleAutoIncFieldName) +} + +func (this exampleAutoIncFieldNameTable) Save(ctx context.Context, exampleAutoIncFieldName *ExampleAutoIncFieldName) error { + return this.table.Save(ctx, exampleAutoIncFieldName) +} + +func (this exampleAutoIncFieldNameTable) Delete(ctx context.Context, exampleAutoIncFieldName *ExampleAutoIncFieldName) error { + return this.table.Delete(ctx, exampleAutoIncFieldName) +} + +func (this exampleAutoIncFieldNameTable) InsertReturningFoo(ctx context.Context, exampleAutoIncFieldName *ExampleAutoIncFieldName) (uint64, error) { + return this.table.InsertReturningPKey(ctx, exampleAutoIncFieldName) +} + +func (this exampleAutoIncFieldNameTable) Has(ctx context.Context, foo uint64) (found bool, err error) { + return this.table.PrimaryKey().Has(ctx, foo) +} + +func (this exampleAutoIncFieldNameTable) Get(ctx context.Context, foo uint64) (*ExampleAutoIncFieldName, error) { + var exampleAutoIncFieldName ExampleAutoIncFieldName + found, err := this.table.PrimaryKey().Get(ctx, &exampleAutoIncFieldName, foo) + if err != nil { + return nil, err + } + if !found { + return nil, ormerrors.NotFound + } + return &exampleAutoIncFieldName, nil +} + +func (this exampleAutoIncFieldNameTable) List(ctx context.Context, prefixKey ExampleAutoIncFieldNameIndexKey, opts ...ormlist.Option) (ExampleAutoIncFieldNameIterator, error) { + it, err := this.table.GetIndexByID(prefixKey.id()).List(ctx, prefixKey.values(), opts...) + return ExampleAutoIncFieldNameIterator{it}, err +} + +func (this exampleAutoIncFieldNameTable) ListRange(ctx context.Context, from, to ExampleAutoIncFieldNameIndexKey, opts ...ormlist.Option) (ExampleAutoIncFieldNameIterator, error) { + it, err := this.table.GetIndexByID(from.id()).ListRange(ctx, from.values(), to.values(), opts...) + return ExampleAutoIncFieldNameIterator{it}, err +} + +func (this exampleAutoIncFieldNameTable) DeleteBy(ctx context.Context, prefixKey ExampleAutoIncFieldNameIndexKey) error { + return this.table.GetIndexByID(prefixKey.id()).DeleteBy(ctx, prefixKey.values()...) +} + +func (this exampleAutoIncFieldNameTable) DeleteRange(ctx context.Context, from, to ExampleAutoIncFieldNameIndexKey) error { + return this.table.GetIndexByID(from.id()).DeleteRange(ctx, from.values(), to.values()) +} + +func (this exampleAutoIncFieldNameTable) doNotImplement() {} + +var _ ExampleAutoIncFieldNameTable = exampleAutoIncFieldNameTable{} + +func NewExampleAutoIncFieldNameTable(db ormtable.Schema) (ExampleAutoIncFieldNameTable, error) { + table := db.GetTable(&ExampleAutoIncFieldName{}) + if table == nil { + return nil, ormerrors.TableNotFound.Wrap(string((&ExampleAutoIncFieldName{}).ProtoReflect().Descriptor().FullName())) + } + return exampleAutoIncFieldNameTable{table.(ormtable.AutoIncrementTable)}, nil +} + type TestSchemaStore interface { ExampleTableTable() ExampleTableTable ExampleAutoIncrementTableTable() ExampleAutoIncrementTableTable ExampleSingletonTable() ExampleSingletonTable ExampleTimestampTable() ExampleTimestampTable SimpleExampleTable() SimpleExampleTable + ExampleAutoIncFieldNameTable() ExampleAutoIncFieldNameTable doNotImplement() } @@ -696,6 +816,7 @@ type testSchemaStore struct { exampleSingleton ExampleSingletonTable exampleTimestamp ExampleTimestampTable simpleExample SimpleExampleTable + exampleAutoIncFieldName ExampleAutoIncFieldNameTable } func (x testSchemaStore) ExampleTableTable() ExampleTableTable { @@ -718,6 +839,10 @@ func (x testSchemaStore) SimpleExampleTable() SimpleExampleTable { return x.simpleExample } +func (x testSchemaStore) ExampleAutoIncFieldNameTable() ExampleAutoIncFieldNameTable { + return x.exampleAutoIncFieldName +} + func (testSchemaStore) doNotImplement() {} var _ TestSchemaStore = testSchemaStore{} @@ -748,11 +873,17 @@ func NewTestSchemaStore(db ormtable.Schema) (TestSchemaStore, error) { return nil, err } + exampleAutoIncFieldNameTable, err := NewExampleAutoIncFieldNameTable(db) + if err != nil { + return nil, err + } + return testSchemaStore{ exampleTableTable, exampleAutoIncrementTableTable, exampleSingletonTable, exampleTimestampTable, simpleExampleTable, + exampleAutoIncFieldNameTable, }, nil } diff --git a/orm/internal/testpb/test_schema.proto b/orm/internal/testpb/test_schema.proto index 0fe4167c625d..ca2137531cf8 100644 --- a/orm/internal/testpb/test_schema.proto +++ b/orm/internal/testpb/test_schema.proto @@ -115,4 +115,14 @@ message SimpleExample { string name = 1; string unique = 2; string not_unique = 3; +} + +// ExampleAutoIncFieldName is a table for testing InsertReturning. +message ExampleAutoIncFieldName { + option (cosmos.orm.v1.table) = { + id: 6 + primary_key: {fields: "foo" auto_increment: true} + }; + uint64 foo = 1; + uint64 bar = 2; } \ No newline at end of file diff --git a/orm/internal/testpb/test_schema.pulsar.go b/orm/internal/testpb/test_schema.pulsar.go index d69e8bb1b450..25719593c075 100644 --- a/orm/internal/testpb/test_schema.pulsar.go +++ b/orm/internal/testpb/test_schema.pulsar.go @@ -1872,7 +1872,7 @@ func (x *ExampleTable_ExampleMessage) ProtoReflect() protoreflect.Message { } func (x *ExampleTable_ExampleMessage) slowProtoReflect() protoreflect.Message { - mi := &file_testpb_test_schema_proto_msgTypes[6] + mi := &file_testpb_test_schema_proto_msgTypes[7] if protoimpl.UnsafeEnabled && x != nil { ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x)) if ms.LoadMessageInfo() == nil { @@ -4397,6 +4397,458 @@ func (x *fastReflection_SimpleExample) ProtoMethods() *protoiface.Methods { } } +var ( + md_ExampleAutoIncFieldName protoreflect.MessageDescriptor + fd_ExampleAutoIncFieldName_foo protoreflect.FieldDescriptor + fd_ExampleAutoIncFieldName_bar protoreflect.FieldDescriptor +) + +func init() { + file_testpb_test_schema_proto_init() + md_ExampleAutoIncFieldName = File_testpb_test_schema_proto.Messages().ByName("ExampleAutoIncFieldName") + fd_ExampleAutoIncFieldName_foo = md_ExampleAutoIncFieldName.Fields().ByName("foo") + fd_ExampleAutoIncFieldName_bar = md_ExampleAutoIncFieldName.Fields().ByName("bar") +} + +var _ protoreflect.Message = (*fastReflection_ExampleAutoIncFieldName)(nil) + +type fastReflection_ExampleAutoIncFieldName ExampleAutoIncFieldName + +func (x *ExampleAutoIncFieldName) ProtoReflect() protoreflect.Message { + return (*fastReflection_ExampleAutoIncFieldName)(x) +} + +func (x *ExampleAutoIncFieldName) slowProtoReflect() protoreflect.Message { + mi := &file_testpb_test_schema_proto_msgTypes[5] + if protoimpl.UnsafeEnabled && x != nil { + ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x)) + if ms.LoadMessageInfo() == nil { + ms.StoreMessageInfo(mi) + } + return ms + } + return mi.MessageOf(x) +} + +var _fastReflection_ExampleAutoIncFieldName_messageType fastReflection_ExampleAutoIncFieldName_messageType +var _ protoreflect.MessageType = fastReflection_ExampleAutoIncFieldName_messageType{} + +type fastReflection_ExampleAutoIncFieldName_messageType struct{} + +func (x fastReflection_ExampleAutoIncFieldName_messageType) Zero() protoreflect.Message { + return (*fastReflection_ExampleAutoIncFieldName)(nil) +} +func (x fastReflection_ExampleAutoIncFieldName_messageType) New() protoreflect.Message { + return new(fastReflection_ExampleAutoIncFieldName) +} +func (x fastReflection_ExampleAutoIncFieldName_messageType) Descriptor() protoreflect.MessageDescriptor { + return md_ExampleAutoIncFieldName +} + +// Descriptor returns message descriptor, which contains only the protobuf +// type information for the message. +func (x *fastReflection_ExampleAutoIncFieldName) Descriptor() protoreflect.MessageDescriptor { + return md_ExampleAutoIncFieldName +} + +// Type returns the message type, which encapsulates both Go and protobuf +// type information. If the Go type information is not needed, +// it is recommended that the message descriptor be used instead. +func (x *fastReflection_ExampleAutoIncFieldName) Type() protoreflect.MessageType { + return _fastReflection_ExampleAutoIncFieldName_messageType +} + +// New returns a newly allocated and mutable empty message. +func (x *fastReflection_ExampleAutoIncFieldName) New() protoreflect.Message { + return new(fastReflection_ExampleAutoIncFieldName) +} + +// Interface unwraps the message reflection interface and +// returns the underlying ProtoMessage interface. +func (x *fastReflection_ExampleAutoIncFieldName) Interface() protoreflect.ProtoMessage { + return (*ExampleAutoIncFieldName)(x) +} + +// Range iterates over every populated field in an undefined order, +// calling f for each field descriptor and value encountered. +// Range returns immediately if f returns false. +// While iterating, mutating operations may only be performed +// on the current field descriptor. +func (x *fastReflection_ExampleAutoIncFieldName) Range(f func(protoreflect.FieldDescriptor, protoreflect.Value) bool) { + if x.Foo != uint64(0) { + value := protoreflect.ValueOfUint64(x.Foo) + if !f(fd_ExampleAutoIncFieldName_foo, value) { + return + } + } + if x.Bar != uint64(0) { + value := protoreflect.ValueOfUint64(x.Bar) + if !f(fd_ExampleAutoIncFieldName_bar, value) { + return + } + } +} + +// Has reports whether a field is populated. +// +// Some fields have the property of nullability where it is possible to +// distinguish between the default value of a field and whether the field +// was explicitly populated with the default value. Singular message fields, +// member fields of a oneof, and proto2 scalar fields are nullable. Such +// fields are populated only if explicitly set. +// +// In other cases (aside from the nullable cases above), +// a proto3 scalar field is populated if it contains a non-zero value, and +// a repeated field is populated if it is non-empty. +func (x *fastReflection_ExampleAutoIncFieldName) Has(fd protoreflect.FieldDescriptor) bool { + switch fd.FullName() { + case "testpb.ExampleAutoIncFieldName.foo": + return x.Foo != uint64(0) + case "testpb.ExampleAutoIncFieldName.bar": + return x.Bar != uint64(0) + default: + if fd.IsExtension() { + panic(fmt.Errorf("proto3 declared messages do not support extensions: testpb.ExampleAutoIncFieldName")) + } + panic(fmt.Errorf("message testpb.ExampleAutoIncFieldName does not contain field %s", fd.FullName())) + } +} + +// Clear clears the field such that a subsequent Has call reports false. +// +// Clearing an extension field clears both the extension type and value +// associated with the given field number. +// +// Clear is a mutating operation and unsafe for concurrent use. +func (x *fastReflection_ExampleAutoIncFieldName) Clear(fd protoreflect.FieldDescriptor) { + switch fd.FullName() { + case "testpb.ExampleAutoIncFieldName.foo": + x.Foo = uint64(0) + case "testpb.ExampleAutoIncFieldName.bar": + x.Bar = uint64(0) + default: + if fd.IsExtension() { + panic(fmt.Errorf("proto3 declared messages do not support extensions: testpb.ExampleAutoIncFieldName")) + } + panic(fmt.Errorf("message testpb.ExampleAutoIncFieldName does not contain field %s", fd.FullName())) + } +} + +// Get retrieves the value for a field. +// +// For unpopulated scalars, it returns the default value, where +// the default value of a bytes scalar is guaranteed to be a copy. +// For unpopulated composite types, it returns an empty, read-only view +// of the value; to obtain a mutable reference, use Mutable. +func (x *fastReflection_ExampleAutoIncFieldName) Get(descriptor protoreflect.FieldDescriptor) protoreflect.Value { + switch descriptor.FullName() { + case "testpb.ExampleAutoIncFieldName.foo": + value := x.Foo + return protoreflect.ValueOfUint64(value) + case "testpb.ExampleAutoIncFieldName.bar": + value := x.Bar + return protoreflect.ValueOfUint64(value) + default: + if descriptor.IsExtension() { + panic(fmt.Errorf("proto3 declared messages do not support extensions: testpb.ExampleAutoIncFieldName")) + } + panic(fmt.Errorf("message testpb.ExampleAutoIncFieldName does not contain field %s", descriptor.FullName())) + } +} + +// Set stores the value for a field. +// +// For a field belonging to a oneof, it implicitly clears any other field +// that may be currently set within the same oneof. +// For extension fields, it implicitly stores the provided ExtensionType. +// When setting a composite type, it is unspecified whether the stored value +// aliases the source's memory in any way. If the composite value is an +// empty, read-only value, then it panics. +// +// Set is a mutating operation and unsafe for concurrent use. +func (x *fastReflection_ExampleAutoIncFieldName) Set(fd protoreflect.FieldDescriptor, value protoreflect.Value) { + switch fd.FullName() { + case "testpb.ExampleAutoIncFieldName.foo": + x.Foo = value.Uint() + case "testpb.ExampleAutoIncFieldName.bar": + x.Bar = value.Uint() + default: + if fd.IsExtension() { + panic(fmt.Errorf("proto3 declared messages do not support extensions: testpb.ExampleAutoIncFieldName")) + } + panic(fmt.Errorf("message testpb.ExampleAutoIncFieldName does not contain field %s", fd.FullName())) + } +} + +// Mutable returns a mutable reference to a composite type. +// +// If the field is unpopulated, it may allocate a composite value. +// For a field belonging to a oneof, it implicitly clears any other field +// that may be currently set within the same oneof. +// For extension fields, it implicitly stores the provided ExtensionType +// if not already stored. +// It panics if the field does not contain a composite type. +// +// Mutable is a mutating operation and unsafe for concurrent use. +func (x *fastReflection_ExampleAutoIncFieldName) Mutable(fd protoreflect.FieldDescriptor) protoreflect.Value { + switch fd.FullName() { + case "testpb.ExampleAutoIncFieldName.foo": + panic(fmt.Errorf("field foo of message testpb.ExampleAutoIncFieldName is not mutable")) + case "testpb.ExampleAutoIncFieldName.bar": + panic(fmt.Errorf("field bar of message testpb.ExampleAutoIncFieldName is not mutable")) + default: + if fd.IsExtension() { + panic(fmt.Errorf("proto3 declared messages do not support extensions: testpb.ExampleAutoIncFieldName")) + } + panic(fmt.Errorf("message testpb.ExampleAutoIncFieldName does not contain field %s", fd.FullName())) + } +} + +// NewField returns a new value that is assignable to the field +// for the given descriptor. For scalars, this returns the default value. +// For lists, maps, and messages, this returns a new, empty, mutable value. +func (x *fastReflection_ExampleAutoIncFieldName) NewField(fd protoreflect.FieldDescriptor) protoreflect.Value { + switch fd.FullName() { + case "testpb.ExampleAutoIncFieldName.foo": + return protoreflect.ValueOfUint64(uint64(0)) + case "testpb.ExampleAutoIncFieldName.bar": + return protoreflect.ValueOfUint64(uint64(0)) + default: + if fd.IsExtension() { + panic(fmt.Errorf("proto3 declared messages do not support extensions: testpb.ExampleAutoIncFieldName")) + } + panic(fmt.Errorf("message testpb.ExampleAutoIncFieldName does not contain field %s", fd.FullName())) + } +} + +// WhichOneof reports which field within the oneof is populated, +// returning nil if none are populated. +// It panics if the oneof descriptor does not belong to this message. +func (x *fastReflection_ExampleAutoIncFieldName) WhichOneof(d protoreflect.OneofDescriptor) protoreflect.FieldDescriptor { + switch d.FullName() { + default: + panic(fmt.Errorf("%s is not a oneof field in testpb.ExampleAutoIncFieldName", d.FullName())) + } + panic("unreachable") +} + +// GetUnknown retrieves the entire list of unknown fields. +// The caller may only mutate the contents of the RawFields +// if the mutated bytes are stored back into the message with SetUnknown. +func (x *fastReflection_ExampleAutoIncFieldName) GetUnknown() protoreflect.RawFields { + return x.unknownFields +} + +// SetUnknown stores an entire list of unknown fields. +// The raw fields must be syntactically valid according to the wire format. +// An implementation may panic if this is not the case. +// Once stored, the caller must not mutate the content of the RawFields. +// An empty RawFields may be passed to clear the fields. +// +// SetUnknown is a mutating operation and unsafe for concurrent use. +func (x *fastReflection_ExampleAutoIncFieldName) SetUnknown(fields protoreflect.RawFields) { + x.unknownFields = fields +} + +// IsValid reports whether the message is valid. +// +// An invalid message is an empty, read-only value. +// +// An invalid message often corresponds to a nil pointer of the concrete +// message type, but the details are implementation dependent. +// Validity is not part of the protobuf data model, and may not +// be preserved in marshaling or other operations. +func (x *fastReflection_ExampleAutoIncFieldName) IsValid() bool { + return x != nil +} + +// ProtoMethods returns optional fastReflectionFeature-path implementations of various operations. +// This method may return nil. +// +// The returned methods type is identical to +// "google.golang.org/protobuf/runtime/protoiface".Methods. +// Consult the protoiface package documentation for details. +func (x *fastReflection_ExampleAutoIncFieldName) ProtoMethods() *protoiface.Methods { + size := func(input protoiface.SizeInput) protoiface.SizeOutput { + x := input.Message.Interface().(*ExampleAutoIncFieldName) + if x == nil { + return protoiface.SizeOutput{ + NoUnkeyedLiterals: input.NoUnkeyedLiterals, + Size: 0, + } + } + options := runtime.SizeInputToOptions(input) + _ = options + var n int + var l int + _ = l + if x.Foo != 0 { + n += 1 + runtime.Sov(uint64(x.Foo)) + } + if x.Bar != 0 { + n += 1 + runtime.Sov(uint64(x.Bar)) + } + if x.unknownFields != nil { + n += len(x.unknownFields) + } + return protoiface.SizeOutput{ + NoUnkeyedLiterals: input.NoUnkeyedLiterals, + Size: n, + } + } + + marshal := func(input protoiface.MarshalInput) (protoiface.MarshalOutput, error) { + x := input.Message.Interface().(*ExampleAutoIncFieldName) + if x == nil { + return protoiface.MarshalOutput{ + NoUnkeyedLiterals: input.NoUnkeyedLiterals, + Buf: input.Buf, + }, nil + } + options := runtime.MarshalInputToOptions(input) + _ = options + size := options.Size(x) + dAtA := make([]byte, size) + i := len(dAtA) + _ = i + var l int + _ = l + if x.unknownFields != nil { + i -= len(x.unknownFields) + copy(dAtA[i:], x.unknownFields) + } + if x.Bar != 0 { + i = runtime.EncodeVarint(dAtA, i, uint64(x.Bar)) + i-- + dAtA[i] = 0x10 + } + if x.Foo != 0 { + i = runtime.EncodeVarint(dAtA, i, uint64(x.Foo)) + i-- + dAtA[i] = 0x8 + } + if input.Buf != nil { + input.Buf = append(input.Buf, dAtA...) + } else { + input.Buf = dAtA + } + return protoiface.MarshalOutput{ + NoUnkeyedLiterals: input.NoUnkeyedLiterals, + Buf: input.Buf, + }, nil + } + unmarshal := func(input protoiface.UnmarshalInput) (protoiface.UnmarshalOutput, error) { + x := input.Message.Interface().(*ExampleAutoIncFieldName) + if x == nil { + return protoiface.UnmarshalOutput{ + NoUnkeyedLiterals: input.NoUnkeyedLiterals, + Flags: input.Flags, + }, nil + } + options := runtime.UnmarshalInputToOptions(input) + _ = options + dAtA := input.Buf + l := len(dAtA) + iNdEx := 0 + for iNdEx < l { + preIndex := iNdEx + var wire uint64 + for shift := uint(0); ; shift += 7 { + if shift >= 64 { + return protoiface.UnmarshalOutput{NoUnkeyedLiterals: input.NoUnkeyedLiterals, Flags: input.Flags}, runtime.ErrIntOverflow + } + if iNdEx >= l { + return protoiface.UnmarshalOutput{NoUnkeyedLiterals: input.NoUnkeyedLiterals, Flags: input.Flags}, io.ErrUnexpectedEOF + } + b := dAtA[iNdEx] + iNdEx++ + wire |= uint64(b&0x7F) << shift + if b < 0x80 { + break + } + } + fieldNum := int32(wire >> 3) + wireType := int(wire & 0x7) + if wireType == 4 { + return protoiface.UnmarshalOutput{NoUnkeyedLiterals: input.NoUnkeyedLiterals, Flags: input.Flags}, fmt.Errorf("proto: ExampleAutoIncFieldName: wiretype end group for non-group") + } + if fieldNum <= 0 { + return protoiface.UnmarshalOutput{NoUnkeyedLiterals: input.NoUnkeyedLiterals, Flags: input.Flags}, fmt.Errorf("proto: ExampleAutoIncFieldName: illegal tag %d (wire type %d)", fieldNum, wire) + } + switch fieldNum { + case 1: + if wireType != 0 { + return protoiface.UnmarshalOutput{NoUnkeyedLiterals: input.NoUnkeyedLiterals, Flags: input.Flags}, fmt.Errorf("proto: wrong wireType = %d for field Foo", wireType) + } + x.Foo = 0 + for shift := uint(0); ; shift += 7 { + if shift >= 64 { + return protoiface.UnmarshalOutput{NoUnkeyedLiterals: input.NoUnkeyedLiterals, Flags: input.Flags}, runtime.ErrIntOverflow + } + if iNdEx >= l { + return protoiface.UnmarshalOutput{NoUnkeyedLiterals: input.NoUnkeyedLiterals, Flags: input.Flags}, io.ErrUnexpectedEOF + } + b := dAtA[iNdEx] + iNdEx++ + x.Foo |= uint64(b&0x7F) << shift + if b < 0x80 { + break + } + } + case 2: + if wireType != 0 { + return protoiface.UnmarshalOutput{NoUnkeyedLiterals: input.NoUnkeyedLiterals, Flags: input.Flags}, fmt.Errorf("proto: wrong wireType = %d for field Bar", wireType) + } + x.Bar = 0 + for shift := uint(0); ; shift += 7 { + if shift >= 64 { + return protoiface.UnmarshalOutput{NoUnkeyedLiterals: input.NoUnkeyedLiterals, Flags: input.Flags}, runtime.ErrIntOverflow + } + if iNdEx >= l { + return protoiface.UnmarshalOutput{NoUnkeyedLiterals: input.NoUnkeyedLiterals, Flags: input.Flags}, io.ErrUnexpectedEOF + } + b := dAtA[iNdEx] + iNdEx++ + x.Bar |= uint64(b&0x7F) << shift + if b < 0x80 { + break + } + } + default: + iNdEx = preIndex + skippy, err := runtime.Skip(dAtA[iNdEx:]) + if err != nil { + return protoiface.UnmarshalOutput{NoUnkeyedLiterals: input.NoUnkeyedLiterals, Flags: input.Flags}, err + } + if (skippy < 0) || (iNdEx+skippy) < 0 { + return protoiface.UnmarshalOutput{NoUnkeyedLiterals: input.NoUnkeyedLiterals, Flags: input.Flags}, runtime.ErrInvalidLength + } + if (iNdEx + skippy) > l { + return protoiface.UnmarshalOutput{NoUnkeyedLiterals: input.NoUnkeyedLiterals, Flags: input.Flags}, io.ErrUnexpectedEOF + } + if !options.DiscardUnknown { + x.unknownFields = append(x.unknownFields, dAtA[iNdEx:iNdEx+skippy]...) + } + iNdEx += skippy + } + } + + if iNdEx > l { + return protoiface.UnmarshalOutput{NoUnkeyedLiterals: input.NoUnkeyedLiterals, Flags: input.Flags}, io.ErrUnexpectedEOF + } + return protoiface.UnmarshalOutput{NoUnkeyedLiterals: input.NoUnkeyedLiterals, Flags: input.Flags}, nil + } + return &protoiface.Methods{ + NoUnkeyedLiterals: struct{}{}, + Flags: protoiface.SupportMarshalDeterministic | protoiface.SupportUnmarshalDiscardUnknown, + Size: size, + Marshal: marshal, + Unmarshal: unmarshal, + Merge: nil, + CheckInitialized: nil, + } +} + // Code generated by protoc-gen-go. DO NOT EDIT. // versions: // protoc-gen-go v1.27.0 @@ -4869,6 +5321,50 @@ func (x *SimpleExample) GetNotUnique() string { return "" } +// ExampleAutoIncFieldName is a table for testing InsertReturning. +type ExampleAutoIncFieldName struct { + state protoimpl.MessageState + sizeCache protoimpl.SizeCache + unknownFields protoimpl.UnknownFields + + Foo uint64 `protobuf:"varint,1,opt,name=foo,proto3" json:"foo,omitempty"` + Bar uint64 `protobuf:"varint,2,opt,name=bar,proto3" json:"bar,omitempty"` +} + +func (x *ExampleAutoIncFieldName) Reset() { + *x = ExampleAutoIncFieldName{} + if protoimpl.UnsafeEnabled { + mi := &file_testpb_test_schema_proto_msgTypes[5] + ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x)) + ms.StoreMessageInfo(mi) + } +} + +func (x *ExampleAutoIncFieldName) String() string { + return protoimpl.X.MessageStringOf(x) +} + +func (*ExampleAutoIncFieldName) ProtoMessage() {} + +// Deprecated: Use ExampleAutoIncFieldName.ProtoReflect.Descriptor instead. +func (*ExampleAutoIncFieldName) Descriptor() ([]byte, []int) { + return file_testpb_test_schema_proto_rawDescGZIP(), []int{5} +} + +func (x *ExampleAutoIncFieldName) GetFoo() uint64 { + if x != nil { + return x.Foo + } + return 0 +} + +func (x *ExampleAutoIncFieldName) GetBar() uint64 { + if x != nil { + return x.Bar + } + return 0 +} + type ExampleTable_ExampleMessage struct { state protoimpl.MessageState sizeCache protoimpl.SizeCache @@ -4881,7 +5377,7 @@ type ExampleTable_ExampleMessage struct { func (x *ExampleTable_ExampleMessage) Reset() { *x = ExampleTable_ExampleMessage{} if protoimpl.UnsafeEnabled { - mi := &file_testpb_test_schema_proto_msgTypes[6] + mi := &file_testpb_test_schema_proto_msgTypes[7] ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x)) ms.StoreMessageInfo(mi) } @@ -4992,23 +5488,28 @@ var file_testpb_test_schema_proto_rawDesc = []byte{ 0x0a, 0x6e, 0x6f, 0x74, 0x5f, 0x75, 0x6e, 0x69, 0x71, 0x75, 0x65, 0x18, 0x03, 0x20, 0x01, 0x28, 0x09, 0x52, 0x09, 0x6e, 0x6f, 0x74, 0x55, 0x6e, 0x69, 0x71, 0x75, 0x65, 0x3a, 0x1e, 0xf2, 0x9e, 0xd3, 0x8e, 0x03, 0x18, 0x0a, 0x06, 0x0a, 0x04, 0x6e, 0x61, 0x6d, 0x65, 0x12, 0x0c, 0x0a, 0x06, - 0x75, 0x6e, 0x69, 0x71, 0x75, 0x65, 0x10, 0x01, 0x18, 0x01, 0x18, 0x05, 0x2a, 0x64, 0x0a, 0x04, - 0x45, 0x6e, 0x75, 0x6d, 0x12, 0x14, 0x0a, 0x10, 0x45, 0x4e, 0x55, 0x4d, 0x5f, 0x55, 0x4e, 0x53, - 0x50, 0x45, 0x43, 0x49, 0x46, 0x49, 0x45, 0x44, 0x10, 0x00, 0x12, 0x0c, 0x0a, 0x08, 0x45, 0x4e, - 0x55, 0x4d, 0x5f, 0x4f, 0x4e, 0x45, 0x10, 0x01, 0x12, 0x0c, 0x0a, 0x08, 0x45, 0x4e, 0x55, 0x4d, - 0x5f, 0x54, 0x57, 0x4f, 0x10, 0x02, 0x12, 0x0d, 0x0a, 0x09, 0x45, 0x4e, 0x55, 0x4d, 0x5f, 0x46, - 0x49, 0x56, 0x45, 0x10, 0x05, 0x12, 0x1b, 0x0a, 0x0e, 0x45, 0x4e, 0x55, 0x4d, 0x5f, 0x4e, 0x45, - 0x47, 0x5f, 0x54, 0x48, 0x52, 0x45, 0x45, 0x10, 0xfd, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, - 0xff, 0x01, 0x42, 0x87, 0x01, 0x0a, 0x0a, 0x63, 0x6f, 0x6d, 0x2e, 0x74, 0x65, 0x73, 0x74, 0x70, - 0x62, 0x42, 0x0f, 0x54, 0x65, 0x73, 0x74, 0x53, 0x63, 0x68, 0x65, 0x6d, 0x61, 0x50, 0x72, 0x6f, - 0x74, 0x6f, 0x50, 0x01, 0x5a, 0x30, 0x67, 0x69, 0x74, 0x68, 0x75, 0x62, 0x2e, 0x63, 0x6f, 0x6d, - 0x2f, 0x63, 0x6f, 0x73, 0x6d, 0x6f, 0x73, 0x2f, 0x63, 0x6f, 0x73, 0x6d, 0x6f, 0x73, 0x2d, 0x73, - 0x64, 0x6b, 0x2f, 0x6f, 0x72, 0x6d, 0x2f, 0x69, 0x6e, 0x74, 0x65, 0x72, 0x6e, 0x61, 0x6c, 0x2f, - 0x74, 0x65, 0x73, 0x74, 0x70, 0x62, 0xa2, 0x02, 0x03, 0x54, 0x58, 0x58, 0xaa, 0x02, 0x06, 0x54, - 0x65, 0x73, 0x74, 0x70, 0x62, 0xca, 0x02, 0x06, 0x54, 0x65, 0x73, 0x74, 0x70, 0x62, 0xe2, 0x02, - 0x12, 0x54, 0x65, 0x73, 0x74, 0x70, 0x62, 0x5c, 0x47, 0x50, 0x42, 0x4d, 0x65, 0x74, 0x61, 0x64, - 0x61, 0x74, 0x61, 0xea, 0x02, 0x06, 0x54, 0x65, 0x73, 0x74, 0x70, 0x62, 0x62, 0x06, 0x70, 0x72, - 0x6f, 0x74, 0x6f, 0x33, + 0x75, 0x6e, 0x69, 0x71, 0x75, 0x65, 0x10, 0x01, 0x18, 0x01, 0x18, 0x05, 0x22, 0x50, 0x0a, 0x17, + 0x45, 0x78, 0x61, 0x6d, 0x70, 0x6c, 0x65, 0x41, 0x75, 0x74, 0x6f, 0x49, 0x6e, 0x63, 0x46, 0x69, + 0x65, 0x6c, 0x64, 0x4e, 0x61, 0x6d, 0x65, 0x12, 0x10, 0x0a, 0x03, 0x66, 0x6f, 0x6f, 0x18, 0x01, + 0x20, 0x01, 0x28, 0x04, 0x52, 0x03, 0x66, 0x6f, 0x6f, 0x12, 0x10, 0x0a, 0x03, 0x62, 0x61, 0x72, + 0x18, 0x02, 0x20, 0x01, 0x28, 0x04, 0x52, 0x03, 0x62, 0x61, 0x72, 0x3a, 0x11, 0xf2, 0x9e, 0xd3, + 0x8e, 0x03, 0x0b, 0x0a, 0x07, 0x0a, 0x03, 0x66, 0x6f, 0x6f, 0x10, 0x01, 0x18, 0x06, 0x2a, 0x64, + 0x0a, 0x04, 0x45, 0x6e, 0x75, 0x6d, 0x12, 0x14, 0x0a, 0x10, 0x45, 0x4e, 0x55, 0x4d, 0x5f, 0x55, + 0x4e, 0x53, 0x50, 0x45, 0x43, 0x49, 0x46, 0x49, 0x45, 0x44, 0x10, 0x00, 0x12, 0x0c, 0x0a, 0x08, + 0x45, 0x4e, 0x55, 0x4d, 0x5f, 0x4f, 0x4e, 0x45, 0x10, 0x01, 0x12, 0x0c, 0x0a, 0x08, 0x45, 0x4e, + 0x55, 0x4d, 0x5f, 0x54, 0x57, 0x4f, 0x10, 0x02, 0x12, 0x0d, 0x0a, 0x09, 0x45, 0x4e, 0x55, 0x4d, + 0x5f, 0x46, 0x49, 0x56, 0x45, 0x10, 0x05, 0x12, 0x1b, 0x0a, 0x0e, 0x45, 0x4e, 0x55, 0x4d, 0x5f, + 0x4e, 0x45, 0x47, 0x5f, 0x54, 0x48, 0x52, 0x45, 0x45, 0x10, 0xfd, 0xff, 0xff, 0xff, 0xff, 0xff, + 0xff, 0xff, 0xff, 0x01, 0x42, 0x87, 0x01, 0x0a, 0x0a, 0x63, 0x6f, 0x6d, 0x2e, 0x74, 0x65, 0x73, + 0x74, 0x70, 0x62, 0x42, 0x0f, 0x54, 0x65, 0x73, 0x74, 0x53, 0x63, 0x68, 0x65, 0x6d, 0x61, 0x50, + 0x72, 0x6f, 0x74, 0x6f, 0x50, 0x01, 0x5a, 0x30, 0x67, 0x69, 0x74, 0x68, 0x75, 0x62, 0x2e, 0x63, + 0x6f, 0x6d, 0x2f, 0x63, 0x6f, 0x73, 0x6d, 0x6f, 0x73, 0x2f, 0x63, 0x6f, 0x73, 0x6d, 0x6f, 0x73, + 0x2d, 0x73, 0x64, 0x6b, 0x2f, 0x6f, 0x72, 0x6d, 0x2f, 0x69, 0x6e, 0x74, 0x65, 0x72, 0x6e, 0x61, + 0x6c, 0x2f, 0x74, 0x65, 0x73, 0x74, 0x70, 0x62, 0xa2, 0x02, 0x03, 0x54, 0x58, 0x58, 0xaa, 0x02, + 0x06, 0x54, 0x65, 0x73, 0x74, 0x70, 0x62, 0xca, 0x02, 0x06, 0x54, 0x65, 0x73, 0x74, 0x70, 0x62, + 0xe2, 0x02, 0x12, 0x54, 0x65, 0x73, 0x74, 0x70, 0x62, 0x5c, 0x47, 0x50, 0x42, 0x4d, 0x65, 0x74, + 0x61, 0x64, 0x61, 0x74, 0x61, 0xea, 0x02, 0x06, 0x54, 0x65, 0x73, 0x74, 0x70, 0x62, 0x62, 0x06, + 0x70, 0x72, 0x6f, 0x74, 0x6f, 0x33, } var ( @@ -5024,7 +5525,7 @@ func file_testpb_test_schema_proto_rawDescGZIP() []byte { } var file_testpb_test_schema_proto_enumTypes = make([]protoimpl.EnumInfo, 1) -var file_testpb_test_schema_proto_msgTypes = make([]protoimpl.MessageInfo, 7) +var file_testpb_test_schema_proto_msgTypes = make([]protoimpl.MessageInfo, 8) var file_testpb_test_schema_proto_goTypes = []interface{}{ (Enum)(0), // 0: testpb.Enum (*ExampleTable)(nil), // 1: testpb.ExampleTable @@ -5032,23 +5533,24 @@ var file_testpb_test_schema_proto_goTypes = []interface{}{ (*ExampleSingleton)(nil), // 3: testpb.ExampleSingleton (*ExampleTimestamp)(nil), // 4: testpb.ExampleTimestamp (*SimpleExample)(nil), // 5: testpb.SimpleExample - nil, // 6: testpb.ExampleTable.MapEntry - (*ExampleTable_ExampleMessage)(nil), // 7: testpb.ExampleTable.ExampleMessage - (*timestamppb.Timestamp)(nil), // 8: google.protobuf.Timestamp - (*durationpb.Duration)(nil), // 9: google.protobuf.Duration + (*ExampleAutoIncFieldName)(nil), // 6: testpb.ExampleAutoIncFieldName + nil, // 7: testpb.ExampleTable.MapEntry + (*ExampleTable_ExampleMessage)(nil), // 8: testpb.ExampleTable.ExampleMessage + (*timestamppb.Timestamp)(nil), // 9: google.protobuf.Timestamp + (*durationpb.Duration)(nil), // 10: google.protobuf.Duration } var file_testpb_test_schema_proto_depIdxs = []int32{ - 8, // 0: testpb.ExampleTable.ts:type_name -> google.protobuf.Timestamp - 9, // 1: testpb.ExampleTable.dur:type_name -> google.protobuf.Duration - 0, // 2: testpb.ExampleTable.e:type_name -> testpb.Enum - 6, // 3: testpb.ExampleTable.map:type_name -> testpb.ExampleTable.MapEntry - 7, // 4: testpb.ExampleTable.msg:type_name -> testpb.ExampleTable.ExampleMessage - 8, // 5: testpb.ExampleTimestamp.ts:type_name -> google.protobuf.Timestamp - 6, // [6:6] is the sub-list for method output_type - 6, // [6:6] is the sub-list for method input_type - 6, // [6:6] is the sub-list for extension type_name - 6, // [6:6] is the sub-list for extension extendee - 0, // [0:6] is the sub-list for field type_name + 9, // 0: testpb.ExampleTable.ts:type_name -> google.protobuf.Timestamp + 10, // 1: testpb.ExampleTable.dur:type_name -> google.protobuf.Duration + 0, // 2: testpb.ExampleTable.e:type_name -> testpb.Enum + 7, // 3: testpb.ExampleTable.map:type_name -> testpb.ExampleTable.MapEntry + 8, // 4: testpb.ExampleTable.msg:type_name -> testpb.ExampleTable.ExampleMessage + 9, // 5: testpb.ExampleTimestamp.ts:type_name -> google.protobuf.Timestamp + 6, // [6:6] is the sub-list for method output_type + 6, // [6:6] is the sub-list for method input_type + 6, // [6:6] is the sub-list for extension type_name + 6, // [6:6] is the sub-list for extension extendee + 0, // [0:6] is the sub-list for field type_name } func init() { file_testpb_test_schema_proto_init() } @@ -5117,7 +5619,19 @@ func file_testpb_test_schema_proto_init() { return nil } } - file_testpb_test_schema_proto_msgTypes[6].Exporter = func(v interface{}, i int) interface{} { + file_testpb_test_schema_proto_msgTypes[5].Exporter = func(v interface{}, i int) interface{} { + switch v := v.(*ExampleAutoIncFieldName); i { + case 0: + return &v.state + case 1: + return &v.sizeCache + case 2: + return &v.unknownFields + default: + return nil + } + } + file_testpb_test_schema_proto_msgTypes[7].Exporter = func(v interface{}, i int) interface{} { switch v := v.(*ExampleTable_ExampleMessage); i { case 0: return &v.state @@ -5139,7 +5653,7 @@ func file_testpb_test_schema_proto_init() { GoPackagePath: reflect.TypeOf(x{}).PkgPath(), RawDescriptor: file_testpb_test_schema_proto_rawDesc, NumEnums: 1, - NumMessages: 7, + NumMessages: 8, NumExtensions: 0, NumServices: 0, }, diff --git a/orm/model/ormtable/auto_increment.go b/orm/model/ormtable/auto_increment.go index 40f625b73fac..2a0eed6f94b6 100644 --- a/orm/model/ormtable/auto_increment.go +++ b/orm/model/ormtable/auto_increment.go @@ -22,7 +22,7 @@ type autoIncrementTable struct { seqCodec *ormkv.SeqCodec } -func (t autoIncrementTable) InsertReturningID(ctx context.Context, message proto.Message) (newId uint64, err error) { +func (t autoIncrementTable) InsertReturningPKey(ctx context.Context, message proto.Message) (newPK uint64, err error) { backend, err := t.getWriteBackend(ctx) if err != nil { return 0, err @@ -61,7 +61,7 @@ func (t autoIncrementTable) Update(ctx context.Context, message proto.Message) e return err } -func (t *autoIncrementTable) save(ctx context.Context, backend Backend, message proto.Message, mode saveMode) (newId uint64, err error) { +func (t *autoIncrementTable) save(ctx context.Context, backend Backend, message proto.Message, mode saveMode) (newPK uint64, err error) { messageRef := message.ProtoReflect() val := messageRef.Get(t.autoIncField).Uint() writer := newBatchIndexCommitmentWriter(backend) @@ -73,12 +73,12 @@ func (t *autoIncrementTable) save(ctx context.Context, backend Backend, message } mode = saveModeInsert - newId, err = t.nextSeqValue(writer.IndexStore()) + newPK, err = t.nextSeqValue(writer.IndexStore()) if err != nil { return 0, err } - messageRef.Set(t.autoIncField, protoreflect.ValueOfUint64(newId)) + messageRef.Set(t.autoIncField, protoreflect.ValueOfUint64(newPK)) } else { if mode == saveModeInsert { return 0, ormerrors.AutoIncrementKeyAlreadySet @@ -87,7 +87,7 @@ func (t *autoIncrementTable) save(ctx context.Context, backend Backend, message mode = saveModeUpdate } - return newId, t.tableImpl.doSave(ctx, writer, message, mode) + return newPK, t.tableImpl.doSave(ctx, writer, message, mode) } func (t *autoIncrementTable) curSeqValue(kv kv.ReadonlyStore) (uint64, error) { @@ -121,11 +121,12 @@ func (t autoIncrementTable) EncodeEntry(entry ormkv.Entry) (k, v []byte, err err } func (t autoIncrementTable) ValidateJSON(reader io.Reader) error { - return t.decodeAutoIncJson(nil, reader, func(message proto.Message, maxID uint64) error { + return t.decodeAutoIncJson(nil, reader, func(message proto.Message, maxSeq uint64) error { messageRef := message.ProtoReflect() - id := messageRef.Get(t.autoIncField).Uint() - if id > maxID { - return fmt.Errorf("invalid ID %d, expected a value <= %d, the highest sequence number", id, maxID) + pkey := messageRef.Get(t.autoIncField).Uint() + if pkey > maxSeq { + return fmt.Errorf("invalid auto increment primary key %d, expected a value <= %d, the highest "+ + "sequence number", pkey, maxSeq) } if t.customJSONValidator != nil { @@ -142,22 +143,23 @@ func (t autoIncrementTable) ImportJSON(ctx context.Context, reader io.Reader) er return err } - return t.decodeAutoIncJson(backend, reader, func(message proto.Message, maxID uint64) error { + return t.decodeAutoIncJson(backend, reader, func(message proto.Message, maxSeq uint64) error { messageRef := message.ProtoReflect() - id := messageRef.Get(t.autoIncField).Uint() - if id == 0 { - // we don't have an ID in the JSON, so we call Save to insert and + pkey := messageRef.Get(t.autoIncField).Uint() + if pkey == 0 { + // we don't have a primary key in the JSON, so we call Save to insert and // generate one _, err = t.save(ctx, backend, message, saveModeInsert) return err } else { - if id > maxID { - return fmt.Errorf("invalid ID %d, expected a value <= %d, the highest sequence number", id, maxID) + if pkey > maxSeq { + return fmt.Errorf("invalid auto increment primary key %d, expected a value <= %d, the highest "+ + "sequence number", pkey, maxSeq) } - // we do have an ID and calling Save will fail because it expects - // either no ID or SAVE_MODE_UPDATE. So instead we drop one level + // we do have a primary key and calling Save will fail because it expects + // either no primary key or SAVE_MODE_UPDATE. So instead we drop one level // down and insert using tableImpl which doesn't know about - // auto-incrementing IDs + // auto-incrementing primary keys. return t.tableImpl.save(ctx, backend, message, saveModeInsert) } }) diff --git a/orm/model/ormtable/auto_increment_test.go b/orm/model/ormtable/auto_increment_test.go index 4f1556f4f1a3..c3180000dc5a 100644 --- a/orm/model/ormtable/auto_increment_test.go +++ b/orm/model/ormtable/auto_increment_test.go @@ -54,7 +54,7 @@ func runAutoIncrementScenario(t *testing.T, table ormtable.AutoIncrementTable, c assert.Equal(t, uint64(1), ex1.Id) ex2 := &testpb.ExampleAutoIncrementTable{X: "bar", Y: 10} - newId, err := table.InsertReturningID(ctx, ex2) + newId, err := table.InsertReturningPKey(ctx, ex2) assert.NilError(t, err) assert.Equal(t, uint64(2), ex2.Id) assert.Equal(t, newId, ex2.Id) @@ -89,9 +89,9 @@ func TestBadJSON(t *testing.T) { store := ormtable.WrapContextDefault(testkv.NewSplitMemBackend()) f, err := os.Open("testdata/bad_auto_inc.json") assert.NilError(t, err) - assert.ErrorContains(t, table.ImportJSON(store, f), "invalid ID") + assert.ErrorContains(t, table.ImportJSON(store, f), "invalid auto increment primary key") f, err = os.Open("testdata/bad_auto_inc2.json") assert.NilError(t, err) - assert.ErrorContains(t, table.ImportJSON(store, f), "invalid ID") + assert.ErrorContains(t, table.ImportJSON(store, f), "invalid auto increment primary key") } diff --git a/orm/model/ormtable/table.go b/orm/model/ormtable/table.go index 7594fcadbbf6..b66520ac8e61 100644 --- a/orm/model/ormtable/table.go +++ b/orm/model/ormtable/table.go @@ -153,7 +153,7 @@ type Schema interface { type AutoIncrementTable interface { Table - // InsertReturningID inserts the provided entry in the store and returns the newly - // generated ID for the message or an error. - InsertReturningID(ctx context.Context, message proto.Message) (newId uint64, err error) + // InsertReturningPKey inserts the provided entry in the store and returns the newly + // generated primary key for the message or an error. + InsertReturningPKey(ctx context.Context, message proto.Message) (newPK uint64, err error) } diff --git a/orm/model/ormtable/table_test.go b/orm/model/ormtable/table_test.go index b02bbe019f71..b8f1365272a3 100644 --- a/orm/model/ormtable/table_test.go +++ b/orm/model/ormtable/table_test.go @@ -24,6 +24,7 @@ import ( sdkerrors "cosmossdk.io/errors" queryv1beta1 "github.com/cosmos/cosmos-sdk/api/cosmos/base/query/v1beta1" + "github.com/cosmos/cosmos-sdk/orm/encoding/ormkv" "github.com/cosmos/cosmos-sdk/orm/internal/testkv" "github.com/cosmos/cosmos-sdk/orm/internal/testpb" @@ -790,3 +791,18 @@ func TestReadonly(t *testing.T) { ctx := ormtable.WrapContextDefault(readBackend) assert.ErrorIs(t, ormerrors.ReadOnly, table.Insert(ctx, &testpb.ExampleTable{})) } + +func TestInsertReturningFieldName(t *testing.T) { + table, err := ormtable.Build(ormtable.Options{ + MessageType: (&testpb.ExampleAutoIncFieldName{}).ProtoReflect().Type(), + }) + backend := testkv.NewSplitMemBackend() + ctx := ormtable.WrapContextDefault(backend) + store, err := testpb.NewExampleAutoIncFieldNameTable(table) + assert.NilError(t, err) + foo, err := store.InsertReturningFoo(ctx, &testpb.ExampleAutoIncFieldName{ + Bar: 45, + }) + assert.NilError(t, err) + assert.Equal(t, uint64(1), foo) +} From d5731fde972ecf1a6a8f7899ce59a1c8f57c419c Mon Sep 17 00:00:00 2001 From: Assaf Morami Date: Sat, 14 May 2022 19:25:34 +0300 Subject: [PATCH 2/5] Fix typo in `tx vesting create-vesting-account` help message (#11958) --- x/auth/vesting/client/cli/tx.go | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/x/auth/vesting/client/cli/tx.go b/x/auth/vesting/client/cli/tx.go index e64411fd7c89..3c88d04500fa 100644 --- a/x/auth/vesting/client/cli/tx.go +++ b/x/auth/vesting/client/cli/tx.go @@ -47,7 +47,7 @@ func NewMsgCreateVestingAccountCmd() *cobra.Command { Short: "Create a new vesting account funded with an allocation of tokens.", Long: `Create a new vesting account funded with an allocation of tokens. The account can either be a delayed or continuous vesting account, which is determined -by the '--delayed' flag. All vesting accouts created will have their start time +by the '--delayed' flag. All vesting accounts created will have their start time set by the committed block's time. The end_time must be provided as a UNIX epoch timestamp.`, Args: cobra.ExactArgs(3), From 4f311620941cdeeb843342291922e27fe35cc1e1 Mon Sep 17 00:00:00 2001 From: "dependabot[bot]" <49699333+dependabot[bot]@users.noreply.github.com> Date: Sun, 15 May 2022 12:40:52 +0000 Subject: [PATCH 3/5] build(deps): Bump github.com/prometheus/client_golang from 1.12.1 to 1.12.2 (#11956) MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Bumps [github.com/prometheus/client_golang](https://github.com/prometheus/client_golang) from 1.12.1 to 1.12.2.
Release notes

Sourced from github.com/prometheus/client_golang's releases.

1.12.2 / 2022-05-13

  • [CHANGE] Added collectors.WithGoCollections that allows to choose what collection of Go runtime metrics user wants: Equivalent of MemStats structure configured using GoRuntimeMemStatsCollection, new based on dedicated runtime/metrics metrics represented by GoRuntimeMetricsCollection option, or both by specifying GoRuntimeMemStatsCollection | GoRuntimeMetricsCollection flag.
  • [CHANGE] :warning: Change in collectors.NewGoCollector metrics: Reverting addition of new ~80 runtime metrics by default. You can enable this back with GoRuntimeMetricsCollection option or GoRuntimeMemStatsCollection | GoRuntimeMetricsCollection for smooth transition.
  • [BUGFIX] Fixed the bug that causes generated histogram metric names to end with _total. ⚠️ This changes 3 metric names in the new Go collector that was reverted from default in this release.
    • go_gc_heap_allocs_by_size_bytes_total -> go_gc_heap_allocs_by_size_bytes,
    • go_gc_heap_frees_by_size_bytes_total -> go_gc_heap_allocs_by_size_bytes
    • go_gc_pauses_seconds_total -> go_gc_pauses_seconds.
  • [CHANCE] Removed -Inf buckets from new Go Collector histograms.

Full Changelog: https://github.com/prometheus/client_golang/compare/v1.12.1...v1.12.2

Changelog

Sourced from github.com/prometheus/client_golang's changelog.

1.12.2 / 2022-01-29

  • [CHANGE] Added collectors.WithGoCollections that allows to choose what collection of Go runtime metrics user wants: Equivalent of MemStats structure configured using GoRuntimeMemStatsCollection, new based on dedicated runtime/metrics metrics represented by GoRuntimeMetricsCollection option, or both by specifying GoRuntimeMemStatsCollection | GoRuntimeMetricsCollection flag.
  • [CHANGE] :warning: Change in collectors.NewGoCollector metrics: Reverting addition of new ~80 runtime metrics by default. You can enable this back with GoRuntimeMetricsCollection option or GoRuntimeMemStatsCollection | GoRuntimeMetricsCollection for smooth transition.
  • [BUGFIX] Fixed the bug that causes generated histogram metric names to end with _total. ⚠️ This changes 3 metric names in the new Go collector that was reverted from default in this release.
    • go_gc_heap_allocs_by_size_bytes_total -> go_gc_heap_allocs_by_size_bytes,
    • go_gc_heap_frees_by_size_bytes_total -> go_gc_heap_allocs_by_size_bytes
    • go_gc_pauses_seconds_total -> go_gc_pauses_seconds.
  • [CHANCE] Removed -Inf buckets from new Go Collector histograms.
Commits
  • e203144 Merge branch 'release-1.12' of github.com:prometheus/client_golang into relea...
  • 0e136d1 Cut v1.12.2 (#1052)
  • a27b6d7 Fix conflicts
  • 5fe1d33 Remove -Inf buckets from go collector histograms (#1049)
  • 049d0fe prometheus: Fix convention violating names for generated collector metrics (#...
  • 7eb9d11 gocollector: Reverted client_golang v1.12 addition of runtime/metrics metrics...
  • d498b3c gocollector: Added options to Go Collector for changing the (#1031)
  • 585540a Fix deprecated NewBuildInfoCollector API
  • 39cf574 Cut v1.12.1 (#978)
  • 9b785b0 Reduce granularity of histogram buckets for Go 1.17 collector (#974)
  • Additional commits viewable in compare view

[![Dependabot compatibility score](https://dependabot-badges.githubapp.com/badges/compatibility_score?dependency-name=github.com/prometheus/client_golang&package-manager=go_modules&previous-version=1.12.1&new-version=1.12.2)](https://docs.github.com/en/github/managing-security-vulnerabilities/about-dependabot-security-updates#about-compatibility-scores) Dependabot will resolve any conflicts with this PR as long as you don't alter it yourself. You can also trigger a rebase manually by commenting `@dependabot rebase`. [//]: # (dependabot-automerge-start) [//]: # (dependabot-automerge-end) ---
Dependabot commands and options
You can trigger Dependabot actions by commenting on this PR: - `@dependabot rebase` will rebase this PR - `@dependabot recreate` will recreate this PR, overwriting any edits that have been made to it - `@dependabot merge` will merge this PR after your CI passes on it - `@dependabot squash and merge` will squash and merge this PR after your CI passes on it - `@dependabot cancel merge` will cancel a previously requested merge and block automerging - `@dependabot reopen` will reopen this PR if it is closed - `@dependabot close` will close this PR and stop Dependabot recreating it. You can achieve the same result by closing it manually - `@dependabot ignore this major version` will close this PR and stop Dependabot creating any more for this major version (unless you reopen the PR or upgrade to it yourself) - `@dependabot ignore this minor version` will close this PR and stop Dependabot creating any more for this minor version (unless you reopen the PR or upgrade to it yourself) - `@dependabot ignore this dependency` will close this PR and stop Dependabot creating any more for this dependency (unless you reopen the PR or upgrade to it yourself)
--- go.mod | 2 +- go.sum | 3 ++- 2 files changed, 3 insertions(+), 2 deletions(-) diff --git a/go.mod b/go.mod index 17b23225eb82..5f877b428de1 100644 --- a/go.mod +++ b/go.mod @@ -38,7 +38,7 @@ require ( github.com/magiconair/properties v1.8.6 github.com/mattn/go-isatty v0.0.14 github.com/pkg/errors v0.9.1 - github.com/prometheus/client_golang v1.12.1 + github.com/prometheus/client_golang v1.12.2 github.com/prometheus/common v0.34.0 github.com/rakyll/statik v0.1.7 github.com/regen-network/cosmos-proto v0.3.1 diff --git a/go.sum b/go.sum index aa55e6d5eafc..27be10770e44 100644 --- a/go.sum +++ b/go.sum @@ -1090,8 +1090,9 @@ github.com/prometheus/client_golang v1.3.0/go.mod h1:hJaj2vgQTGQmVCsAACORcieXFeD github.com/prometheus/client_golang v1.4.0/go.mod h1:e9GMxYsXl05ICDXkRhurwBS4Q3OK1iX/F2sw+iXX5zU= github.com/prometheus/client_golang v1.7.1/go.mod h1:PY5Wy2awLA44sXw4AOSfFBetzPP4j5+D6mVACh+pe2M= github.com/prometheus/client_golang v1.11.0/go.mod h1:Z6t4BnS23TR94PD6BsDNk8yVqroYurpAkEiz0P2BEV0= -github.com/prometheus/client_golang v1.12.1 h1:ZiaPsmm9uiBeaSMRznKsCDNtPCS0T3JVDGF+06gjBzk= github.com/prometheus/client_golang v1.12.1/go.mod h1:3Z9XVyYiZYEO+YQWt3RD2R3jrbd179Rt297l4aS6nDY= +github.com/prometheus/client_golang v1.12.2 h1:51L9cDoUHVrXx4zWYlcLQIZ+d+VXHgqnYKkIuq4g/34= +github.com/prometheus/client_golang v1.12.2/go.mod h1:3Z9XVyYiZYEO+YQWt3RD2R3jrbd179Rt297l4aS6nDY= github.com/prometheus/client_model v0.0.0-20180712105110-5c3871d89910/go.mod h1:MbSGuTsp3dbXC40dX6PRTWyKYBIrTGTE9sqQNg2J8bo= github.com/prometheus/client_model v0.0.0-20190115171406-56726106282f/go.mod h1:MbSGuTsp3dbXC40dX6PRTWyKYBIrTGTE9sqQNg2J8bo= github.com/prometheus/client_model v0.0.0-20190129233127-fd36f4220a90/go.mod h1:xMI15A0UPsDsEKsMN9yxemIoYk6Tm2C1GtYGdfGttqA= From b2b29d4909395ce3bf6944ce0b740fb5a689b218 Mon Sep 17 00:00:00 2001 From: Amaury <1293565+amaurym@users.noreply.github.com> Date: Sun, 15 May 2022 15:02:53 +0200 Subject: [PATCH 4/5] chore: Audit crypto folder (#11932) ## Description ref: #11362 I did **NOT** review the following folders, as they contain cryptography which I don't think I'm competent enough to give a useful review: - [ ] `crypto/xsalsa20symmetric` (new in v046, ported from TM i think) - [ ] `crypto/keys/secp256k1` (some new stuff in v046 too) Also performed some manual tests as part of #11939: - [x] Create keys on v0.45, make sure they still work in v0.46 https://github.com/cosmos/cosmos-sdk/issues/11939#issuecomment-1124881492 - [x] Create new keys in v0.46 https://github.com/cosmos/cosmos-sdk/issues/11939#issuecomment-1124881492 - [x] `--multisig` flag works with an address that's not in the keyring (see [repro](https://github.com/cosmos/cosmos-sdk/issues/9553)) --- ### Author Checklist *All items are required. Please add a note to the item if the item is not applicable and please add links to any relevant follow up issues.* I have... - [ ] included the correct [type prefix](https://github.com/commitizen/conventional-commit-types/blob/v3.0.0/index.json) in the PR title - [ ] added `!` to the type prefix if API or client breaking change - [ ] targeted the correct branch (see [PR Targeting](https://github.com/cosmos/cosmos-sdk/blob/main/CONTRIBUTING.md#pr-targeting)) - [ ] provided a link to the relevant issue or specification - [ ] followed the guidelines for [building modules](https://github.com/cosmos/cosmos-sdk/blob/main/docs/building-modules) - [ ] included the necessary unit and integration [tests](https://github.com/cosmos/cosmos-sdk/blob/main/CONTRIBUTING.md#testing) - [ ] added a changelog entry to `CHANGELOG.md` - [ ] included comments for [documenting Go code](https://blog.golang.org/godoc) - [ ] updated the relevant documentation or specification - [ ] reviewed "Files changed" and left comments if necessary - [ ] confirmed all CI checks have passed ### Reviewers Checklist *All items are required. Please add a note if the item is not applicable and please add your handle next to the items reviewed if you only reviewed selected items.* I have... - [ ] confirmed the correct [type prefix](https://github.com/commitizen/conventional-commit-types/blob/v3.0.0/index.json) in the PR title - [ ] confirmed `!` in the type prefix if API or client breaking change - [ ] confirmed all author checklist items have been addressed - [ ] reviewed state machine logic - [ ] reviewed API design and naming - [ ] reviewed documentation is accurate - [ ] reviewed tests and test coverage - [ ] manually tested (if applicable) --- CHANGELOG.md | 5 +- api/cosmos/crypto/keyring/v1/record.pulsar.go | 135 ++++-------------- client/keys/export.go | 21 ++- client/keys/migrate.go | 4 +- client/keys/migrate_test.go | 4 +- crypto/keyring/doc.go | 10 +- crypto/keyring/keyring.go | 128 +++++++---------- crypto/keyring/keyring_test.go | 10 +- crypto/keyring/migration_test.go | 34 ++--- crypto/keyring/record.go | 2 +- crypto/keyring/record.pb.go | 101 ++++--------- crypto/keyring/record_test.go | 1 - proto/cosmos/crypto/keyring/v1/record.proto | 9 +- 13 files changed, 161 insertions(+), 303 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index a622be931b2d..625212007f1a 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -89,7 +89,8 @@ Ref: https://keepachangelog.com/en/1.0.0/ ### API Breaking Changes -* (types ) [#11881](https://github.com/cosmos/cosmos-sdk/issues/11881) Rename `AccAddressFromHex` to `AccAddressFromHexUnsafe`. +* (crypto/keyring) [#11932](https://github.com/cosmos/cosmos-sdk/pull/11932) Remove `Unsafe*` interfaces from keyring package. Please use interface casting if you wish to access those unsafe functions. +* (types) [#11881](https://github.com/cosmos/cosmos-sdk/issues/11881) Rename `AccAddressFromHex` to `AccAddressFromHexUnsafe`. * (types) [#11788](https://github.com/cosmos/cosmos-sdk/pull/11788) The `Int` and `Uint` types have been moved to their own dedicated module, `math`. Aliases are kept in the SDK's root `types` package, however, it is encouraged to utilize the new `math` module. As a result, the `Int#ToDec` API has been removed. * (grpc) [\#11642](https://github.com/cosmos/cosmos-sdk/pull/11642) The `RegisterTendermintService` method in the `tmservice` package now requires a `abciQueryFn` query function parameter. * [\#11496](https://github.com/cosmos/cosmos-sdk/pull/11496) Refactor abstractions for snapshot and pruning; snapshot intervals eventually pruned; unit tests. @@ -98,7 +99,7 @@ Ref: https://keepachangelog.com/en/1.0.0/ * [\#10950](https://github.com/cosmos/cosmos-sdk/pull/10950) Add `envPrefix` parameter to `cmd.Execute`. * (x/mint) [\#10441](https://github.com/cosmos/cosmos-sdk/pull/10441) The `NewAppModule` function now accepts an inflation calculation function as an argument. * [\#10295](https://github.com/cosmos/cosmos-sdk/pull/10295) Remove store type aliases from /types -* [\#9695](https://github.com/cosmos/cosmos-sdk/pull/9695) Migrate keys from `Info` -> `Record` +* [\#9695](https://github.com/cosmos/cosmos-sdk/pull/9695) Migrate keys from `Info` (serialized as amino) -> `Record` (serialized as proto) * Add new `codec.Codec` argument in: * `keyring.NewInMemory` * `keyring.New` diff --git a/api/cosmos/crypto/keyring/v1/record.pulsar.go b/api/cosmos/crypto/keyring/v1/record.pulsar.go index 778a84d976b5..7a330c9c247d 100644 --- a/api/cosmos/crypto/keyring/v1/record.pulsar.go +++ b/api/cosmos/crypto/keyring/v1/record.pulsar.go @@ -945,16 +945,14 @@ func (x *fastReflection_Record) ProtoMethods() *protoiface.Methods { } var ( - md_Record_Local protoreflect.MessageDescriptor - fd_Record_Local_priv_key protoreflect.FieldDescriptor - fd_Record_Local_priv_key_type protoreflect.FieldDescriptor + md_Record_Local protoreflect.MessageDescriptor + fd_Record_Local_priv_key protoreflect.FieldDescriptor ) func init() { file_cosmos_crypto_keyring_v1_record_proto_init() md_Record_Local = File_cosmos_crypto_keyring_v1_record_proto.Messages().ByName("Record").Messages().ByName("Local") fd_Record_Local_priv_key = md_Record_Local.Fields().ByName("priv_key") - fd_Record_Local_priv_key_type = md_Record_Local.Fields().ByName("priv_key_type") } var _ protoreflect.Message = (*fastReflection_Record_Local)(nil) @@ -1028,12 +1026,6 @@ func (x *fastReflection_Record_Local) Range(f func(protoreflect.FieldDescriptor, return } } - if x.PrivKeyType != "" { - value := protoreflect.ValueOfString(x.PrivKeyType) - if !f(fd_Record_Local_priv_key_type, value) { - return - } - } } // Has reports whether a field is populated. @@ -1051,8 +1043,6 @@ func (x *fastReflection_Record_Local) Has(fd protoreflect.FieldDescriptor) bool switch fd.FullName() { case "cosmos.crypto.keyring.v1.Record.Local.priv_key": return x.PrivKey != nil - case "cosmos.crypto.keyring.v1.Record.Local.priv_key_type": - return x.PrivKeyType != "" default: if fd.IsExtension() { panic(fmt.Errorf("proto3 declared messages do not support extensions: cosmos.crypto.keyring.v1.Record.Local")) @@ -1071,8 +1061,6 @@ func (x *fastReflection_Record_Local) Clear(fd protoreflect.FieldDescriptor) { switch fd.FullName() { case "cosmos.crypto.keyring.v1.Record.Local.priv_key": x.PrivKey = nil - case "cosmos.crypto.keyring.v1.Record.Local.priv_key_type": - x.PrivKeyType = "" default: if fd.IsExtension() { panic(fmt.Errorf("proto3 declared messages do not support extensions: cosmos.crypto.keyring.v1.Record.Local")) @@ -1092,9 +1080,6 @@ func (x *fastReflection_Record_Local) Get(descriptor protoreflect.FieldDescripto case "cosmos.crypto.keyring.v1.Record.Local.priv_key": value := x.PrivKey return protoreflect.ValueOfMessage(value.ProtoReflect()) - case "cosmos.crypto.keyring.v1.Record.Local.priv_key_type": - value := x.PrivKeyType - return protoreflect.ValueOfString(value) default: if descriptor.IsExtension() { panic(fmt.Errorf("proto3 declared messages do not support extensions: cosmos.crypto.keyring.v1.Record.Local")) @@ -1117,8 +1102,6 @@ func (x *fastReflection_Record_Local) Set(fd protoreflect.FieldDescriptor, value switch fd.FullName() { case "cosmos.crypto.keyring.v1.Record.Local.priv_key": x.PrivKey = value.Message().Interface().(*anypb.Any) - case "cosmos.crypto.keyring.v1.Record.Local.priv_key_type": - x.PrivKeyType = value.Interface().(string) default: if fd.IsExtension() { panic(fmt.Errorf("proto3 declared messages do not support extensions: cosmos.crypto.keyring.v1.Record.Local")) @@ -1144,8 +1127,6 @@ func (x *fastReflection_Record_Local) Mutable(fd protoreflect.FieldDescriptor) p x.PrivKey = new(anypb.Any) } return protoreflect.ValueOfMessage(x.PrivKey.ProtoReflect()) - case "cosmos.crypto.keyring.v1.Record.Local.priv_key_type": - panic(fmt.Errorf("field priv_key_type of message cosmos.crypto.keyring.v1.Record.Local is not mutable")) default: if fd.IsExtension() { panic(fmt.Errorf("proto3 declared messages do not support extensions: cosmos.crypto.keyring.v1.Record.Local")) @@ -1162,8 +1143,6 @@ func (x *fastReflection_Record_Local) NewField(fd protoreflect.FieldDescriptor) case "cosmos.crypto.keyring.v1.Record.Local.priv_key": m := new(anypb.Any) return protoreflect.ValueOfMessage(m.ProtoReflect()) - case "cosmos.crypto.keyring.v1.Record.Local.priv_key_type": - return protoreflect.ValueOfString("") default: if fd.IsExtension() { panic(fmt.Errorf("proto3 declared messages do not support extensions: cosmos.crypto.keyring.v1.Record.Local")) @@ -1237,10 +1216,6 @@ func (x *fastReflection_Record_Local) ProtoMethods() *protoiface.Methods { l = options.Size(x.PrivKey) n += 1 + l + runtime.Sov(uint64(l)) } - l = len(x.PrivKeyType) - if l > 0 { - n += 1 + l + runtime.Sov(uint64(l)) - } if x.unknownFields != nil { n += len(x.unknownFields) } @@ -1270,13 +1245,6 @@ func (x *fastReflection_Record_Local) ProtoMethods() *protoiface.Methods { i -= len(x.unknownFields) copy(dAtA[i:], x.unknownFields) } - if len(x.PrivKeyType) > 0 { - i -= len(x.PrivKeyType) - copy(dAtA[i:], x.PrivKeyType) - i = runtime.EncodeVarint(dAtA, i, uint64(len(x.PrivKeyType))) - i-- - dAtA[i] = 0x12 - } if x.PrivKey != nil { encoded, err := options.Marshal(x.PrivKey) if err != nil { @@ -1376,38 +1344,6 @@ func (x *fastReflection_Record_Local) ProtoMethods() *protoiface.Methods { return protoiface.UnmarshalOutput{NoUnkeyedLiterals: input.NoUnkeyedLiterals, Flags: input.Flags}, err } iNdEx = postIndex - case 2: - if wireType != 2 { - return protoiface.UnmarshalOutput{NoUnkeyedLiterals: input.NoUnkeyedLiterals, Flags: input.Flags}, fmt.Errorf("proto: wrong wireType = %d for field PrivKeyType", wireType) - } - var stringLen uint64 - for shift := uint(0); ; shift += 7 { - if shift >= 64 { - return protoiface.UnmarshalOutput{NoUnkeyedLiterals: input.NoUnkeyedLiterals, Flags: input.Flags}, runtime.ErrIntOverflow - } - if iNdEx >= l { - return protoiface.UnmarshalOutput{NoUnkeyedLiterals: input.NoUnkeyedLiterals, Flags: input.Flags}, io.ErrUnexpectedEOF - } - b := dAtA[iNdEx] - iNdEx++ - stringLen |= uint64(b&0x7F) << shift - if b < 0x80 { - break - } - } - intStringLen := int(stringLen) - if intStringLen < 0 { - return protoiface.UnmarshalOutput{NoUnkeyedLiterals: input.NoUnkeyedLiterals, Flags: input.Flags}, runtime.ErrInvalidLength - } - postIndex := iNdEx + intStringLen - if postIndex < 0 { - return protoiface.UnmarshalOutput{NoUnkeyedLiterals: input.NoUnkeyedLiterals, Flags: input.Flags}, runtime.ErrInvalidLength - } - if postIndex > l { - return protoiface.UnmarshalOutput{NoUnkeyedLiterals: input.NoUnkeyedLiterals, Flags: input.Flags}, io.ErrUnexpectedEOF - } - x.PrivKeyType = string(dAtA[iNdEx:postIndex]) - iNdEx = postIndex default: iNdEx = preIndex skippy, err := runtime.Skip(dAtA[iNdEx:]) @@ -2699,22 +2635,22 @@ type isRecord_Item interface { } type Record_Local_ struct { - // local stores the public information about a locally stored key + // local stores the private key locally. Local *Record_Local `protobuf:"bytes,3,opt,name=local,proto3,oneof"` } type Record_Ledger_ struct { - // ledger stores the public information about a Ledger key + // ledger stores the information about a Ledger key. Ledger *Record_Ledger `protobuf:"bytes,4,opt,name=ledger,proto3,oneof"` } type Record_Multi_ struct { - // Multi does not store any information. + // Multi does not store any other information. Multi *Record_Multi `protobuf:"bytes,5,opt,name=multi,proto3,oneof"` } type Record_Offline_ struct { - // Offline does not store any information. + // Offline does not store any other information. Offline *Record_Offline `protobuf:"bytes,6,opt,name=offline,proto3,oneof"` } @@ -2733,8 +2669,7 @@ type Record_Local struct { sizeCache protoimpl.SizeCache unknownFields protoimpl.UnknownFields - PrivKey *anypb.Any `protobuf:"bytes,1,opt,name=priv_key,json=privKey,proto3" json:"priv_key,omitempty"` - PrivKeyType string `protobuf:"bytes,2,opt,name=priv_key_type,json=privKeyType,proto3" json:"priv_key_type,omitempty"` + PrivKey *anypb.Any `protobuf:"bytes,1,opt,name=priv_key,json=privKey,proto3" json:"priv_key,omitempty"` } func (x *Record_Local) Reset() { @@ -2764,13 +2699,6 @@ func (x *Record_Local) GetPrivKey() *anypb.Any { return nil } -func (x *Record_Local) GetPrivKeyType() string { - if x != nil { - return x.PrivKeyType - } - return "" -} - // Ledger item type Record_Ledger struct { state protoimpl.MessageState @@ -2873,7 +2801,7 @@ var file_cosmos_crypto_keyring_v1_record_proto_rawDesc = []byte{ 0x70, 0x72, 0x6f, 0x74, 0x6f, 0x62, 0x75, 0x66, 0x2f, 0x61, 0x6e, 0x79, 0x2e, 0x70, 0x72, 0x6f, 0x74, 0x6f, 0x1a, 0x1c, 0x63, 0x6f, 0x73, 0x6d, 0x6f, 0x73, 0x2f, 0x63, 0x72, 0x79, 0x70, 0x74, 0x6f, 0x2f, 0x68, 0x64, 0x2f, 0x76, 0x31, 0x2f, 0x68, 0x64, 0x2e, 0x70, 0x72, 0x6f, 0x74, 0x6f, - 0x22, 0x8e, 0x04, 0x0a, 0x06, 0x52, 0x65, 0x63, 0x6f, 0x72, 0x64, 0x12, 0x12, 0x0a, 0x04, 0x6e, + 0x22, 0xea, 0x03, 0x0a, 0x06, 0x52, 0x65, 0x63, 0x6f, 0x72, 0x64, 0x12, 0x12, 0x0a, 0x04, 0x6e, 0x61, 0x6d, 0x65, 0x18, 0x01, 0x20, 0x01, 0x28, 0x09, 0x52, 0x04, 0x6e, 0x61, 0x6d, 0x65, 0x12, 0x2d, 0x0a, 0x07, 0x70, 0x75, 0x62, 0x5f, 0x6b, 0x65, 0x79, 0x18, 0x02, 0x20, 0x01, 0x28, 0x0b, 0x32, 0x14, 0x2e, 0x67, 0x6f, 0x6f, 0x67, 0x6c, 0x65, 0x2e, 0x70, 0x72, 0x6f, 0x74, 0x6f, 0x62, @@ -2894,34 +2822,31 @@ var file_cosmos_crypto_keyring_v1_record_proto_rawDesc = []byte{ 0x28, 0x0b, 0x32, 0x28, 0x2e, 0x63, 0x6f, 0x73, 0x6d, 0x6f, 0x73, 0x2e, 0x63, 0x72, 0x79, 0x70, 0x74, 0x6f, 0x2e, 0x6b, 0x65, 0x79, 0x72, 0x69, 0x6e, 0x67, 0x2e, 0x76, 0x31, 0x2e, 0x52, 0x65, 0x63, 0x6f, 0x72, 0x64, 0x2e, 0x4f, 0x66, 0x66, 0x6c, 0x69, 0x6e, 0x65, 0x48, 0x00, 0x52, 0x07, - 0x6f, 0x66, 0x66, 0x6c, 0x69, 0x6e, 0x65, 0x1a, 0x5c, 0x0a, 0x05, 0x4c, 0x6f, 0x63, 0x61, 0x6c, + 0x6f, 0x66, 0x66, 0x6c, 0x69, 0x6e, 0x65, 0x1a, 0x38, 0x0a, 0x05, 0x4c, 0x6f, 0x63, 0x61, 0x6c, 0x12, 0x2f, 0x0a, 0x08, 0x70, 0x72, 0x69, 0x76, 0x5f, 0x6b, 0x65, 0x79, 0x18, 0x01, 0x20, 0x01, 0x28, 0x0b, 0x32, 0x14, 0x2e, 0x67, 0x6f, 0x6f, 0x67, 0x6c, 0x65, 0x2e, 0x70, 0x72, 0x6f, 0x74, 0x6f, 0x62, 0x75, 0x66, 0x2e, 0x41, 0x6e, 0x79, 0x52, 0x07, 0x70, 0x72, 0x69, 0x76, 0x4b, 0x65, - 0x79, 0x12, 0x22, 0x0a, 0x0d, 0x70, 0x72, 0x69, 0x76, 0x5f, 0x6b, 0x65, 0x79, 0x5f, 0x74, 0x79, - 0x70, 0x65, 0x18, 0x02, 0x20, 0x01, 0x28, 0x09, 0x52, 0x0b, 0x70, 0x72, 0x69, 0x76, 0x4b, 0x65, - 0x79, 0x54, 0x79, 0x70, 0x65, 0x1a, 0x3e, 0x0a, 0x06, 0x4c, 0x65, 0x64, 0x67, 0x65, 0x72, 0x12, - 0x34, 0x0a, 0x04, 0x70, 0x61, 0x74, 0x68, 0x18, 0x01, 0x20, 0x01, 0x28, 0x0b, 0x32, 0x20, 0x2e, - 0x63, 0x6f, 0x73, 0x6d, 0x6f, 0x73, 0x2e, 0x63, 0x72, 0x79, 0x70, 0x74, 0x6f, 0x2e, 0x68, 0x64, - 0x2e, 0x76, 0x31, 0x2e, 0x42, 0x49, 0x50, 0x34, 0x34, 0x50, 0x61, 0x72, 0x61, 0x6d, 0x73, 0x52, - 0x04, 0x70, 0x61, 0x74, 0x68, 0x1a, 0x07, 0x0a, 0x05, 0x4d, 0x75, 0x6c, 0x74, 0x69, 0x1a, 0x09, - 0x0a, 0x07, 0x4f, 0x66, 0x66, 0x6c, 0x69, 0x6e, 0x65, 0x42, 0x06, 0x0a, 0x04, 0x69, 0x74, 0x65, - 0x6d, 0x42, 0xe7, 0x01, 0x0a, 0x1c, 0x63, 0x6f, 0x6d, 0x2e, 0x63, 0x6f, 0x73, 0x6d, 0x6f, 0x73, - 0x2e, 0x63, 0x72, 0x79, 0x70, 0x74, 0x6f, 0x2e, 0x6b, 0x65, 0x79, 0x72, 0x69, 0x6e, 0x67, 0x2e, - 0x76, 0x31, 0x42, 0x0b, 0x52, 0x65, 0x63, 0x6f, 0x72, 0x64, 0x50, 0x72, 0x6f, 0x74, 0x6f, 0x50, - 0x01, 0x5a, 0x33, 0x63, 0x6f, 0x73, 0x6d, 0x6f, 0x73, 0x73, 0x64, 0x6b, 0x2e, 0x69, 0x6f, 0x2f, - 0x61, 0x70, 0x69, 0x2f, 0x63, 0x6f, 0x73, 0x6d, 0x6f, 0x73, 0x2f, 0x63, 0x72, 0x79, 0x70, 0x74, - 0x6f, 0x2f, 0x6b, 0x65, 0x79, 0x72, 0x69, 0x6e, 0x67, 0x2f, 0x76, 0x31, 0x3b, 0x6b, 0x65, 0x79, - 0x72, 0x69, 0x6e, 0x67, 0x76, 0x31, 0xa2, 0x02, 0x03, 0x43, 0x43, 0x4b, 0xaa, 0x02, 0x18, 0x43, - 0x6f, 0x73, 0x6d, 0x6f, 0x73, 0x2e, 0x43, 0x72, 0x79, 0x70, 0x74, 0x6f, 0x2e, 0x4b, 0x65, 0x79, - 0x72, 0x69, 0x6e, 0x67, 0x2e, 0x56, 0x31, 0xca, 0x02, 0x18, 0x43, 0x6f, 0x73, 0x6d, 0x6f, 0x73, - 0x5c, 0x43, 0x72, 0x79, 0x70, 0x74, 0x6f, 0x5c, 0x4b, 0x65, 0x79, 0x72, 0x69, 0x6e, 0x67, 0x5c, - 0x56, 0x31, 0xe2, 0x02, 0x24, 0x43, 0x6f, 0x73, 0x6d, 0x6f, 0x73, 0x5c, 0x43, 0x72, 0x79, 0x70, - 0x74, 0x6f, 0x5c, 0x4b, 0x65, 0x79, 0x72, 0x69, 0x6e, 0x67, 0x5c, 0x56, 0x31, 0x5c, 0x47, 0x50, - 0x42, 0x4d, 0x65, 0x74, 0x61, 0x64, 0x61, 0x74, 0x61, 0xea, 0x02, 0x1b, 0x43, 0x6f, 0x73, 0x6d, - 0x6f, 0x73, 0x3a, 0x3a, 0x43, 0x72, 0x79, 0x70, 0x74, 0x6f, 0x3a, 0x3a, 0x4b, 0x65, 0x79, 0x72, - 0x69, 0x6e, 0x67, 0x3a, 0x3a, 0x56, 0x31, 0xc8, 0xe1, 0x1e, 0x00, 0x62, 0x06, 0x70, 0x72, 0x6f, - 0x74, 0x6f, 0x33, + 0x79, 0x1a, 0x3e, 0x0a, 0x06, 0x4c, 0x65, 0x64, 0x67, 0x65, 0x72, 0x12, 0x34, 0x0a, 0x04, 0x70, + 0x61, 0x74, 0x68, 0x18, 0x01, 0x20, 0x01, 0x28, 0x0b, 0x32, 0x20, 0x2e, 0x63, 0x6f, 0x73, 0x6d, + 0x6f, 0x73, 0x2e, 0x63, 0x72, 0x79, 0x70, 0x74, 0x6f, 0x2e, 0x68, 0x64, 0x2e, 0x76, 0x31, 0x2e, + 0x42, 0x49, 0x50, 0x34, 0x34, 0x50, 0x61, 0x72, 0x61, 0x6d, 0x73, 0x52, 0x04, 0x70, 0x61, 0x74, + 0x68, 0x1a, 0x07, 0x0a, 0x05, 0x4d, 0x75, 0x6c, 0x74, 0x69, 0x1a, 0x09, 0x0a, 0x07, 0x4f, 0x66, + 0x66, 0x6c, 0x69, 0x6e, 0x65, 0x42, 0x06, 0x0a, 0x04, 0x69, 0x74, 0x65, 0x6d, 0x42, 0xe7, 0x01, + 0x0a, 0x1c, 0x63, 0x6f, 0x6d, 0x2e, 0x63, 0x6f, 0x73, 0x6d, 0x6f, 0x73, 0x2e, 0x63, 0x72, 0x79, + 0x70, 0x74, 0x6f, 0x2e, 0x6b, 0x65, 0x79, 0x72, 0x69, 0x6e, 0x67, 0x2e, 0x76, 0x31, 0x42, 0x0b, + 0x52, 0x65, 0x63, 0x6f, 0x72, 0x64, 0x50, 0x72, 0x6f, 0x74, 0x6f, 0x50, 0x01, 0x5a, 0x33, 0x63, + 0x6f, 0x73, 0x6d, 0x6f, 0x73, 0x73, 0x64, 0x6b, 0x2e, 0x69, 0x6f, 0x2f, 0x61, 0x70, 0x69, 0x2f, + 0x63, 0x6f, 0x73, 0x6d, 0x6f, 0x73, 0x2f, 0x63, 0x72, 0x79, 0x70, 0x74, 0x6f, 0x2f, 0x6b, 0x65, + 0x79, 0x72, 0x69, 0x6e, 0x67, 0x2f, 0x76, 0x31, 0x3b, 0x6b, 0x65, 0x79, 0x72, 0x69, 0x6e, 0x67, + 0x76, 0x31, 0xa2, 0x02, 0x03, 0x43, 0x43, 0x4b, 0xaa, 0x02, 0x18, 0x43, 0x6f, 0x73, 0x6d, 0x6f, + 0x73, 0x2e, 0x43, 0x72, 0x79, 0x70, 0x74, 0x6f, 0x2e, 0x4b, 0x65, 0x79, 0x72, 0x69, 0x6e, 0x67, + 0x2e, 0x56, 0x31, 0xca, 0x02, 0x18, 0x43, 0x6f, 0x73, 0x6d, 0x6f, 0x73, 0x5c, 0x43, 0x72, 0x79, + 0x70, 0x74, 0x6f, 0x5c, 0x4b, 0x65, 0x79, 0x72, 0x69, 0x6e, 0x67, 0x5c, 0x56, 0x31, 0xe2, 0x02, + 0x24, 0x43, 0x6f, 0x73, 0x6d, 0x6f, 0x73, 0x5c, 0x43, 0x72, 0x79, 0x70, 0x74, 0x6f, 0x5c, 0x4b, + 0x65, 0x79, 0x72, 0x69, 0x6e, 0x67, 0x5c, 0x56, 0x31, 0x5c, 0x47, 0x50, 0x42, 0x4d, 0x65, 0x74, + 0x61, 0x64, 0x61, 0x74, 0x61, 0xea, 0x02, 0x1b, 0x43, 0x6f, 0x73, 0x6d, 0x6f, 0x73, 0x3a, 0x3a, + 0x43, 0x72, 0x79, 0x70, 0x74, 0x6f, 0x3a, 0x3a, 0x4b, 0x65, 0x79, 0x72, 0x69, 0x6e, 0x67, 0x3a, + 0x3a, 0x56, 0x31, 0xc8, 0xe1, 0x1e, 0x00, 0x62, 0x06, 0x70, 0x72, 0x6f, 0x74, 0x6f, 0x33, } var ( diff --git a/client/keys/export.go b/client/keys/export.go index 13491b5e839a..7e2f7250d38f 100644 --- a/client/keys/export.go +++ b/client/keys/export.go @@ -2,6 +2,7 @@ package keys import ( "bufio" + "encoding/hex" "fmt" "github.com/spf13/cobra" @@ -9,6 +10,7 @@ import ( "github.com/cosmos/cosmos-sdk/client" "github.com/cosmos/cosmos-sdk/client/input" "github.com/cosmos/cosmos-sdk/crypto/keyring" + "github.com/cosmos/cosmos-sdk/crypto/types" ) const ( @@ -75,7 +77,7 @@ func exportUnsafeUnarmored(cmd *cobra.Command, uid string, buf *bufio.Reader, kr return nil } - hexPrivKey, err := keyring.NewUnsafe(kr).UnsafeExportPrivKeyHex(uid) + hexPrivKey, err := unsafeExportPrivKeyHex(kr.(unsafeExporter), uid) if err != nil { return err } @@ -84,3 +86,20 @@ func exportUnsafeUnarmored(cmd *cobra.Command, uid string, buf *bufio.Reader, kr return nil } + +// unsafeExporter is implemented by key stores that support unsafe export +// of private keys' material. +type unsafeExporter interface { + // ExportPrivateKeyObject returns a private key in unarmored format. + ExportPrivateKeyObject(uid string) (types.PrivKey, error) +} + +// unsafeExportPrivKeyHex exports private keys in unarmored hexadecimal format. +func unsafeExportPrivKeyHex(ks unsafeExporter, uid string) (privkey string, err error) { + priv, err := ks.ExportPrivateKeyObject(uid) + if err != nil { + return "", err + } + + return hex.EncodeToString(priv.Bytes()), nil +} diff --git a/client/keys/migrate.go b/client/keys/migrate.go index ff6cde2244a3..f76206f6ed9f 100644 --- a/client/keys/migrate.go +++ b/client/keys/migrate.go @@ -34,10 +34,10 @@ func runMigrateCmd(cmd *cobra.Command, _ []string) error { return err } - if _, err = clientCtx.Keyring.MigrateAll(); err != nil { + if err = clientCtx.Keyring.MigrateAll(); err != nil { return err } - cmd.Println("Keys migration has been successfully executed") + cmd.Println("Keys migration has been successfully executed.") return nil } diff --git a/client/keys/migrate_test.go b/client/keys/migrate_test.go index 48eefb168661..3e5e54942a91 100644 --- a/client/keys/migrate_test.go +++ b/client/keys/migrate_test.go @@ -55,9 +55,9 @@ func (s *MigrateTestSuite) Test_runListAndShowCmd() { serializedLegacyMultiInfo := keyring.MarshalInfo(legacyMultiInfo) item := design99keyring.Item{ - Key: s.appName, + Key: s.appName + ".info", Data: serializedLegacyMultiInfo, - Description: "SDK kerying version", + Description: "SDK keyring version", } //run test simd keys list - to see that the migrated key is there diff --git a/crypto/keyring/doc.go b/crypto/keyring/doc.go index 04a8b98cdfba..b642680c0662 100644 --- a/crypto/keyring/doc.go +++ b/crypto/keyring/doc.go @@ -1,17 +1,11 @@ // Package keys provides common key management API. // // -// The Keybase interface +// The Keyring interface // -// The Keybase interface defines the methods that a type needs to implement to be used +// The Keyring interface defines the methods that a type needs to implement to be used // as key storage backend. This package provides few implementations out-of-the-box. // -// NewLegacy -// -// The NewLegacy constructor returns an on-disk implementation backed by LevelDB storage that has been -// the default implementation used by the SDK until v0.38.0. Due to security concerns, it is -// recommended to drop it in favor of the NewKeyring constructor as it will be removed in future releases. -// // NewInMemory // // The NewInMemory constructor returns an implementation backed by an in-memory, goroutine-safe diff --git a/crypto/keyring/keyring.go b/crypto/keyring/keyring.go index 7cd3bd310730..303b0ed07fce 100644 --- a/crypto/keyring/keyring.go +++ b/crypto/keyring/keyring.go @@ -100,13 +100,6 @@ type Keyring interface { Migrator } -// UnsafeKeyring exposes unsafe operations such as unsafe unarmored export in -// addition to those that are made available by the Keyring interface. -type UnsafeKeyring interface { - Keyring - UnsafeExporter -} - // Signer is implemented by key stores that want to provide signing capabilities. type Signer interface { // Sign sign byte messages with a user key. @@ -125,9 +118,9 @@ type Importer interface { ImportPubKey(uid string, armor string) error } -// Migrator is implemented by key stores and enables migration of keys from amino to proto +// Migrator is implemented by key stores and enables migration of keys from amino to proto type Migrator interface { - MigrateAll() (bool, error) + MigrateAll() error } // Exporter is implemented by key stores that support export of public and private keys. @@ -142,13 +135,6 @@ type Exporter interface { ExportPrivKeyArmorByAddress(address sdk.Address, encryptPassphrase string) (armor string, err error) } -// UnsafeExporter is implemented by key stores that support unsafe export -// of private keys' material. -type UnsafeExporter interface { - // UnsafeExportPrivKeyHex returns a private key in unarmored hex format - UnsafeExportPrivKeyHex(uid string) (string, error) -} - // Option overrides keyring configuration options. type Option func(options *Options) @@ -500,7 +486,7 @@ func wrapKeyNotFound(err error, msg string) error { } func (ks keystore) List() ([]*Record, error) { - if _, err := ks.MigrateAll(); err != nil { + if err := ks.MigrateAll(); err != nil { return nil, err } @@ -512,7 +498,7 @@ func (ks keystore) List() ([]*Record, error) { var res []*Record //nolint:prealloc sort.Strings(keys) for _, key := range keys { - if strings.Contains(key, addressSuffix) { + if strings.HasSuffix(key, addressSuffix) { continue } @@ -597,7 +583,7 @@ func (ks keystore) isSupportedSigningAlgo(algo SignatureAlgo) bool { } func (ks keystore) Key(uid string) (*Record, error) { - k, _, err := ks.migrate(uid) + k, err := ks.migrate(uid) if err != nil { return nil, err } @@ -778,7 +764,11 @@ func (ks keystore) writeLocalKey(name string, privKey types.PrivKey) (*Record, e return k, ks.writeRecord(k) } -// writeRecord persists a keyring item in keystore if it does not exist there +// writeRecord persists a keyring item in keystore if it does not exist there. +// For each key record, we actually write 2 items: +// - one with key `.info`, with Data = the serialized protobuf key +// - another with key `.address`, with Data = the uid (i.e. the key name) +// This is to be able to query keys both by name and by address. func (ks keystore) writeRecord(k *Record) error { addr, err := k.GetAddress() if err != nil { @@ -797,7 +787,7 @@ func (ks keystore) writeRecord(k *Record) error { serializedRecord, err := ks.cdc.Marshal(k) if err != nil { - return fmt.Errorf("unable to serialize record, err - %s", err) + return fmt.Errorf("unable to serialize record; %+w", err) } item := keyring.Item{ @@ -871,83 +861,96 @@ func (ks keystore) writeMultisigKey(name string, pk types.PubKey) (*Record, erro return k, ks.writeRecord(k) } -func (ks keystore) MigrateAll() (bool, error) { +func (ks keystore) MigrateAll() error { keys, err := ks.db.Keys() if err != nil { - return false, err + return err } if len(keys) == 0 { - return false, nil + return nil } - var migrated bool for _, key := range keys { - if strings.Contains(key, addressSuffix) { + // The keyring items with `.address` suffix only holds as Data the + // key name uid, so there's nothing to migrate. + if strings.HasSuffix(key, addressSuffix) { continue } - _, migrated2, err := ks.migrate(key) + _, err := ks.migrate(key) if err != nil { - fmt.Printf("migrate err: %q", err) + fmt.Printf("migrate err for key %s: %q\n", key, err) continue } - - if migrated2 { - migrated = true - } } - return migrated, nil + return nil } // migrate converts keyring.Item from amino to proto serialization format. -func (ks keystore) migrate(key string) (*Record, bool, error) { - if !(strings.HasSuffix(key, infoSuffix)) && !(strings.HasPrefix(key, sdk.Bech32PrefixAccAddr)) { +// the `key` argument can be a key uid (e.g. "alice") or with the '.info' +// suffix (e.g. "alice.info"). +// +// It operates as follows: +// 1. retrieve any key +// 2. try to decode it using protobuf +// 3. if ok, then return the key, do nothing else +// 4. if it fails, then try to decode it using amino +// 5. convert from the amino struct to the protobuf struct +// 6. write the proto-encoded key back to the keyring +func (ks keystore) migrate(key string) (*Record, error) { + if !strings.HasSuffix(key, infoSuffix) { key = infoKey(key) } + + // 1. get the key. item, err := ks.db.Get(key) if err != nil { - return nil, false, wrapKeyNotFound(err, key) + return nil, wrapKeyNotFound(err, key) } if len(item.Data) == 0 { - return nil, false, sdkerrors.Wrap(sdkerrors.ErrKeyNotFound, key) + return nil, sdkerrors.Wrap(sdkerrors.ErrKeyNotFound, key) } - // 2.try to deserialize using proto, if good then continue, otherwise try to deserialize using amino + // 2. Try to deserialize using proto k, err := ks.protoUnmarshalRecord(item.Data) + // 3. If ok then return the key if err == nil { - return k, false, nil + return k, nil } - LegacyInfo, err := unMarshalLegacyInfo(item.Data) + // 4. Try to decode with amino + legacyInfo, err := unMarshalLegacyInfo(item.Data) if err != nil { - return nil, false, fmt.Errorf("unable to unmarshal item.Data, err: %w", err) + return nil, fmt.Errorf("unable to unmarshal item.Data, err: %w", err) } - // 4.serialize info using proto - k, err = ks.convertFromLegacyInfo(LegacyInfo) + // 5. Convert and serialize info using proto + k, err = ks.convertFromLegacyInfo(legacyInfo) if err != nil { - return nil, false, fmt.Errorf("convertFromLegacyInfo, err: %w", err) + return nil, fmt.Errorf("convertFromLegacyInfo, err: %w", err) } serializedRecord, err := ks.cdc.Marshal(k) if err != nil { - return nil, false, fmt.Errorf("unable to serialize record, err: %w", err) + return nil, fmt.Errorf("unable to serialize record, err: %w", err) } item = keyring.Item{ - Key: key, - Data: serializedRecord, - Description: "SDK kerying version", + Key: key, + Data: serializedRecord, } - // 5.overwrite the keyring entry with + + // 6. Overwrite the keyring entry with the new proto-encoded key. if err := ks.SetItem(item); err != nil { - return nil, false, fmt.Errorf("unable to set keyring.Item, err: %w", err) + return nil, fmt.Errorf("unable to set keyring.Item, err: %w", err) } - return k, true, nil + fmt.Printf("Successfully migrated key %s.\n", key) + + return k, nil } func (ks keystore) protoUnmarshalRecord(bz []byte) (*Record, error) { @@ -996,29 +999,6 @@ func (ks keystore) convertFromLegacyInfo(info LegacyInfo) (*Record, error) { } } -type unsafeKeystore struct { - keystore -} - -// NewUnsafe returns a new keyring that provides support for unsafe operations. -func NewUnsafe(kr Keyring) UnsafeKeyring { - // The type assertion is against the only keystore - // implementation that is currently provided. - ks := kr.(keystore) - - return unsafeKeystore{ks} -} - -// UnsafeExportPrivKeyHex exports private keys in unarmored hexadecimal format. -func (ks unsafeKeystore) UnsafeExportPrivKeyHex(uid string) (privkey string, err error) { - priv, err := ks.ExportPrivateKeyObject(uid) - if err != nil { - return "", err - } - - return hex.EncodeToString(priv.Bytes()), nil -} - func addrHexKeyAsString(address sdk.Address) string { return fmt.Sprintf("%s.%s", hex.EncodeToString(address.Bytes()), addressSuffix) } diff --git a/crypto/keyring/keyring_test.go b/crypto/keyring/keyring_test.go index f258c05e3cf4..a0a006b4f112 100644 --- a/crypto/keyring/keyring_test.go +++ b/crypto/keyring/keyring_test.go @@ -1287,17 +1287,13 @@ func TestAltKeyring_UnsafeExportPrivKeyHex(t *testing.T) { _, _, err = kr.NewMnemonic(uid, English, sdk.FullFundraiserPath, DefaultBIP39Passphrase, hd.Secp256k1) require.NoError(t, err) - unsafeKeyring := NewUnsafe(kr) - privKey, err := unsafeKeyring.UnsafeExportPrivKeyHex(uid) + privKey, err := kr.(keystore).ExportPrivateKeyObject(uid) require.NoError(t, err) - require.Equal(t, 64, len(privKey)) - - _, err = hex.DecodeString(privKey) - require.NoError(t, err) + require.Equal(t, 64, len(hex.EncodeToString(privKey.Bytes()))) // test error on non existing key - _, err = unsafeKeyring.UnsafeExportPrivKeyHex("non-existing") + _, err = kr.(keystore).ExportPrivateKeyObject("non-existing") require.Error(t, err) } diff --git a/crypto/keyring/migration_test.go b/crypto/keyring/migration_test.go index cfe55bd657a9..939bc4a83ef0 100644 --- a/crypto/keyring/migration_test.go +++ b/crypto/keyring/migration_test.go @@ -16,7 +16,7 @@ import ( sdkerrors "github.com/cosmos/cosmos-sdk/types/errors" ) -const n1 = "cosmos" +const n1 = "cosmos.info" type MigrationTestSuite struct { suite.Suite @@ -57,8 +57,7 @@ func (s *MigrationTestSuite) TestMigrateLegacyLocalKey() { s.Require().NoError(s.ks.SetItem(item)) - _, migrated, err := s.ks.migrate(n1) - s.Require().True(migrated) + _, err := s.ks.migrate(n1) s.Require().NoError(err) } @@ -76,8 +75,7 @@ func (s *MigrationTestSuite) TestMigrateLegacyLedgerKey() { s.Require().NoError(s.ks.SetItem(item)) - _, migrated, err := s.ks.migrate(n1) - s.Require().True(migrated) + _, err := s.ks.migrate(n1) s.Require().NoError(err) } @@ -93,8 +91,7 @@ func (s *MigrationTestSuite) TestMigrateLegacyOfflineKey() { s.Require().NoError(s.ks.SetItem(item)) - _, migrated, err := s.ks.migrate(n1) - s.Require().True(migrated) + _, err := s.ks.migrate(n1) s.Require().NoError(err) } @@ -117,8 +114,7 @@ func (s *MigrationTestSuite) TestMigrateLegacyMultiKey() { s.Require().NoError(s.ks.SetItem(item)) - _, migrated, err := s.ks.migrate(n1) - s.Require().True(migrated) + _, err = s.ks.migrate(n1) s.Require().NoError(err) } @@ -137,7 +133,7 @@ func (s *MigrationTestSuite) TestMigrateLocalRecord() { s.Require().NoError(s.ks.SetItem(item)) - k2, migrated, err := s.ks.migrate(n1) + k2, err := s.ks.migrate(n1) s.Require().Equal(k2.Name, k1.Name) pub, err := k2.GetPubKey() @@ -148,7 +144,6 @@ func (s *MigrationTestSuite) TestMigrateLocalRecord() { s.Require().NoError(err) s.Require().Equal(priv, s.priv) - s.Require().False(migrated) s.Require().NoError(err) } @@ -162,8 +157,7 @@ func (s *MigrationTestSuite) TestMigrateOneRandomItemError() { s.Require().NoError(s.ks.SetItem(errItem)) - _, migrated, err := s.ks.migrate(n1) - s.Require().False(migrated) + _, err := s.ks.migrate(n1) s.Require().Error(err) } @@ -197,14 +191,12 @@ func (s *MigrationTestSuite) TestMigrateAllLegacyMultiOffline() { s.Require().NoError(s.ks.SetItem(item)) - migrated, err := s.kb.MigrateAll() - s.Require().True(migrated) + err = s.kb.MigrateAll() s.Require().NoError(err) } func (s *MigrationTestSuite) TestMigrateAllNoItem() { - migrated, err := s.kb.MigrateAll() - s.Require().False(migrated) + err := s.kb.MigrateAll() s.Require().NoError(err) } @@ -221,9 +213,8 @@ func (s *MigrationTestSuite) TestMigrateErrUnknownItemKey() { s.Require().NoError(s.ks.SetItem(item)) incorrectItemKey := n1 + "1" - _, migrated, err := s.ks.migrate(incorrectItemKey) - s.Require().False(migrated) - s.Require().EqualError(err, sdkerrors.Wrap(sdkerrors.ErrKeyNotFound, incorrectItemKey).Error()) + _, err := s.ks.migrate(incorrectItemKey) + s.Require().EqualError(err, sdkerrors.Wrap(sdkerrors.ErrKeyNotFound, infoKey(incorrectItemKey)).Error()) } func (s *MigrationTestSuite) TestMigrateErrEmptyItemData() { @@ -235,8 +226,7 @@ func (s *MigrationTestSuite) TestMigrateErrEmptyItemData() { s.Require().NoError(s.ks.SetItem(item)) - _, migrated, err := s.ks.migrate(n1) - s.Require().False(migrated) + _, err := s.ks.migrate(n1) s.Require().EqualError(err, sdkerrors.Wrap(sdkerrors.ErrKeyNotFound, n1).Error()) } func TestMigrationTestSuite(t *testing.T) { diff --git a/crypto/keyring/record.go b/crypto/keyring/record.go index acc84f6490b1..1b1885648e5e 100644 --- a/crypto/keyring/record.go +++ b/crypto/keyring/record.go @@ -28,7 +28,7 @@ func NewLocalRecord(name string, priv cryptotypes.PrivKey, pk cryptotypes.PubKey return nil, err } - recordLocal := &Record_Local{any, priv.Type()} + recordLocal := &Record_Local{any} recordLocalItem := &Record_Local_{recordLocal} return newRecord(name, pk, recordLocalItem) diff --git a/crypto/keyring/record.pb.go b/crypto/keyring/record.pb.go index c94e1ce0faa8..5e8df719a5c6 100644 --- a/crypto/keyring/record.pb.go +++ b/crypto/keyring/record.pb.go @@ -146,8 +146,7 @@ func (*Record) XXX_OneofWrappers() []interface{} { // Item is a keyring item stored in a keyring backend. // Local item type Record_Local struct { - PrivKey *types.Any `protobuf:"bytes,1,opt,name=priv_key,json=privKey,proto3" json:"priv_key,omitempty"` - PrivKeyType string `protobuf:"bytes,2,opt,name=priv_key_type,json=privKeyType,proto3" json:"priv_key_type,omitempty"` + PrivKey *types.Any `protobuf:"bytes,1,opt,name=priv_key,json=privKey,proto3" json:"priv_key,omitempty"` } func (m *Record_Local) Reset() { *m = Record_Local{} } @@ -308,34 +307,33 @@ func init() { } var fileDescriptor_36d640103edea005 = []byte{ - // 424 bytes of a gzipped FileDescriptorProto - 0x1f, 0x8b, 0x08, 0x00, 0x00, 0x00, 0x00, 0x00, 0x02, 0xff, 0x8c, 0x92, 0x4d, 0x8b, 0xd4, 0x30, - 0x18, 0xc7, 0x5b, 0xed, 0xb4, 0x4e, 0x16, 0x2f, 0x61, 0x0f, 0xb5, 0x48, 0x19, 0x16, 0xd4, 0x01, - 0xd9, 0x84, 0xd5, 0x39, 0x2f, 0xec, 0xe0, 0x61, 0x16, 0x15, 0x97, 0xe0, 0x49, 0x84, 0xa5, 0x2f, - 0x99, 0xb6, 0x4c, 0xdb, 0x84, 0x4c, 0x3b, 0x90, 0x2f, 0x21, 0x7e, 0xac, 0x3d, 0xee, 0xd1, 0xa3, - 0xce, 0x7c, 0x11, 0xc9, 0x93, 0xf6, 0xe0, 0x82, 0x8e, 0xa7, 0xa6, 0xe4, 0xf7, 0xfc, 0x5f, 0x1e, - 0x82, 0x5e, 0x64, 0x62, 0xdb, 0x88, 0x2d, 0xcd, 0x94, 0x96, 0x9d, 0xa0, 0x1b, 0xae, 0x55, 0xd5, - 0x16, 0x74, 0x77, 0x41, 0x15, 0xcf, 0x84, 0xca, 0x89, 0x54, 0xa2, 0x13, 0x38, 0xb4, 0x18, 0xb1, - 0x18, 0x19, 0x30, 0xb2, 0xbb, 0x88, 0x4e, 0x0b, 0x51, 0x08, 0x80, 0xa8, 0x39, 0x59, 0x3e, 0x7a, - 0x56, 0x08, 0x51, 0xd4, 0x9c, 0xc2, 0x5f, 0xda, 0xaf, 0x69, 0xd2, 0xea, 0xe1, 0xea, 0xf9, 0x9f, - 0x8e, 0x65, 0x6e, 0xcc, 0xca, 0xc1, 0xe8, 0xec, 0x9b, 0x87, 0x7c, 0x06, 0xce, 0x18, 0x23, 0xaf, - 0x4d, 0x1a, 0x1e, 0xba, 0x33, 0x77, 0x3e, 0x65, 0x70, 0xc6, 0xe7, 0x28, 0x90, 0x7d, 0x7a, 0xbb, - 0xe1, 0x3a, 0x7c, 0x34, 0x73, 0xe7, 0x27, 0x6f, 0x4e, 0x89, 0x75, 0x22, 0xa3, 0x13, 0xb9, 0x6a, - 0x35, 0xf3, 0x65, 0x9f, 0xbe, 0xe7, 0x1a, 0x5f, 0xa2, 0x49, 0x2d, 0xb2, 0xa4, 0x0e, 0x1f, 0x03, - 0xfc, 0x92, 0xfc, 0xad, 0x06, 0xb1, 0x9e, 0xe4, 0x83, 0xa1, 0x57, 0x0e, 0xb3, 0x63, 0xf8, 0x0a, - 0xf9, 0x35, 0xcf, 0x0b, 0xae, 0x42, 0x0f, 0x04, 0x5e, 0x1d, 0x17, 0x00, 0x7c, 0xe5, 0xb0, 0x61, - 0xd0, 0x44, 0x68, 0xfa, 0xba, 0xab, 0xc2, 0xc9, 0x7f, 0x46, 0xf8, 0x68, 0x68, 0x13, 0x01, 0xc6, - 0xf0, 0x3b, 0x14, 0x88, 0xf5, 0xba, 0xae, 0x5a, 0x1e, 0xfa, 0xa0, 0x30, 0x3f, 0xaa, 0xf0, 0xc9, - 0xf2, 0x2b, 0x87, 0x8d, 0xa3, 0xd1, 0x57, 0x34, 0x81, 0x6a, 0x98, 0xa2, 0x27, 0x52, 0x55, 0x3b, - 0xd8, 0xa0, 0xfb, 0x8f, 0x0d, 0x06, 0x86, 0x32, 0x2b, 0x3c, 0x43, 0x4f, 0xc7, 0x81, 0xdb, 0x4e, - 0x4b, 0x0e, 0x7b, 0x9f, 0xb2, 0x93, 0xe1, 0xfe, 0xb3, 0x96, 0x3c, 0xba, 0x44, 0xbe, 0xed, 0x8d, - 0x17, 0xc8, 0x93, 0x49, 0x57, 0x0e, 0xd2, 0xb3, 0x07, 0x51, 0xcb, 0xdc, 0xa4, 0x5c, 0x5e, 0xdf, - 0x2c, 0x16, 0x37, 0x89, 0x4a, 0x9a, 0x2d, 0x03, 0x3a, 0x0a, 0xd0, 0x04, 0x5a, 0x47, 0x53, 0x14, - 0x0c, 0xe1, 0x97, 0x3e, 0xf2, 0xaa, 0x8e, 0x37, 0xcb, 0xeb, 0xbb, 0x5f, 0xb1, 0x73, 0xb7, 0x8f, - 0xdd, 0xfb, 0x7d, 0xec, 0xfe, 0xdc, 0xc7, 0xee, 0xf7, 0x43, 0xec, 0xdc, 0x1f, 0x62, 0xe7, 0xc7, - 0x21, 0x76, 0xbe, 0xbc, 0x2e, 0xaa, 0xae, 0xec, 0x53, 0x92, 0x89, 0x86, 0x8e, 0xef, 0x0a, 0x3e, - 0xe7, 0xdb, 0x7c, 0xf3, 0xe0, 0x51, 0xa7, 0x3e, 0x34, 0x7c, 0xfb, 0x3b, 0x00, 0x00, 0xff, 0xff, - 0xe8, 0x29, 0x24, 0x50, 0xf4, 0x02, 0x00, 0x00, + // 408 bytes of a gzipped FileDescriptorProto + 0x1f, 0x8b, 0x08, 0x00, 0x00, 0x00, 0x00, 0x00, 0x02, 0xff, 0x8c, 0x92, 0x3d, 0x6b, 0xdb, 0x40, + 0x1c, 0xc6, 0xa5, 0x5a, 0x2f, 0xf5, 0x75, 0x3b, 0x3c, 0xa8, 0xa2, 0x08, 0x53, 0x68, 0x6b, 0x28, + 0xbe, 0xc3, 0xad, 0x87, 0x4e, 0x06, 0x9b, 0x0e, 0x36, 0x4e, 0x88, 0xd1, 0x98, 0x25, 0xe8, 0xe5, + 0x2c, 0x09, 0x4b, 0x3a, 0x71, 0x92, 0x0c, 0xfa, 0x16, 0xf9, 0x58, 0x1e, 0x3d, 0x66, 0x4c, 0xec, + 0x2d, 0x9f, 0x22, 0xdc, 0x9d, 0x3c, 0xc4, 0x90, 0x38, 0x93, 0x4e, 0xdc, 0xef, 0xf9, 0x3f, 0xcf, + 0x73, 0xfc, 0xc1, 0x8f, 0x80, 0x96, 0x19, 0x2d, 0x71, 0xc0, 0x9a, 0xa2, 0xa2, 0x78, 0x43, 0x1a, + 0x96, 0xe4, 0x11, 0xde, 0x8e, 0x30, 0x23, 0x01, 0x65, 0x21, 0x2a, 0x18, 0xad, 0x28, 0xb4, 0x24, + 0x86, 0x24, 0x86, 0x5a, 0x0c, 0x6d, 0x47, 0x76, 0x2f, 0xa2, 0x11, 0x15, 0x10, 0xe6, 0x27, 0xc9, + 0xdb, 0x5f, 0x23, 0x4a, 0xa3, 0x94, 0x60, 0xf1, 0xe7, 0xd7, 0x6b, 0xec, 0xe5, 0x4d, 0x7b, 0xf5, + 0xed, 0xb5, 0x63, 0x1c, 0x72, 0xb3, 0xb8, 0x35, 0xfa, 0xfe, 0xdc, 0x01, 0x86, 0x2b, 0x9c, 0x21, + 0x04, 0x5a, 0xee, 0x65, 0xc4, 0x52, 0xfb, 0xea, 0xa0, 0xeb, 0x8a, 0x33, 0x1c, 0x02, 0xb3, 0xa8, + 0xfd, 0xbb, 0x0d, 0x69, 0xac, 0x4f, 0x7d, 0x75, 0xf0, 0xe5, 0x4f, 0x0f, 0x49, 0x27, 0x74, 0x72, + 0x42, 0xd3, 0xbc, 0x71, 0x8d, 0xa2, 0xf6, 0x97, 0xa4, 0x81, 0x13, 0xa0, 0xa7, 0x34, 0xf0, 0x52, + 0xab, 0x23, 0xe0, 0x9f, 0xe8, 0xad, 0x1a, 0x48, 0x7a, 0xa2, 0x2b, 0x4e, 0xcf, 0x15, 0x57, 0xca, + 0xe0, 0x14, 0x18, 0x29, 0x09, 0x23, 0xc2, 0x2c, 0x4d, 0x0c, 0xf8, 0x75, 0x79, 0x80, 0xc0, 0xe7, + 0x8a, 0xdb, 0x0a, 0x79, 0x84, 0xac, 0x4e, 0xab, 0xc4, 0xd2, 0x3f, 0x18, 0xe1, 0x9a, 0xd3, 0x3c, + 0x82, 0x90, 0xc1, 0xff, 0xc0, 0xa4, 0xeb, 0x75, 0x9a, 0xe4, 0xc4, 0x32, 0xc4, 0x84, 0xc1, 0xc5, + 0x09, 0x37, 0x92, 0x9f, 0x2b, 0xee, 0x49, 0x6a, 0xff, 0x03, 0xba, 0xa8, 0x06, 0x31, 0xf8, 0x5c, + 0xb0, 0x64, 0x2b, 0x5e, 0x50, 0x7d, 0xe7, 0x05, 0x4d, 0x4e, 0x2d, 0x49, 0x63, 0x4f, 0x80, 0x21, + 0x3b, 0xc1, 0x31, 0xd0, 0x0a, 0xaf, 0x8a, 0x5b, 0x59, 0xff, 0x2c, 0x46, 0x1c, 0xf2, 0x04, 0xb3, + 0xc5, 0x6a, 0x3c, 0x5e, 0x79, 0xcc, 0xcb, 0x4a, 0x57, 0xd0, 0xb6, 0x09, 0x74, 0xd1, 0xc8, 0xee, + 0x02, 0xb3, 0x0d, 0x36, 0x33, 0x80, 0x96, 0x54, 0x24, 0x9b, 0x2d, 0x76, 0x4f, 0x8e, 0xb2, 0x3b, + 0x38, 0xea, 0xfe, 0xe0, 0xa8, 0x8f, 0x07, 0x47, 0xbd, 0x3f, 0x3a, 0xca, 0xfe, 0xe8, 0x28, 0x0f, + 0x47, 0x47, 0xb9, 0xfd, 0x1d, 0x25, 0x55, 0x5c, 0xfb, 0x28, 0xa0, 0x19, 0x3e, 0xed, 0x8c, 0xf8, + 0x0c, 0xcb, 0x70, 0x73, 0xb6, 0xb0, 0xbe, 0x21, 0xd2, 0xff, 0x7d, 0x09, 0x00, 0x00, 0xff, 0xff, + 0x64, 0x83, 0x0c, 0x89, 0xd0, 0x02, 0x00, 0x00, } func (m *Record) Marshal() (dAtA []byte, err error) { @@ -493,13 +491,6 @@ func (m *Record_Local) MarshalToSizedBuffer(dAtA []byte) (int, error) { _ = i var l int _ = l - if len(m.PrivKeyType) > 0 { - i -= len(m.PrivKeyType) - copy(dAtA[i:], m.PrivKeyType) - i = encodeVarintRecord(dAtA, i, uint64(len(m.PrivKeyType))) - i-- - dAtA[i] = 0x12 - } if m.PrivKey != nil { { size, err := m.PrivKey.MarshalToSizedBuffer(dAtA[:i]) @@ -685,10 +676,6 @@ func (m *Record_Local) Size() (n int) { l = m.PrivKey.Size() n += 1 + l + sovRecord(uint64(l)) } - l = len(m.PrivKeyType) - if l > 0 { - n += 1 + l + sovRecord(uint64(l)) - } return n } @@ -1052,38 +1039,6 @@ func (m *Record_Local) Unmarshal(dAtA []byte) error { return err } iNdEx = postIndex - case 2: - if wireType != 2 { - return fmt.Errorf("proto: wrong wireType = %d for field PrivKeyType", wireType) - } - var stringLen uint64 - for shift := uint(0); ; shift += 7 { - if shift >= 64 { - return ErrIntOverflowRecord - } - if iNdEx >= l { - return io.ErrUnexpectedEOF - } - b := dAtA[iNdEx] - iNdEx++ - stringLen |= uint64(b&0x7F) << shift - if b < 0x80 { - break - } - } - intStringLen := int(stringLen) - if intStringLen < 0 { - return ErrInvalidLengthRecord - } - postIndex := iNdEx + intStringLen - if postIndex < 0 { - return ErrInvalidLengthRecord - } - if postIndex > l { - return io.ErrUnexpectedEOF - } - m.PrivKeyType = string(dAtA[iNdEx:postIndex]) - iNdEx = postIndex default: iNdEx = preIndex skippy, err := skipRecord(dAtA[iNdEx:]) diff --git a/crypto/keyring/record_test.go b/crypto/keyring/record_test.go index 6c17379b4653..2ec0401d87ff 100644 --- a/crypto/keyring/record_test.go +++ b/crypto/keyring/record_test.go @@ -78,7 +78,6 @@ func (s *RecordTestSuite) TestLocalRecordMarshaling() { anyPrivKey, err := codectypes.NewAnyWithValue(s.priv) s.Require().NoError(err) s.Require().Equal(localRecord2.PrivKey, anyPrivKey) - s.Require().Equal(localRecord2.PrivKeyType, s.priv.Type()) } func (s *RecordTestSuite) TestLedgerRecordMarshaling() { diff --git a/proto/cosmos/crypto/keyring/v1/record.proto b/proto/cosmos/crypto/keyring/v1/record.proto index 1461c0193c9b..ca70aa984af6 100644 --- a/proto/cosmos/crypto/keyring/v1/record.proto +++ b/proto/cosmos/crypto/keyring/v1/record.proto @@ -18,13 +18,13 @@ message Record { // Record contains one of the following items oneof item { - // local stores the public information about a locally stored key + // local stores the private key locally. Local local = 3; - // ledger stores the public information about a Ledger key + // ledger stores the information about a Ledger key. Ledger ledger = 4; - // Multi does not store any information. + // Multi does not store any other information. Multi multi = 5; - // Offline does not store any information. + // Offline does not store any other information. Offline offline = 6; } @@ -32,7 +32,6 @@ message Record { // Local item message Local { google.protobuf.Any priv_key = 1; - string priv_key_type = 2; } // Ledger item From ac9754f367723d618768e493b054de932bbfa0f2 Mon Sep 17 00:00:00 2001 From: "dependabot[bot]" <49699333+dependabot[bot]@users.noreply.github.com> Date: Sun, 15 May 2022 14:06:14 +0000 Subject: [PATCH 5/5] build(deps): Bump google.golang.org/grpc from 1.46.0 to 1.46.2 (#11964) Bumps [google.golang.org/grpc](https://github.com/grpc/grpc-go) from 1.46.0 to 1.46.2.
Release notes

Sourced from google.golang.org/grpc's releases.

Release v1.46.2

Bug Fixes

  • client: fix potential panic during RPC retries (#5323)
  • xds: fix leak of deleted CDS resources from CSDS view (#5339)
Commits

[![Dependabot compatibility score](https://dependabot-badges.githubapp.com/badges/compatibility_score?dependency-name=google.golang.org/grpc&package-manager=go_modules&previous-version=1.46.0&new-version=1.46.2)](https://docs.github.com/en/github/managing-security-vulnerabilities/about-dependabot-security-updates#about-compatibility-scores) Dependabot will resolve any conflicts with this PR as long as you don't alter it yourself. You can also trigger a rebase manually by commenting `@dependabot rebase`. [//]: # (dependabot-automerge-start) [//]: # (dependabot-automerge-end) ---
Dependabot commands and options
You can trigger Dependabot actions by commenting on this PR: - `@dependabot rebase` will rebase this PR - `@dependabot recreate` will recreate this PR, overwriting any edits that have been made to it - `@dependabot merge` will merge this PR after your CI passes on it - `@dependabot squash and merge` will squash and merge this PR after your CI passes on it - `@dependabot cancel merge` will cancel a previously requested merge and block automerging - `@dependabot reopen` will reopen this PR if it is closed - `@dependabot close` will close this PR and stop Dependabot recreating it. You can achieve the same result by closing it manually - `@dependabot ignore this major version` will close this PR and stop Dependabot creating any more for this major version (unless you reopen the PR or upgrade to it yourself) - `@dependabot ignore this minor version` will close this PR and stop Dependabot creating any more for this minor version (unless you reopen the PR or upgrade to it yourself) - `@dependabot ignore this dependency` will close this PR and stop Dependabot creating any more for this dependency (unless you reopen the PR or upgrade to it yourself)
--- go.mod | 2 +- go.sum | 4 ++-- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/go.mod b/go.mod index 5f877b428de1..d435bf4ccfe2 100644 --- a/go.mod +++ b/go.mod @@ -55,7 +55,7 @@ require ( github.com/tendermint/tm-db v0.6.6 golang.org/x/crypto v0.0.0-20220411220226-7b82a4e95df4 google.golang.org/genproto v0.0.0-20220407144326-9054f6ed7bac - google.golang.org/grpc v1.46.0 + google.golang.org/grpc v1.46.2 google.golang.org/protobuf v1.28.0 pgregory.net/rapid v0.4.7 sigs.k8s.io/yaml v1.3.0 diff --git a/go.sum b/go.sum index 27be10770e44..c20e494f12e5 100644 --- a/go.sum +++ b/go.sum @@ -2018,8 +2018,8 @@ google.golang.org/grpc v1.42.0/go.mod h1:k+4IHHFw41K8+bbowsex27ge2rCb65oeWqe4jJ5 google.golang.org/grpc v1.43.0/go.mod h1:k+4IHHFw41K8+bbowsex27ge2rCb65oeWqe4jJ590SU= google.golang.org/grpc v1.44.0/go.mod h1:k+4IHHFw41K8+bbowsex27ge2rCb65oeWqe4jJ590SU= google.golang.org/grpc v1.45.0/go.mod h1:lN7owxKUQEqMfSyQikvvk5tf/6zMPsrK+ONuO11+0rQ= -google.golang.org/grpc v1.46.0 h1:oCjezcn6g6A75TGoKYBPgKmVBLexhYLM6MebdrPApP8= -google.golang.org/grpc v1.46.0/go.mod h1:vN9eftEi1UMyUsIF80+uQXhHjbXYbm0uXoFCACuMGWk= +google.golang.org/grpc v1.46.2 h1:u+MLGgVf7vRdjEYZ8wDFhAVNmhkbJ5hmrA1LMWK1CAQ= +google.golang.org/grpc v1.46.2/go.mod h1:vN9eftEi1UMyUsIF80+uQXhHjbXYbm0uXoFCACuMGWk= google.golang.org/grpc/cmd/protoc-gen-go-grpc v1.1.0/go.mod h1:6Kw0yEErY5E/yWrBtf03jp27GLLJujG4z/JK95pnjjw= google.golang.org/protobuf v0.0.0-20200109180630-ec00e32a8dfd/go.mod h1:DFci5gLYBciE7Vtevhsrf46CRTquxDuWsQurQQe4oz8= google.golang.org/protobuf v0.0.0-20200221191635-4d8936d0db64/go.mod h1:kwYJMbMJ01Woi6D6+Kah6886xMZcty6N08ah7+eCXa0=