From 92bcef09567bcbe2215db8905d8a19287f24e873 Mon Sep 17 00:00:00 2001 From: forcodedancing Date: Tue, 17 Oct 2023 20:59:00 +0800 Subject: [PATCH] refine codes --- go.mod | 2 +- go.sum | 4 ++-- x/permission/types/types.go | 44 +++++++++++++++------------------- x/storage/keeper/msg_server.go | 7 ------ 4 files changed, 22 insertions(+), 35 deletions(-) diff --git a/go.mod b/go.mod index 01889cf22..4fffd0a5a 100644 --- a/go.mod +++ b/go.mod @@ -178,7 +178,7 @@ replace ( github.com/cometbft/cometbft => github.com/bnb-chain/greenfield-cometbft v1.0.0 github.com/cometbft/cometbft-db => github.com/bnb-chain/greenfield-cometbft-db v0.8.1-alpha.1 github.com/confio/ics23/go => github.com/cosmos/cosmos-sdk/ics23/go v0.8.0 - github.com/cosmos/cosmos-sdk => github.com/forcodedancing/greenfield-cosmos-sdk v0.2.1-0.20230918080629-546708eba818 + github.com/cosmos/cosmos-sdk => github.com/forcodedancing/greenfield-cosmos-sdk v0.2.1-0.20231016120649-fcdced9e012e github.com/cosmos/iavl => github.com/bnb-chain/greenfield-iavl v0.20.1 github.com/syndtr/goleveldb => github.com/syndtr/goleveldb v1.0.1-0.20210819022825-2ae1ddf74ef7 ) diff --git a/go.sum b/go.sum index 520965704..081c8024e 100644 --- a/go.sum +++ b/go.sum @@ -368,8 +368,8 @@ github.com/fjl/memsize v0.0.0-20190710130421-bcb5799ab5e5/go.mod h1:VvhXpOYNQvB+ github.com/flynn/go-shlex v0.0.0-20150515145356-3f9db97f8568/go.mod h1:xEzjJPgXI435gkrCt3MPfRiAkVrwSbHsst4LCFVfpJc= github.com/flynn/noise v1.0.0/go.mod h1:xbMo+0i6+IGbYdJhF31t2eR1BIU0CYc12+BNAKwUTag= github.com/fogleman/gg v1.2.1-0.20190220221249-0403632d5b90/go.mod h1:R/bRT+9gY/C5z7JzPU0zXsXHKM4/ayA+zqcVNZzPa1k= -github.com/forcodedancing/greenfield-cosmos-sdk v0.2.1-0.20230918080629-546708eba818 h1:HyAROtp8xHuuzZzJTXfwVm0c+qTJs3ahPFtEpJFs5lM= -github.com/forcodedancing/greenfield-cosmos-sdk v0.2.1-0.20230918080629-546708eba818/go.mod h1:y3hDhQhil5hMIhwBTpu07RZBF30ZITkoE+GHhVZChtY= +github.com/forcodedancing/greenfield-cosmos-sdk v0.2.1-0.20231016120649-fcdced9e012e h1:nHk7ex6a2iwYl/L5ZpffJSlWC81+2IVyw5q9S1dsnKU= +github.com/forcodedancing/greenfield-cosmos-sdk v0.2.1-0.20231016120649-fcdced9e012e/go.mod h1:BGVMW9gRFKGzCwK/8CmDGe3sK9r9QujL1Uz2FMMM+/s= github.com/fortytw2/leaktest v1.3.0 h1:u8491cBMTQ8ft8aeV+adlcytMZylmA5nnwwkRZjI8vw= github.com/fortytw2/leaktest v1.3.0/go.mod h1:jDsjWgpAGjm2CA7WthBh/CdZYEPF31XHquHwclZch5g= github.com/francoispqt/gojay v1.2.13/go.mod h1:ehT5mTG4ua4581f1++1WLG0vPdaA9HaiDsoyrBGkyDY= diff --git a/x/permission/types/types.go b/x/permission/types/types.go index 894ab76f3..1f187534d 100644 --- a/x/permission/types/types.go +++ b/x/permission/types/types.go @@ -214,35 +214,29 @@ func (s *Statement) ValidateBasic(resType resource.ResourceType) error { return nil } -func (s *Statement) ValidateAfterNagqu(resType resource.ResourceType) error { - if s.Effect == EFFECT_UNSPECIFIED { - return ErrInvalidStatement.Wrap("Please specify the Effect explicitly. Not allowed set EFFECT_UNSPECIFIED") - } - switch resType { - case resource.RESOURCE_TYPE_UNSPECIFIED: - return ErrInvalidStatement.Wrap("Please specify the ResourceType explicitly. Not allowed set RESOURCE_TYPE_UNSPECIFIED") - case resource.RESOURCE_TYPE_BUCKET: - for _, r := range s.Resources { - _, err := regexp.Compile(r) - if err != nil { - return ErrInvalidStatement.Wrapf("The Resources regexp compile failed, err: %s", err) +func (s *Statement) ValidateRuntime(ctx sdk.Context, resType resource.ResourceType) error { + if ctx.IsUpgraded(upgradetypes.Nagqu) { + switch resType { + case resource.RESOURCE_TYPE_BUCKET: + for _, r := range s.Resources { + _, err := regexp.Compile(r) + if err != nil { + return ErrInvalidStatement.Wrapf("The Resources regexp compile failed, err: %s", err) + } } + case resource.RESOURCE_TYPE_OBJECT: + if s.Resources != nil { + return ErrInvalidStatement.Wrap("The Resources option can only be used at the bucket level. ") + } + case resource.RESOURCE_TYPE_GROUP: + if s.Resources != nil { + return ErrInvalidStatement.Wrap("The Resources option can only be used at the bucket level. ") + } + default: + return ErrInvalidStatement.Wrap("unknown resource type.") } - case resource.RESOURCE_TYPE_OBJECT: - if s.Resources != nil { - return ErrInvalidStatement.Wrap("The Resources option can only be used at the bucket level. ") - } - case resource.RESOURCE_TYPE_GROUP: - if s.Resources != nil { - return ErrInvalidStatement.Wrap("The Resources option can only be used at the bucket level. ") - } - default: - return ErrInvalidStatement.Wrap("unknown resource type.") } - return nil -} -func (s *Statement) ValidateRuntime(ctx sdk.Context, resType resource.ResourceType) error { var bucketAllowedActions map[ActionType]bool if ctx.IsUpgraded(upgradetypes.Pampas) { bucketAllowedActions = BucketAllowedActionsAfterPampas diff --git a/x/storage/keeper/msg_server.go b/x/storage/keeper/msg_server.go index 84b444088..6f7773afa 100644 --- a/x/storage/keeper/msg_server.go +++ b/x/storage/keeper/msg_server.go @@ -8,7 +8,6 @@ import ( "cosmossdk.io/math" sdk "github.com/cosmos/cosmos-sdk/types" govtypes "github.com/cosmos/cosmos-sdk/x/gov/types" - upgradetypes "github.com/cosmos/cosmos-sdk/x/upgrade/types" types2 "github.com/bnb-chain/greenfield/types" gnfderrors "github.com/bnb-chain/greenfield/types/errors" @@ -370,12 +369,6 @@ func (k msgServer) PutPolicy(goCtx context.Context, msg *types.MsgPutPolicy) (*t if s.ExpirationTime != nil && s.ExpirationTime.Before(ctx.BlockTime()) { return nil, permtypes.ErrPermissionExpired.Wrapf("The specified statement expiration time is less than the current block time, block time: %s", ctx.BlockTime().String()) } - if ctx.IsUpgraded(upgradetypes.Nagqu) { - err := s.ValidateAfterNagqu(grn.ResourceType()) - if err != nil { - return nil, err - } - } } policy := &permtypes.Policy{