From abc3e56d8368fa4ced8cd7d735ee8995577b5a4b Mon Sep 17 00:00:00 2001 From: Aaron Craelius Date: Thu, 3 Feb 2022 17:56:30 -0500 Subject: [PATCH 1/5] feat(orm)!: return ormerrors.NotFound for Get methods in codegen --- orm/internal/codegen/table.go | 22 ++++++++++----- orm/internal/testpb/bank.cosmos_orm.go | 16 ++++++++--- orm/internal/testpb/test_schema.cosmos_orm.go | 28 +++++++++++++++---- orm/model/ormdb/module_test.go | 26 +++++++++-------- orm/types/ormerrors/errors.go | 1 + 5 files changed, 65 insertions(+), 28 deletions(-) diff --git a/orm/internal/codegen/table.go b/orm/internal/codegen/table.go index 970a02260ca9..45b53d81686a 100644 --- a/orm/internal/codegen/table.go +++ b/orm/internal/codegen/table.go @@ -64,6 +64,7 @@ func (t tableGen) genStoreInterface() { t.P("Save(ctx ", contextPkg.Ident("Context"), ", ", t.param(t.msg.GoIdent.GoName), " *", t.QualifiedGoIdent(t.msg.GoIdent), ") error") t.P("Delete(ctx ", contextPkg.Ident("Context"), ", ", t.param(t.msg.GoIdent.GoName), " *", t.QualifiedGoIdent(t.msg.GoIdent), ") error") t.P("Has(ctx ", contextPkg.Ident("Context"), ", ", t.fieldsArgs(t.primaryKeyFields.Names()), ") (found bool, err error)") + t.P("// Get returns nil, ormerrors.NotFound if the record wasn't found.") t.P("Get(ctx ", contextPkg.Ident("Context"), ", ", t.fieldsArgs(t.primaryKeyFields.Names()), ") (*", t.QualifiedGoIdent(t.msg.GoIdent), ", error)") for _, idx := range t.uniqueIndexes { @@ -80,7 +81,7 @@ func (t tableGen) genStoreInterface() { } // returns the has and get (in that order) function signature for unique indexes. -func (t tableGen) uniqueIndexSig(idxFields string) (string, string) { +func (t tableGen) uniqueIndexSig(idxFields string) (string, string, string) { fieldsSlc := strings.Split(idxFields, ",") camelFields := t.fieldsToCamelCase(idxFields) @@ -90,12 +91,13 @@ func (t tableGen) uniqueIndexSig(idxFields string) (string, string) { hasFuncSig := fmt.Sprintf("%s (ctx context.Context, %s) (found bool, err error)", hasFuncName, args) getFuncSig := fmt.Sprintf("%s (ctx context.Context, %s) (*%s, error)", getFuncName, args, t.msg.GoIdent.GoName) - return hasFuncSig, getFuncSig + return hasFuncSig, getFuncSig, getFuncName } func (t tableGen) genUniqueIndexSig(idx *ormv1alpha1.SecondaryIndexDescriptor) { - hasSig, getSig := t.uniqueIndexSig(idx.Fields) + hasSig, getSig, getFuncName := t.uniqueIndexSig(idx.Fields) t.P(hasSig) + t.P("// ", getFuncName, " returns nil, ormerrors.NotFound if the record wasn't found.") t.P(getSig) } @@ -191,16 +193,19 @@ func (t tableGen) genStoreImpl() { t.P(receiver, "Get(ctx ", contextPkg.Ident("Context"), ", ", t.fieldsArgs(t.primaryKeyFields.Names()), ") (*", varTypeName, ", error) {") t.P("var ", varName, " ", varTypeName) t.P("found, err := ", receiverVar, ".table.PrimaryKey().Get(ctx, &", varName, ", ", t.primaryKeyFields.String(), ")") - t.P("if !found {") + t.P("if err != nil {") t.P("return nil, err") t.P("}") - t.P("return &", varName, ", err") + t.P("if !found {") + t.P("return nil, ", ormErrPkg.Ident("NotFound")) + t.P("}") + t.P("return &", varName, ", nil") t.P("}") t.P() for _, idx := range t.uniqueIndexes { fields := strings.Split(idx.Fields, ",") - hasName, getName := t.uniqueIndexSig(idx.Fields) + hasName, getName, _ := t.uniqueIndexSig(idx.Fields) // has t.P("func (", receiverVar, " ", t.messageStoreReceiverName(t.msg), ") ", hasName, "{") @@ -224,9 +229,12 @@ func (t tableGen) genStoreImpl() { t.P(field, ",") } t.P(")") - t.P("if !found {") + t.P("if err != nil {") t.P("return nil, err") t.P("}") + t.P("if !found {") + t.P("return nil, ", ormErrPkg.Ident("NotFound")) + t.P("}") t.P("return &", varName, ", nil") t.P("}") t.P() diff --git a/orm/internal/testpb/bank.cosmos_orm.go b/orm/internal/testpb/bank.cosmos_orm.go index 3ef895947007..c4e3adc49671 100644 --- a/orm/internal/testpb/bank.cosmos_orm.go +++ b/orm/internal/testpb/bank.cosmos_orm.go @@ -17,6 +17,7 @@ type BalanceStore interface { Save(ctx context.Context, balance *Balance) error Delete(ctx context.Context, balance *Balance) error Has(ctx context.Context, address string, denom string) (found bool, err error) + // Get returns ormerrors.NotFound if the record wasn't found. Get(ctx context.Context, address string, denom string) (*Balance, error) List(ctx context.Context, prefixKey BalanceIndexKey, opts ...ormlist.Option) (BalanceIterator, error) ListRange(ctx context.Context, from, to BalanceIndexKey, opts ...ormlist.Option) (BalanceIterator, error) @@ -103,10 +104,13 @@ func (this balanceStore) Has(ctx context.Context, address string, denom string) func (this balanceStore) Get(ctx context.Context, address string, denom string) (*Balance, error) { var balance Balance found, err := this.table.PrimaryKey().Get(ctx, &balance, address, denom) - if !found { + if err != nil { return nil, err } - return &balance, err + if !found { + return nil, ormerrors.NotFound + } + return &balance, nil } func (this balanceStore) List(ctx context.Context, prefixKey BalanceIndexKey, opts ...ormlist.Option) (BalanceIterator, error) { @@ -145,6 +149,7 @@ type SupplyStore interface { Save(ctx context.Context, supply *Supply) error Delete(ctx context.Context, supply *Supply) error Has(ctx context.Context, denom string) (found bool, err error) + // Get returns ormerrors.NotFound if the record wasn't found. Get(ctx context.Context, denom string) (*Supply, error) List(ctx context.Context, prefixKey SupplyIndexKey, opts ...ormlist.Option) (SupplyIterator, error) ListRange(ctx context.Context, from, to SupplyIndexKey, opts ...ormlist.Option) (SupplyIterator, error) @@ -213,10 +218,13 @@ func (this supplyStore) Has(ctx context.Context, denom string) (found bool, err func (this supplyStore) Get(ctx context.Context, denom string) (*Supply, error) { var supply Supply found, err := this.table.PrimaryKey().Get(ctx, &supply, denom) - if !found { + if err != nil { return nil, err } - return &supply, err + if !found { + return nil, ormerrors.NotFound + } + return &supply, nil } func (this supplyStore) List(ctx context.Context, prefixKey SupplyIndexKey, opts ...ormlist.Option) (SupplyIterator, error) { diff --git a/orm/internal/testpb/test_schema.cosmos_orm.go b/orm/internal/testpb/test_schema.cosmos_orm.go index 6ebf57c45d02..a4fd35f6ca5a 100644 --- a/orm/internal/testpb/test_schema.cosmos_orm.go +++ b/orm/internal/testpb/test_schema.cosmos_orm.go @@ -17,8 +17,10 @@ type ExampleTableStore interface { Save(ctx context.Context, exampleTable *ExampleTable) error Delete(ctx context.Context, exampleTable *ExampleTable) error Has(ctx context.Context, u32 uint32, i64 int64, str string) (found bool, err error) + // Get returns ormerrors.NotFound if the record wasn't found. Get(ctx context.Context, u32 uint32, i64 int64, str string) (*ExampleTable, error) HasByU64Str(ctx context.Context, u64 uint64, str string) (found bool, err error) + // GetByU64Str returns ormerrors.NotFound if the record wasn't found. GetByU64Str(ctx context.Context, u64 uint64, str string) (*ExampleTable, error) List(ctx context.Context, prefixKey ExampleTableIndexKey, opts ...ormlist.Option) (ExampleTableIterator, error) ListRange(ctx context.Context, from, to ExampleTableIndexKey, opts ...ormlist.Option) (ExampleTableIterator, error) @@ -151,10 +153,13 @@ func (this exampleTableStore) Has(ctx context.Context, u32 uint32, i64 int64, st func (this exampleTableStore) Get(ctx context.Context, u32 uint32, i64 int64, str string) (*ExampleTable, error) { var exampleTable ExampleTable found, err := this.table.PrimaryKey().Get(ctx, &exampleTable, u32, i64, str) - if !found { + if err != nil { return nil, err } - return &exampleTable, err + if !found { + return nil, ormerrors.NotFound + } + return &exampleTable, nil } func (this exampleTableStore) HasByU64Str(ctx context.Context, u64 uint64, str string) (found bool, err error) { @@ -170,9 +175,12 @@ func (this exampleTableStore) GetByU64Str(ctx context.Context, u64 uint64, str s u64, str, ) - if !found { + if err != nil { return nil, err } + if !found { + return nil, ormerrors.NotFound + } return &exampleTable, nil } @@ -213,8 +221,10 @@ type ExampleAutoIncrementTableStore interface { Save(ctx context.Context, exampleAutoIncrementTable *ExampleAutoIncrementTable) error Delete(ctx context.Context, exampleAutoIncrementTable *ExampleAutoIncrementTable) error Has(ctx context.Context, id uint64) (found bool, err error) + // Get returns ormerrors.NotFound if the record wasn't found. Get(ctx context.Context, id uint64) (*ExampleAutoIncrementTable, error) HasByX(ctx context.Context, x string) (found bool, err error) + // GetByX returns ormerrors.NotFound if the record wasn't found. GetByX(ctx context.Context, x string) (*ExampleAutoIncrementTable, error) List(ctx context.Context, prefixKey ExampleAutoIncrementTableIndexKey, opts ...ormlist.Option) (ExampleAutoIncrementTableIterator, error) ListRange(ctx context.Context, from, to ExampleAutoIncrementTableIndexKey, opts ...ormlist.Option) (ExampleAutoIncrementTableIterator, error) @@ -300,10 +310,13 @@ func (this exampleAutoIncrementTableStore) Has(ctx context.Context, id uint64) ( func (this exampleAutoIncrementTableStore) Get(ctx context.Context, id uint64) (*ExampleAutoIncrementTable, error) { var exampleAutoIncrementTable ExampleAutoIncrementTable found, err := this.table.PrimaryKey().Get(ctx, &exampleAutoIncrementTable, id) - if !found { + if err != nil { return nil, err } - return &exampleAutoIncrementTable, err + if !found { + return nil, ormerrors.NotFound + } + return &exampleAutoIncrementTable, nil } func (this exampleAutoIncrementTableStore) HasByX(ctx context.Context, x string) (found bool, err error) { @@ -317,9 +330,12 @@ func (this exampleAutoIncrementTableStore) GetByX(ctx context.Context, x string) found, err := this.table.GetIndexByID(1).(ormtable.UniqueIndex).Get(ctx, &exampleAutoIncrementTable, x, ) - if !found { + if err != nil { return nil, err } + if !found { + return nil, ormerrors.NotFound + } return &exampleAutoIncrementTable, nil } diff --git a/orm/model/ormdb/module_test.go b/orm/model/ormdb/module_test.go index 515c8c517eb3..948b52a7d46a 100644 --- a/orm/model/ormdb/module_test.go +++ b/orm/model/ormdb/module_test.go @@ -7,6 +7,10 @@ import ( "strings" "testing" + "github.com/cosmos/cosmos-sdk/orm/types/ormerrors" + + "github.com/cosmos/cosmos-sdk/errors" + "google.golang.org/protobuf/reflect/protoreflect" "gotest.tools/v3/assert" "gotest.tools/v3/golden" @@ -41,7 +45,7 @@ func (k keeper) Send(ctx context.Context, from, to, denom string, amount uint64) func (k keeper) Mint(ctx context.Context, acct, denom string, amount uint64) error { supply, err := k.store.SupplyStore().Get(ctx, denom) - if err != nil { + if err != nil && !errors.IsOf(err, ormerrors.NotFound) { return err } @@ -66,10 +70,6 @@ func (k keeper) Burn(ctx context.Context, acct, denom string, amount uint64) err return err } - if supply == nil { - return fmt.Errorf("no supply for %s", denom) - } - if amount > supply.Amount { return fmt.Errorf("insufficient supply") } @@ -90,7 +90,11 @@ func (k keeper) Burn(ctx context.Context, acct, denom string, amount uint64) err func (k keeper) Balance(ctx context.Context, acct, denom string) (uint64, error) { balance, err := k.store.BalanceStore().Get(ctx, acct, denom) - if balance == nil { + if err != nil { + if errors.IsOf(err, ormerrors.NotFound) { + return 0, nil + } + return 0, err } return balance.Amount, err @@ -99,6 +103,10 @@ func (k keeper) Balance(ctx context.Context, acct, denom string) (uint64, error) func (k keeper) Supply(ctx context.Context, denom string) (uint64, error) { supply, err := k.store.SupplyStore().Get(ctx, denom) if supply == nil { + if errors.IsOf(err, ormerrors.NotFound) { + return 0, nil + } + return 0, err } return supply.Amount, err @@ -106,7 +114,7 @@ func (k keeper) Supply(ctx context.Context, denom string) (uint64, error) { func (k keeper) addBalance(ctx context.Context, acct, denom string, amount uint64) error { balance, err := k.store.BalanceStore().Get(ctx, acct, denom) - if err != nil { + if err != nil && !errors.IsOf(err, ormerrors.NotFound) { return err } @@ -130,10 +138,6 @@ func (k keeper) safeSubBalance(ctx context.Context, acct, denom string, amount u return err } - if balance == nil { - return fmt.Errorf("acct %x has no balance for %s", acct, denom) - } - if amount > balance.Amount { return fmt.Errorf("insufficient funds") } diff --git a/orm/types/ormerrors/errors.go b/orm/types/ormerrors/errors.go index e922aa76ea03..224e24b4b19b 100644 --- a/orm/types/ormerrors/errors.go +++ b/orm/types/ormerrors/errors.go @@ -32,4 +32,5 @@ var ( InvalidTableDefinition = errors.New(codespace, 25, "invalid table definition") InvalidFileDescriptorID = errors.New(codespace, 26, "invalid file descriptor ID") TableNotFound = errors.New(codespace, 27, "table not found") + NotFound = errors.New(codespace, 28, "not found") ) From 29a4e00fcec4c25574b52df18468b365ca66d104 Mon Sep 17 00:00:00 2001 From: Aaron Craelius Date: Thu, 3 Feb 2022 18:52:17 -0500 Subject: [PATCH 2/5] add ormerrors.IsNotFound() --- orm/internal/codegen/table.go | 6 ++++-- orm/internal/testpb/bank.cosmos_orm.go | 4 ++-- orm/internal/testpb/test_schema.cosmos_orm.go | 8 ++++---- orm/model/ormdb/module_test.go | 10 ++++------ orm/types/ormerrors/errors.go | 5 +++++ 5 files changed, 19 insertions(+), 14 deletions(-) diff --git a/orm/internal/codegen/table.go b/orm/internal/codegen/table.go index 45b53d81686a..af6f4e22af33 100644 --- a/orm/internal/codegen/table.go +++ b/orm/internal/codegen/table.go @@ -23,6 +23,8 @@ type tableGen struct { ormTable ormtable.Table } +const notFoundDocs = " returns nil and an error which responds true to ormerrors.IsNotFound() if the record was not found." + func newTableGen(fileGen fileGen, msg *protogen.Message, table *ormv1alpha1.TableDescriptor) (*tableGen, error) { t := &tableGen{fileGen: fileGen, msg: msg, table: table, fields: map[protoreflect.Name]*protogen.Field{}} t.primaryKeyFields = fieldnames.CommaSeparatedFieldNames(table.PrimaryKey.Fields) @@ -64,7 +66,7 @@ func (t tableGen) genStoreInterface() { t.P("Save(ctx ", contextPkg.Ident("Context"), ", ", t.param(t.msg.GoIdent.GoName), " *", t.QualifiedGoIdent(t.msg.GoIdent), ") error") t.P("Delete(ctx ", contextPkg.Ident("Context"), ", ", t.param(t.msg.GoIdent.GoName), " *", t.QualifiedGoIdent(t.msg.GoIdent), ") error") t.P("Has(ctx ", contextPkg.Ident("Context"), ", ", t.fieldsArgs(t.primaryKeyFields.Names()), ") (found bool, err error)") - t.P("// Get returns nil, ormerrors.NotFound if the record wasn't found.") + t.P("// Get", notFoundDocs) t.P("Get(ctx ", contextPkg.Ident("Context"), ", ", t.fieldsArgs(t.primaryKeyFields.Names()), ") (*", t.QualifiedGoIdent(t.msg.GoIdent), ", error)") for _, idx := range t.uniqueIndexes { @@ -97,7 +99,7 @@ func (t tableGen) uniqueIndexSig(idxFields string) (string, string, string) { func (t tableGen) genUniqueIndexSig(idx *ormv1alpha1.SecondaryIndexDescriptor) { hasSig, getSig, getFuncName := t.uniqueIndexSig(idx.Fields) t.P(hasSig) - t.P("// ", getFuncName, " returns nil, ormerrors.NotFound if the record wasn't found.") + t.P("// ", getFuncName, notFoundDocs) t.P(getSig) } diff --git a/orm/internal/testpb/bank.cosmos_orm.go b/orm/internal/testpb/bank.cosmos_orm.go index c4e3adc49671..377fe7b41a74 100644 --- a/orm/internal/testpb/bank.cosmos_orm.go +++ b/orm/internal/testpb/bank.cosmos_orm.go @@ -17,7 +17,7 @@ type BalanceStore interface { Save(ctx context.Context, balance *Balance) error Delete(ctx context.Context, balance *Balance) error Has(ctx context.Context, address string, denom string) (found bool, err error) - // Get returns ormerrors.NotFound if the record wasn't found. + // Get returns nil and an error which responds true to ormerrors.IsNotFound() if the record was not found. Get(ctx context.Context, address string, denom string) (*Balance, error) List(ctx context.Context, prefixKey BalanceIndexKey, opts ...ormlist.Option) (BalanceIterator, error) ListRange(ctx context.Context, from, to BalanceIndexKey, opts ...ormlist.Option) (BalanceIterator, error) @@ -149,7 +149,7 @@ type SupplyStore interface { Save(ctx context.Context, supply *Supply) error Delete(ctx context.Context, supply *Supply) error Has(ctx context.Context, denom string) (found bool, err error) - // Get returns ormerrors.NotFound if the record wasn't found. + // Get returns nil and an error which responds true to ormerrors.IsNotFound() if the record was not found. Get(ctx context.Context, denom string) (*Supply, error) List(ctx context.Context, prefixKey SupplyIndexKey, opts ...ormlist.Option) (SupplyIterator, error) ListRange(ctx context.Context, from, to SupplyIndexKey, opts ...ormlist.Option) (SupplyIterator, error) diff --git a/orm/internal/testpb/test_schema.cosmos_orm.go b/orm/internal/testpb/test_schema.cosmos_orm.go index a4fd35f6ca5a..a3d96c71e36b 100644 --- a/orm/internal/testpb/test_schema.cosmos_orm.go +++ b/orm/internal/testpb/test_schema.cosmos_orm.go @@ -17,10 +17,10 @@ type ExampleTableStore interface { Save(ctx context.Context, exampleTable *ExampleTable) error Delete(ctx context.Context, exampleTable *ExampleTable) error Has(ctx context.Context, u32 uint32, i64 int64, str string) (found bool, err error) - // Get returns ormerrors.NotFound if the record wasn't found. + // Get returns nil and an error which responds true to ormerrors.IsNotFound() if the record was not found. Get(ctx context.Context, u32 uint32, i64 int64, str string) (*ExampleTable, error) HasByU64Str(ctx context.Context, u64 uint64, str string) (found bool, err error) - // GetByU64Str returns ormerrors.NotFound if the record wasn't found. + // GetByU64Str returns nil and an error which responds true to ormerrors.IsNotFound() if the record was not found. GetByU64Str(ctx context.Context, u64 uint64, str string) (*ExampleTable, error) List(ctx context.Context, prefixKey ExampleTableIndexKey, opts ...ormlist.Option) (ExampleTableIterator, error) ListRange(ctx context.Context, from, to ExampleTableIndexKey, opts ...ormlist.Option) (ExampleTableIterator, error) @@ -221,10 +221,10 @@ type ExampleAutoIncrementTableStore interface { Save(ctx context.Context, exampleAutoIncrementTable *ExampleAutoIncrementTable) error Delete(ctx context.Context, exampleAutoIncrementTable *ExampleAutoIncrementTable) error Has(ctx context.Context, id uint64) (found bool, err error) - // Get returns ormerrors.NotFound if the record wasn't found. + // Get returns nil and an error which responds true to ormerrors.IsNotFound() if the record was not found. Get(ctx context.Context, id uint64) (*ExampleAutoIncrementTable, error) HasByX(ctx context.Context, x string) (found bool, err error) - // GetByX returns ormerrors.NotFound if the record wasn't found. + // GetByX returns nil and an error which responds true to ormerrors.IsNotFound() if the record was not found. GetByX(ctx context.Context, x string) (*ExampleAutoIncrementTable, error) List(ctx context.Context, prefixKey ExampleAutoIncrementTableIndexKey, opts ...ormlist.Option) (ExampleAutoIncrementTableIterator, error) ListRange(ctx context.Context, from, to ExampleAutoIncrementTableIndexKey, opts ...ormlist.Option) (ExampleAutoIncrementTableIterator, error) diff --git a/orm/model/ormdb/module_test.go b/orm/model/ormdb/module_test.go index 948b52a7d46a..797e35c46a37 100644 --- a/orm/model/ormdb/module_test.go +++ b/orm/model/ormdb/module_test.go @@ -9,8 +9,6 @@ import ( "github.com/cosmos/cosmos-sdk/orm/types/ormerrors" - "github.com/cosmos/cosmos-sdk/errors" - "google.golang.org/protobuf/reflect/protoreflect" "gotest.tools/v3/assert" "gotest.tools/v3/golden" @@ -45,7 +43,7 @@ func (k keeper) Send(ctx context.Context, from, to, denom string, amount uint64) func (k keeper) Mint(ctx context.Context, acct, denom string, amount uint64) error { supply, err := k.store.SupplyStore().Get(ctx, denom) - if err != nil && !errors.IsOf(err, ormerrors.NotFound) { + if err != nil && !ormerrors.IsNotFound(err) { return err } @@ -91,7 +89,7 @@ func (k keeper) Burn(ctx context.Context, acct, denom string, amount uint64) err func (k keeper) Balance(ctx context.Context, acct, denom string) (uint64, error) { balance, err := k.store.BalanceStore().Get(ctx, acct, denom) if err != nil { - if errors.IsOf(err, ormerrors.NotFound) { + if ormerrors.IsNotFound(err) { return 0, nil } @@ -103,7 +101,7 @@ func (k keeper) Balance(ctx context.Context, acct, denom string) (uint64, error) func (k keeper) Supply(ctx context.Context, denom string) (uint64, error) { supply, err := k.store.SupplyStore().Get(ctx, denom) if supply == nil { - if errors.IsOf(err, ormerrors.NotFound) { + if ormerrors.IsNotFound(err) { return 0, nil } @@ -114,7 +112,7 @@ func (k keeper) Supply(ctx context.Context, denom string) (uint64, error) { func (k keeper) addBalance(ctx context.Context, acct, denom string, amount uint64) error { balance, err := k.store.BalanceStore().Get(ctx, acct, denom) - if err != nil && !errors.IsOf(err, ormerrors.NotFound) { + if err != nil && !ormerrors.IsNotFound(err) { return err } diff --git a/orm/types/ormerrors/errors.go b/orm/types/ormerrors/errors.go index 224e24b4b19b..45287631ce47 100644 --- a/orm/types/ormerrors/errors.go +++ b/orm/types/ormerrors/errors.go @@ -4,6 +4,11 @@ import "github.com/cosmos/cosmos-sdk/errors" var codespace = "orm" +// IsNotFound returns true if the error indicates that the record was not found. +func IsNotFound(err error) bool { + return errors.IsOf(err, NotFound) +} + var ( InvalidTableId = errors.New(codespace, 1, "invalid or missing table or single id, need a non-zero value") MissingPrimaryKey = errors.New(codespace, 2, "table is missing primary key") From f1edae286a5d5fed11e815409e5e1f0ba5301567 Mon Sep 17 00:00:00 2001 From: Aaron Craelius Date: Fri, 4 Feb 2022 10:11:22 -0500 Subject: [PATCH 3/5] revert --- baseapp/grpcrouter.go | 4 +--- client/config/config_test.go | 5 ++--- client/grpc_query.go | 8 +++----- codec/proto_codec.go | 6 ++---- server/grpc/server.go | 3 +-- server/grpc/server_test.go | 3 +-- x/group/client/testutil/tx.go | 7 +++---- x/group/msgs_test.go | 20 ++++++++++---------- 8 files changed, 23 insertions(+), 33 deletions(-) diff --git a/baseapp/grpcrouter.go b/baseapp/grpcrouter.go index 9c793b07e3ea..9746532cfcba 100644 --- a/baseapp/grpcrouter.go +++ b/baseapp/grpcrouter.go @@ -2,10 +2,8 @@ package baseapp import ( "fmt" - - "google.golang.org/grpc/encoding" - "github.com/cosmos/cosmos-sdk/codec" + "google.golang.org/grpc/encoding" "github.com/cosmos/cosmos-sdk/client/grpc/reflection" diff --git a/client/config/config_test.go b/client/config/config_test.go index 988fb7d6e392..41817a59d2df 100644 --- a/client/config/config_test.go +++ b/client/config/config_test.go @@ -3,13 +3,12 @@ package config_test import ( "bytes" "fmt" + "github.com/cosmos/cosmos-sdk/codec" + codectypes "github.com/cosmos/cosmos-sdk/codec/types" "io" "os" "testing" - "github.com/cosmos/cosmos-sdk/codec" - codectypes "github.com/cosmos/cosmos-sdk/codec/types" - "github.com/stretchr/testify/require" "github.com/cosmos/cosmos-sdk/client" diff --git a/client/grpc_query.go b/client/grpc_query.go index 9f84122078b8..4ba896700de7 100644 --- a/client/grpc_query.go +++ b/client/grpc_query.go @@ -4,13 +4,11 @@ import ( gocontext "context" "errors" "fmt" - "reflect" - "strconv" - + "github.com/cosmos/cosmos-sdk/codec" proto "github.com/gogo/protobuf/proto" "google.golang.org/grpc/encoding" - - "github.com/cosmos/cosmos-sdk/codec" + "reflect" + "strconv" gogogrpc "github.com/gogo/protobuf/grpc" abci "github.com/tendermint/tendermint/abci/types" diff --git a/codec/proto_codec.go b/codec/proto_codec.go index 71ac88ad2155..75f0ade5a7be 100644 --- a/codec/proto_codec.go +++ b/codec/proto_codec.go @@ -4,15 +4,13 @@ import ( "encoding/binary" "errors" "fmt" - "strings" - legacyproto "github.com/golang/protobuf/proto" "google.golang.org/grpc/encoding" + "strings" + "github.com/cosmos/cosmos-sdk/codec/types" "github.com/gogo/protobuf/jsonpb" gogoproto "github.com/gogo/protobuf/proto" - - "github.com/cosmos/cosmos-sdk/codec/types" ) // ProtoCodecMarshaler defines an interface for codecs that utilize Protobuf for both diff --git a/server/grpc/server.go b/server/grpc/server.go index a12c560077b1..ae96ac647ff4 100644 --- a/server/grpc/server.go +++ b/server/grpc/server.go @@ -2,11 +2,10 @@ package grpc import ( "fmt" + "github.com/cosmos/cosmos-sdk/codec" "net" "time" - "github.com/cosmos/cosmos-sdk/codec" - "google.golang.org/grpc" "github.com/cosmos/cosmos-sdk/client" diff --git a/server/grpc/server_test.go b/server/grpc/server_test.go index 5655d700c684..082399425306 100644 --- a/server/grpc/server_test.go +++ b/server/grpc/server_test.go @@ -6,11 +6,10 @@ package grpc_test import ( "context" "fmt" + "github.com/cosmos/cosmos-sdk/codec" "testing" "time" - "github.com/cosmos/cosmos-sdk/codec" - "github.com/jhump/protoreflect/grpcreflect" "github.com/stretchr/testify/require" diff --git a/x/group/client/testutil/tx.go b/x/group/client/testutil/tx.go index dadf77190d11..8827bbb1660c 100644 --- a/x/group/client/testutil/tx.go +++ b/x/group/client/testutil/tx.go @@ -5,10 +5,6 @@ import ( "strconv" "strings" - "github.com/gogo/protobuf/proto" - "github.com/stretchr/testify/suite" - tmcli "github.com/tendermint/tendermint/libs/cli" - "github.com/cosmos/cosmos-sdk/client/flags" "github.com/cosmos/cosmos-sdk/crypto/hd" "github.com/cosmos/cosmos-sdk/crypto/keyring" @@ -16,6 +12,9 @@ import ( "github.com/cosmos/cosmos-sdk/testutil/cli" sdk "github.com/cosmos/cosmos-sdk/types" banktestutil "github.com/cosmos/cosmos-sdk/x/bank/client/testutil" + "github.com/gogo/protobuf/proto" + "github.com/stretchr/testify/suite" + tmcli "github.com/tendermint/tendermint/libs/cli" "github.com/cosmos/cosmos-sdk/testutil/network" "github.com/cosmos/cosmos-sdk/x/group" diff --git a/x/group/msgs_test.go b/x/group/msgs_test.go index a98b5d703744..884b5d5dfec6 100644 --- a/x/group/msgs_test.go +++ b/x/group/msgs_test.go @@ -36,7 +36,7 @@ func TestMsgCreateGroup(t *testing.T) { &group.MsgCreateGroup{ Admin: admin.String(), Members: []group.Member{ - { + group.Member{ Address: "invalid address", }, }, @@ -49,7 +49,7 @@ func TestMsgCreateGroup(t *testing.T) { &group.MsgCreateGroup{ Admin: admin.String(), Members: []group.Member{ - { + group.Member{ Address: member1.String(), Weight: "-1", }, @@ -63,7 +63,7 @@ func TestMsgCreateGroup(t *testing.T) { &group.MsgCreateGroup{ Admin: admin.String(), Members: []group.Member{ - { + group.Member{ Address: member1.String(), Weight: "0", }, @@ -77,12 +77,12 @@ func TestMsgCreateGroup(t *testing.T) { &group.MsgCreateGroup{ Admin: admin.String(), Members: []group.Member{ - { + group.Member{ Address: member1.String(), Weight: "1", Metadata: []byte("metadata"), }, - { + group.Member{ Address: member1.String(), Weight: "1", Metadata: []byte("metadata"), @@ -97,7 +97,7 @@ func TestMsgCreateGroup(t *testing.T) { &group.MsgCreateGroup{ Admin: admin.String(), Members: []group.Member{ - { + group.Member{ Address: member1.String(), Weight: "1", Metadata: []byte("metadata"), @@ -121,12 +121,12 @@ func TestMsgCreateGroup(t *testing.T) { &group.MsgCreateGroup{ Admin: admin.String(), Members: []group.Member{ - { + group.Member{ Address: member1.String(), Weight: "1", Metadata: []byte("metadata"), }, - { + group.Member{ Address: member2.String(), Weight: "1", Metadata: []byte("metadata"), @@ -311,7 +311,7 @@ func TestMsgUpdateGroupMembers(t *testing.T) { GroupId: 1, Admin: admin.String(), MemberUpdates: []group.Member{ - { + group.Member{ Address: member1.String(), Weight: "1", Metadata: []byte("metadata"), @@ -327,7 +327,7 @@ func TestMsgUpdateGroupMembers(t *testing.T) { GroupId: 1, Admin: admin.String(), MemberUpdates: []group.Member{ - { + group.Member{ Address: member1.String(), Weight: "0", Metadata: []byte("metadata"), From 7bf59cacb92e52ac065756ff2f625fcad9f0847b Mon Sep 17 00:00:00 2001 From: Aaron Craelius Date: Fri, 4 Feb 2022 10:11:56 -0500 Subject: [PATCH 4/5] revert --- api/cosmos/group/v1beta1/events.pulsar.go | 7 +++---- api/cosmos/group/v1beta1/tx.pulsar.go | 10 ++++------ api/cosmos/group/v1beta1/types.pulsar.go | 7 +++---- 3 files changed, 10 insertions(+), 14 deletions(-) diff --git a/api/cosmos/group/v1beta1/events.pulsar.go b/api/cosmos/group/v1beta1/events.pulsar.go index bb53cde7b6dc..31844ed5cc15 100644 --- a/api/cosmos/group/v1beta1/events.pulsar.go +++ b/api/cosmos/group/v1beta1/events.pulsar.go @@ -3,15 +3,14 @@ package groupv1beta1 import ( fmt "fmt" - io "io" - reflect "reflect" - sync "sync" - _ "github.com/cosmos/cosmos-proto" runtime "github.com/cosmos/cosmos-proto/runtime" protoreflect "google.golang.org/protobuf/reflect/protoreflect" protoiface "google.golang.org/protobuf/runtime/protoiface" protoimpl "google.golang.org/protobuf/runtime/protoimpl" + io "io" + reflect "reflect" + sync "sync" ) var ( diff --git a/api/cosmos/group/v1beta1/tx.pulsar.go b/api/cosmos/group/v1beta1/tx.pulsar.go index d99b13022330..1cecc26e8695 100644 --- a/api/cosmos/group/v1beta1/tx.pulsar.go +++ b/api/cosmos/group/v1beta1/tx.pulsar.go @@ -3,19 +3,17 @@ package groupv1beta1 import ( fmt "fmt" - io "io" - reflect "reflect" - sync "sync" - _ "github.com/cosmos/cosmos-proto" runtime "github.com/cosmos/cosmos-proto/runtime" + _ "github.com/cosmos/cosmos-sdk/api/cosmos/msg/v1" _ "github.com/gogo/protobuf/gogoproto" protoreflect "google.golang.org/protobuf/reflect/protoreflect" protoiface "google.golang.org/protobuf/runtime/protoiface" protoimpl "google.golang.org/protobuf/runtime/protoimpl" anypb "google.golang.org/protobuf/types/known/anypb" - - _ "github.com/cosmos/cosmos-sdk/api/cosmos/msg/v1" + io "io" + reflect "reflect" + sync "sync" ) var _ protoreflect.List = (*_MsgCreateGroup_2_list)(nil) diff --git a/api/cosmos/group/v1beta1/types.pulsar.go b/api/cosmos/group/v1beta1/types.pulsar.go index a89dd413a9ab..fa92c112e234 100644 --- a/api/cosmos/group/v1beta1/types.pulsar.go +++ b/api/cosmos/group/v1beta1/types.pulsar.go @@ -3,10 +3,6 @@ package groupv1beta1 import ( fmt "fmt" - io "io" - reflect "reflect" - sync "sync" - _ "github.com/cosmos/cosmos-proto" runtime "github.com/cosmos/cosmos-proto/runtime" _ "github.com/gogo/protobuf/gogoproto" @@ -16,6 +12,9 @@ import ( anypb "google.golang.org/protobuf/types/known/anypb" durationpb "google.golang.org/protobuf/types/known/durationpb" timestamppb "google.golang.org/protobuf/types/known/timestamppb" + io "io" + reflect "reflect" + sync "sync" ) var ( From 60b4a4504f10fe6cd0591ccf559794d3334ad5b9 Mon Sep 17 00:00:00 2001 From: Aaron Craelius Date: Fri, 4 Feb 2022 10:15:35 -0500 Subject: [PATCH 5/5] update go.mod --- orm/go.mod | 4 ++-- orm/go.sum | 10 ++++------ 2 files changed, 6 insertions(+), 8 deletions(-) diff --git a/orm/go.mod b/orm/go.mod index b100bb004232..daccd89d901c 100644 --- a/orm/go.mod +++ b/orm/go.mod @@ -4,7 +4,7 @@ go 1.17 require ( github.com/cosmos/cosmos-proto v1.0.0-alpha7 - github.com/cosmos/cosmos-sdk/api v0.1.0-alpha3 + github.com/cosmos/cosmos-sdk/api v0.1.0-alpha4 github.com/cosmos/cosmos-sdk/errors v1.0.0-beta.2 github.com/iancoleman/strcase v0.2.0 github.com/stretchr/testify v1.7.0 @@ -41,7 +41,7 @@ require ( golang.org/x/text v0.3.6 // indirect golang.org/x/xerrors v0.0.0-20200804184101-5ec99f83aff1 // indirect google.golang.org/genproto v0.0.0-20211223182754-3ac035c7e7cb // indirect - google.golang.org/grpc v1.43.0 // indirect + google.golang.org/grpc v1.44.0 // indirect gopkg.in/yaml.v2 v2.4.0 // indirect gopkg.in/yaml.v3 v3.0.0-20200313102051-9f266ea9e77c // indirect ) diff --git a/orm/go.sum b/orm/go.sum index 69adf509a1dd..3c381d297a08 100644 --- a/orm/go.sum +++ b/orm/go.sum @@ -23,11 +23,10 @@ github.com/cncf/xds/go v0.0.0-20211011173535-cb28da3451f1/go.mod h1:eXthEFrGJvWH github.com/coreos/etcd v3.3.10+incompatible/go.mod h1:uF7uidLiAD3TWHmW31ZFd/JWoc32PjwdhPthX9715RE= github.com/coreos/go-etcd v2.0.0+incompatible/go.mod h1:Jez6KQU2B/sWsbdaef3ED8NzMklzPG4d5KIOhIy30Tk= github.com/coreos/go-semver v0.2.0/go.mod h1:nnelYz7RCh+5ahJtPPxZlU+153eP4D4r3EedlOD2RNk= -github.com/cosmos/cosmos-proto v1.0.0-alpha6/go.mod h1:msdDWOvfStHLG+Z2y2SJ0dcqimZ2vc8M1MPnZ4jOF7U= github.com/cosmos/cosmos-proto v1.0.0-alpha7 h1:yqYUOHF2jopwZh4dVQp3xgqwftE5/2hkrwIV6vkUbO0= github.com/cosmos/cosmos-proto v1.0.0-alpha7/go.mod h1:dosO4pSAbJF8zWCzCoTWP7nNsjcvSUBQmniFxDg5daw= -github.com/cosmos/cosmos-sdk/api v0.1.0-alpha3 h1:tqpedvX/1UgQyX3W2hlW6Xg801FyojYT/NOHbW0oG+s= -github.com/cosmos/cosmos-sdk/api v0.1.0-alpha3/go.mod h1:Ht15guGn9F8b0lv8NkjXE9/asAvVUOt2n4gvQ4q5MyU= +github.com/cosmos/cosmos-sdk/api v0.1.0-alpha4 h1:z2si9sQNUTj2jw+24SujuUxcoNS3TVga/fdYsS4rJII= +github.com/cosmos/cosmos-sdk/api v0.1.0-alpha4/go.mod h1:gZu6sOu2vl4Fd7I+BjDSx2bxndwPgFLGfOegek3SQQo= github.com/cosmos/cosmos-sdk/errors v1.0.0-beta.2 h1:bBglNlra8ZHb4dmbEE8V85ihLA+DkriSm7tcx6x/JWo= github.com/cosmos/cosmos-sdk/errors v1.0.0-beta.2/go.mod h1:Gi7pzVRnvZ1N16JAXpLADzng0ePoE7YeEHaULSFB2Ts= github.com/cpuguy83/go-md2man v1.0.10/go.mod h1:SmD6nW6nTyfqj6ABTjUi3V3JVMnlJmwcJI5acqYI6dE= @@ -250,8 +249,8 @@ google.golang.org/grpc v1.33.1/go.mod h1:fr5YgcSWrqhRRxogOsw7RzIpsmvOZ6IcH4kBYTp google.golang.org/grpc v1.36.0/go.mod h1:qjiiYl8FncCW8feJPdyg3v6XW24KsRHe+dy9BAGRRjU= google.golang.org/grpc v1.40.0/go.mod h1:ogyxbiOoUXAkP+4+xa6PZSE9DZgIHtSpzjDTB9KAK34= google.golang.org/grpc v1.42.0/go.mod h1:k+4IHHFw41K8+bbowsex27ge2rCb65oeWqe4jJ590SU= -google.golang.org/grpc v1.43.0 h1:Eeu7bZtDZ2DpRCsLhUlcrLnvYaMK1Gz86a+hMVvELmM= -google.golang.org/grpc v1.43.0/go.mod h1:k+4IHHFw41K8+bbowsex27ge2rCb65oeWqe4jJ590SU= +google.golang.org/grpc v1.44.0 h1:weqSxi/TMs1SqFRMHCtBgXRs8k3X39QIDEZ0pRcttUg= +google.golang.org/grpc v1.44.0/go.mod h1:k+4IHHFw41K8+bbowsex27ge2rCb65oeWqe4jJ590SU= 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= google.golang.org/protobuf v0.0.0-20200228230310-ab0ca4ff8a60/go.mod h1:cfTl7dwQJ+fmap5saPgwCLgHXTUD7jkjRqWcaiX5VyM= @@ -263,7 +262,6 @@ google.golang.org/protobuf v1.23.1-0.20200526195155-81db48ad09cc/go.mod h1:EGpAD google.golang.org/protobuf v1.25.0/go.mod h1:9JNX74DMeImyA3h4bdi1ymwjUzf21/xIlbajtzgsN7c= google.golang.org/protobuf v1.26.0-rc.1/go.mod h1:jlhhOSvTdKEhbULTjvd4ARK9grFBp09yW+WbY/TyQbw= google.golang.org/protobuf v1.26.0/go.mod h1:9q0QmTI4eRPtz6boOQmLYwt+qCgq0jsYwAQnmE0givc= -google.golang.org/protobuf v1.27.0/go.mod h1:9q0QmTI4eRPtz6boOQmLYwt+qCgq0jsYwAQnmE0givc= google.golang.org/protobuf v1.27.1 h1:SnqbnDw1V7RiZcXPx5MEeqPv2s79L9i7BJUlG/+RurQ= google.golang.org/protobuf v1.27.1/go.mod h1:9q0QmTI4eRPtz6boOQmLYwt+qCgq0jsYwAQnmE0givc= gopkg.in/check.v1 v0.0.0-20161208181325-20d25e280405/go.mod h1:Co6ibVJAznAaIkqp8huTwlJQCZ016jof/cbN4VW5Yz0=