From a2bd4e8b3937e57a2a870520efae326fed833019 Mon Sep 17 00:00:00 2001 From: marbar3778 Date: Tue, 10 Oct 2023 15:09:06 +0200 Subject: [PATCH 1/4] remove validate genesis from authz --- x/authz/module/module.go | 8 +------- 1 file changed, 1 insertion(+), 7 deletions(-) diff --git a/x/authz/module/module.go b/x/authz/module/module.go index f6379853bf78..7716b415f26e 100644 --- a/x/authz/module/module.go +++ b/x/authz/module/module.go @@ -13,7 +13,6 @@ import ( "cosmossdk.io/core/appmodule" "cosmossdk.io/core/store" "cosmossdk.io/depinject" - "cosmossdk.io/errors" "github.com/cosmos/cosmos-sdk/baseapp" sdkclient "github.com/cosmos/cosmos-sdk/client" @@ -78,12 +77,7 @@ func (AppModuleBasic) DefaultGenesis(cdc codec.JSONCodec) json.RawMessage { // ValidateGenesis performs genesis state validation for the authz module. func (AppModuleBasic) ValidateGenesis(cdc codec.JSONCodec, config sdkclient.TxEncodingConfig, bz json.RawMessage) error { - var data authz.GenesisState - if err := cdc.UnmarshalJSON(bz, &data); err != nil { - return errors.Wrapf(err, "failed to unmarshal %s genesis state", authz.ModuleName) - } - - return authz.ValidateGenesis(data) + return nil } // RegisterGRPCGatewayRoutes registers the gRPC Gateway routes for the authz module. From f24ebe9ac92bcfec0e25f985991d7da54b4e822d Mon Sep 17 00:00:00 2001 From: marbar3778 Date: Tue, 10 Oct 2023 15:10:17 +0200 Subject: [PATCH 2/4] remove dead code --- x/authz/genesis.go | 5 ----- 1 file changed, 5 deletions(-) diff --git a/x/authz/genesis.go b/x/authz/genesis.go index d14bbbb18a8c..938a77892bae 100644 --- a/x/authz/genesis.go +++ b/x/authz/genesis.go @@ -11,11 +11,6 @@ func NewGenesisState(entries []GrantAuthorization) *GenesisState { } } -// ValidateGenesis check the given genesis state has no integrity issues -func ValidateGenesis(data GenesisState) error { - return nil -} - // DefaultGenesisState - Return a default genesis state func DefaultGenesisState() *GenesisState { return &GenesisState{} From 72a776b7eb2b697c9ece0ea3f879e1df790f144d Mon Sep 17 00:00:00 2001 From: marbar3778 Date: Wed, 11 Oct 2023 11:58:12 +0200 Subject: [PATCH 3/4] validate granter and grantee is not empty --- x/authz/genesis.go | 16 ++++++++++++++++ x/authz/module/module.go | 8 +++++++- 2 files changed, 23 insertions(+), 1 deletion(-) diff --git a/x/authz/genesis.go b/x/authz/genesis.go index 938a77892bae..9413f43ae978 100644 --- a/x/authz/genesis.go +++ b/x/authz/genesis.go @@ -1,6 +1,8 @@ package authz import ( + "errors" + cdctypes "github.com/cosmos/cosmos-sdk/codec/types" ) @@ -11,6 +13,20 @@ func NewGenesisState(entries []GrantAuthorization) *GenesisState { } } +// ValidateGenesis check the given genesis state has no integrity issues +func ValidateGenesis(data GenesisState) error { + for _, a := range data.Authorization { + if a.Grantee == "" { + return errors.New("missing grantee") + } + if a.Granter == "" { + return errors.New("missing granter") + } + + } + return nil +} + // DefaultGenesisState - Return a default genesis state func DefaultGenesisState() *GenesisState { return &GenesisState{} diff --git a/x/authz/module/module.go b/x/authz/module/module.go index 7716b415f26e..f6379853bf78 100644 --- a/x/authz/module/module.go +++ b/x/authz/module/module.go @@ -13,6 +13,7 @@ import ( "cosmossdk.io/core/appmodule" "cosmossdk.io/core/store" "cosmossdk.io/depinject" + "cosmossdk.io/errors" "github.com/cosmos/cosmos-sdk/baseapp" sdkclient "github.com/cosmos/cosmos-sdk/client" @@ -77,7 +78,12 @@ func (AppModuleBasic) DefaultGenesis(cdc codec.JSONCodec) json.RawMessage { // ValidateGenesis performs genesis state validation for the authz module. func (AppModuleBasic) ValidateGenesis(cdc codec.JSONCodec, config sdkclient.TxEncodingConfig, bz json.RawMessage) error { - return nil + var data authz.GenesisState + if err := cdc.UnmarshalJSON(bz, &data); err != nil { + return errors.Wrapf(err, "failed to unmarshal %s genesis state", authz.ModuleName) + } + + return authz.ValidateGenesis(data) } // RegisterGRPCGatewayRoutes registers the gRPC Gateway routes for the authz module. From 136b6bc08d1b5e956b875c661f9b125603645cd4 Mon Sep 17 00:00:00 2001 From: marbar3778 Date: Wed, 11 Oct 2023 15:46:15 +0200 Subject: [PATCH 4/4] print index --- x/authz/genesis.go | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/x/authz/genesis.go b/x/authz/genesis.go index 9413f43ae978..169684e0734f 100644 --- a/x/authz/genesis.go +++ b/x/authz/genesis.go @@ -1,7 +1,7 @@ package authz import ( - "errors" + fmt "fmt" cdctypes "github.com/cosmos/cosmos-sdk/codec/types" ) @@ -15,12 +15,12 @@ func NewGenesisState(entries []GrantAuthorization) *GenesisState { // ValidateGenesis check the given genesis state has no integrity issues func ValidateGenesis(data GenesisState) error { - for _, a := range data.Authorization { + for i, a := range data.Authorization { if a.Grantee == "" { - return errors.New("missing grantee") + return fmt.Errorf("authorization: %d, missing grantee", i) } if a.Granter == "" { - return errors.New("missing granter") + return fmt.Errorf("authorization: %d,missing granter", i) } }