From 7833410198471353f2658eff16700ccc8bee1194 Mon Sep 17 00:00:00 2001 From: Robert Zaremba Date: Thu, 1 Apr 2021 15:24:04 +0200 Subject: [PATCH 01/44] x/authz: audit updates --- store/gaskv/store.go | 2 +- types/service_msg.go | 4 ++-- x/authz/keeper/keeper.go | 27 +++++++++++---------------- 3 files changed, 14 insertions(+), 19 deletions(-) diff --git a/store/gaskv/store.go b/store/gaskv/store.go index 47d796727acc..04a4aaeebc68 100644 --- a/store/gaskv/store.go +++ b/store/gaskv/store.go @@ -178,7 +178,7 @@ func (gi *gasIterator) Error() error { return gi.parent.Error() } -// consumeSeekGas consumes a flat gas cost for seeking and a variable gas cost +// consumeSeekGas consumes on each iteration step a flat gas cost and a variable gas cost // based on the current value's length. func (gi *gasIterator) consumeSeekGas() { value := gi.Value() diff --git a/types/service_msg.go b/types/service_msg.go index ee6cede2eb16..564de40c700d 100644 --- a/types/service_msg.go +++ b/types/service_msg.go @@ -6,8 +6,8 @@ import ( "github.com/gogo/protobuf/proto" ) -// MsgRequest is the interface a transaction message, defined as a proto -// service method, must fulfill. +// MsgRequest is a functionality each transaction message (parameter of a protobuf service RPC) +// must implement. type MsgRequest interface { proto.Message // ValidateBasic does a simple validation check that diff --git a/x/authz/keeper/keeper.go b/x/authz/keeper/keeper.go index dcbee170cb1e..49c70635c213 100644 --- a/x/authz/keeper/keeper.go +++ b/x/authz/keeper/keeper.go @@ -82,6 +82,7 @@ func (k Keeper) DispatchActions(ctx sdk.Context, grantee sdk.AccAddress, service return nil, sdkerrors.Wrapf(sdkerrors.ErrInvalidRequest, "authorization can be given to msg with only one signer") } granter := signers[0] + // if granter != grantee then check authorization.Accept, otherwise we implicitly accept. if !granter.Equals(grantee) { authorization, _ := k.GetOrRevokeAuthorization(ctx, grantee, granter, serviceMsg.MethodName) if authorization == nil { @@ -129,16 +130,7 @@ func (k Keeper) Grant(ctx sdk.Context, grantee, granter sdk.AccAddress, authoriz bz := k.cdc.MustMarshalBinaryBare(&grant) grantStoreKey := types.GetAuthorizationStoreKey(grantee, granter, authorization.MethodName()) store.Set(grantStoreKey, bz) - - ctx.EventManager().EmitEvent( - sdk.NewEvent( - types.EventGrantAuthorization, - sdk.NewAttribute(types.AttributeKeyGrantType, authorization.MethodName()), - sdk.NewAttribute(sdk.AttributeKeyModule, types.AttributeValueCategory), - sdk.NewAttribute(types.AttributeKeyGranterAddress, granter.String()), - sdk.NewAttribute(types.AttributeKeyGranteeAddress, grantee.String()), - ), - ) + emitEvent(ctx, types.EventGrantAuthorization, grantee, granter) return nil } @@ -151,17 +143,20 @@ func (k Keeper) Revoke(ctx sdk.Context, grantee sdk.AccAddress, granter sdk.AccA return sdkerrors.Wrap(sdkerrors.ErrNotFound, "authorization not found") } store.Delete(grantStoreKey) + emitEvent(ctx, types.EventRevokeAuthorization, grantee, granter) + return nil +} +func emitEvent(ctx sdk.Context, name string, grantee sdk.AccAddress, granter sdk.AccAddress) { ctx.EventManager().EmitEvent( sdk.NewEvent( - types.EventRevokeAuthorization, + name, sdk.NewAttribute(sdk.AttributeKeyModule, types.AttributeValueCategory), - sdk.NewAttribute(types.AttributeKeyGrantType, msgType), + sdk.NewAttributemitEvene(types.AttributeKeyGrantType, msgType), sdk.NewAttribute(types.AttributeKeyGranterAddress, granter.String()), sdk.NewAttribute(types.AttributeKeyGranteeAddress, grantee.String()), ), ) - return nil } // GetAuthorizations Returns list of `Authorizations` granted to the grantee by the granter. @@ -178,9 +173,9 @@ func (k Keeper) GetAuthorizations(ctx sdk.Context, grantee sdk.AccAddress, grant return authorizations } -// GetOrRevokeAuthorization Returns any `Authorization` (or `nil`), with the expiration time, -// granted to the grantee by the granter for the provided msg type. -// If the Authorization is expired already, it will revoke the authorization and return nil +// GetOrRevokeAuthorization returns an `Authorization` and it's expiration time if the granter +// has a grant for (granter, message name) pair. If there is no grant `nil` is returned. +// If the grant is expired, the grant is revoked, removed from the storage, and `nil` is returned. func (k Keeper) GetOrRevokeAuthorization(ctx sdk.Context, grantee sdk.AccAddress, granter sdk.AccAddress, msgType string) (cap exported.Authorization, expiration time.Time) { grant, found := k.getAuthorizationGrant(ctx, types.GetAuthorizationStoreKey(grantee, granter, msgType)) if !found { From 45a9ee37450294cad30c128ce32ffc8521e25df7 Mon Sep 17 00:00:00 2001 From: Robert Zaremba Date: Wed, 14 Apr 2021 16:02:52 +0200 Subject: [PATCH 02/44] audit with Aaron --- proto/cosmos/authz/v1beta1/query.proto | 23 +++-------------------- x/authz/keeper/keeper.go | 20 +++++++++++--------- x/bank/types/send_authorization.go | 8 +++++++- 3 files changed, 21 insertions(+), 30 deletions(-) diff --git a/proto/cosmos/authz/v1beta1/query.proto b/proto/cosmos/authz/v1beta1/query.proto index 7a73325815a5..da5e86e2de2d 100644 --- a/proto/cosmos/authz/v1beta1/query.proto +++ b/proto/cosmos/authz/v1beta1/query.proto @@ -9,35 +9,18 @@ option go_package = "github.com/cosmos/cosmos-sdk/x/authz/types"; // Query defines the gRPC querier service. service Query { - // Returns any `Authorization` (or `nil`), with the expiration time, granted to the grantee by the granter for the - // provided msg type. - rpc Authorization(QueryAuthorizationRequest) returns (QueryAuthorizationResponse) { - option (google.api.http).get = "/cosmos/authz/v1beta1/granters/{granter}/grantees/{grantee}/grant"; - } - // Returns list of `Authorization`, granted to the grantee by the granter. rpc Authorizations(QueryAuthorizationsRequest) returns (QueryAuthorizationsResponse) { - option (google.api.http).get = "/cosmos/authz/v1beta1/granters/{granter}/grantees/{grantee}/grants"; + option (google.api.http).get = "/cosmos/authz/v1beta1/"; } } -// QueryAuthorizationRequest is the request type for the Query/Authorization RPC method. -message QueryAuthorizationRequest { - string granter = 1; - string grantee = 2; - string method_name = 3; -} - -// QueryAuthorizationResponse is the response type for the Query/Authorization RPC method. -message QueryAuthorizationResponse { - // authorization is a authorization granted for grantee by granter. - cosmos.authz.v1beta1.AuthorizationGrant authorization = 1; -} - // QueryAuthorizationsRequest is the request type for the Query/Authorizations RPC method. message QueryAuthorizationsRequest { string granter = 1; string grantee = 2; + // If method name is not included then we return all authorizations for given granter and grantee + string method_name = 3; // pagination defines an pagination for the request. cosmos.base.query.v1beta1.PageRequest pagination = 3; } diff --git a/x/authz/keeper/keeper.go b/x/authz/keeper/keeper.go index 49c70635c213..8c6e12a9d125 100644 --- a/x/authz/keeper/keeper.go +++ b/x/authz/keeper/keeper.go @@ -148,15 +148,17 @@ func (k Keeper) Revoke(ctx sdk.Context, grantee sdk.AccAddress, granter sdk.AccA } func emitEvent(ctx sdk.Context, name string, grantee sdk.AccAddress, granter sdk.AccAddress) { - ctx.EventManager().EmitEvent( - sdk.NewEvent( - name, - sdk.NewAttribute(sdk.AttributeKeyModule, types.AttributeValueCategory), - sdk.NewAttributemitEvene(types.AttributeKeyGrantType, msgType), - sdk.NewAttribute(types.AttributeKeyGranterAddress, granter.String()), - sdk.NewAttribute(types.AttributeKeyGranteeAddress, grantee.String()), - ), - ) + ctx.EventManager().EmitTypedEvent( /* the proto event */ ) + // ctx.EventManager().EmitEvent( + // sdk.NewEvent( + // types.EventRevokeAuthorization, + // sdk.NewAttribute(sdk.AttributeKeyModule, types.AttributeValueCategory), + // sdk.NewAttribute(types.AttributeKeyGrantType, msgType), + // sdk.NewAttribute(types.AttributeKeyGranterAddress, granter.String()), + // sdk.NewAttribute(types.AttributeKeyGranteeAddress, grantee.String()), + // ), + // ) + return nil } // GetAuthorizations Returns list of `Authorizations` granted to the grantee by the granter. diff --git a/x/bank/types/send_authorization.go b/x/bank/types/send_authorization.go index 82d1bf1e630b..9249ddd83106 100644 --- a/x/bank/types/send_authorization.go +++ b/x/bank/types/send_authorization.go @@ -24,8 +24,14 @@ func (authorization SendAuthorization) MethodName() string { return "/cosmos.bank.v1beta1.Msg/Send" } +type AcceptResponse struct { + updated authz.Authorization + delete, accept bool +} + // Accept implements Authorization.Accept. -func (authorization SendAuthorization) Accept(ctx sdk.Context, msg sdk.ServiceMsg) (updated authz.Authorization, delete bool, err error) { +// func (authorization SendAuthorization) Accept(ctx sdk.Context, msg sdk.ServiceMsg) (updated authz.Authorization, delete bool, err error) { +func (authorization SendAuthorization) Accept(ctx sdk.Context, msg sdk.ServiceMsg) (AcceptResponse, error) { if reflect.TypeOf(msg.Request) == reflect.TypeOf(&MsgSend{}) { msg, ok := msg.Request.(*MsgSend) if ok { From 83780d3a317c5b022837a322689bed913395ef43 Mon Sep 17 00:00:00 2001 From: Robert Zaremba Date: Mon, 19 Apr 2021 20:44:38 +0200 Subject: [PATCH 03/44] authz: Update Authorization.Accept method --- x/authz/exported/authorizations.go | 15 +++++++- x/authz/types/generic_authorization.go | 18 +++++----- x/bank/types/send_authorization.go | 48 ++++++++++---------------- x/staking/types/authz.go | 45 ++++++++++++------------ 4 files changed, 65 insertions(+), 61 deletions(-) diff --git a/x/authz/exported/authorizations.go b/x/authz/exported/authorizations.go index 32fea0b0b3a8..fc671ee4f986 100644 --- a/x/authz/exported/authorizations.go +++ b/x/authz/exported/authorizations.go @@ -15,9 +15,22 @@ type Authorization interface { // Accept determines whether this grant permits the provided sdk.ServiceMsg to be performed, and if // so provides an upgraded authorization instance. - Accept(ctx sdk.Context, msg sdk.ServiceMsg) (updated Authorization, delete bool, err error) + Accept(ctx sdk.Context, msg sdk.ServiceMsg) (AcceptResponse, error) // ValidateBasic does a simple validation check that // doesn't require access to any other information. ValidateBasic() error } + +// AcceptResponse instruments the controller of an authz message if the request is accepted +// and if it should be updated or deleted. +type AcceptResponse struct { + // If Accept=true, the controller can accept and authorization and handle the update. + Accept bool + // If Delete=true, the controller must delete the authorization object and release + // storage resources. + Delete bool + // Controller, who is calling Authorization.Accept must check if `Updated != nil`. If yes, + // it must use the updated version and handle the update on the storage level. + Updated Authorization +} diff --git a/x/authz/types/generic_authorization.go b/x/authz/types/generic_authorization.go index 101f3acf1664..6ecf9781417f 100644 --- a/x/authz/types/generic_authorization.go +++ b/x/authz/types/generic_authorization.go @@ -4,11 +4,11 @@ import ( sdk "github.com/cosmos/cosmos-sdk/types" sdkerrors "github.com/cosmos/cosmos-sdk/types/errors" "github.com/cosmos/cosmos-sdk/types/msgservice" - "github.com/cosmos/cosmos-sdk/x/authz/exported" + authz "github.com/cosmos/cosmos-sdk/x/authz/exported" ) var ( - _ exported.Authorization = &GenericAuthorization{} + _ authz.Authorization = &GenericAuthorization{} ) // NewGenericAuthorization creates a new GenericAuthorization object. @@ -19,19 +19,19 @@ func NewGenericAuthorization(methodName string) *GenericAuthorization { } // MethodName implements Authorization.MethodName. -func (authorization GenericAuthorization) MethodName() string { - return authorization.MessageName +func (a GenericAuthorization) MethodName() string { + return a.MessageName } // Accept implements Authorization.Accept. -func (authorization GenericAuthorization) Accept(ctx sdk.Context, msg sdk.ServiceMsg) (updated exported.Authorization, delete bool, err error) { - return &authorization, false, nil +func (a GenericAuthorization) Accept(ctx sdk.Context, msg sdk.ServiceMsg) (authz.AcceptResponse, error) { + return authz.AcceptResponse{Accept: true}, nil } // ValidateBasic implements Authorization.ValidateBasic. -func (authorization GenericAuthorization) ValidateBasic() error { - if !msgservice.IsServiceMsg(authorization.MessageName) { - return sdkerrors.Wrapf(sdkerrors.ErrInvalidType, " %s is not a valid service msg", authorization.MessageName) +func (a GenericAuthorization) ValidateBasic() error { + if !msgservice.IsServiceMsg(a.MessageName) { + return sdkerrors.Wrapf(sdkerrors.ErrInvalidType, " %s is not a valid service msg", a.MessageName) } return nil } diff --git a/x/bank/types/send_authorization.go b/x/bank/types/send_authorization.go index 9249ddd83106..586d58fcbde7 100644 --- a/x/bank/types/send_authorization.go +++ b/x/bank/types/send_authorization.go @@ -1,8 +1,6 @@ package types import ( - "reflect" - sdk "github.com/cosmos/cosmos-sdk/types" sdkerrors "github.com/cosmos/cosmos-sdk/types/errors" authz "github.com/cosmos/cosmos-sdk/x/authz/exported" @@ -20,42 +18,34 @@ func NewSendAuthorization(spendLimit sdk.Coins) *SendAuthorization { } // MethodName implements Authorization.MethodName. -func (authorization SendAuthorization) MethodName() string { +func (a SendAuthorization) MethodName() string { return "/cosmos.bank.v1beta1.Msg/Send" } -type AcceptResponse struct { - updated authz.Authorization - delete, accept bool -} - // Accept implements Authorization.Accept. -// func (authorization SendAuthorization) Accept(ctx sdk.Context, msg sdk.ServiceMsg) (updated authz.Authorization, delete bool, err error) { -func (authorization SendAuthorization) Accept(ctx sdk.Context, msg sdk.ServiceMsg) (AcceptResponse, error) { - if reflect.TypeOf(msg.Request) == reflect.TypeOf(&MsgSend{}) { - msg, ok := msg.Request.(*MsgSend) - if ok { - limitLeft, isNegative := authorization.SpendLimit.SafeSub(msg.Amount) - if isNegative { - return nil, false, sdkerrors.Wrapf(sdkerrors.ErrInsufficientFunds, "requested amount is more than spend limit") - } - if limitLeft.IsZero() { - return nil, true, nil - } - - return &SendAuthorization{SpendLimit: limitLeft}, false, nil - } +func (a SendAuthorization) Accept(ctx sdk.Context, msg sdk.ServiceMsg) (authz.AcceptResponse, error) { + msgR, ok := msg.Request.(*MsgSend) + if !ok { + return authz.AcceptResponse{}, sdkerrors.ErrInvalidType.Wrap("type mismatch") } - return nil, false, sdkerrors.Wrapf(sdkerrors.ErrInvalidType, "type mismatch") + limitLeft, isNegative := a.SpendLimit.SafeSub(msgR.Amount) + if isNegative { + return authz.AcceptResponse{}, sdkerrors.ErrInsufficientFunds.Wrapf("requested amount is more than spend limit") + } + if limitLeft.IsZero() { + return authz.AcceptResponse{Accept: true, Delete: true}, nil + } + + return authz.AcceptResponse{Accept: true, Delete: false, Updated: &SendAuthorization{SpendLimit: limitLeft}}, nil } // ValidateBasic implements Authorization.ValidateBasic. -func (authorization SendAuthorization) ValidateBasic() error { - if authorization.SpendLimit == nil { - return sdkerrors.Wrapf(sdkerrors.ErrInvalidCoins, "spend limit cannot be nil") +func (a SendAuthorization) ValidateBasic() error { + if a.SpendLimit == nil { + return sdkerrors.ErrInvalidCoins.Wrap("spend limit cannot be nil") } - if !authorization.SpendLimit.IsAllPositive() { - return sdkerrors.Wrapf(sdkerrors.ErrInvalidCoins, "spend limit cannot be negitive") + if !a.SpendLimit.IsAllPositive() { + return sdkerrors.ErrInvalidCoins.Wrapf("spend limit cannot be negitive") } return nil } diff --git a/x/staking/types/authz.go b/x/staking/types/authz.go index 32e8b719d1f2..8058a024bbd8 100644 --- a/x/staking/types/authz.go +++ b/x/staking/types/authz.go @@ -41,19 +41,19 @@ func NewStakeAuthorization(allowed []sdk.ValAddress, denied []sdk.ValAddress, au } // MethodName implements Authorization.MethodName. -func (authorization StakeAuthorization) MethodName() string { - authzType, err := normalizeAuthzType(authorization.AuthorizationType) +func (a StakeAuthorization) MethodName() string { + authzType, err := normalizeAuthzType(a.AuthorizationType) if err != nil { panic(err) } return authzType } -func (authorization StakeAuthorization) ValidateBasic() error { - if authorization.MaxTokens != nil && authorization.MaxTokens.IsNegative() { - return sdkerrors.Wrapf(sdkerrors.ErrInvalidCoins, "negative coin amount: %v", authorization.MaxTokens) +func (a StakeAuthorization) ValidateBasic() error { + if a.MaxTokens != nil && a.MaxTokens.IsNegative() { + return sdkerrors.Wrapf(sdkerrors.ErrInvalidCoins, "negative coin amount: %v", a.MaxTokens) } - if authorization.AuthorizationType == AuthorizationType_AUTHORIZATION_TYPE_UNSPECIFIED { + if a.AuthorizationType == AuthorizationType_AUTHORIZATION_TYPE_UNSPECIFIED { return sdkerrors.Wrapf(sdkerrors.ErrInvalidType, "unknown authorization type") } @@ -61,7 +61,8 @@ func (authorization StakeAuthorization) ValidateBasic() error { } // Accept implements Authorization.Accept. -func (authorization StakeAuthorization) Accept(ctx sdk.Context, msg sdk.ServiceMsg) (updated authz.Authorization, delete bool, err error) { +// func (authorization StakeAuthorization) Accept(ctx sdk.Context, msg sdk.ServiceMsg) (updated authz.Authorization, delete bool, err error) { +func (a StakeAuthorization) Accept(ctx sdk.Context, msg sdk.ServiceMsg) (authz.AcceptResponse, error) { var validatorAddress string var amount sdk.Coin @@ -76,11 +77,11 @@ func (authorization StakeAuthorization) Accept(ctx sdk.Context, msg sdk.ServiceM validatorAddress = msg.ValidatorDstAddress amount = msg.Amount default: - return nil, false, sdkerrors.Wrapf(sdkerrors.ErrInvalidRequest, "unknown msg type") + return authz.AcceptResponse{}, sdkerrors.ErrInvalidRequest.Wrap("unknown msg type") } isValidatorExists := false - allowedList := authorization.GetAllowList().GetAddress() + allowedList := a.GetAllowList().GetAddress() for _, validator := range allowedList { ctx.GasMeter().ConsumeGas(gasCostPerIteration, "stake authorization") if validator == validatorAddress { @@ -89,38 +90,38 @@ func (authorization StakeAuthorization) Accept(ctx sdk.Context, msg sdk.ServiceM } } - denyList := authorization.GetDenyList().GetAddress() + denyList := a.GetDenyList().GetAddress() for _, validator := range denyList { ctx.GasMeter().ConsumeGas(gasCostPerIteration, "stake authorization") if validator == validatorAddress { - return nil, false, sdkerrors.Wrapf(sdkerrors.ErrUnauthorized, " cannot delegate/undelegate to %s validator", validator) + return authz.AcceptResponse{}, sdkerrors.ErrUnauthorized.Wrapf(" cannot delegate/undelegate to %s validator", validator) } } if !isValidatorExists { - return nil, false, sdkerrors.Wrapf(sdkerrors.ErrUnauthorized, "cannot delegate/undelegate to %s validator", validatorAddress) + return authz.AcceptResponse{}, sdkerrors.ErrUnauthorized.Wrapf("cannot delegate/undelegate to %s validator", validatorAddress) } - if authorization.MaxTokens == nil { - return &StakeAuthorization{Validators: authorization.GetValidators(), AuthorizationType: authorization.GetAuthorizationType()}, false, nil + if a.MaxTokens == nil { + return authz.AcceptResponse{Accept: true, Delete: false, + Updated: &StakeAuthorization{Validators: a.GetValidators(), AuthorizationType: a.GetAuthorizationType()}}, nil } - limitLeft := authorization.MaxTokens.Sub(amount) + limitLeft := a.MaxTokens.Sub(amount) if limitLeft.IsZero() { - return nil, true, nil + return authz.AcceptResponse{Accept: true, Delete: true}, nil } - - return &StakeAuthorization{Validators: authorization.GetValidators(), MaxTokens: &limitLeft, AuthorizationType: authorization.GetAuthorizationType()}, false, nil - + return authz.AcceptResponse{Accept: true, Delete: false, + Updated: &StakeAuthorization{Validators: a.GetValidators(), AuthorizationType: a.GetAuthorizationType(), MaxTokens: &limitLeft}}, nil } func validateAndBech32fy(allowed []sdk.ValAddress, denied []sdk.ValAddress) ([]string, []string, error) { if len(allowed) == 0 && len(denied) == 0 { - return nil, nil, sdkerrors.Wrapf(sdkerrors.ErrInvalidRequest, "both allowed & deny list cannot be empty") + return nil, nil, sdkerrors.ErrInvalidRequest.Wrap("both allowed & deny list cannot be empty") } if len(allowed) > 0 && len(denied) > 0 { - return nil, nil, sdkerrors.Wrapf(sdkerrors.ErrInvalidRequest, "cannot set both allowed & deny list") + return nil, nil, sdkerrors.ErrInvalidRequest.Wrap("cannot set both allowed & deny list") } allowedValidators := make([]string, len(allowed)) @@ -148,6 +149,6 @@ func normalizeAuthzType(authzType AuthorizationType) (string, error) { case AuthorizationType_AUTHORIZATION_TYPE_REDELEGATE: return TypeBeginRedelegate, nil default: - return "", sdkerrors.Wrapf(sdkerrors.ErrInvalidType, "unknown authorization type %T", authzType) + return "", sdkerrors.ErrInvalidType.Wrapf("unknown authorization type %T", authzType) } } From d25848064af7c5cf22efd1d5bab2c4eb92069e07 Mon Sep 17 00:00:00 2001 From: Robert Zaremba Date: Mon, 19 Apr 2021 20:56:17 +0200 Subject: [PATCH 04/44] authz: add event proto definitions --- x/authz/keeper/keeper.go | 20 ++++++++++---------- 1 file changed, 10 insertions(+), 10 deletions(-) diff --git a/x/authz/keeper/keeper.go b/x/authz/keeper/keeper.go index 8c6e12a9d125..dd183d270a72 100644 --- a/x/authz/keeper/keeper.go +++ b/x/authz/keeper/keeper.go @@ -148,16 +148,16 @@ func (k Keeper) Revoke(ctx sdk.Context, grantee sdk.AccAddress, granter sdk.AccA } func emitEvent(ctx sdk.Context, name string, grantee sdk.AccAddress, granter sdk.AccAddress) { - ctx.EventManager().EmitTypedEvent( /* the proto event */ ) - // ctx.EventManager().EmitEvent( - // sdk.NewEvent( - // types.EventRevokeAuthorization, - // sdk.NewAttribute(sdk.AttributeKeyModule, types.AttributeValueCategory), - // sdk.NewAttribute(types.AttributeKeyGrantType, msgType), - // sdk.NewAttribute(types.AttributeKeyGranterAddress, granter.String()), - // sdk.NewAttribute(types.AttributeKeyGranteeAddress, grantee.String()), - // ), - // ) + // TODO: ctx.EventManager().EmitTypedEvent( /* the proto event */ ) + ctx.EventManager().EmitEvent( + sdk.NewEvent( + types.EventRevokeAuthorization, + sdk.NewAttribute(sdk.AttributeKeyModule, types.AttributeValueCategory), + sdk.NewAttribute(types.AttributeKeyGrantType, msgType), + sdk.NewAttribute(types.AttributeKeyGranterAddress, granter.String()), + sdk.NewAttribute(types.AttributeKeyGranteeAddress, grantee.String()), + ), + ) return nil } From 8de54d0d7b85c312f111fd6a2c40d50f0bd4408f Mon Sep 17 00:00:00 2001 From: Robert Zaremba Date: Mon, 19 Apr 2021 21:47:15 +0200 Subject: [PATCH 05/44] update query service --- proto/cosmos/authz/v1beta1/query.proto | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/proto/cosmos/authz/v1beta1/query.proto b/proto/cosmos/authz/v1beta1/query.proto index da5e86e2de2d..8a08065b478f 100644 --- a/proto/cosmos/authz/v1beta1/query.proto +++ b/proto/cosmos/authz/v1beta1/query.proto @@ -22,7 +22,7 @@ message QueryAuthorizationsRequest { // If method name is not included then we return all authorizations for given granter and grantee string method_name = 3; // pagination defines an pagination for the request. - cosmos.base.query.v1beta1.PageRequest pagination = 3; + cosmos.base.query.v1beta1.PageRequest pagination = 4; } // QueryAuthorizationsResponse is the response type for the Query/Authorizations RPC method. From a721a97deba8be8417b7c9a3f9b66aade265ce7f Mon Sep 17 00:00:00 2001 From: Robert Zaremba Date: Mon, 19 Apr 2021 22:02:21 +0200 Subject: [PATCH 06/44] authz: use typed events --- docs/core/proto-docs.md | 56 ++ proto/cosmos/authz/v1beta1/event.proto | 35 ++ proto/cosmos/authz/v1beta1/query.proto | 52 +- x/authz/keeper/keeper.go | 53 +- x/authz/simulation/operations.go | 2 +- x/authz/types/event.pb.go | 805 +++++++++++++++++++++++++ x/authz/types/events.go | 14 - 7 files changed, 970 insertions(+), 47 deletions(-) create mode 100644 proto/cosmos/authz/v1beta1/event.proto create mode 100644 x/authz/types/event.pb.go delete mode 100644 x/authz/types/events.go diff --git a/docs/core/proto-docs.md b/docs/core/proto-docs.md index 0044d6689648..6ea377e9c71a 100644 --- a/docs/core/proto-docs.md +++ b/docs/core/proto-docs.md @@ -30,6 +30,10 @@ - [AuthorizationGrant](#cosmos.authz.v1beta1.AuthorizationGrant) - [GenericAuthorization](#cosmos.authz.v1beta1.GenericAuthorization) +- [cosmos/authz/v1beta1/event.proto](#cosmos/authz/v1beta1/event.proto) + - [EventGrant](#cosmos.authz.v1beta1.EventGrant) + - [EventRevoke](#cosmos.authz.v1beta1.EventRevoke) + - [cosmos/authz/v1beta1/genesis.proto](#cosmos/authz/v1beta1/genesis.proto) - [GenesisState](#cosmos.authz.v1beta1.GenesisState) - [GrantAuthorization](#cosmos.authz.v1beta1.GrantAuthorization) @@ -906,6 +910,58 @@ the provided method on behalf of the granter's account. + + + + + + + + + + + +

Top

+ +## cosmos/authz/v1beta1/event.proto + + + + + +### EventGrant +EventGrant is emitted on Msg/Grant + + +| Field | Type | Label | Description | +| ----- | ---- | ----- | ----------- | +| `module` | [string](#string) | | Module which invokes the authorizaiton grant TODO: not sure if this is needed. It's always have the same value | +| `msg` | [string](#string) | | Msg type for which an autorization is granted | +| `granter` | [string](#string) | | Granter account address | +| `grantee` | [string](#string) | | Grantee account address | + + + + + + + + +### EventRevoke +EventRevoke is emitted on Msg/Revoke + + +| Field | Type | Label | Description | +| ----- | ---- | ----- | ----------- | +| `module` | [string](#string) | | Module which invokes the authorizaiton revokation | +| `msg` | [string](#string) | | Msg type for which an autorization is revoked | +| `granter` | [string](#string) | | Granter account address | +| `grantee` | [string](#string) | | Grantee account address | + + + + + diff --git a/proto/cosmos/authz/v1beta1/event.proto b/proto/cosmos/authz/v1beta1/event.proto new file mode 100644 index 000000000000..10c189231733 --- /dev/null +++ b/proto/cosmos/authz/v1beta1/event.proto @@ -0,0 +1,35 @@ +syntax = "proto3"; +package cosmos.authz.v1beta1; + +// import "cosmos_proto/cosmos.proto"; +// import "google/protobuf/timestamp.proto"; +// import "gogoproto/gogo.proto"; +// import "google/protobuf/any.proto"; + +option go_package = "github.com/cosmos/cosmos-sdk/x/authz/types"; + + +// EventGrant is emitted on Msg/Grant +message EventGrant { + // Module which invokes the authorizaiton grant + // TODO: not sure if this is needed. It's always have the same value + string module = 1; + // Msg type for which an autorization is granted + string msg = 2; + // Granter account address + string granter = 3; + // Grantee account address + string grantee = 4; +} + +// EventRevoke is emitted on Msg/Revoke +message EventRevoke { + // Module which invokes the authorizaiton revokation + string module = 1; + // Msg type for which an autorization is revoked + string msg = 2; + // Granter account address + string granter = 3; + // Grantee account address + string grantee = 4; +} diff --git a/proto/cosmos/authz/v1beta1/query.proto b/proto/cosmos/authz/v1beta1/query.proto index 8a08065b478f..1061388d27ff 100644 --- a/proto/cosmos/authz/v1beta1/query.proto +++ b/proto/cosmos/authz/v1beta1/query.proto @@ -7,22 +7,66 @@ import "cosmos/authz/v1beta1/authz.proto"; option go_package = "github.com/cosmos/cosmos-sdk/x/authz/types"; +// // Query defines the gRPC querier service. +// service Query { +// // Returns list of `Authorization`, granted to the grantee by the granter. +// rpc Authorizations(QueryAuthorizationsRequest) returns (QueryAuthorizationsResponse) { +// option (google.api.http).get = "/cosmos/authz/v1beta1/"; +// } +// } + +// // QueryAuthorizationsRequest is the request type for the Query/Authorizations RPC method. +// message QueryAuthorizationsRequest { +// string granter = 1; +// string grantee = 2; +// // If method name is not included then we return all authorizations for given granter and grantee +// string method_name = 3; +// // pagination defines an pagination for the request. +// cosmos.base.query.v1beta1.PageRequest pagination = 4; +// } + +// // QueryAuthorizationsResponse is the response type for the Query/Authorizations RPC method. +// message QueryAuthorizationsResponse { +// // authorizations is a list of grants granted for grantee by granter. +// repeated cosmos.authz.v1beta1.AuthorizationGrant authorizations = 1; +// // pagination defines an pagination for the response. +// cosmos.base.query.v1beta1.PageResponse pagination = 2; +// } + + // Query defines the gRPC querier service. service Query { + // Returns any `Authorization` (or `nil`), with the expiration time, granted to the grantee by the granter for the + // provided msg type. + rpc Authorization(QueryAuthorizationRequest) returns (QueryAuthorizationResponse) { + option (google.api.http).get = "/cosmos/authz/v1beta1/granters/{granter}/grantees/{grantee}/grant"; + } + // Returns list of `Authorization`, granted to the grantee by the granter. rpc Authorizations(QueryAuthorizationsRequest) returns (QueryAuthorizationsResponse) { - option (google.api.http).get = "/cosmos/authz/v1beta1/"; + option (google.api.http).get = "/cosmos/authz/v1beta1/granters/{granter}/grantees/{grantee}/grants"; } } +// QueryAuthorizationRequest is the request type for the Query/Authorization RPC method. +message QueryAuthorizationRequest { + string granter = 1; + string grantee = 2; + string method_name = 3; +} + +// QueryAuthorizationResponse is the response type for the Query/Authorization RPC method. +message QueryAuthorizationResponse { + // authorization is a authorization granted for grantee by granter. + cosmos.authz.v1beta1.AuthorizationGrant authorization = 1; +} + // QueryAuthorizationsRequest is the request type for the Query/Authorizations RPC method. message QueryAuthorizationsRequest { string granter = 1; string grantee = 2; - // If method name is not included then we return all authorizations for given granter and grantee - string method_name = 3; // pagination defines an pagination for the request. - cosmos.base.query.v1beta1.PageRequest pagination = 4; + cosmos.base.query.v1beta1.PageRequest pagination = 3; } // QueryAuthorizationsResponse is the response type for the Query/Authorizations RPC method. diff --git a/x/authz/keeper/keeper.go b/x/authz/keeper/keeper.go index dd183d270a72..b3d002177274 100644 --- a/x/authz/keeper/keeper.go +++ b/x/authz/keeper/keeper.go @@ -52,12 +52,12 @@ func (k Keeper) update(ctx sdk.Context, grantee sdk.AccAddress, granter sdk.AccA grantStoreKey := types.GetAuthorizationStoreKey(grantee, granter, updated.MethodName()) grant, found := k.getAuthorizationGrant(ctx, grantStoreKey) if !found { - return sdkerrors.Wrapf(sdkerrors.ErrNotFound, "authorization not found") + return sdkerrors.ErrNotFound.Wrap("authorization not found") } msg, ok := updated.(proto.Message) if !ok { - sdkerrors.Wrapf(sdkerrors.ErrPackAny, "cannot proto marshal %T", updated) + sdkerrors.ErrPackAny.Wrapf("cannot proto marshal %T", updated) } any, err := codectypes.NewAnyWithValue(msg) @@ -79,32 +79,35 @@ func (k Keeper) DispatchActions(ctx sdk.Context, grantee sdk.AccAddress, service for _, serviceMsg := range serviceMsgs { signers := serviceMsg.GetSigners() if len(signers) != 1 { - return nil, sdkerrors.Wrapf(sdkerrors.ErrInvalidRequest, "authorization can be given to msg with only one signer") + return nil, sdkerrors.ErrInvalidRequest.Wrap("authorization can be given to msg with only one signer") } granter := signers[0] // if granter != grantee then check authorization.Accept, otherwise we implicitly accept. if !granter.Equals(grantee) { authorization, _ := k.GetOrRevokeAuthorization(ctx, grantee, granter, serviceMsg.MethodName) if authorization == nil { - return nil, sdkerrors.Wrapf(sdkerrors.ErrUnauthorized, "authorization not found") + return nil, sdkerrors.ErrUnauthorized.Wrap("authorization not found") } - updated, del, err := authorization.Accept(ctx, serviceMsg) + resp, err := authorization.Accept(ctx, serviceMsg) if err != nil { return nil, err } - if del { + if resp.Delete { k.Revoke(ctx, grantee, granter, serviceMsg.Type()) - } else if updated != nil { - err = k.update(ctx, grantee, granter, updated) + } else if resp.Updated != nil { + err = k.update(ctx, grantee, granter, resp.Updated) if err != nil { return nil, err } } + if !resp.Accept { + return nil, sdkerrors.ErrUnauthorized + } } handler := k.router.Handler(serviceMsg.Route()) if handler == nil { - return nil, sdkerrors.Wrapf(sdkerrors.ErrUnknownRequest, "unrecognized message route: %s", serviceMsg.Route()) + return nil, sdkerrors.ErrUnknownRequest.Wrapf("unrecognized message route: %s", serviceMsg.Route()) } msgResult, err = handler(ctx, serviceMsg.Request) @@ -130,8 +133,12 @@ func (k Keeper) Grant(ctx sdk.Context, grantee, granter sdk.AccAddress, authoriz bz := k.cdc.MustMarshalBinaryBare(&grant) grantStoreKey := types.GetAuthorizationStoreKey(grantee, granter, authorization.MethodName()) store.Set(grantStoreKey, bz) - emitEvent(ctx, types.EventGrantAuthorization, grantee, granter) - return nil + return ctx.EventManager().EmitTypedEvent(&types.EventGrant{ + Module: types.ModuleName, + Msg: authorization.MethodName(), + Granter: granter.String(), + Grantee: grantee.String(), + }) } // Revoke method revokes any authorization for the provided message type granted to the grantee by the granter. @@ -140,25 +147,15 @@ func (k Keeper) Revoke(ctx sdk.Context, grantee sdk.AccAddress, granter sdk.AccA grantStoreKey := types.GetAuthorizationStoreKey(grantee, granter, msgType) _, found := k.getAuthorizationGrant(ctx, grantStoreKey) if !found { - return sdkerrors.Wrap(sdkerrors.ErrNotFound, "authorization not found") + return sdkerrors.ErrNotFound.Wrap("authorization not found") } store.Delete(grantStoreKey) - emitEvent(ctx, types.EventRevokeAuthorization, grantee, granter) - return nil -} - -func emitEvent(ctx sdk.Context, name string, grantee sdk.AccAddress, granter sdk.AccAddress) { - // TODO: ctx.EventManager().EmitTypedEvent( /* the proto event */ ) - ctx.EventManager().EmitEvent( - sdk.NewEvent( - types.EventRevokeAuthorization, - sdk.NewAttribute(sdk.AttributeKeyModule, types.AttributeValueCategory), - sdk.NewAttribute(types.AttributeKeyGrantType, msgType), - sdk.NewAttribute(types.AttributeKeyGranterAddress, granter.String()), - sdk.NewAttribute(types.AttributeKeyGranteeAddress, grantee.String()), - ), - ) - return nil + return ctx.EventManager().EmitTypedEvent(&types.EventRevoke{ + Module: types.ModuleName, + Msg: msgType, + Granter: granter.String(), + Grantee: grantee.String(), + }) } // GetAuthorizations Returns list of `Authorizations` granted to the grantee by the granter. diff --git a/x/authz/simulation/operations.go b/x/authz/simulation/operations.go index 8fef468b06db..cb368b8afbc0 100644 --- a/x/authz/simulation/operations.go +++ b/x/authz/simulation/operations.go @@ -253,7 +253,7 @@ func SimulateMsgExecuteAuthorized(ak types.AccountKeeper, bk types.BankKeeper, k msg := types.NewMsgExecAuthorized(grantee.Address, []sdk.ServiceMsg{execMsg}) sendGrant := targetGrant.Authorization.GetCachedValue().(*banktype.SendAuthorization) - _, _, err = sendGrant.Accept(ctx, execMsg) + _, err = sendGrant.Accept(ctx, execMsg) if err != nil { return simtypes.NoOpMsg(types.ModuleName, TypeMsgExecDelegated, err.Error()), nil, nil } diff --git a/x/authz/types/event.pb.go b/x/authz/types/event.pb.go new file mode 100644 index 000000000000..6c48acea40f8 --- /dev/null +++ b/x/authz/types/event.pb.go @@ -0,0 +1,805 @@ +// Code generated by protoc-gen-gogo. DO NOT EDIT. +// source: cosmos/authz/v1beta1/event.proto + +package types + +import ( + fmt "fmt" + proto "github.com/gogo/protobuf/proto" + io "io" + math "math" + math_bits "math/bits" +) + +// Reference imports to suppress errors if they are not otherwise used. +var _ = proto.Marshal +var _ = fmt.Errorf +var _ = math.Inf + +// This is a compile-time assertion to ensure that this generated file +// is compatible with the proto package it is being compiled against. +// A compilation error at this line likely means your copy of the +// proto package needs to be updated. +const _ = proto.GoGoProtoPackageIsVersion3 // please upgrade the proto package + +// EventGrant is emitted on Msg/Grant +type EventGrant struct { + // Module which invokes the authorizaiton grant + // TODO: not sure if this is needed. It's always have the same value + Module string `protobuf:"bytes,1,opt,name=module,proto3" json:"module,omitempty"` + // Msg type for which an autorization is granted + Msg string `protobuf:"bytes,2,opt,name=msg,proto3" json:"msg,omitempty"` + // Granter account address + Granter string `protobuf:"bytes,3,opt,name=granter,proto3" json:"granter,omitempty"` + // Grantee account address + Grantee string `protobuf:"bytes,4,opt,name=grantee,proto3" json:"grantee,omitempty"` +} + +func (m *EventGrant) Reset() { *m = EventGrant{} } +func (m *EventGrant) String() string { return proto.CompactTextString(m) } +func (*EventGrant) ProtoMessage() {} +func (*EventGrant) Descriptor() ([]byte, []int) { + return fileDescriptor_1f88cbc71a8baf1f, []int{0} +} +func (m *EventGrant) XXX_Unmarshal(b []byte) error { + return m.Unmarshal(b) +} +func (m *EventGrant) XXX_Marshal(b []byte, deterministic bool) ([]byte, error) { + if deterministic { + return xxx_messageInfo_EventGrant.Marshal(b, m, deterministic) + } else { + b = b[:cap(b)] + n, err := m.MarshalToSizedBuffer(b) + if err != nil { + return nil, err + } + return b[:n], nil + } +} +func (m *EventGrant) XXX_Merge(src proto.Message) { + xxx_messageInfo_EventGrant.Merge(m, src) +} +func (m *EventGrant) XXX_Size() int { + return m.Size() +} +func (m *EventGrant) XXX_DiscardUnknown() { + xxx_messageInfo_EventGrant.DiscardUnknown(m) +} + +var xxx_messageInfo_EventGrant proto.InternalMessageInfo + +func (m *EventGrant) GetModule() string { + if m != nil { + return m.Module + } + return "" +} + +func (m *EventGrant) GetMsg() string { + if m != nil { + return m.Msg + } + return "" +} + +func (m *EventGrant) GetGranter() string { + if m != nil { + return m.Granter + } + return "" +} + +func (m *EventGrant) GetGrantee() string { + if m != nil { + return m.Grantee + } + return "" +} + +// EventRevoke is emitted on Msg/Revoke +type EventRevoke struct { + // Module which invokes the authorizaiton revokation + Module string `protobuf:"bytes,1,opt,name=module,proto3" json:"module,omitempty"` + // Msg type for which an autorization is revoked + Msg string `protobuf:"bytes,2,opt,name=msg,proto3" json:"msg,omitempty"` + // Granter account address + Granter string `protobuf:"bytes,3,opt,name=granter,proto3" json:"granter,omitempty"` + // Grantee account address + Grantee string `protobuf:"bytes,4,opt,name=grantee,proto3" json:"grantee,omitempty"` +} + +func (m *EventRevoke) Reset() { *m = EventRevoke{} } +func (m *EventRevoke) String() string { return proto.CompactTextString(m) } +func (*EventRevoke) ProtoMessage() {} +func (*EventRevoke) Descriptor() ([]byte, []int) { + return fileDescriptor_1f88cbc71a8baf1f, []int{1} +} +func (m *EventRevoke) XXX_Unmarshal(b []byte) error { + return m.Unmarshal(b) +} +func (m *EventRevoke) XXX_Marshal(b []byte, deterministic bool) ([]byte, error) { + if deterministic { + return xxx_messageInfo_EventRevoke.Marshal(b, m, deterministic) + } else { + b = b[:cap(b)] + n, err := m.MarshalToSizedBuffer(b) + if err != nil { + return nil, err + } + return b[:n], nil + } +} +func (m *EventRevoke) XXX_Merge(src proto.Message) { + xxx_messageInfo_EventRevoke.Merge(m, src) +} +func (m *EventRevoke) XXX_Size() int { + return m.Size() +} +func (m *EventRevoke) XXX_DiscardUnknown() { + xxx_messageInfo_EventRevoke.DiscardUnknown(m) +} + +var xxx_messageInfo_EventRevoke proto.InternalMessageInfo + +func (m *EventRevoke) GetModule() string { + if m != nil { + return m.Module + } + return "" +} + +func (m *EventRevoke) GetMsg() string { + if m != nil { + return m.Msg + } + return "" +} + +func (m *EventRevoke) GetGranter() string { + if m != nil { + return m.Granter + } + return "" +} + +func (m *EventRevoke) GetGrantee() string { + if m != nil { + return m.Grantee + } + return "" +} + +func init() { + proto.RegisterType((*EventGrant)(nil), "cosmos.authz.v1beta1.EventGrant") + proto.RegisterType((*EventRevoke)(nil), "cosmos.authz.v1beta1.EventRevoke") +} + +func init() { proto.RegisterFile("cosmos/authz/v1beta1/event.proto", fileDescriptor_1f88cbc71a8baf1f) } + +var fileDescriptor_1f88cbc71a8baf1f = []byte{ + // 212 bytes of a gzipped FileDescriptorProto + 0x1f, 0x8b, 0x08, 0x00, 0x00, 0x00, 0x00, 0x00, 0x02, 0xff, 0xe2, 0x52, 0x48, 0xce, 0x2f, 0xce, + 0xcd, 0x2f, 0xd6, 0x4f, 0x2c, 0x2d, 0xc9, 0xa8, 0xd2, 0x2f, 0x33, 0x4c, 0x4a, 0x2d, 0x49, 0x34, + 0xd4, 0x4f, 0x2d, 0x4b, 0xcd, 0x2b, 0xd1, 0x2b, 0x28, 0xca, 0x2f, 0xc9, 0x17, 0x12, 0x81, 0xa8, + 0xd0, 0x03, 0xab, 0xd0, 0x83, 0xaa, 0x50, 0xca, 0xe2, 0xe2, 0x72, 0x05, 0x29, 0x72, 0x2f, 0x4a, + 0xcc, 0x2b, 0x11, 0x12, 0xe3, 0x62, 0xcb, 0xcd, 0x4f, 0x29, 0xcd, 0x49, 0x95, 0x60, 0x54, 0x60, + 0xd4, 0xe0, 0x0c, 0x82, 0xf2, 0x84, 0x04, 0xb8, 0x98, 0x73, 0x8b, 0xd3, 0x25, 0x98, 0xc0, 0x82, + 0x20, 0xa6, 0x90, 0x04, 0x17, 0x7b, 0x3a, 0x48, 0x4b, 0x6a, 0x91, 0x04, 0x33, 0x58, 0x14, 0xc6, + 0x45, 0xc8, 0xa4, 0x4a, 0xb0, 0x20, 0xcb, 0xa4, 0x2a, 0x65, 0x73, 0x71, 0x83, 0xed, 0x0a, 0x4a, + 0x2d, 0xcb, 0xcf, 0x4e, 0xa5, 0xad, 0x65, 0x4e, 0x2e, 0x27, 0x1e, 0xc9, 0x31, 0x5e, 0x78, 0x24, + 0xc7, 0xf8, 0xe0, 0x91, 0x1c, 0xe3, 0x84, 0xc7, 0x72, 0x0c, 0x17, 0x1e, 0xcb, 0x31, 0xdc, 0x78, + 0x2c, 0xc7, 0x10, 0xa5, 0x95, 0x9e, 0x59, 0x92, 0x51, 0x9a, 0xa4, 0x97, 0x9c, 0x9f, 0xab, 0x0f, + 0x0d, 0x35, 0x08, 0xa5, 0x5b, 0x9c, 0x92, 0xad, 0x5f, 0x01, 0x0d, 0xc2, 0x92, 0xca, 0x82, 0xd4, + 0xe2, 0x24, 0x36, 0x70, 0xd8, 0x19, 0x03, 0x02, 0x00, 0x00, 0xff, 0xff, 0x6c, 0x04, 0x6b, 0x5a, + 0x5f, 0x01, 0x00, 0x00, +} + +func (m *EventGrant) Marshal() (dAtA []byte, err error) { + size := m.Size() + dAtA = make([]byte, size) + n, err := m.MarshalToSizedBuffer(dAtA[:size]) + if err != nil { + return nil, err + } + return dAtA[:n], nil +} + +func (m *EventGrant) MarshalTo(dAtA []byte) (int, error) { + size := m.Size() + return m.MarshalToSizedBuffer(dAtA[:size]) +} + +func (m *EventGrant) MarshalToSizedBuffer(dAtA []byte) (int, error) { + i := len(dAtA) + _ = i + var l int + _ = l + if len(m.Grantee) > 0 { + i -= len(m.Grantee) + copy(dAtA[i:], m.Grantee) + i = encodeVarintEvent(dAtA, i, uint64(len(m.Grantee))) + i-- + dAtA[i] = 0x22 + } + if len(m.Granter) > 0 { + i -= len(m.Granter) + copy(dAtA[i:], m.Granter) + i = encodeVarintEvent(dAtA, i, uint64(len(m.Granter))) + i-- + dAtA[i] = 0x1a + } + if len(m.Msg) > 0 { + i -= len(m.Msg) + copy(dAtA[i:], m.Msg) + i = encodeVarintEvent(dAtA, i, uint64(len(m.Msg))) + i-- + dAtA[i] = 0x12 + } + if len(m.Module) > 0 { + i -= len(m.Module) + copy(dAtA[i:], m.Module) + i = encodeVarintEvent(dAtA, i, uint64(len(m.Module))) + i-- + dAtA[i] = 0xa + } + return len(dAtA) - i, nil +} + +func (m *EventRevoke) Marshal() (dAtA []byte, err error) { + size := m.Size() + dAtA = make([]byte, size) + n, err := m.MarshalToSizedBuffer(dAtA[:size]) + if err != nil { + return nil, err + } + return dAtA[:n], nil +} + +func (m *EventRevoke) MarshalTo(dAtA []byte) (int, error) { + size := m.Size() + return m.MarshalToSizedBuffer(dAtA[:size]) +} + +func (m *EventRevoke) MarshalToSizedBuffer(dAtA []byte) (int, error) { + i := len(dAtA) + _ = i + var l int + _ = l + if len(m.Grantee) > 0 { + i -= len(m.Grantee) + copy(dAtA[i:], m.Grantee) + i = encodeVarintEvent(dAtA, i, uint64(len(m.Grantee))) + i-- + dAtA[i] = 0x22 + } + if len(m.Granter) > 0 { + i -= len(m.Granter) + copy(dAtA[i:], m.Granter) + i = encodeVarintEvent(dAtA, i, uint64(len(m.Granter))) + i-- + dAtA[i] = 0x1a + } + if len(m.Msg) > 0 { + i -= len(m.Msg) + copy(dAtA[i:], m.Msg) + i = encodeVarintEvent(dAtA, i, uint64(len(m.Msg))) + i-- + dAtA[i] = 0x12 + } + if len(m.Module) > 0 { + i -= len(m.Module) + copy(dAtA[i:], m.Module) + i = encodeVarintEvent(dAtA, i, uint64(len(m.Module))) + i-- + dAtA[i] = 0xa + } + return len(dAtA) - i, nil +} + +func encodeVarintEvent(dAtA []byte, offset int, v uint64) int { + offset -= sovEvent(v) + base := offset + for v >= 1<<7 { + dAtA[offset] = uint8(v&0x7f | 0x80) + v >>= 7 + offset++ + } + dAtA[offset] = uint8(v) + return base +} +func (m *EventGrant) Size() (n int) { + if m == nil { + return 0 + } + var l int + _ = l + l = len(m.Module) + if l > 0 { + n += 1 + l + sovEvent(uint64(l)) + } + l = len(m.Msg) + if l > 0 { + n += 1 + l + sovEvent(uint64(l)) + } + l = len(m.Granter) + if l > 0 { + n += 1 + l + sovEvent(uint64(l)) + } + l = len(m.Grantee) + if l > 0 { + n += 1 + l + sovEvent(uint64(l)) + } + return n +} + +func (m *EventRevoke) Size() (n int) { + if m == nil { + return 0 + } + var l int + _ = l + l = len(m.Module) + if l > 0 { + n += 1 + l + sovEvent(uint64(l)) + } + l = len(m.Msg) + if l > 0 { + n += 1 + l + sovEvent(uint64(l)) + } + l = len(m.Granter) + if l > 0 { + n += 1 + l + sovEvent(uint64(l)) + } + l = len(m.Grantee) + if l > 0 { + n += 1 + l + sovEvent(uint64(l)) + } + return n +} + +func sovEvent(x uint64) (n int) { + return (math_bits.Len64(x|1) + 6) / 7 +} +func sozEvent(x uint64) (n int) { + return sovEvent(uint64((x << 1) ^ uint64((int64(x) >> 63)))) +} +func (m *EventGrant) Unmarshal(dAtA []byte) error { + l := len(dAtA) + iNdEx := 0 + for iNdEx < l { + preIndex := iNdEx + var wire uint64 + for shift := uint(0); ; shift += 7 { + if shift >= 64 { + return ErrIntOverflowEvent + } + if iNdEx >= l { + return 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 fmt.Errorf("proto: EventGrant: wiretype end group for non-group") + } + if fieldNum <= 0 { + return fmt.Errorf("proto: EventGrant: illegal tag %d (wire type %d)", fieldNum, wire) + } + switch fieldNum { + case 1: + if wireType != 2 { + return fmt.Errorf("proto: wrong wireType = %d for field Module", wireType) + } + var stringLen uint64 + for shift := uint(0); ; shift += 7 { + if shift >= 64 { + return ErrIntOverflowEvent + } + 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 ErrInvalidLengthEvent + } + postIndex := iNdEx + intStringLen + if postIndex < 0 { + return ErrInvalidLengthEvent + } + if postIndex > l { + return io.ErrUnexpectedEOF + } + m.Module = string(dAtA[iNdEx:postIndex]) + iNdEx = postIndex + case 2: + if wireType != 2 { + return fmt.Errorf("proto: wrong wireType = %d for field Msg", wireType) + } + var stringLen uint64 + for shift := uint(0); ; shift += 7 { + if shift >= 64 { + return ErrIntOverflowEvent + } + 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 ErrInvalidLengthEvent + } + postIndex := iNdEx + intStringLen + if postIndex < 0 { + return ErrInvalidLengthEvent + } + if postIndex > l { + return io.ErrUnexpectedEOF + } + m.Msg = string(dAtA[iNdEx:postIndex]) + iNdEx = postIndex + case 3: + if wireType != 2 { + return fmt.Errorf("proto: wrong wireType = %d for field Granter", wireType) + } + var stringLen uint64 + for shift := uint(0); ; shift += 7 { + if shift >= 64 { + return ErrIntOverflowEvent + } + 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 ErrInvalidLengthEvent + } + postIndex := iNdEx + intStringLen + if postIndex < 0 { + return ErrInvalidLengthEvent + } + if postIndex > l { + return io.ErrUnexpectedEOF + } + m.Granter = string(dAtA[iNdEx:postIndex]) + iNdEx = postIndex + case 4: + if wireType != 2 { + return fmt.Errorf("proto: wrong wireType = %d for field Grantee", wireType) + } + var stringLen uint64 + for shift := uint(0); ; shift += 7 { + if shift >= 64 { + return ErrIntOverflowEvent + } + 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 ErrInvalidLengthEvent + } + postIndex := iNdEx + intStringLen + if postIndex < 0 { + return ErrInvalidLengthEvent + } + if postIndex > l { + return io.ErrUnexpectedEOF + } + m.Grantee = string(dAtA[iNdEx:postIndex]) + iNdEx = postIndex + default: + iNdEx = preIndex + skippy, err := skipEvent(dAtA[iNdEx:]) + if err != nil { + return err + } + if (skippy < 0) || (iNdEx+skippy) < 0 { + return ErrInvalidLengthEvent + } + if (iNdEx + skippy) > l { + return io.ErrUnexpectedEOF + } + iNdEx += skippy + } + } + + if iNdEx > l { + return io.ErrUnexpectedEOF + } + return nil +} +func (m *EventRevoke) Unmarshal(dAtA []byte) error { + l := len(dAtA) + iNdEx := 0 + for iNdEx < l { + preIndex := iNdEx + var wire uint64 + for shift := uint(0); ; shift += 7 { + if shift >= 64 { + return ErrIntOverflowEvent + } + if iNdEx >= l { + return 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 fmt.Errorf("proto: EventRevoke: wiretype end group for non-group") + } + if fieldNum <= 0 { + return fmt.Errorf("proto: EventRevoke: illegal tag %d (wire type %d)", fieldNum, wire) + } + switch fieldNum { + case 1: + if wireType != 2 { + return fmt.Errorf("proto: wrong wireType = %d for field Module", wireType) + } + var stringLen uint64 + for shift := uint(0); ; shift += 7 { + if shift >= 64 { + return ErrIntOverflowEvent + } + 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 ErrInvalidLengthEvent + } + postIndex := iNdEx + intStringLen + if postIndex < 0 { + return ErrInvalidLengthEvent + } + if postIndex > l { + return io.ErrUnexpectedEOF + } + m.Module = string(dAtA[iNdEx:postIndex]) + iNdEx = postIndex + case 2: + if wireType != 2 { + return fmt.Errorf("proto: wrong wireType = %d for field Msg", wireType) + } + var stringLen uint64 + for shift := uint(0); ; shift += 7 { + if shift >= 64 { + return ErrIntOverflowEvent + } + 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 ErrInvalidLengthEvent + } + postIndex := iNdEx + intStringLen + if postIndex < 0 { + return ErrInvalidLengthEvent + } + if postIndex > l { + return io.ErrUnexpectedEOF + } + m.Msg = string(dAtA[iNdEx:postIndex]) + iNdEx = postIndex + case 3: + if wireType != 2 { + return fmt.Errorf("proto: wrong wireType = %d for field Granter", wireType) + } + var stringLen uint64 + for shift := uint(0); ; shift += 7 { + if shift >= 64 { + return ErrIntOverflowEvent + } + 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 ErrInvalidLengthEvent + } + postIndex := iNdEx + intStringLen + if postIndex < 0 { + return ErrInvalidLengthEvent + } + if postIndex > l { + return io.ErrUnexpectedEOF + } + m.Granter = string(dAtA[iNdEx:postIndex]) + iNdEx = postIndex + case 4: + if wireType != 2 { + return fmt.Errorf("proto: wrong wireType = %d for field Grantee", wireType) + } + var stringLen uint64 + for shift := uint(0); ; shift += 7 { + if shift >= 64 { + return ErrIntOverflowEvent + } + 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 ErrInvalidLengthEvent + } + postIndex := iNdEx + intStringLen + if postIndex < 0 { + return ErrInvalidLengthEvent + } + if postIndex > l { + return io.ErrUnexpectedEOF + } + m.Grantee = string(dAtA[iNdEx:postIndex]) + iNdEx = postIndex + default: + iNdEx = preIndex + skippy, err := skipEvent(dAtA[iNdEx:]) + if err != nil { + return err + } + if (skippy < 0) || (iNdEx+skippy) < 0 { + return ErrInvalidLengthEvent + } + if (iNdEx + skippy) > l { + return io.ErrUnexpectedEOF + } + iNdEx += skippy + } + } + + if iNdEx > l { + return io.ErrUnexpectedEOF + } + return nil +} +func skipEvent(dAtA []byte) (n int, err error) { + l := len(dAtA) + iNdEx := 0 + depth := 0 + for iNdEx < l { + var wire uint64 + for shift := uint(0); ; shift += 7 { + if shift >= 64 { + return 0, ErrIntOverflowEvent + } + if iNdEx >= l { + return 0, io.ErrUnexpectedEOF + } + b := dAtA[iNdEx] + iNdEx++ + wire |= (uint64(b) & 0x7F) << shift + if b < 0x80 { + break + } + } + wireType := int(wire & 0x7) + switch wireType { + case 0: + for shift := uint(0); ; shift += 7 { + if shift >= 64 { + return 0, ErrIntOverflowEvent + } + if iNdEx >= l { + return 0, io.ErrUnexpectedEOF + } + iNdEx++ + if dAtA[iNdEx-1] < 0x80 { + break + } + } + case 1: + iNdEx += 8 + case 2: + var length int + for shift := uint(0); ; shift += 7 { + if shift >= 64 { + return 0, ErrIntOverflowEvent + } + if iNdEx >= l { + return 0, io.ErrUnexpectedEOF + } + b := dAtA[iNdEx] + iNdEx++ + length |= (int(b) & 0x7F) << shift + if b < 0x80 { + break + } + } + if length < 0 { + return 0, ErrInvalidLengthEvent + } + iNdEx += length + case 3: + depth++ + case 4: + if depth == 0 { + return 0, ErrUnexpectedEndOfGroupEvent + } + depth-- + case 5: + iNdEx += 4 + default: + return 0, fmt.Errorf("proto: illegal wireType %d", wireType) + } + if iNdEx < 0 { + return 0, ErrInvalidLengthEvent + } + if depth == 0 { + return iNdEx, nil + } + } + return 0, io.ErrUnexpectedEOF +} + +var ( + ErrInvalidLengthEvent = fmt.Errorf("proto: negative length found during unmarshaling") + ErrIntOverflowEvent = fmt.Errorf("proto: integer overflow") + ErrUnexpectedEndOfGroupEvent = fmt.Errorf("proto: unexpected end of group") +) diff --git a/x/authz/types/events.go b/x/authz/types/events.go deleted file mode 100644 index 9da0f68b14fd..000000000000 --- a/x/authz/types/events.go +++ /dev/null @@ -1,14 +0,0 @@ -package types - -// authz module events -const ( - EventGrantAuthorization = "grant-authorization" - EventRevokeAuthorization = "revoke-authorization" - EventExecuteAuthorization = "execute-authorization" - - AttributeKeyGrantType = "grant-type" - AttributeKeyGranteeAddress = "grantee" - AttributeKeyGranterAddress = "granter" - - AttributeValueCategory = ModuleName -) From 0f6158fdabb6ca9e57a5fbd8ee5017602a4eb150 Mon Sep 17 00:00:00 2001 From: Robert Zaremba Date: Tue, 20 Apr 2021 01:28:56 +0200 Subject: [PATCH 07/44] refactore and rename query authorizations --- Makefile | 4 +- docs/core/proto-docs.md | 56 +- proto/cosmos/authz/v1beta1/query.proto | 96 ++-- x/authz/client/cli/query.go | 100 +--- x/authz/keeper/grpc_query.go | 69 +-- x/authz/types/query.pb.go | 688 +++++-------------------- x/authz/types/query.pb.gw.go | 230 +-------- 7 files changed, 250 insertions(+), 993 deletions(-) diff --git a/Makefile b/Makefile index a26681ea8e5f..bb60726baeb9 100644 --- a/Makefile +++ b/Makefile @@ -371,9 +371,11 @@ devdoc-update: proto-all: proto-format proto-lint proto-gen +protoContainer=cosmos-proto-gen proto-gen: @echo "Generating Protobuf files" - $(DOCKER) run --rm -v $(CURDIR):/workspace --workdir /workspace tendermintdev/sdk-proto-gen:v0.1 sh ./scripts/protocgen.sh + if docker ps -a --format '{{.Names}}' | grep -Eq "^${protoContainer}"; then docker restart $(protoContainer); else docker run --name $(protoContainer) -v $(CURDIR):/workspace --workdir /workspace tendermintdev/sdk-proto-gen:v0.1 sh ./scripts/protocgen.sh; fi +# $(DOCKER) run --rm -v $(CURDIR):/workspace --workdir /workspace tendermintdev/sdk-proto-gen:v0.1 sh ./scripts/protocgen.sh proto-format: @echo "Formatting Protobuf files" diff --git a/docs/core/proto-docs.md b/docs/core/proto-docs.md index 6ea377e9c71a..efc33a75d5d2 100644 --- a/docs/core/proto-docs.md +++ b/docs/core/proto-docs.md @@ -39,10 +39,8 @@ - [GrantAuthorization](#cosmos.authz.v1beta1.GrantAuthorization) - [cosmos/authz/v1beta1/query.proto](#cosmos/authz/v1beta1/query.proto) - - [QueryAuthorizationRequest](#cosmos.authz.v1beta1.QueryAuthorizationRequest) - - [QueryAuthorizationResponse](#cosmos.authz.v1beta1.QueryAuthorizationResponse) - - [QueryAuthorizationsRequest](#cosmos.authz.v1beta1.QueryAuthorizationsRequest) - - [QueryAuthorizationsResponse](#cosmos.authz.v1beta1.QueryAuthorizationsResponse) + - [QueryGrantsRequest](#cosmos.authz.v1beta1.QueryGrantsRequest) + - [QueryGrantsResponse](#cosmos.authz.v1beta1.QueryGrantsResponse) - [Query](#cosmos.authz.v1beta1.Query) @@ -1028,48 +1026,17 @@ GrantAuthorization defines the GenesisState/GrantAuthorization type. - + -### QueryAuthorizationRequest -QueryAuthorizationRequest is the request type for the Query/Authorization RPC method. - - -| Field | Type | Label | Description | -| ----- | ---- | ----- | ----------- | -| `granter` | [string](#string) | | | -| `grantee` | [string](#string) | | | -| `method_name` | [string](#string) | | | - - - - - - - - -### QueryAuthorizationResponse -QueryAuthorizationResponse is the response type for the Query/Authorization RPC method. - - -| Field | Type | Label | Description | -| ----- | ---- | ----- | ----------- | -| `authorization` | [AuthorizationGrant](#cosmos.authz.v1beta1.AuthorizationGrant) | | authorization is a authorization granted for grantee by granter. | - - - - - - - - -### QueryAuthorizationsRequest -QueryAuthorizationsRequest is the request type for the Query/Authorizations RPC method. +### QueryGrantsRequest +QueryGrantsRequest is the request type for the Query/Grants RPC method. | Field | Type | Label | Description | | ----- | ---- | ----- | ----------- | | `granter` | [string](#string) | | | | `grantee` | [string](#string) | | | +| `msg_type_url` | [string](#string) | | Optional, msg_type_url, when set, will query only grants matching give msg type. | | `pagination` | [cosmos.base.query.v1beta1.PageRequest](#cosmos.base.query.v1beta1.PageRequest) | | pagination defines an pagination for the request. | @@ -1077,15 +1044,15 @@ QueryAuthorizationsRequest is the request type for the Query/Authorizations RPC - + -### QueryAuthorizationsResponse -QueryAuthorizationsResponse is the response type for the Query/Authorizations RPC method. +### QueryGrantsResponse +QueryGrantsResponse is the response type for the Query/Authorizations RPC method. | Field | Type | Label | Description | | ----- | ---- | ----- | ----------- | -| `authorizations` | [AuthorizationGrant](#cosmos.authz.v1beta1.AuthorizationGrant) | repeated | authorizations is a list of grants granted for grantee by granter. | +| `grants` | [AuthorizationGrant](#cosmos.authz.v1beta1.AuthorizationGrant) | repeated | authorizations is a list of grants granted for grantee by granter. | | `pagination` | [cosmos.base.query.v1beta1.PageResponse](#cosmos.base.query.v1beta1.PageResponse) | | pagination defines an pagination for the response. | @@ -1106,8 +1073,7 @@ Query defines the gRPC querier service. | Method Name | Request Type | Response Type | Description | HTTP Verb | Endpoint | | ----------- | ------------ | ------------- | ------------| ------- | -------- | -| `Authorization` | [QueryAuthorizationRequest](#cosmos.authz.v1beta1.QueryAuthorizationRequest) | [QueryAuthorizationResponse](#cosmos.authz.v1beta1.QueryAuthorizationResponse) | Returns any `Authorization` (or `nil`), with the expiration time, granted to the grantee by the granter for the provided msg type. | GET|/cosmos/authz/v1beta1/granters/{granter}/grantees/{grantee}/grant| -| `Authorizations` | [QueryAuthorizationsRequest](#cosmos.authz.v1beta1.QueryAuthorizationsRequest) | [QueryAuthorizationsResponse](#cosmos.authz.v1beta1.QueryAuthorizationsResponse) | Returns list of `Authorization`, granted to the grantee by the granter. | GET|/cosmos/authz/v1beta1/granters/{granter}/grantees/{grantee}/grants| +| `Grants` | [QueryGrantsRequest](#cosmos.authz.v1beta1.QueryGrantsRequest) | [QueryGrantsResponse](#cosmos.authz.v1beta1.QueryGrantsResponse) | Returns list of `Authorization`, granted to the grantee by the granter. | GET|/cosmos/authz/v1beta1/grants| diff --git a/proto/cosmos/authz/v1beta1/query.proto b/proto/cosmos/authz/v1beta1/query.proto index 1061388d27ff..c49e3b29f23b 100644 --- a/proto/cosmos/authz/v1beta1/query.proto +++ b/proto/cosmos/authz/v1beta1/query.proto @@ -7,22 +7,66 @@ import "cosmos/authz/v1beta1/authz.proto"; option go_package = "github.com/cosmos/cosmos-sdk/x/authz/types"; +// Query defines the gRPC querier service. +service Query { + // Returns list of `Authorization`, granted to the grantee by the granter. + rpc Grants(QueryGrantsRequest) returns (QueryGrantsResponse) { + option (google.api.http).get = "/cosmos/authz/v1beta1/grants"; + } +} + +// QueryGrantsRequest is the request type for the Query/Grants RPC method. +message QueryGrantsRequest { + string granter = 1; + string grantee = 2; + // Optional, msg_type_url, when set, will query only grants matching give msg type. + string msg_type_url = 3; + // pagination defines an pagination for the request. + cosmos.base.query.v1beta1.PageRequest pagination = 4; +} + +// QueryGrantsResponse is the response type for the Query/Authorizations RPC method. +message QueryGrantsResponse { + // authorizations is a list of grants granted for grantee by granter. + repeated cosmos.authz.v1beta1.AuthorizationGrant grants = 1; + // pagination defines an pagination for the response. + cosmos.base.query.v1beta1.PageResponse pagination = 2; +} + + // // Query defines the gRPC querier service. // service Query { +// // Returns any `Authorization` (or `nil`), with the expiration time, granted to the grantee by the granter for the +// // provided msg type. +// rpc Authorization(QueryAuthorizationRequest) returns (QueryAuthorizationResponse) { +// option (google.api.http).get = "/cosmos/authz/v1beta1/granters/{granter}/grantees/{grantee}/grant"; +// } + // // Returns list of `Authorization`, granted to the grantee by the granter. // rpc Authorizations(QueryAuthorizationsRequest) returns (QueryAuthorizationsResponse) { -// option (google.api.http).get = "/cosmos/authz/v1beta1/"; +// option (google.api.http).get = "/cosmos/authz/v1beta1/granters/{granter}/grantees/{grantee}/grants"; // } // } +// // QueryAuthorizationRequest is the request type for the Query/Authorization RPC method. +// message QueryAuthorizationRequest { +// string granter = 1; +// string grantee = 2; +// string method_name = 3; +// } + +// // QueryAuthorizationResponse is the response type for the Query/Authorization RPC method. +// message QueryAuthorizationResponse { +// // authorization is a authorization granted for grantee by granter. +// cosmos.authz.v1beta1.AuthorizationGrant authorization = 1; +// } + // // QueryAuthorizationsRequest is the request type for the Query/Authorizations RPC method. // message QueryAuthorizationsRequest { // string granter = 1; // string grantee = 2; -// // If method name is not included then we return all authorizations for given granter and grantee -// string method_name = 3; // // pagination defines an pagination for the request. -// cosmos.base.query.v1beta1.PageRequest pagination = 4; +// cosmos.base.query.v1beta1.PageRequest pagination = 3; // } // // QueryAuthorizationsResponse is the response type for the Query/Authorizations RPC method. @@ -32,47 +76,3 @@ option go_package = "github.com/cosmos/cosmos-sdk/x/authz/types"; // // pagination defines an pagination for the response. // cosmos.base.query.v1beta1.PageResponse pagination = 2; // } - - -// Query defines the gRPC querier service. -service Query { - // Returns any `Authorization` (or `nil`), with the expiration time, granted to the grantee by the granter for the - // provided msg type. - rpc Authorization(QueryAuthorizationRequest) returns (QueryAuthorizationResponse) { - option (google.api.http).get = "/cosmos/authz/v1beta1/granters/{granter}/grantees/{grantee}/grant"; - } - - // Returns list of `Authorization`, granted to the grantee by the granter. - rpc Authorizations(QueryAuthorizationsRequest) returns (QueryAuthorizationsResponse) { - option (google.api.http).get = "/cosmos/authz/v1beta1/granters/{granter}/grantees/{grantee}/grants"; - } -} - -// QueryAuthorizationRequest is the request type for the Query/Authorization RPC method. -message QueryAuthorizationRequest { - string granter = 1; - string grantee = 2; - string method_name = 3; -} - -// QueryAuthorizationResponse is the response type for the Query/Authorization RPC method. -message QueryAuthorizationResponse { - // authorization is a authorization granted for grantee by granter. - cosmos.authz.v1beta1.AuthorizationGrant authorization = 1; -} - -// QueryAuthorizationsRequest is the request type for the Query/Authorizations RPC method. -message QueryAuthorizationsRequest { - string granter = 1; - string grantee = 2; - // pagination defines an pagination for the request. - cosmos.base.query.v1beta1.PageRequest pagination = 3; -} - -// QueryAuthorizationsResponse is the response type for the Query/Authorizations RPC method. -message QueryAuthorizationsResponse { - // authorizations is a list of grants granted for grantee by granter. - repeated cosmos.authz.v1beta1.AuthorizationGrant authorizations = 1; - // pagination defines an pagination for the response. - cosmos.base.query.v1beta1.PageResponse pagination = 2; -} diff --git a/x/authz/client/cli/query.go b/x/authz/client/cli/query.go index 269a68e099f0..297a8f695cb7 100644 --- a/x/authz/client/cli/query.go +++ b/x/authz/client/cli/query.go @@ -1,7 +1,6 @@ package cli import ( - "context" "fmt" "strings" @@ -27,24 +26,27 @@ func GetQueryCmd() *cobra.Command { } authorizationQueryCmd.AddCommand( - GetCmdQueryAuthorization(), - GetCmdQueryAuthorizations(), + GetCmdQueryGrants(), ) return authorizationQueryCmd } -// GetCmdQueryAuthorizations implements the query authorizations command. -func GetCmdQueryAuthorizations() *cobra.Command { +// GetCmdQueryGrants implements the query authorization command. +func GetCmdQueryGrants() *cobra.Command { cmd := &cobra.Command{ - Use: "authorizations [granter-addr] [grantee-addr]", - Args: cobra.ExactArgs(2), - Short: "query list of authorizations for a granter-grantee pair", + Use: "authorization [granter-addr] [grantee-addr] [msg-type-url]?", + Args: cobra.RangeArgs(2, 3), + Short: "query grants for a granter-grantee pair and optionally a msg-type-url", Long: strings.TrimSpace( - fmt.Sprintf(`Query list of authorizations for a granter-grantee pair: -Example: -$ %s query %s authorizations cosmos1skj.. cosmos1skjwj.. -`, version.AppName, types.ModuleName), + fmt.Sprintf(`Query authorization grants for a granter-grantee pair. If msg-type-url +is set, it will select grants only for that msg type. +Examples: +$ %s query %s grants cosmos1skj.. cosmos1skjwj.. +$ %s query %s grants cosmos1skjw.. cosmos1skjwj.. %s +`, + version.AppName, types.ModuleName, + version.AppName, types.ModuleName, bank.SendAuthorization{}.MethodName()), ), RunE: func(cmd *cobra.Command, args []string) error { clientCtx, err := client.GetClientQueryContext(cmd) @@ -53,87 +55,39 @@ $ %s query %s authorizations cosmos1skj.. cosmos1skjwj.. } queryClient := types.NewQueryClient(clientCtx) - granterAddr, err := sdk.AccAddressFromBech32(args[0]) - if err != nil { - return err - } - - granteeAddr, err := sdk.AccAddressFromBech32(args[1]) - if err != nil { - return err - } - - pageReq, err := client.ReadPageRequest(cmd.Flags()) - if err != nil { - return err - } - - res, err := queryClient.Authorizations( - context.Background(), - &types.QueryAuthorizationsRequest{ - Granter: granterAddr.String(), - Grantee: granteeAddr.String(), - Pagination: pageReq, - }, - ) + granter, err := sdk.AccAddressFromBech32(args[0]) if err != nil { return err } - - return clientCtx.PrintProto(res) - }, - } - flags.AddQueryFlagsToCmd(cmd) - flags.AddPaginationFlagsToCmd(cmd, "authorizations") - return cmd -} - -// GetCmdQueryAuthorization implements the query authorization command. -func GetCmdQueryAuthorization() *cobra.Command { - cmd := &cobra.Command{ - Use: "authorization [granter-addr] [grantee-addr] [msg-type]", - Args: cobra.ExactArgs(3), - Short: "query authorization for a granter-grantee pair", - Long: strings.TrimSpace( - fmt.Sprintf(`Query authorization for a granter-grantee pair that matches the given msg-type: -Example: -$ %s query %s authorization cosmos1skjw.. cosmos1skjwj.. %s -`, version.AppName, types.ModuleName, bank.SendAuthorization{}.MethodName()), - ), - RunE: func(cmd *cobra.Command, args []string) error { - clientCtx, err := client.GetClientQueryContext(cmd) + grantee, err := sdk.AccAddressFromBech32(args[1]) if err != nil { return err } - queryClient := types.NewQueryClient(clientCtx) - - granter, err := sdk.AccAddressFromBech32(args[0]) - if err != nil { - return err + var msgAuthorized = "" + if len(args) >= 3 { + msgAuthorized = args[2] } - - grantee, err := sdk.AccAddressFromBech32(args[1]) + pageReq, err := client.ReadPageRequest(cmd.Flags()) if err != nil { return err } - msgAuthorized := args[2] - - res, err := queryClient.Authorization( - context.Background(), - &types.QueryAuthorizationRequest{ + res, err := queryClient.Grants( + cmd.Context(), + &types.QueryGrantsRequest{ Granter: granter.String(), Grantee: grantee.String(), - MethodName: msgAuthorized, - }, + MsgTypeUrl: msgAuthorized, + Pagination: pageReq}, ) if err != nil { return err } - return clientCtx.PrintProto(res.Authorization) + return clientCtx.PrintProto(res) }, } flags.AddQueryFlagsToCmd(cmd) + flags.AddPaginationFlagsToCmd(cmd, "grants") return cmd } diff --git a/x/authz/keeper/grpc_query.go b/x/authz/keeper/grpc_query.go index 7b1fcb1995dd..5bb44960d31c 100644 --- a/x/authz/keeper/grpc_query.go +++ b/x/authz/keeper/grpc_query.go @@ -19,18 +19,17 @@ import ( var _ types.QueryServer = Keeper{} // Authorizations implements the Query/Authorizations gRPC method. -func (k Keeper) Authorizations(c context.Context, req *types.QueryAuthorizationsRequest) (*types.QueryAuthorizationsResponse, error) { +func (k Keeper) Grants(c context.Context, req *types.QueryGrantsRequest) (*types.QueryGrantsResponse, error) { if req == nil { return nil, status.Errorf(codes.InvalidArgument, "empty request") } granter, err := sdk.AccAddressFromBech32(req.Granter) - if err != nil { return nil, err } - grantee, err := sdk.AccAddressFromBech32(req.Grantee) + grantee, err := sdk.AccAddressFromBech32(req.Grantee) if err != nil { return nil, err } @@ -39,6 +38,24 @@ func (k Keeper) Authorizations(c context.Context, req *types.QueryAuthorizations store := ctx.KVStore(k.storeKey) key := types.GetAuthorizationStoreKey(grantee, granter, "") authStore := prefix.NewStore(store, key) + + if req.MsgTypeUrl != "" { + authorization, expiration := k.GetOrRevokeAuthorization(ctx, grantee, granter, req.MsgTypeUrl) + if authorization == nil { + return nil, status.Errorf(codes.NotFound, "no authorization found for %s type", req.MsgTypeUrl) + } + authorizationAny, err := codectypes.NewAnyWithValue(authorization) + if err != nil { + return nil, status.Errorf(codes.Internal, err.Error()) + } + return &types.QueryGrantsResponse{ + Grants: []*types.AuthorizationGrant{&types.AuthorizationGrant{ + Authorization: authorizationAny, + Expiration: expiration, + }}, + }, nil + } + var authorizations []*types.AuthorizationGrant pageRes, err := query.FilteredPaginate(authStore, req.Pagination, func(key []byte, value []byte, accumulate bool) (bool, error) { auth, err := unmarshalAuthorization(k.cdc, value) @@ -67,9 +84,9 @@ func (k Keeper) Authorizations(c context.Context, req *types.QueryAuthorizations return nil, err } - return &types.QueryAuthorizationsResponse{ - Authorizations: authorizations, - Pagination: pageRes, + return &types.QueryGrantsResponse{ + Grants: authorizations, + Pagination: pageRes, }, nil } @@ -78,43 +95,3 @@ func unmarshalAuthorization(cdc codec.BinaryMarshaler, value []byte) (v types.Au err = cdc.UnmarshalBinaryBare(value, &v) return v, err } - -// Authorization implements the Query/Authorization gRPC method. -func (k Keeper) Authorization(c context.Context, req *types.QueryAuthorizationRequest) (*types.QueryAuthorizationResponse, error) { - if req == nil { - return nil, status.Errorf(codes.InvalidArgument, "empty request") - } - - if req.MethodName == "" { - return nil, status.Errorf(codes.InvalidArgument, "empty method-name") - } - - granter, err := sdk.AccAddressFromBech32(req.Granter) - - if err != nil { - return nil, err - } - grantee, err := sdk.AccAddressFromBech32(req.Grantee) - - if err != nil { - return nil, err - } - ctx := sdk.UnwrapSDKContext(c) - - authorization, expiration := k.GetOrRevokeAuthorization(ctx, grantee, granter, req.MethodName) - if authorization == nil { - return nil, status.Errorf(codes.NotFound, "no authorization found for %s type", req.MethodName) - } - - authorizationAny, err := codectypes.NewAnyWithValue(authorization) - if err != nil { - return nil, status.Errorf(codes.Internal, err.Error()) - } - - return &types.QueryAuthorizationResponse{ - Authorization: &types.AuthorizationGrant{ - Authorization: authorizationAny, - Expiration: expiration, - }, - }, nil -} diff --git a/x/authz/types/query.pb.go b/x/authz/types/query.pb.go index 493412f7524f..ccc5e5a8e820 100644 --- a/x/authz/types/query.pb.go +++ b/x/authz/types/query.pb.go @@ -29,25 +29,28 @@ var _ = math.Inf // proto package needs to be updated. const _ = proto.GoGoProtoPackageIsVersion3 // please upgrade the proto package -// QueryAuthorizationRequest is the request type for the Query/Authorization RPC method. -type QueryAuthorizationRequest struct { - Granter string `protobuf:"bytes,1,opt,name=granter,proto3" json:"granter,omitempty"` - Grantee string `protobuf:"bytes,2,opt,name=grantee,proto3" json:"grantee,omitempty"` - MethodName string `protobuf:"bytes,3,opt,name=method_name,json=methodName,proto3" json:"method_name,omitempty"` +// QueryGrantsRequest is the request type for the Query/Grants RPC method. +type QueryGrantsRequest struct { + Granter string `protobuf:"bytes,1,opt,name=granter,proto3" json:"granter,omitempty"` + Grantee string `protobuf:"bytes,2,opt,name=grantee,proto3" json:"grantee,omitempty"` + // Optional, msg_type_url, when set, will query only grants matching give msg type. + MsgTypeUrl string `protobuf:"bytes,3,opt,name=msg_type_url,json=msgTypeUrl,proto3" json:"msg_type_url,omitempty"` + // pagination defines an pagination for the request. + Pagination *query.PageRequest `protobuf:"bytes,4,opt,name=pagination,proto3" json:"pagination,omitempty"` } -func (m *QueryAuthorizationRequest) Reset() { *m = QueryAuthorizationRequest{} } -func (m *QueryAuthorizationRequest) String() string { return proto.CompactTextString(m) } -func (*QueryAuthorizationRequest) ProtoMessage() {} -func (*QueryAuthorizationRequest) Descriptor() ([]byte, []int) { +func (m *QueryGrantsRequest) Reset() { *m = QueryGrantsRequest{} } +func (m *QueryGrantsRequest) String() string { return proto.CompactTextString(m) } +func (*QueryGrantsRequest) ProtoMessage() {} +func (*QueryGrantsRequest) Descriptor() ([]byte, []int) { return fileDescriptor_376d714ffdeb1545, []int{0} } -func (m *QueryAuthorizationRequest) XXX_Unmarshal(b []byte) error { +func (m *QueryGrantsRequest) XXX_Unmarshal(b []byte) error { return m.Unmarshal(b) } -func (m *QueryAuthorizationRequest) XXX_Marshal(b []byte, deterministic bool) ([]byte, error) { +func (m *QueryGrantsRequest) XXX_Marshal(b []byte, deterministic bool) ([]byte, error) { if deterministic { - return xxx_messageInfo_QueryAuthorizationRequest.Marshal(b, m, deterministic) + return xxx_messageInfo_QueryGrantsRequest.Marshal(b, m, deterministic) } else { b = b[:cap(b)] n, err := m.MarshalToSizedBuffer(b) @@ -57,167 +60,66 @@ func (m *QueryAuthorizationRequest) XXX_Marshal(b []byte, deterministic bool) ([ return b[:n], nil } } -func (m *QueryAuthorizationRequest) XXX_Merge(src proto.Message) { - xxx_messageInfo_QueryAuthorizationRequest.Merge(m, src) +func (m *QueryGrantsRequest) XXX_Merge(src proto.Message) { + xxx_messageInfo_QueryGrantsRequest.Merge(m, src) } -func (m *QueryAuthorizationRequest) XXX_Size() int { +func (m *QueryGrantsRequest) XXX_Size() int { return m.Size() } -func (m *QueryAuthorizationRequest) XXX_DiscardUnknown() { - xxx_messageInfo_QueryAuthorizationRequest.DiscardUnknown(m) +func (m *QueryGrantsRequest) XXX_DiscardUnknown() { + xxx_messageInfo_QueryGrantsRequest.DiscardUnknown(m) } -var xxx_messageInfo_QueryAuthorizationRequest proto.InternalMessageInfo +var xxx_messageInfo_QueryGrantsRequest proto.InternalMessageInfo -func (m *QueryAuthorizationRequest) GetGranter() string { +func (m *QueryGrantsRequest) GetGranter() string { if m != nil { return m.Granter } return "" } -func (m *QueryAuthorizationRequest) GetGrantee() string { +func (m *QueryGrantsRequest) GetGrantee() string { if m != nil { return m.Grantee } return "" } -func (m *QueryAuthorizationRequest) GetMethodName() string { - if m != nil { - return m.MethodName - } - return "" -} - -// QueryAuthorizationResponse is the response type for the Query/Authorization RPC method. -type QueryAuthorizationResponse struct { - // authorization is a authorization granted for grantee by granter. - Authorization *AuthorizationGrant `protobuf:"bytes,1,opt,name=authorization,proto3" json:"authorization,omitempty"` -} - -func (m *QueryAuthorizationResponse) Reset() { *m = QueryAuthorizationResponse{} } -func (m *QueryAuthorizationResponse) String() string { return proto.CompactTextString(m) } -func (*QueryAuthorizationResponse) ProtoMessage() {} -func (*QueryAuthorizationResponse) Descriptor() ([]byte, []int) { - return fileDescriptor_376d714ffdeb1545, []int{1} -} -func (m *QueryAuthorizationResponse) XXX_Unmarshal(b []byte) error { - return m.Unmarshal(b) -} -func (m *QueryAuthorizationResponse) XXX_Marshal(b []byte, deterministic bool) ([]byte, error) { - if deterministic { - return xxx_messageInfo_QueryAuthorizationResponse.Marshal(b, m, deterministic) - } else { - b = b[:cap(b)] - n, err := m.MarshalToSizedBuffer(b) - if err != nil { - return nil, err - } - return b[:n], nil - } -} -func (m *QueryAuthorizationResponse) XXX_Merge(src proto.Message) { - xxx_messageInfo_QueryAuthorizationResponse.Merge(m, src) -} -func (m *QueryAuthorizationResponse) XXX_Size() int { - return m.Size() -} -func (m *QueryAuthorizationResponse) XXX_DiscardUnknown() { - xxx_messageInfo_QueryAuthorizationResponse.DiscardUnknown(m) -} - -var xxx_messageInfo_QueryAuthorizationResponse proto.InternalMessageInfo - -func (m *QueryAuthorizationResponse) GetAuthorization() *AuthorizationGrant { - if m != nil { - return m.Authorization - } - return nil -} - -// QueryAuthorizationsRequest is the request type for the Query/Authorizations RPC method. -type QueryAuthorizationsRequest struct { - Granter string `protobuf:"bytes,1,opt,name=granter,proto3" json:"granter,omitempty"` - Grantee string `protobuf:"bytes,2,opt,name=grantee,proto3" json:"grantee,omitempty"` - // pagination defines an pagination for the request. - Pagination *query.PageRequest `protobuf:"bytes,3,opt,name=pagination,proto3" json:"pagination,omitempty"` -} - -func (m *QueryAuthorizationsRequest) Reset() { *m = QueryAuthorizationsRequest{} } -func (m *QueryAuthorizationsRequest) String() string { return proto.CompactTextString(m) } -func (*QueryAuthorizationsRequest) ProtoMessage() {} -func (*QueryAuthorizationsRequest) Descriptor() ([]byte, []int) { - return fileDescriptor_376d714ffdeb1545, []int{2} -} -func (m *QueryAuthorizationsRequest) XXX_Unmarshal(b []byte) error { - return m.Unmarshal(b) -} -func (m *QueryAuthorizationsRequest) XXX_Marshal(b []byte, deterministic bool) ([]byte, error) { - if deterministic { - return xxx_messageInfo_QueryAuthorizationsRequest.Marshal(b, m, deterministic) - } else { - b = b[:cap(b)] - n, err := m.MarshalToSizedBuffer(b) - if err != nil { - return nil, err - } - return b[:n], nil - } -} -func (m *QueryAuthorizationsRequest) XXX_Merge(src proto.Message) { - xxx_messageInfo_QueryAuthorizationsRequest.Merge(m, src) -} -func (m *QueryAuthorizationsRequest) XXX_Size() int { - return m.Size() -} -func (m *QueryAuthorizationsRequest) XXX_DiscardUnknown() { - xxx_messageInfo_QueryAuthorizationsRequest.DiscardUnknown(m) -} - -var xxx_messageInfo_QueryAuthorizationsRequest proto.InternalMessageInfo - -func (m *QueryAuthorizationsRequest) GetGranter() string { - if m != nil { - return m.Granter - } - return "" -} - -func (m *QueryAuthorizationsRequest) GetGrantee() string { +func (m *QueryGrantsRequest) GetMsgTypeUrl() string { if m != nil { - return m.Grantee + return m.MsgTypeUrl } return "" } -func (m *QueryAuthorizationsRequest) GetPagination() *query.PageRequest { +func (m *QueryGrantsRequest) GetPagination() *query.PageRequest { if m != nil { return m.Pagination } return nil } -// QueryAuthorizationsResponse is the response type for the Query/Authorizations RPC method. -type QueryAuthorizationsResponse struct { +// QueryGrantsResponse is the response type for the Query/Authorizations RPC method. +type QueryGrantsResponse struct { // authorizations is a list of grants granted for grantee by granter. - Authorizations []*AuthorizationGrant `protobuf:"bytes,1,rep,name=authorizations,proto3" json:"authorizations,omitempty"` + Grants []*AuthorizationGrant `protobuf:"bytes,1,rep,name=grants,proto3" json:"grants,omitempty"` // pagination defines an pagination for the response. Pagination *query.PageResponse `protobuf:"bytes,2,opt,name=pagination,proto3" json:"pagination,omitempty"` } -func (m *QueryAuthorizationsResponse) Reset() { *m = QueryAuthorizationsResponse{} } -func (m *QueryAuthorizationsResponse) String() string { return proto.CompactTextString(m) } -func (*QueryAuthorizationsResponse) ProtoMessage() {} -func (*QueryAuthorizationsResponse) Descriptor() ([]byte, []int) { - return fileDescriptor_376d714ffdeb1545, []int{3} +func (m *QueryGrantsResponse) Reset() { *m = QueryGrantsResponse{} } +func (m *QueryGrantsResponse) String() string { return proto.CompactTextString(m) } +func (*QueryGrantsResponse) ProtoMessage() {} +func (*QueryGrantsResponse) Descriptor() ([]byte, []int) { + return fileDescriptor_376d714ffdeb1545, []int{1} } -func (m *QueryAuthorizationsResponse) XXX_Unmarshal(b []byte) error { +func (m *QueryGrantsResponse) XXX_Unmarshal(b []byte) error { return m.Unmarshal(b) } -func (m *QueryAuthorizationsResponse) XXX_Marshal(b []byte, deterministic bool) ([]byte, error) { +func (m *QueryGrantsResponse) XXX_Marshal(b []byte, deterministic bool) ([]byte, error) { if deterministic { - return xxx_messageInfo_QueryAuthorizationsResponse.Marshal(b, m, deterministic) + return xxx_messageInfo_QueryGrantsResponse.Marshal(b, m, deterministic) } else { b = b[:cap(b)] n, err := m.MarshalToSizedBuffer(b) @@ -227,26 +129,26 @@ func (m *QueryAuthorizationsResponse) XXX_Marshal(b []byte, deterministic bool) return b[:n], nil } } -func (m *QueryAuthorizationsResponse) XXX_Merge(src proto.Message) { - xxx_messageInfo_QueryAuthorizationsResponse.Merge(m, src) +func (m *QueryGrantsResponse) XXX_Merge(src proto.Message) { + xxx_messageInfo_QueryGrantsResponse.Merge(m, src) } -func (m *QueryAuthorizationsResponse) XXX_Size() int { +func (m *QueryGrantsResponse) XXX_Size() int { return m.Size() } -func (m *QueryAuthorizationsResponse) XXX_DiscardUnknown() { - xxx_messageInfo_QueryAuthorizationsResponse.DiscardUnknown(m) +func (m *QueryGrantsResponse) XXX_DiscardUnknown() { + xxx_messageInfo_QueryGrantsResponse.DiscardUnknown(m) } -var xxx_messageInfo_QueryAuthorizationsResponse proto.InternalMessageInfo +var xxx_messageInfo_QueryGrantsResponse proto.InternalMessageInfo -func (m *QueryAuthorizationsResponse) GetAuthorizations() []*AuthorizationGrant { +func (m *QueryGrantsResponse) GetGrants() []*AuthorizationGrant { if m != nil { - return m.Authorizations + return m.Grants } return nil } -func (m *QueryAuthorizationsResponse) GetPagination() *query.PageResponse { +func (m *QueryGrantsResponse) GetPagination() *query.PageResponse { if m != nil { return m.Pagination } @@ -254,45 +156,39 @@ func (m *QueryAuthorizationsResponse) GetPagination() *query.PageResponse { } func init() { - proto.RegisterType((*QueryAuthorizationRequest)(nil), "cosmos.authz.v1beta1.QueryAuthorizationRequest") - proto.RegisterType((*QueryAuthorizationResponse)(nil), "cosmos.authz.v1beta1.QueryAuthorizationResponse") - proto.RegisterType((*QueryAuthorizationsRequest)(nil), "cosmos.authz.v1beta1.QueryAuthorizationsRequest") - proto.RegisterType((*QueryAuthorizationsResponse)(nil), "cosmos.authz.v1beta1.QueryAuthorizationsResponse") + proto.RegisterType((*QueryGrantsRequest)(nil), "cosmos.authz.v1beta1.QueryGrantsRequest") + proto.RegisterType((*QueryGrantsResponse)(nil), "cosmos.authz.v1beta1.QueryGrantsResponse") } func init() { proto.RegisterFile("cosmos/authz/v1beta1/query.proto", fileDescriptor_376d714ffdeb1545) } var fileDescriptor_376d714ffdeb1545 = []byte{ - // 461 bytes of a gzipped FileDescriptorProto - 0x1f, 0x8b, 0x08, 0x00, 0x00, 0x00, 0x00, 0x00, 0x02, 0xff, 0xa4, 0x94, 0x31, 0x8f, 0xd3, 0x30, - 0x14, 0xc7, 0xeb, 0x56, 0x80, 0x70, 0x75, 0x37, 0x58, 0x0c, 0x21, 0xa0, 0x50, 0x65, 0x80, 0xd3, - 0x49, 0xc4, 0xb4, 0x7c, 0x82, 0x3b, 0x4e, 0x9c, 0x60, 0x38, 0x1d, 0x19, 0x59, 0x90, 0xd3, 0x3e, - 0x25, 0x11, 0x4d, 0x9c, 0xc6, 0x0e, 0xa2, 0x45, 0x2c, 0xac, 0x2c, 0x48, 0x2c, 0x7c, 0x14, 0x16, - 0x06, 0x36, 0xc6, 0x4a, 0x2c, 0x8c, 0xa8, 0xe5, 0x83, 0xa0, 0xda, 0x4e, 0x9b, 0xa0, 0xa0, 0x6b, - 0xd5, 0x29, 0xc9, 0x7b, 0xef, 0xff, 0xfe, 0xbf, 0xf7, 0x6c, 0x05, 0xf7, 0x86, 0x5c, 0x24, 0x5c, - 0x50, 0x56, 0xc8, 0x68, 0x46, 0xdf, 0xf4, 0x03, 0x90, 0xac, 0x4f, 0x27, 0x05, 0xe4, 0x53, 0x2f, - 0xcb, 0xb9, 0xe4, 0xe4, 0x96, 0xae, 0xf0, 0x54, 0x85, 0x67, 0x2a, 0xec, 0xbb, 0x21, 0xe7, 0xe1, - 0x18, 0x28, 0xcb, 0x62, 0xca, 0xd2, 0x94, 0x4b, 0x26, 0x63, 0x9e, 0x0a, 0xad, 0xb1, 0x8f, 0x4d, - 0xd7, 0x80, 0x09, 0xd0, 0xcd, 0xd6, 0xad, 0x33, 0x16, 0xc6, 0xa9, 0x2a, 0x36, 0xb5, 0xcd, 0x04, - 0xda, 0x4d, 0x55, 0xb8, 0x19, 0xbe, 0xfd, 0x62, 0xd5, 0xe3, 0xa4, 0x90, 0x11, 0xcf, 0xe3, 0x99, - 0x52, 0xfb, 0x30, 0x29, 0x40, 0x48, 0x62, 0xe1, 0x1b, 0x61, 0xce, 0x52, 0x09, 0xb9, 0x85, 0x7a, - 0xe8, 0xe8, 0xa6, 0x5f, 0x7e, 0x6e, 0x32, 0x60, 0xb5, 0xab, 0x19, 0x20, 0xf7, 0x70, 0x37, 0x01, - 0x19, 0xf1, 0xd1, 0xab, 0x94, 0x25, 0x60, 0x75, 0x54, 0x16, 0xeb, 0xd0, 0x05, 0x4b, 0xc0, 0x1d, - 0x63, 0xbb, 0xc9, 0x51, 0x64, 0x3c, 0x15, 0x40, 0x2e, 0xf0, 0x01, 0xab, 0x26, 0x94, 0x71, 0x77, - 0x70, 0xe4, 0x35, 0x6d, 0xca, 0xab, 0xf5, 0x38, 0x5f, 0x11, 0xf8, 0x75, 0xb9, 0xfb, 0x05, 0x35, - 0xd9, 0x89, 0x7d, 0x26, 0x7c, 0x8a, 0xf1, 0x66, 0xd1, 0x6a, 0xc0, 0xee, 0xe0, 0x7e, 0xc9, 0xb7, - 0x3a, 0x15, 0x4f, 0x1f, 0x71, 0x09, 0x79, 0xc9, 0x42, 0x30, 0x7e, 0x7e, 0x45, 0xe9, 0x7e, 0x45, - 0xf8, 0x4e, 0x23, 0x9a, 0x59, 0xc5, 0x25, 0x3e, 0xac, 0xcd, 0x22, 0x2c, 0xd4, 0xeb, 0xec, 0xb4, - 0x8b, 0x7f, 0xf4, 0xe4, 0xbc, 0x46, 0xde, 0x56, 0xe4, 0x0f, 0xae, 0x24, 0xd7, 0x38, 0x55, 0xf4, - 0xc1, 0xc7, 0x0e, 0xbe, 0xa6, 0xd0, 0xc9, 0x37, 0x84, 0x0f, 0x6a, 0xce, 0x84, 0x36, 0xe3, 0xfd, - 0xf7, 0x96, 0xd9, 0x8f, 0xb6, 0x17, 0x68, 0x14, 0xf7, 0xd9, 0x87, 0x9f, 0x7f, 0x3e, 0xb7, 0x9f, - 0x90, 0x13, 0xda, 0x78, 0xbf, 0xcd, 0x11, 0x0a, 0xfa, 0xce, 0xbc, 0xbd, 0x37, 0x21, 0x58, 0x87, - 0xc0, 0x84, 0xc8, 0x77, 0x84, 0x0f, 0xeb, 0xfb, 0x27, 0x5b, 0xf3, 0x94, 0xb7, 0xc8, 0xee, 0xef, - 0xa0, 0x30, 0x23, 0x3c, 0x57, 0x23, 0x9c, 0x91, 0xd3, 0xbd, 0x47, 0x10, 0xa7, 0x67, 0x3f, 0x16, - 0x0e, 0x9a, 0x2f, 0x1c, 0xf4, 0x7b, 0xe1, 0xa0, 0x4f, 0x4b, 0xa7, 0x35, 0x5f, 0x3a, 0xad, 0x5f, - 0x4b, 0xa7, 0xf5, 0xf2, 0x38, 0x8c, 0x65, 0x54, 0x04, 0xde, 0x90, 0x27, 0xa5, 0x8f, 0x7e, 0x3c, - 0x14, 0xa3, 0xd7, 0xf4, 0xad, 0x31, 0x95, 0xd3, 0x0c, 0x44, 0x70, 0x5d, 0xfd, 0x10, 0x1e, 0xff, - 0x0d, 0x00, 0x00, 0xff, 0xff, 0x91, 0xf5, 0x18, 0x65, 0xb6, 0x04, 0x00, 0x00, + // 395 bytes of a gzipped FileDescriptorProto + 0x1f, 0x8b, 0x08, 0x00, 0x00, 0x00, 0x00, 0x00, 0x02, 0xff, 0x8c, 0x92, 0xc1, 0x4a, 0xeb, 0x40, + 0x14, 0x86, 0x3b, 0xed, 0xbd, 0xbd, 0xdc, 0xe9, 0x5d, 0xcd, 0x75, 0x11, 0x4a, 0x09, 0xa1, 0x88, + 0xc6, 0x82, 0x13, 0x5a, 0x5f, 0x40, 0x45, 0xec, 0x56, 0x83, 0x6e, 0xdc, 0x94, 0x49, 0x1d, 0xa6, + 0xc1, 0x26, 0x93, 0x66, 0x26, 0x62, 0xbb, 0xd4, 0xb5, 0x20, 0xf8, 0x02, 0x3e, 0x83, 0x4f, 0xe1, + 0xb2, 0xe0, 0xc6, 0xa5, 0xb4, 0x3e, 0x88, 0x64, 0x66, 0x6a, 0x5b, 0xac, 0xe8, 0x2a, 0x24, 0xe7, + 0x3f, 0xdf, 0xf9, 0xe6, 0x4c, 0xa0, 0xd3, 0xe5, 0x22, 0xe2, 0xc2, 0x23, 0x99, 0xec, 0x8d, 0xbc, + 0xcb, 0x66, 0x40, 0x25, 0x69, 0x7a, 0x83, 0x8c, 0xa6, 0x43, 0x9c, 0xa4, 0x5c, 0x72, 0xb4, 0xa6, + 0x13, 0x58, 0x25, 0xb0, 0x49, 0x54, 0x6b, 0x8c, 0x73, 0xd6, 0xa7, 0x1e, 0x49, 0x42, 0x8f, 0xc4, + 0x31, 0x97, 0x44, 0x86, 0x3c, 0x16, 0xba, 0xa7, 0xda, 0x30, 0xd4, 0x80, 0x08, 0xaa, 0x61, 0x1f, + 0xe8, 0x84, 0xb0, 0x30, 0x56, 0x61, 0x93, 0x5d, 0x6d, 0xa0, 0xa7, 0xa9, 0x44, 0xfd, 0x11, 0x40, + 0x74, 0x9c, 0x43, 0xda, 0x29, 0x89, 0xa5, 0xf0, 0xe9, 0x20, 0xa3, 0x42, 0x22, 0x0b, 0xfe, 0x61, + 0xf9, 0x07, 0x9a, 0x5a, 0xc0, 0x01, 0xee, 0x5f, 0x7f, 0xf6, 0x3a, 0xaf, 0x50, 0xab, 0xb8, 0x58, + 0xa1, 0xc8, 0x81, 0xff, 0x22, 0xc1, 0x3a, 0x72, 0x98, 0xd0, 0x4e, 0x96, 0xf6, 0xad, 0x92, 0x2a, + 0xc3, 0x48, 0xb0, 0x93, 0x61, 0x42, 0x4f, 0xd3, 0x3e, 0x3a, 0x84, 0x70, 0xae, 0x68, 0xfd, 0x72, + 0x80, 0x5b, 0x69, 0x6d, 0x60, 0xb3, 0x83, 0xfc, 0x3c, 0x58, 0x2f, 0xc7, 0x88, 0xe2, 0x23, 0xc2, + 0xa8, 0x31, 0xf2, 0x17, 0x3a, 0xeb, 0x0f, 0x00, 0xfe, 0x5f, 0x92, 0x16, 0x09, 0x8f, 0x05, 0x45, + 0xbb, 0xb0, 0xac, 0x64, 0x84, 0x05, 0x9c, 0x92, 0x5b, 0x69, 0xb9, 0x78, 0xd5, 0x7e, 0xf1, 0x5e, + 0x26, 0x7b, 0x3c, 0x0d, 0x47, 0x0a, 0xa6, 0x10, 0xbe, 0xe9, 0x43, 0xed, 0x25, 0xc3, 0xa2, 0x32, + 0xdc, 0xfc, 0xd6, 0x50, 0x8f, 0x5f, 0x54, 0x6c, 0xdd, 0x02, 0xf8, 0x5b, 0x29, 0xa2, 0x1b, 0x00, + 0xcb, 0xda, 0x13, 0x7d, 0xe1, 0xf3, 0x79, 0xff, 0xd5, 0xad, 0x1f, 0x24, 0xf5, 0xd4, 0xfa, 0xfa, + 0xf5, 0xf3, 0xdb, 0x7d, 0xd1, 0x46, 0x35, 0x6f, 0xe5, 0x65, 0xeb, 0x83, 0xed, 0x1f, 0x3c, 0x4d, + 0x6c, 0x30, 0x9e, 0xd8, 0xe0, 0x75, 0x62, 0x83, 0xbb, 0xa9, 0x5d, 0x18, 0x4f, 0xed, 0xc2, 0xcb, + 0xd4, 0x2e, 0x9c, 0x35, 0x58, 0x28, 0x7b, 0x59, 0x80, 0xbb, 0x3c, 0x9a, 0x11, 0xf4, 0x63, 0x5b, + 0x9c, 0x5f, 0x78, 0x57, 0x06, 0x97, 0xdf, 0xaa, 0x08, 0xca, 0xea, 0xa7, 0xd9, 0x79, 0x0f, 0x00, + 0x00, 0xff, 0xff, 0x77, 0xd6, 0x12, 0xe0, 0xda, 0x02, 0x00, 0x00, } // Reference imports to suppress errors if they are not otherwise used. @@ -307,11 +203,8 @@ const _ = grpc.SupportPackageIsVersion4 // // For semantics around ctx use and closing/ending streaming RPCs, please refer to https://godoc.org/google.golang.org/grpc#ClientConn.NewStream. type QueryClient interface { - // Returns any `Authorization` (or `nil`), with the expiration time, granted to the grantee by the granter for the - // provided msg type. - Authorization(ctx context.Context, in *QueryAuthorizationRequest, opts ...grpc.CallOption) (*QueryAuthorizationResponse, error) // Returns list of `Authorization`, granted to the grantee by the granter. - Authorizations(ctx context.Context, in *QueryAuthorizationsRequest, opts ...grpc.CallOption) (*QueryAuthorizationsResponse, error) + Grants(ctx context.Context, in *QueryGrantsRequest, opts ...grpc.CallOption) (*QueryGrantsResponse, error) } type queryClient struct { @@ -322,18 +215,9 @@ func NewQueryClient(cc grpc1.ClientConn) QueryClient { return &queryClient{cc} } -func (c *queryClient) Authorization(ctx context.Context, in *QueryAuthorizationRequest, opts ...grpc.CallOption) (*QueryAuthorizationResponse, error) { - out := new(QueryAuthorizationResponse) - err := c.cc.Invoke(ctx, "/cosmos.authz.v1beta1.Query/Authorization", in, out, opts...) - if err != nil { - return nil, err - } - return out, nil -} - -func (c *queryClient) Authorizations(ctx context.Context, in *QueryAuthorizationsRequest, opts ...grpc.CallOption) (*QueryAuthorizationsResponse, error) { - out := new(QueryAuthorizationsResponse) - err := c.cc.Invoke(ctx, "/cosmos.authz.v1beta1.Query/Authorizations", in, out, opts...) +func (c *queryClient) Grants(ctx context.Context, in *QueryGrantsRequest, opts ...grpc.CallOption) (*QueryGrantsResponse, error) { + out := new(QueryGrantsResponse) + err := c.cc.Invoke(ctx, "/cosmos.authz.v1beta1.Query/Grants", in, out, opts...) if err != nil { return nil, err } @@ -342,60 +226,36 @@ func (c *queryClient) Authorizations(ctx context.Context, in *QueryAuthorization // QueryServer is the server API for Query service. type QueryServer interface { - // Returns any `Authorization` (or `nil`), with the expiration time, granted to the grantee by the granter for the - // provided msg type. - Authorization(context.Context, *QueryAuthorizationRequest) (*QueryAuthorizationResponse, error) // Returns list of `Authorization`, granted to the grantee by the granter. - Authorizations(context.Context, *QueryAuthorizationsRequest) (*QueryAuthorizationsResponse, error) + Grants(context.Context, *QueryGrantsRequest) (*QueryGrantsResponse, error) } // UnimplementedQueryServer can be embedded to have forward compatible implementations. type UnimplementedQueryServer struct { } -func (*UnimplementedQueryServer) Authorization(ctx context.Context, req *QueryAuthorizationRequest) (*QueryAuthorizationResponse, error) { - return nil, status.Errorf(codes.Unimplemented, "method Authorization not implemented") -} -func (*UnimplementedQueryServer) Authorizations(ctx context.Context, req *QueryAuthorizationsRequest) (*QueryAuthorizationsResponse, error) { - return nil, status.Errorf(codes.Unimplemented, "method Authorizations not implemented") +func (*UnimplementedQueryServer) Grants(ctx context.Context, req *QueryGrantsRequest) (*QueryGrantsResponse, error) { + return nil, status.Errorf(codes.Unimplemented, "method Grants not implemented") } func RegisterQueryServer(s grpc1.Server, srv QueryServer) { s.RegisterService(&_Query_serviceDesc, srv) } -func _Query_Authorization_Handler(srv interface{}, ctx context.Context, dec func(interface{}) error, interceptor grpc.UnaryServerInterceptor) (interface{}, error) { - in := new(QueryAuthorizationRequest) +func _Query_Grants_Handler(srv interface{}, ctx context.Context, dec func(interface{}) error, interceptor grpc.UnaryServerInterceptor) (interface{}, error) { + in := new(QueryGrantsRequest) if err := dec(in); err != nil { return nil, err } if interceptor == nil { - return srv.(QueryServer).Authorization(ctx, in) + return srv.(QueryServer).Grants(ctx, in) } info := &grpc.UnaryServerInfo{ Server: srv, - FullMethod: "/cosmos.authz.v1beta1.Query/Authorization", + FullMethod: "/cosmos.authz.v1beta1.Query/Grants", } handler := func(ctx context.Context, req interface{}) (interface{}, error) { - return srv.(QueryServer).Authorization(ctx, req.(*QueryAuthorizationRequest)) - } - return interceptor(ctx, in, info, handler) -} - -func _Query_Authorizations_Handler(srv interface{}, ctx context.Context, dec func(interface{}) error, interceptor grpc.UnaryServerInterceptor) (interface{}, error) { - in := new(QueryAuthorizationsRequest) - if err := dec(in); err != nil { - return nil, err - } - if interceptor == nil { - return srv.(QueryServer).Authorizations(ctx, in) - } - info := &grpc.UnaryServerInfo{ - Server: srv, - FullMethod: "/cosmos.authz.v1beta1.Query/Authorizations", - } - handler := func(ctx context.Context, req interface{}) (interface{}, error) { - return srv.(QueryServer).Authorizations(ctx, req.(*QueryAuthorizationsRequest)) + return srv.(QueryServer).Grants(ctx, req.(*QueryGrantsRequest)) } return interceptor(ctx, in, info, handler) } @@ -405,98 +265,15 @@ var _Query_serviceDesc = grpc.ServiceDesc{ HandlerType: (*QueryServer)(nil), Methods: []grpc.MethodDesc{ { - MethodName: "Authorization", - Handler: _Query_Authorization_Handler, - }, - { - MethodName: "Authorizations", - Handler: _Query_Authorizations_Handler, + MethodName: "Grants", + Handler: _Query_Grants_Handler, }, }, Streams: []grpc.StreamDesc{}, Metadata: "cosmos/authz/v1beta1/query.proto", } -func (m *QueryAuthorizationRequest) Marshal() (dAtA []byte, err error) { - size := m.Size() - dAtA = make([]byte, size) - n, err := m.MarshalToSizedBuffer(dAtA[:size]) - if err != nil { - return nil, err - } - return dAtA[:n], nil -} - -func (m *QueryAuthorizationRequest) MarshalTo(dAtA []byte) (int, error) { - size := m.Size() - return m.MarshalToSizedBuffer(dAtA[:size]) -} - -func (m *QueryAuthorizationRequest) MarshalToSizedBuffer(dAtA []byte) (int, error) { - i := len(dAtA) - _ = i - var l int - _ = l - if len(m.MethodName) > 0 { - i -= len(m.MethodName) - copy(dAtA[i:], m.MethodName) - i = encodeVarintQuery(dAtA, i, uint64(len(m.MethodName))) - i-- - dAtA[i] = 0x1a - } - if len(m.Grantee) > 0 { - i -= len(m.Grantee) - copy(dAtA[i:], m.Grantee) - i = encodeVarintQuery(dAtA, i, uint64(len(m.Grantee))) - i-- - dAtA[i] = 0x12 - } - if len(m.Granter) > 0 { - i -= len(m.Granter) - copy(dAtA[i:], m.Granter) - i = encodeVarintQuery(dAtA, i, uint64(len(m.Granter))) - i-- - dAtA[i] = 0xa - } - return len(dAtA) - i, nil -} - -func (m *QueryAuthorizationResponse) Marshal() (dAtA []byte, err error) { - size := m.Size() - dAtA = make([]byte, size) - n, err := m.MarshalToSizedBuffer(dAtA[:size]) - if err != nil { - return nil, err - } - return dAtA[:n], nil -} - -func (m *QueryAuthorizationResponse) MarshalTo(dAtA []byte) (int, error) { - size := m.Size() - return m.MarshalToSizedBuffer(dAtA[:size]) -} - -func (m *QueryAuthorizationResponse) MarshalToSizedBuffer(dAtA []byte) (int, error) { - i := len(dAtA) - _ = i - var l int - _ = l - if m.Authorization != nil { - { - size, err := m.Authorization.MarshalToSizedBuffer(dAtA[:i]) - if err != nil { - return 0, err - } - i -= size - i = encodeVarintQuery(dAtA, i, uint64(size)) - } - i-- - dAtA[i] = 0xa - } - return len(dAtA) - i, nil -} - -func (m *QueryAuthorizationsRequest) Marshal() (dAtA []byte, err error) { +func (m *QueryGrantsRequest) Marshal() (dAtA []byte, err error) { size := m.Size() dAtA = make([]byte, size) n, err := m.MarshalToSizedBuffer(dAtA[:size]) @@ -506,12 +283,12 @@ func (m *QueryAuthorizationsRequest) Marshal() (dAtA []byte, err error) { return dAtA[:n], nil } -func (m *QueryAuthorizationsRequest) MarshalTo(dAtA []byte) (int, error) { +func (m *QueryGrantsRequest) MarshalTo(dAtA []byte) (int, error) { size := m.Size() return m.MarshalToSizedBuffer(dAtA[:size]) } -func (m *QueryAuthorizationsRequest) MarshalToSizedBuffer(dAtA []byte) (int, error) { +func (m *QueryGrantsRequest) MarshalToSizedBuffer(dAtA []byte) (int, error) { i := len(dAtA) _ = i var l int @@ -526,6 +303,13 @@ func (m *QueryAuthorizationsRequest) MarshalToSizedBuffer(dAtA []byte) (int, err i = encodeVarintQuery(dAtA, i, uint64(size)) } i-- + dAtA[i] = 0x22 + } + if len(m.MsgTypeUrl) > 0 { + i -= len(m.MsgTypeUrl) + copy(dAtA[i:], m.MsgTypeUrl) + i = encodeVarintQuery(dAtA, i, uint64(len(m.MsgTypeUrl))) + i-- dAtA[i] = 0x1a } if len(m.Grantee) > 0 { @@ -545,7 +329,7 @@ func (m *QueryAuthorizationsRequest) MarshalToSizedBuffer(dAtA []byte) (int, err return len(dAtA) - i, nil } -func (m *QueryAuthorizationsResponse) Marshal() (dAtA []byte, err error) { +func (m *QueryGrantsResponse) Marshal() (dAtA []byte, err error) { size := m.Size() dAtA = make([]byte, size) n, err := m.MarshalToSizedBuffer(dAtA[:size]) @@ -555,12 +339,12 @@ func (m *QueryAuthorizationsResponse) Marshal() (dAtA []byte, err error) { return dAtA[:n], nil } -func (m *QueryAuthorizationsResponse) MarshalTo(dAtA []byte) (int, error) { +func (m *QueryGrantsResponse) MarshalTo(dAtA []byte) (int, error) { size := m.Size() return m.MarshalToSizedBuffer(dAtA[:size]) } -func (m *QueryAuthorizationsResponse) MarshalToSizedBuffer(dAtA []byte) (int, error) { +func (m *QueryGrantsResponse) MarshalToSizedBuffer(dAtA []byte) (int, error) { i := len(dAtA) _ = i var l int @@ -577,10 +361,10 @@ func (m *QueryAuthorizationsResponse) MarshalToSizedBuffer(dAtA []byte) (int, er i-- dAtA[i] = 0x12 } - if len(m.Authorizations) > 0 { - for iNdEx := len(m.Authorizations) - 1; iNdEx >= 0; iNdEx-- { + if len(m.Grants) > 0 { + for iNdEx := len(m.Grants) - 1; iNdEx >= 0; iNdEx-- { { - size, err := m.Authorizations[iNdEx].MarshalToSizedBuffer(dAtA[:i]) + size, err := m.Grants[iNdEx].MarshalToSizedBuffer(dAtA[:i]) if err != nil { return 0, err } @@ -605,7 +389,7 @@ func encodeVarintQuery(dAtA []byte, offset int, v uint64) int { dAtA[offset] = uint8(v) return base } -func (m *QueryAuthorizationRequest) Size() (n int) { +func (m *QueryGrantsRequest) Size() (n int) { if m == nil { return 0 } @@ -619,37 +403,7 @@ func (m *QueryAuthorizationRequest) Size() (n int) { if l > 0 { n += 1 + l + sovQuery(uint64(l)) } - l = len(m.MethodName) - if l > 0 { - n += 1 + l + sovQuery(uint64(l)) - } - return n -} - -func (m *QueryAuthorizationResponse) Size() (n int) { - if m == nil { - return 0 - } - var l int - _ = l - if m.Authorization != nil { - l = m.Authorization.Size() - n += 1 + l + sovQuery(uint64(l)) - } - return n -} - -func (m *QueryAuthorizationsRequest) Size() (n int) { - if m == nil { - return 0 - } - var l int - _ = l - l = len(m.Granter) - if l > 0 { - n += 1 + l + sovQuery(uint64(l)) - } - l = len(m.Grantee) + l = len(m.MsgTypeUrl) if l > 0 { n += 1 + l + sovQuery(uint64(l)) } @@ -660,14 +414,14 @@ func (m *QueryAuthorizationsRequest) Size() (n int) { return n } -func (m *QueryAuthorizationsResponse) Size() (n int) { +func (m *QueryGrantsResponse) Size() (n int) { if m == nil { return 0 } var l int _ = l - if len(m.Authorizations) > 0 { - for _, e := range m.Authorizations { + if len(m.Grants) > 0 { + for _, e := range m.Grants { l = e.Size() n += 1 + l + sovQuery(uint64(l)) } @@ -685,7 +439,7 @@ func sovQuery(x uint64) (n int) { func sozQuery(x uint64) (n int) { return sovQuery(uint64((x << 1) ^ uint64((int64(x) >> 63)))) } -func (m *QueryAuthorizationRequest) Unmarshal(dAtA []byte) error { +func (m *QueryGrantsRequest) Unmarshal(dAtA []byte) error { l := len(dAtA) iNdEx := 0 for iNdEx < l { @@ -708,10 +462,10 @@ func (m *QueryAuthorizationRequest) Unmarshal(dAtA []byte) error { fieldNum := int32(wire >> 3) wireType := int(wire & 0x7) if wireType == 4 { - return fmt.Errorf("proto: QueryAuthorizationRequest: wiretype end group for non-group") + return fmt.Errorf("proto: QueryGrantsRequest: wiretype end group for non-group") } if fieldNum <= 0 { - return fmt.Errorf("proto: QueryAuthorizationRequest: illegal tag %d (wire type %d)", fieldNum, wire) + return fmt.Errorf("proto: QueryGrantsRequest: illegal tag %d (wire type %d)", fieldNum, wire) } switch fieldNum { case 1: @@ -780,175 +534,7 @@ func (m *QueryAuthorizationRequest) Unmarshal(dAtA []byte) error { iNdEx = postIndex case 3: if wireType != 2 { - return fmt.Errorf("proto: wrong wireType = %d for field MethodName", wireType) - } - var stringLen uint64 - for shift := uint(0); ; shift += 7 { - if shift >= 64 { - return ErrIntOverflowQuery - } - 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 ErrInvalidLengthQuery - } - postIndex := iNdEx + intStringLen - if postIndex < 0 { - return ErrInvalidLengthQuery - } - if postIndex > l { - return io.ErrUnexpectedEOF - } - m.MethodName = string(dAtA[iNdEx:postIndex]) - iNdEx = postIndex - default: - iNdEx = preIndex - skippy, err := skipQuery(dAtA[iNdEx:]) - if err != nil { - return err - } - if (skippy < 0) || (iNdEx+skippy) < 0 { - return ErrInvalidLengthQuery - } - if (iNdEx + skippy) > l { - return io.ErrUnexpectedEOF - } - iNdEx += skippy - } - } - - if iNdEx > l { - return io.ErrUnexpectedEOF - } - return nil -} -func (m *QueryAuthorizationResponse) Unmarshal(dAtA []byte) error { - l := len(dAtA) - iNdEx := 0 - for iNdEx < l { - preIndex := iNdEx - var wire uint64 - for shift := uint(0); ; shift += 7 { - if shift >= 64 { - return ErrIntOverflowQuery - } - if iNdEx >= l { - return 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 fmt.Errorf("proto: QueryAuthorizationResponse: wiretype end group for non-group") - } - if fieldNum <= 0 { - return fmt.Errorf("proto: QueryAuthorizationResponse: illegal tag %d (wire type %d)", fieldNum, wire) - } - switch fieldNum { - case 1: - if wireType != 2 { - return fmt.Errorf("proto: wrong wireType = %d for field Authorization", wireType) - } - var msglen int - for shift := uint(0); ; shift += 7 { - if shift >= 64 { - return ErrIntOverflowQuery - } - if iNdEx >= l { - return io.ErrUnexpectedEOF - } - b := dAtA[iNdEx] - iNdEx++ - msglen |= int(b&0x7F) << shift - if b < 0x80 { - break - } - } - if msglen < 0 { - return ErrInvalidLengthQuery - } - postIndex := iNdEx + msglen - if postIndex < 0 { - return ErrInvalidLengthQuery - } - if postIndex > l { - return io.ErrUnexpectedEOF - } - if m.Authorization == nil { - m.Authorization = &AuthorizationGrant{} - } - if err := m.Authorization.Unmarshal(dAtA[iNdEx:postIndex]); err != nil { - return err - } - iNdEx = postIndex - default: - iNdEx = preIndex - skippy, err := skipQuery(dAtA[iNdEx:]) - if err != nil { - return err - } - if (skippy < 0) || (iNdEx+skippy) < 0 { - return ErrInvalidLengthQuery - } - if (iNdEx + skippy) > l { - return io.ErrUnexpectedEOF - } - iNdEx += skippy - } - } - - if iNdEx > l { - return io.ErrUnexpectedEOF - } - return nil -} -func (m *QueryAuthorizationsRequest) Unmarshal(dAtA []byte) error { - l := len(dAtA) - iNdEx := 0 - for iNdEx < l { - preIndex := iNdEx - var wire uint64 - for shift := uint(0); ; shift += 7 { - if shift >= 64 { - return ErrIntOverflowQuery - } - if iNdEx >= l { - return 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 fmt.Errorf("proto: QueryAuthorizationsRequest: wiretype end group for non-group") - } - if fieldNum <= 0 { - return fmt.Errorf("proto: QueryAuthorizationsRequest: illegal tag %d (wire type %d)", fieldNum, wire) - } - switch fieldNum { - case 1: - if wireType != 2 { - return fmt.Errorf("proto: wrong wireType = %d for field Granter", wireType) + return fmt.Errorf("proto: wrong wireType = %d for field MsgTypeUrl", wireType) } var stringLen uint64 for shift := uint(0); ; shift += 7 { @@ -976,41 +562,9 @@ func (m *QueryAuthorizationsRequest) Unmarshal(dAtA []byte) error { if postIndex > l { return io.ErrUnexpectedEOF } - m.Granter = string(dAtA[iNdEx:postIndex]) + m.MsgTypeUrl = string(dAtA[iNdEx:postIndex]) iNdEx = postIndex - case 2: - if wireType != 2 { - return fmt.Errorf("proto: wrong wireType = %d for field Grantee", wireType) - } - var stringLen uint64 - for shift := uint(0); ; shift += 7 { - if shift >= 64 { - return ErrIntOverflowQuery - } - 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 ErrInvalidLengthQuery - } - postIndex := iNdEx + intStringLen - if postIndex < 0 { - return ErrInvalidLengthQuery - } - if postIndex > l { - return io.ErrUnexpectedEOF - } - m.Grantee = string(dAtA[iNdEx:postIndex]) - iNdEx = postIndex - case 3: + case 4: if wireType != 2 { return fmt.Errorf("proto: wrong wireType = %d for field Pagination", wireType) } @@ -1067,7 +621,7 @@ func (m *QueryAuthorizationsRequest) Unmarshal(dAtA []byte) error { } return nil } -func (m *QueryAuthorizationsResponse) Unmarshal(dAtA []byte) error { +func (m *QueryGrantsResponse) Unmarshal(dAtA []byte) error { l := len(dAtA) iNdEx := 0 for iNdEx < l { @@ -1090,15 +644,15 @@ func (m *QueryAuthorizationsResponse) Unmarshal(dAtA []byte) error { fieldNum := int32(wire >> 3) wireType := int(wire & 0x7) if wireType == 4 { - return fmt.Errorf("proto: QueryAuthorizationsResponse: wiretype end group for non-group") + return fmt.Errorf("proto: QueryGrantsResponse: wiretype end group for non-group") } if fieldNum <= 0 { - return fmt.Errorf("proto: QueryAuthorizationsResponse: illegal tag %d (wire type %d)", fieldNum, wire) + return fmt.Errorf("proto: QueryGrantsResponse: illegal tag %d (wire type %d)", fieldNum, wire) } switch fieldNum { case 1: if wireType != 2 { - return fmt.Errorf("proto: wrong wireType = %d for field Authorizations", wireType) + return fmt.Errorf("proto: wrong wireType = %d for field Grants", wireType) } var msglen int for shift := uint(0); ; shift += 7 { @@ -1125,8 +679,8 @@ func (m *QueryAuthorizationsResponse) Unmarshal(dAtA []byte) error { if postIndex > l { return io.ErrUnexpectedEOF } - m.Authorizations = append(m.Authorizations, &AuthorizationGrant{}) - if err := m.Authorizations[len(m.Authorizations)-1].Unmarshal(dAtA[iNdEx:postIndex]); err != nil { + m.Grants = append(m.Grants, &AuthorizationGrant{}) + if err := m.Grants[len(m.Grants)-1].Unmarshal(dAtA[iNdEx:postIndex]); err != nil { return err } iNdEx = postIndex diff --git a/x/authz/types/query.pb.gw.go b/x/authz/types/query.pb.gw.go index d353c1bf07fb..3fb00f6ca59c 100644 --- a/x/authz/types/query.pb.gw.go +++ b/x/authz/types/query.pb.gw.go @@ -32,189 +32,37 @@ var _ = utilities.NewDoubleArray var _ = descriptor.ForMessage var ( - filter_Query_Authorization_0 = &utilities.DoubleArray{Encoding: map[string]int{"granter": 0, "grantee": 1}, Base: []int{1, 1, 2, 0, 0}, Check: []int{0, 1, 1, 2, 3}} + filter_Query_Grants_0 = &utilities.DoubleArray{Encoding: map[string]int{}, Base: []int(nil), Check: []int(nil)} ) -func request_Query_Authorization_0(ctx context.Context, marshaler runtime.Marshaler, client QueryClient, req *http.Request, pathParams map[string]string) (proto.Message, runtime.ServerMetadata, error) { - var protoReq QueryAuthorizationRequest +func request_Query_Grants_0(ctx context.Context, marshaler runtime.Marshaler, client QueryClient, req *http.Request, pathParams map[string]string) (proto.Message, runtime.ServerMetadata, error) { + var protoReq QueryGrantsRequest var metadata runtime.ServerMetadata - var ( - val string - ok bool - err error - _ = err - ) - - val, ok = pathParams["granter"] - if !ok { - return nil, metadata, status.Errorf(codes.InvalidArgument, "missing parameter %s", "granter") - } - - protoReq.Granter, err = runtime.String(val) - - if err != nil { - return nil, metadata, status.Errorf(codes.InvalidArgument, "type mismatch, parameter: %s, error: %v", "granter", err) - } - - val, ok = pathParams["grantee"] - if !ok { - return nil, metadata, status.Errorf(codes.InvalidArgument, "missing parameter %s", "grantee") - } - - protoReq.Grantee, err = runtime.String(val) - - if err != nil { - return nil, metadata, status.Errorf(codes.InvalidArgument, "type mismatch, parameter: %s, error: %v", "grantee", err) - } - - if err := req.ParseForm(); err != nil { - return nil, metadata, status.Errorf(codes.InvalidArgument, "%v", err) - } - if err := runtime.PopulateQueryParameters(&protoReq, req.Form, filter_Query_Authorization_0); err != nil { - return nil, metadata, status.Errorf(codes.InvalidArgument, "%v", err) - } - - msg, err := client.Authorization(ctx, &protoReq, grpc.Header(&metadata.HeaderMD), grpc.Trailer(&metadata.TrailerMD)) - return msg, metadata, err - -} - -func local_request_Query_Authorization_0(ctx context.Context, marshaler runtime.Marshaler, server QueryServer, req *http.Request, pathParams map[string]string) (proto.Message, runtime.ServerMetadata, error) { - var protoReq QueryAuthorizationRequest - var metadata runtime.ServerMetadata - - var ( - val string - ok bool - err error - _ = err - ) - - val, ok = pathParams["granter"] - if !ok { - return nil, metadata, status.Errorf(codes.InvalidArgument, "missing parameter %s", "granter") - } - - protoReq.Granter, err = runtime.String(val) - - if err != nil { - return nil, metadata, status.Errorf(codes.InvalidArgument, "type mismatch, parameter: %s, error: %v", "granter", err) - } - - val, ok = pathParams["grantee"] - if !ok { - return nil, metadata, status.Errorf(codes.InvalidArgument, "missing parameter %s", "grantee") - } - - protoReq.Grantee, err = runtime.String(val) - - if err != nil { - return nil, metadata, status.Errorf(codes.InvalidArgument, "type mismatch, parameter: %s, error: %v", "grantee", err) - } - if err := req.ParseForm(); err != nil { return nil, metadata, status.Errorf(codes.InvalidArgument, "%v", err) } - if err := runtime.PopulateQueryParameters(&protoReq, req.Form, filter_Query_Authorization_0); err != nil { + if err := runtime.PopulateQueryParameters(&protoReq, req.Form, filter_Query_Grants_0); err != nil { return nil, metadata, status.Errorf(codes.InvalidArgument, "%v", err) } - msg, err := server.Authorization(ctx, &protoReq) + msg, err := client.Grants(ctx, &protoReq, grpc.Header(&metadata.HeaderMD), grpc.Trailer(&metadata.TrailerMD)) return msg, metadata, err } -var ( - filter_Query_Authorizations_0 = &utilities.DoubleArray{Encoding: map[string]int{"granter": 0, "grantee": 1}, Base: []int{1, 1, 2, 0, 0}, Check: []int{0, 1, 1, 2, 3}} -) - -func request_Query_Authorizations_0(ctx context.Context, marshaler runtime.Marshaler, client QueryClient, req *http.Request, pathParams map[string]string) (proto.Message, runtime.ServerMetadata, error) { - var protoReq QueryAuthorizationsRequest +func local_request_Query_Grants_0(ctx context.Context, marshaler runtime.Marshaler, server QueryServer, req *http.Request, pathParams map[string]string) (proto.Message, runtime.ServerMetadata, error) { + var protoReq QueryGrantsRequest var metadata runtime.ServerMetadata - var ( - val string - ok bool - err error - _ = err - ) - - val, ok = pathParams["granter"] - if !ok { - return nil, metadata, status.Errorf(codes.InvalidArgument, "missing parameter %s", "granter") - } - - protoReq.Granter, err = runtime.String(val) - - if err != nil { - return nil, metadata, status.Errorf(codes.InvalidArgument, "type mismatch, parameter: %s, error: %v", "granter", err) - } - - val, ok = pathParams["grantee"] - if !ok { - return nil, metadata, status.Errorf(codes.InvalidArgument, "missing parameter %s", "grantee") - } - - protoReq.Grantee, err = runtime.String(val) - - if err != nil { - return nil, metadata, status.Errorf(codes.InvalidArgument, "type mismatch, parameter: %s, error: %v", "grantee", err) - } - if err := req.ParseForm(); err != nil { return nil, metadata, status.Errorf(codes.InvalidArgument, "%v", err) } - if err := runtime.PopulateQueryParameters(&protoReq, req.Form, filter_Query_Authorizations_0); err != nil { + if err := runtime.PopulateQueryParameters(&protoReq, req.Form, filter_Query_Grants_0); err != nil { return nil, metadata, status.Errorf(codes.InvalidArgument, "%v", err) } - msg, err := client.Authorizations(ctx, &protoReq, grpc.Header(&metadata.HeaderMD), grpc.Trailer(&metadata.TrailerMD)) - return msg, metadata, err - -} - -func local_request_Query_Authorizations_0(ctx context.Context, marshaler runtime.Marshaler, server QueryServer, req *http.Request, pathParams map[string]string) (proto.Message, runtime.ServerMetadata, error) { - var protoReq QueryAuthorizationsRequest - var metadata runtime.ServerMetadata - - var ( - val string - ok bool - err error - _ = err - ) - - val, ok = pathParams["granter"] - if !ok { - return nil, metadata, status.Errorf(codes.InvalidArgument, "missing parameter %s", "granter") - } - - protoReq.Granter, err = runtime.String(val) - - if err != nil { - return nil, metadata, status.Errorf(codes.InvalidArgument, "type mismatch, parameter: %s, error: %v", "granter", err) - } - - val, ok = pathParams["grantee"] - if !ok { - return nil, metadata, status.Errorf(codes.InvalidArgument, "missing parameter %s", "grantee") - } - - protoReq.Grantee, err = runtime.String(val) - - if err != nil { - return nil, metadata, status.Errorf(codes.InvalidArgument, "type mismatch, parameter: %s, error: %v", "grantee", err) - } - - if err := req.ParseForm(); err != nil { - return nil, metadata, status.Errorf(codes.InvalidArgument, "%v", err) - } - if err := runtime.PopulateQueryParameters(&protoReq, req.Form, filter_Query_Authorizations_0); err != nil { - return nil, metadata, status.Errorf(codes.InvalidArgument, "%v", err) - } - - msg, err := server.Authorizations(ctx, &protoReq) + msg, err := server.Grants(ctx, &protoReq) return msg, metadata, err } @@ -225,7 +73,7 @@ func local_request_Query_Authorizations_0(ctx context.Context, marshaler runtime // Note that using this registration option will cause many gRPC library features (such as grpc.SendHeader, etc) to stop working. Consider using RegisterQueryHandlerFromEndpoint instead. func RegisterQueryHandlerServer(ctx context.Context, mux *runtime.ServeMux, server QueryServer) error { - mux.Handle("GET", pattern_Query_Authorization_0, func(w http.ResponseWriter, req *http.Request, pathParams map[string]string) { + mux.Handle("GET", pattern_Query_Grants_0, func(w http.ResponseWriter, req *http.Request, pathParams map[string]string) { ctx, cancel := context.WithCancel(req.Context()) defer cancel() inboundMarshaler, outboundMarshaler := runtime.MarshalerForRequest(mux, req) @@ -234,34 +82,14 @@ func RegisterQueryHandlerServer(ctx context.Context, mux *runtime.ServeMux, serv runtime.HTTPError(ctx, mux, outboundMarshaler, w, req, err) return } - resp, md, err := local_request_Query_Authorization_0(rctx, inboundMarshaler, server, req, pathParams) + resp, md, err := local_request_Query_Grants_0(rctx, inboundMarshaler, server, req, pathParams) ctx = runtime.NewServerMetadataContext(ctx, md) if err != nil { runtime.HTTPError(ctx, mux, outboundMarshaler, w, req, err) return } - forward_Query_Authorization_0(ctx, mux, outboundMarshaler, w, req, resp, mux.GetForwardResponseOptions()...) - - }) - - mux.Handle("GET", pattern_Query_Authorizations_0, func(w http.ResponseWriter, req *http.Request, pathParams map[string]string) { - ctx, cancel := context.WithCancel(req.Context()) - defer cancel() - inboundMarshaler, outboundMarshaler := runtime.MarshalerForRequest(mux, req) - rctx, err := runtime.AnnotateIncomingContext(ctx, mux, req) - if err != nil { - runtime.HTTPError(ctx, mux, outboundMarshaler, w, req, err) - return - } - resp, md, err := local_request_Query_Authorizations_0(rctx, inboundMarshaler, server, req, pathParams) - ctx = runtime.NewServerMetadataContext(ctx, md) - if err != nil { - runtime.HTTPError(ctx, mux, outboundMarshaler, w, req, err) - return - } - - forward_Query_Authorizations_0(ctx, mux, outboundMarshaler, w, req, resp, mux.GetForwardResponseOptions()...) + forward_Query_Grants_0(ctx, mux, outboundMarshaler, w, req, resp, mux.GetForwardResponseOptions()...) }) @@ -306,27 +134,7 @@ func RegisterQueryHandler(ctx context.Context, mux *runtime.ServeMux, conn *grpc // "QueryClient" to call the correct interceptors. func RegisterQueryHandlerClient(ctx context.Context, mux *runtime.ServeMux, client QueryClient) error { - mux.Handle("GET", pattern_Query_Authorization_0, func(w http.ResponseWriter, req *http.Request, pathParams map[string]string) { - ctx, cancel := context.WithCancel(req.Context()) - defer cancel() - inboundMarshaler, outboundMarshaler := runtime.MarshalerForRequest(mux, req) - rctx, err := runtime.AnnotateContext(ctx, mux, req) - if err != nil { - runtime.HTTPError(ctx, mux, outboundMarshaler, w, req, err) - return - } - resp, md, err := request_Query_Authorization_0(rctx, inboundMarshaler, client, req, pathParams) - ctx = runtime.NewServerMetadataContext(ctx, md) - if err != nil { - runtime.HTTPError(ctx, mux, outboundMarshaler, w, req, err) - return - } - - forward_Query_Authorization_0(ctx, mux, outboundMarshaler, w, req, resp, mux.GetForwardResponseOptions()...) - - }) - - mux.Handle("GET", pattern_Query_Authorizations_0, func(w http.ResponseWriter, req *http.Request, pathParams map[string]string) { + mux.Handle("GET", pattern_Query_Grants_0, func(w http.ResponseWriter, req *http.Request, pathParams map[string]string) { ctx, cancel := context.WithCancel(req.Context()) defer cancel() inboundMarshaler, outboundMarshaler := runtime.MarshalerForRequest(mux, req) @@ -335,14 +143,14 @@ func RegisterQueryHandlerClient(ctx context.Context, mux *runtime.ServeMux, clie runtime.HTTPError(ctx, mux, outboundMarshaler, w, req, err) return } - resp, md, err := request_Query_Authorizations_0(rctx, inboundMarshaler, client, req, pathParams) + resp, md, err := request_Query_Grants_0(rctx, inboundMarshaler, client, req, pathParams) ctx = runtime.NewServerMetadataContext(ctx, md) if err != nil { runtime.HTTPError(ctx, mux, outboundMarshaler, w, req, err) return } - forward_Query_Authorizations_0(ctx, mux, outboundMarshaler, w, req, resp, mux.GetForwardResponseOptions()...) + forward_Query_Grants_0(ctx, mux, outboundMarshaler, w, req, resp, mux.GetForwardResponseOptions()...) }) @@ -350,13 +158,9 @@ func RegisterQueryHandlerClient(ctx context.Context, mux *runtime.ServeMux, clie } var ( - pattern_Query_Authorization_0 = runtime.MustPattern(runtime.NewPattern(1, []int{2, 0, 2, 1, 2, 2, 2, 3, 1, 0, 4, 1, 5, 4, 2, 5, 1, 0, 4, 1, 5, 6, 2, 7}, []string{"cosmos", "authz", "v1beta1", "granters", "granter", "grantees", "grantee", "grant"}, "", runtime.AssumeColonVerbOpt(false))) - - pattern_Query_Authorizations_0 = runtime.MustPattern(runtime.NewPattern(1, []int{2, 0, 2, 1, 2, 2, 2, 3, 1, 0, 4, 1, 5, 4, 2, 5, 1, 0, 4, 1, 5, 6, 2, 7}, []string{"cosmos", "authz", "v1beta1", "granters", "granter", "grantees", "grantee", "grants"}, "", runtime.AssumeColonVerbOpt(false))) + pattern_Query_Grants_0 = runtime.MustPattern(runtime.NewPattern(1, []int{2, 0, 2, 1, 2, 2, 2, 3}, []string{"cosmos", "authz", "v1beta1", "grants"}, "", runtime.AssumeColonVerbOpt(false))) ) var ( - forward_Query_Authorization_0 = runtime.ForwardResponseMessage - - forward_Query_Authorizations_0 = runtime.ForwardResponseMessage + forward_Query_Grants_0 = runtime.ForwardResponseMessage ) From 5e029a8587ebe9d58bad2e368805deb84503bb0b Mon Sep 17 00:00:00 2001 From: Robert Zaremba Date: Tue, 20 Apr 2021 01:36:51 +0200 Subject: [PATCH 08/44] remve Authorization infix from proto services --- Makefile | 2 +- docs/core/proto-docs.md | 62 ++-- proto/cosmos/authz/v1beta1/authz.proto | 8 +- proto/cosmos/authz/v1beta1/query.proto | 2 +- proto/cosmos/authz/v1beta1/tx.proto | 24 +- x/authz/keeper/grpc_query.go | 8 +- x/authz/keeper/keeper.go | 8 +- x/authz/keeper/keeper_test.go | 2 +- x/authz/simulation/decoder.go | 2 +- x/authz/types/authz.pb.go | 116 ++++--- x/authz/types/generic_authorization.go | 8 +- x/authz/types/generic_authorization_test.go | 2 +- x/authz/types/query.pb.go | 56 ++-- x/authz/types/tx.pb.go | 330 ++++++++++---------- 14 files changed, 313 insertions(+), 317 deletions(-) diff --git a/Makefile b/Makefile index bb60726baeb9..630a2a528fb1 100644 --- a/Makefile +++ b/Makefile @@ -374,7 +374,7 @@ proto-all: proto-format proto-lint proto-gen protoContainer=cosmos-proto-gen proto-gen: @echo "Generating Protobuf files" - if docker ps -a --format '{{.Names}}' | grep -Eq "^${protoContainer}"; then docker restart $(protoContainer); else docker run --name $(protoContainer) -v $(CURDIR):/workspace --workdir /workspace tendermintdev/sdk-proto-gen:v0.1 sh ./scripts/protocgen.sh; fi + if docker ps -a --format '{{.Names}}' | grep -Eq "^${protoContainer}"; then docker start $(protoContainer); else docker run --name $(protoContainer) -v $(CURDIR):/workspace --workdir /workspace tendermintdev/sdk-proto-gen:v0.1 sh ./scripts/protocgen.sh; fi # $(DOCKER) run --rm -v $(CURDIR):/workspace --workdir /workspace tendermintdev/sdk-proto-gen:v0.1 sh ./scripts/protocgen.sh proto-format: diff --git a/docs/core/proto-docs.md b/docs/core/proto-docs.md index efc33a75d5d2..b7cb860955e8 100644 --- a/docs/core/proto-docs.md +++ b/docs/core/proto-docs.md @@ -27,8 +27,8 @@ - [Query](#cosmos.auth.v1beta1.Query) - [cosmos/authz/v1beta1/authz.proto](#cosmos/authz/v1beta1/authz.proto) - - [AuthorizationGrant](#cosmos.authz.v1beta1.AuthorizationGrant) - [GenericAuthorization](#cosmos.authz.v1beta1.GenericAuthorization) + - [Grant](#cosmos.authz.v1beta1.Grant) - [cosmos/authz/v1beta1/event.proto](#cosmos/authz/v1beta1/event.proto) - [EventGrant](#cosmos.authz.v1beta1.EventGrant) @@ -59,10 +59,10 @@ - [cosmos/authz/v1beta1/tx.proto](#cosmos/authz/v1beta1/tx.proto) - [MsgExecAuthorizedRequest](#cosmos.authz.v1beta1.MsgExecAuthorizedRequest) - [MsgExecAuthorizedResponse](#cosmos.authz.v1beta1.MsgExecAuthorizedResponse) - - [MsgGrantAuthorizationRequest](#cosmos.authz.v1beta1.MsgGrantAuthorizationRequest) - - [MsgGrantAuthorizationResponse](#cosmos.authz.v1beta1.MsgGrantAuthorizationResponse) - - [MsgRevokeAuthorizationRequest](#cosmos.authz.v1beta1.MsgRevokeAuthorizationRequest) - - [MsgRevokeAuthorizationResponse](#cosmos.authz.v1beta1.MsgRevokeAuthorizationResponse) + - [MsgGrantRequest](#cosmos.authz.v1beta1.MsgGrantRequest) + - [MsgGrantResponse](#cosmos.authz.v1beta1.MsgGrantResponse) + - [MsgRevokeRequest](#cosmos.authz.v1beta1.MsgRevokeRequest) + - [MsgRevokeResponse](#cosmos.authz.v1beta1.MsgRevokeResponse) - [Msg](#cosmos.authz.v1beta1.Msg) @@ -876,33 +876,33 @@ Query defines the gRPC querier service. - + -### AuthorizationGrant -AuthorizationGrant gives permissions to execute -the provide method with expiration time. +### GenericAuthorization +GenericAuthorization gives the grantee unrestricted permissions to execute +the provided method on behalf of the granter's account. | Field | Type | Label | Description | | ----- | ---- | ----- | ----------- | -| `authorization` | [google.protobuf.Any](#google.protobuf.Any) | | | -| `expiration` | [google.protobuf.Timestamp](#google.protobuf.Timestamp) | | | +| `msg_type_url` | [string](#string) | | Msg method to grant unrestricted permissions to execute | - + -### GenericAuthorization -GenericAuthorization gives the grantee unrestricted permissions to execute -the provided method on behalf of the granter's account. +### Grant +AuthorizationGrant gives permissions to execute +the provide method with expiration time. | Field | Type | Label | Description | | ----- | ---- | ----- | ----------- | -| `method_name` | [string](#string) | | method name to grant unrestricted permissions to execute Note: MethodName() is already a method on `GenericAuthorization` type, we need some custom naming here so using `MessageName` | +| `authorization` | [google.protobuf.Any](#google.protobuf.Any) | | | +| `expiration` | [google.protobuf.Timestamp](#google.protobuf.Timestamp) | | | @@ -1052,7 +1052,7 @@ QueryGrantsResponse is the response type for the Query/Authorizations RPC method | Field | Type | Label | Description | | ----- | ---- | ----- | ----------- | -| `grants` | [AuthorizationGrant](#cosmos.authz.v1beta1.AuthorizationGrant) | repeated | authorizations is a list of grants granted for grantee by granter. | +| `grants` | [Grant](#cosmos.authz.v1beta1.Grant) | repeated | authorizations is a list of grants granted for grantee by granter. | | `pagination` | [cosmos.base.query.v1beta1.PageResponse](#cosmos.base.query.v1beta1.PageResponse) | | pagination defines an pagination for the response. | @@ -1316,10 +1316,10 @@ MsgExecAuthorizedResponse defines the Msg/MsgExecAuthorizedResponse response typ - + -### MsgGrantAuthorizationRequest -MsgGrantAuthorizationRequest grants the provided authorization to the grantee on the granter's +### MsgGrantRequest +MsgGrantRequest grants the provided authorization to the grantee on the granter's account with the provided expiration time. @@ -1335,20 +1335,20 @@ account with the provided expiration time. - + -### MsgGrantAuthorizationResponse -MsgGrantAuthorizationResponse defines the Msg/MsgGrantAuthorization response type. +### MsgGrantResponse +MsgGrantResponse defines the Msg/MsgGrant response type. - + -### MsgRevokeAuthorizationRequest -MsgRevokeAuthorizationRequest revokes any authorization with the provided sdk.Msg type on the +### MsgRevokeRequest +MsgRevokeRequest revokes any authorization with the provided sdk.Msg type on the granter's account with that has been granted to the grantee. @@ -1363,10 +1363,10 @@ granter's account with that has been granted to the grantee. - + -### MsgRevokeAuthorizationResponse -MsgRevokeAuthorizationResponse defines the Msg/MsgRevokeAuthorizationResponse response type. +### MsgRevokeResponse +MsgRevokeResponse defines the Msg/MsgRevokeResponse response type. @@ -1386,9 +1386,9 @@ Msg defines the authz Msg service. | Method Name | Request Type | Response Type | Description | HTTP Verb | Endpoint | | ----------- | ------------ | ------------- | ------------| ------- | -------- | -| `GrantAuthorization` | [MsgGrantAuthorizationRequest](#cosmos.authz.v1beta1.MsgGrantAuthorizationRequest) | [MsgGrantAuthorizationResponse](#cosmos.authz.v1beta1.MsgGrantAuthorizationResponse) | GrantAuthorization grants the provided authorization to the grantee on the granter's account with the provided expiration time. | | +| `Grantxx` | [MsgGrantRequest](#cosmos.authz.v1beta1.MsgGrantRequest) | [MsgGrantResponse](#cosmos.authz.v1beta1.MsgGrantResponse) | Grant grants the provided authorization to the grantee on the granter's account with the provided expiration time. | | | `ExecAuthorized` | [MsgExecAuthorizedRequest](#cosmos.authz.v1beta1.MsgExecAuthorizedRequest) | [MsgExecAuthorizedResponse](#cosmos.authz.v1beta1.MsgExecAuthorizedResponse) | ExecAuthorized attempts to execute the provided messages using authorizations granted to the grantee. Each message should have only one signer corresponding to the granter of the authorization. | | -| `RevokeAuthorization` | [MsgRevokeAuthorizationRequest](#cosmos.authz.v1beta1.MsgRevokeAuthorizationRequest) | [MsgRevokeAuthorizationResponse](#cosmos.authz.v1beta1.MsgRevokeAuthorizationResponse) | RevokeAuthorization revokes any authorization corresponding to the provided method name on the granter's account that has been granted to the grantee. | | +| `Revoke` | [MsgRevokeRequest](#cosmos.authz.v1beta1.MsgRevokeRequest) | [MsgRevokeResponse](#cosmos.authz.v1beta1.MsgRevokeResponse) | Revoke revokes any authorization corresponding to the provided method name on the granter's account that has been granted to the grantee. | | diff --git a/proto/cosmos/authz/v1beta1/authz.proto b/proto/cosmos/authz/v1beta1/authz.proto index 43078f8666f1..1cc8c18e28c8 100644 --- a/proto/cosmos/authz/v1beta1/authz.proto +++ b/proto/cosmos/authz/v1beta1/authz.proto @@ -13,15 +13,13 @@ option go_package = "github.com/cosmos/cosmos-sdk/x/authz/types"; message GenericAuthorization { option (cosmos_proto.implements_interface) = "Authorization"; - // method name to grant unrestricted permissions to execute - // Note: MethodName() is already a method on `GenericAuthorization` type, - // we need some custom naming here so using `MessageName` - string method_name = 1 [(gogoproto.customname) = "MessageName"]; + // Msg method to grant unrestricted permissions to execute + string msg_type_url = 1; } // AuthorizationGrant gives permissions to execute // the provide method with expiration time. -message AuthorizationGrant { +message Grant { google.protobuf.Any authorization = 1 [(cosmos_proto.accepts_interface) = "Authorization"]; google.protobuf.Timestamp expiration = 2 [(gogoproto.stdtime) = true, (gogoproto.nullable) = false]; } diff --git a/proto/cosmos/authz/v1beta1/query.proto b/proto/cosmos/authz/v1beta1/query.proto index c49e3b29f23b..98898405a0f5 100644 --- a/proto/cosmos/authz/v1beta1/query.proto +++ b/proto/cosmos/authz/v1beta1/query.proto @@ -28,7 +28,7 @@ message QueryGrantsRequest { // QueryGrantsResponse is the response type for the Query/Authorizations RPC method. message QueryGrantsResponse { // authorizations is a list of grants granted for grantee by granter. - repeated cosmos.authz.v1beta1.AuthorizationGrant grants = 1; + repeated cosmos.authz.v1beta1.Grant grants = 1; // pagination defines an pagination for the response. cosmos.base.query.v1beta1.PageResponse pagination = 2; } diff --git a/proto/cosmos/authz/v1beta1/tx.proto b/proto/cosmos/authz/v1beta1/tx.proto index 69e3e6f1fba2..bd75ab6a801c 100644 --- a/proto/cosmos/authz/v1beta1/tx.proto +++ b/proto/cosmos/authz/v1beta1/tx.proto @@ -10,23 +10,23 @@ option go_package = "github.com/cosmos/cosmos-sdk/x/authz/types"; // Msg defines the authz Msg service. service Msg { - // GrantAuthorization grants the provided authorization to the grantee on the granter's + // Grant grants the provided authorization to the grantee on the granter's // account with the provided expiration time. - rpc GrantAuthorization(MsgGrantAuthorizationRequest) returns (MsgGrantAuthorizationResponse); + rpc Grantxx(MsgGrantRequest) returns (MsgGrantResponse); // ExecAuthorized attempts to execute the provided messages using // authorizations granted to the grantee. Each message should have only // one signer corresponding to the granter of the authorization. rpc ExecAuthorized(MsgExecAuthorizedRequest) returns (MsgExecAuthorizedResponse); - // RevokeAuthorization revokes any authorization corresponding to the provided method name on the + // Revoke revokes any authorization corresponding to the provided method name on the // granter's account that has been granted to the grantee. - rpc RevokeAuthorization(MsgRevokeAuthorizationRequest) returns (MsgRevokeAuthorizationResponse); + rpc Revoke(MsgRevokeRequest) returns (MsgRevokeResponse); } -// MsgGrantAuthorizationRequest grants the provided authorization to the grantee on the granter's +// MsgGrantRequest grants the provided authorization to the grantee on the granter's // account with the provided expiration time. -message MsgGrantAuthorizationRequest { +message MsgGrantRequest { string granter = 1; string grantee = 2; @@ -47,16 +47,16 @@ message MsgExecAuthorizedRequest { repeated google.protobuf.Any msgs = 2; } -// MsgGrantAuthorizationResponse defines the Msg/MsgGrantAuthorization response type. -message MsgGrantAuthorizationResponse {} +// MsgGrantResponse defines the Msg/MsgGrant response type. +message MsgGrantResponse {} -// MsgRevokeAuthorizationRequest revokes any authorization with the provided sdk.Msg type on the +// MsgRevokeRequest revokes any authorization with the provided sdk.Msg type on the // granter's account with that has been granted to the grantee. -message MsgRevokeAuthorizationRequest { +message MsgRevokeRequest { string granter = 1; string grantee = 2; string method_name = 3; } -// MsgRevokeAuthorizationResponse defines the Msg/MsgRevokeAuthorizationResponse response type. -message MsgRevokeAuthorizationResponse {} +// MsgRevokeResponse defines the Msg/MsgRevokeResponse response type. +message MsgRevokeResponse {} diff --git a/x/authz/keeper/grpc_query.go b/x/authz/keeper/grpc_query.go index 5bb44960d31c..0e38b560ac65 100644 --- a/x/authz/keeper/grpc_query.go +++ b/x/authz/keeper/grpc_query.go @@ -49,14 +49,14 @@ func (k Keeper) Grants(c context.Context, req *types.QueryGrantsRequest) (*types return nil, status.Errorf(codes.Internal, err.Error()) } return &types.QueryGrantsResponse{ - Grants: []*types.AuthorizationGrant{&types.AuthorizationGrant{ + Grants: []*types.Grant{&types.Grant{ Authorization: authorizationAny, Expiration: expiration, }}, }, nil } - var authorizations []*types.AuthorizationGrant + var authorizations []*types.Grant pageRes, err := query.FilteredPaginate(authStore, req.Pagination, func(key []byte, value []byte, accumulate bool) (bool, error) { auth, err := unmarshalAuthorization(k.cdc, value) if err != nil { @@ -73,7 +73,7 @@ func (k Keeper) Grants(c context.Context, req *types.QueryGrantsRequest) (*types if err != nil { return false, status.Errorf(codes.Internal, err.Error()) } - authorizations = append(authorizations, &types.AuthorizationGrant{ + authorizations = append(authorizations, &types.Grant{ Authorization: authorizationAny, Expiration: auth.Expiration, }) @@ -91,7 +91,7 @@ func (k Keeper) Grants(c context.Context, req *types.QueryGrantsRequest) (*types } // unmarshal an authorization from a store value -func unmarshalAuthorization(cdc codec.BinaryMarshaler, value []byte) (v types.AuthorizationGrant, err error) { +func unmarshalAuthorization(cdc codec.BinaryMarshaler, value []byte) (v types.Grant, err error) { err = cdc.UnmarshalBinaryBare(value, &v) return v, err } diff --git a/x/authz/keeper/keeper.go b/x/authz/keeper/keeper.go index b3d002177274..119c59945614 100644 --- a/x/authz/keeper/keeper.go +++ b/x/authz/keeper/keeper.go @@ -38,7 +38,7 @@ func (k Keeper) Logger(ctx sdk.Context) log.Logger { } // getAuthorizationGrant returns grant between granter and grantee for the given msg type -func (k Keeper) getAuthorizationGrant(ctx sdk.Context, grantStoreKey []byte) (grant types.AuthorizationGrant, found bool) { +func (k Keeper) getAuthorizationGrant(ctx sdk.Context, grantStoreKey []byte) (grant types.Grant, found bool) { store := ctx.KVStore(k.storeKey) bz := store.Get(grantStoreKey) if bz == nil { @@ -164,7 +164,7 @@ func (k Keeper) GetAuthorizations(ctx sdk.Context, grantee sdk.AccAddress, grant key := types.GetAuthorizationStoreKey(grantee, granter, "") iter := sdk.KVStorePrefixIterator(store, key) defer iter.Close() - var authorization types.AuthorizationGrant + var authorization types.Grant for ; iter.Valid(); iter.Next() { k.cdc.MustUnmarshalBinaryBare(iter.Value(), &authorization) authorizations = append(authorizations, authorization.GetAuthorizationGrant()) @@ -190,12 +190,12 @@ func (k Keeper) GetOrRevokeAuthorization(ctx sdk.Context, grantee sdk.AccAddress // IterateGrants iterates over all authorization grants func (k Keeper) IterateGrants(ctx sdk.Context, - handler func(granterAddr sdk.AccAddress, granteeAddr sdk.AccAddress, grant types.AuthorizationGrant) bool) { + handler func(granterAddr sdk.AccAddress, granteeAddr sdk.AccAddress, grant types.Grant) bool) { store := ctx.KVStore(k.storeKey) iter := sdk.KVStorePrefixIterator(store, types.GrantKey) defer iter.Close() for ; iter.Valid(); iter.Next() { - var grant types.AuthorizationGrant + var grant types.Grant granterAddr, granteeAddr := types.ExtractAddressesFromGrantKey(iter.Key()) k.cdc.MustUnmarshalBinaryBare(iter.Value(), &grant) if handler(granterAddr, granteeAddr, grant) { diff --git a/x/authz/keeper/keeper_test.go b/x/authz/keeper/keeper_test.go index 161fed6e98bd..9c8e0f86db0d 100644 --- a/x/authz/keeper/keeper_test.go +++ b/x/authz/keeper/keeper_test.go @@ -118,7 +118,7 @@ func (s *TestSuite) TestKeeperIter() { authorization, _ = app.AuthzKeeper.GetOrRevokeAuthorization(ctx, granteeAddr, granterAddr, "abcd") s.Require().Nil(authorization) - app.AuthzKeeper.IterateGrants(ctx, func(granter, grantee sdk.AccAddress, grant types.AuthorizationGrant) bool { + app.AuthzKeeper.IterateGrants(ctx, func(granter, grantee sdk.AccAddress, grant types.Grant) bool { s.Require().Equal(granter, granterAddr) s.Require().Equal(grantee, granteeAddr) return true diff --git a/x/authz/simulation/decoder.go b/x/authz/simulation/decoder.go index c87f7a70c13a..c1e4c407b607 100644 --- a/x/authz/simulation/decoder.go +++ b/x/authz/simulation/decoder.go @@ -15,7 +15,7 @@ func NewDecodeStore(cdc codec.Marshaler) func(kvA, kvB kv.Pair) string { return func(kvA, kvB kv.Pair) string { switch { case bytes.Equal(kvA.Key[:1], types.GrantKey): - var grantA, grantB types.AuthorizationGrant + var grantA, grantB types.Grant cdc.MustUnmarshalBinaryBare(kvA.Value, &grantA) cdc.MustUnmarshalBinaryBare(kvB.Value, &grantB) return fmt.Sprintf("%v\n%v", grantA, grantB) diff --git a/x/authz/types/authz.pb.go b/x/authz/types/authz.pb.go index 2e77267b7505..3872e85b775a 100644 --- a/x/authz/types/authz.pb.go +++ b/x/authz/types/authz.pb.go @@ -32,10 +32,8 @@ const _ = proto.GoGoProtoPackageIsVersion3 // please upgrade the proto package // GenericAuthorization gives the grantee unrestricted permissions to execute // the provided method on behalf of the granter's account. type GenericAuthorization struct { - // method name to grant unrestricted permissions to execute - // Note: MethodName() is already a method on `GenericAuthorization` type, - // we need some custom naming here so using `MessageName` - MessageName string `protobuf:"bytes,1,opt,name=method_name,json=methodName,proto3" json:"method_name,omitempty"` + // Msg method to grant unrestricted permissions to execute + MsgTypeUrl string `protobuf:"bytes,1,opt,name=msg_type_url,json=msgTypeUrl,proto3" json:"msg_type_url,omitempty"` } func (m *GenericAuthorization) Reset() { *m = GenericAuthorization{} } @@ -71,32 +69,32 @@ func (m *GenericAuthorization) XXX_DiscardUnknown() { var xxx_messageInfo_GenericAuthorization proto.InternalMessageInfo -func (m *GenericAuthorization) GetMessageName() string { +func (m *GenericAuthorization) GetMsgTypeUrl() string { if m != nil { - return m.MessageName + return m.MsgTypeUrl } return "" } // AuthorizationGrant gives permissions to execute // the provide method with expiration time. -type AuthorizationGrant struct { +type Grant struct { Authorization *types.Any `protobuf:"bytes,1,opt,name=authorization,proto3" json:"authorization,omitempty"` Expiration time.Time `protobuf:"bytes,2,opt,name=expiration,proto3,stdtime" json:"expiration"` } -func (m *AuthorizationGrant) Reset() { *m = AuthorizationGrant{} } -func (m *AuthorizationGrant) String() string { return proto.CompactTextString(m) } -func (*AuthorizationGrant) ProtoMessage() {} -func (*AuthorizationGrant) Descriptor() ([]byte, []int) { +func (m *Grant) Reset() { *m = Grant{} } +func (m *Grant) String() string { return proto.CompactTextString(m) } +func (*Grant) ProtoMessage() {} +func (*Grant) Descriptor() ([]byte, []int) { return fileDescriptor_544dc2e84b61c637, []int{1} } -func (m *AuthorizationGrant) XXX_Unmarshal(b []byte) error { +func (m *Grant) XXX_Unmarshal(b []byte) error { return m.Unmarshal(b) } -func (m *AuthorizationGrant) XXX_Marshal(b []byte, deterministic bool) ([]byte, error) { +func (m *Grant) XXX_Marshal(b []byte, deterministic bool) ([]byte, error) { if deterministic { - return xxx_messageInfo_AuthorizationGrant.Marshal(b, m, deterministic) + return xxx_messageInfo_Grant.Marshal(b, m, deterministic) } else { b = b[:cap(b)] n, err := m.MarshalToSizedBuffer(b) @@ -106,26 +104,26 @@ func (m *AuthorizationGrant) XXX_Marshal(b []byte, deterministic bool) ([]byte, return b[:n], nil } } -func (m *AuthorizationGrant) XXX_Merge(src proto.Message) { - xxx_messageInfo_AuthorizationGrant.Merge(m, src) +func (m *Grant) XXX_Merge(src proto.Message) { + xxx_messageInfo_Grant.Merge(m, src) } -func (m *AuthorizationGrant) XXX_Size() int { +func (m *Grant) XXX_Size() int { return m.Size() } -func (m *AuthorizationGrant) XXX_DiscardUnknown() { - xxx_messageInfo_AuthorizationGrant.DiscardUnknown(m) +func (m *Grant) XXX_DiscardUnknown() { + xxx_messageInfo_Grant.DiscardUnknown(m) } -var xxx_messageInfo_AuthorizationGrant proto.InternalMessageInfo +var xxx_messageInfo_Grant proto.InternalMessageInfo -func (m *AuthorizationGrant) GetAuthorization() *types.Any { +func (m *Grant) GetAuthorization() *types.Any { if m != nil { return m.Authorization } return nil } -func (m *AuthorizationGrant) GetExpiration() time.Time { +func (m *Grant) GetExpiration() time.Time { if m != nil { return m.Expiration } @@ -134,34 +132,34 @@ func (m *AuthorizationGrant) GetExpiration() time.Time { func init() { proto.RegisterType((*GenericAuthorization)(nil), "cosmos.authz.v1beta1.GenericAuthorization") - proto.RegisterType((*AuthorizationGrant)(nil), "cosmos.authz.v1beta1.AuthorizationGrant") + proto.RegisterType((*Grant)(nil), "cosmos.authz.v1beta1.Grant") } func init() { proto.RegisterFile("cosmos/authz/v1beta1/authz.proto", fileDescriptor_544dc2e84b61c637) } var fileDescriptor_544dc2e84b61c637 = []byte{ - // 333 bytes of a gzipped FileDescriptorProto - 0x1f, 0x8b, 0x08, 0x00, 0x00, 0x00, 0x00, 0x00, 0x02, 0xff, 0x64, 0x91, 0xc1, 0x4e, 0xfa, 0x40, - 0x10, 0xc6, 0xbb, 0xff, 0xc3, 0x3f, 0xba, 0x84, 0x18, 0x9a, 0x1e, 0x84, 0x43, 0x4b, 0x38, 0x19, - 0x13, 0x5a, 0xd1, 0x9b, 0x37, 0x1a, 0x12, 0x4e, 0x78, 0x20, 0x9e, 0xf4, 0x40, 0xb6, 0x30, 0xb6, - 0x8d, 0x6e, 0xa7, 0xe9, 0x6e, 0x0d, 0xf0, 0x14, 0xbc, 0x86, 0x77, 0x1f, 0x82, 0x78, 0x22, 0x9e, - 0x3c, 0xa1, 0x29, 0x2f, 0x62, 0xe8, 0x2e, 0x09, 0xe0, 0x69, 0x67, 0xbe, 0xfd, 0xbe, 0xdf, 0x4e, - 0x76, 0x68, 0x73, 0x8c, 0x82, 0xa3, 0xf0, 0x58, 0x2e, 0xa3, 0xb9, 0xf7, 0xda, 0x09, 0x40, 0xb2, - 0x8e, 0xea, 0xdc, 0x34, 0x43, 0x89, 0xa6, 0xa5, 0x1c, 0xae, 0xd2, 0xb4, 0xa3, 0x51, 0x57, 0xea, - 0xa8, 0xf4, 0x78, 0xda, 0x52, 0x36, 0x0d, 0x27, 0x44, 0x0c, 0x5f, 0xc0, 0x2b, 0xbb, 0x20, 0x7f, - 0xf2, 0x64, 0xcc, 0x41, 0x48, 0xc6, 0x53, 0x6d, 0xb0, 0x42, 0x0c, 0x51, 0x05, 0xb7, 0x95, 0x56, - 0xeb, 0xc7, 0x31, 0x96, 0xcc, 0xd4, 0x55, 0xeb, 0x91, 0x5a, 0x7d, 0x48, 0x20, 0x8b, 0xc7, 0xdd, - 0x5c, 0x46, 0x98, 0xc5, 0x73, 0x26, 0x63, 0x4c, 0xcc, 0x2b, 0x5a, 0xe1, 0x20, 0x23, 0x9c, 0x8c, - 0x12, 0xc6, 0xe1, 0x9c, 0x34, 0xc9, 0xc5, 0xa9, 0x7f, 0x56, 0xac, 0x9d, 0xca, 0x00, 0x84, 0x60, - 0x21, 0xdc, 0x31, 0x0e, 0x43, 0xaa, 0x3c, 0xdb, 0xfa, 0xb6, 0xf6, 0xf9, 0xde, 0xae, 0x1e, 0x40, - 0x5a, 0x6f, 0x84, 0x9a, 0x07, 0x4a, 0x3f, 0x63, 0x89, 0x34, 0x07, 0xb4, 0xca, 0xf6, 0xd5, 0x92, - 0x5e, 0xb9, 0xb6, 0x5c, 0x35, 0xa6, 0xbb, 0x1b, 0xd3, 0xed, 0x26, 0x33, 0xbf, 0xf6, 0x71, 0x8c, - 0x1d, 0x1e, 0xa6, 0xcd, 0x1e, 0xa5, 0x30, 0x4d, 0xe3, 0x4c, 0xb1, 0xfe, 0x95, 0xac, 0xc6, 0x1f, - 0xd6, 0xfd, 0xee, 0xa7, 0xfc, 0x93, 0xe5, 0xda, 0x31, 0x16, 0xdf, 0x0e, 0x19, 0xee, 0xe5, 0xfc, - 0xde, 0xb2, 0xb0, 0xc9, 0xaa, 0xb0, 0xc9, 0x4f, 0x61, 0x93, 0xc5, 0xc6, 0x36, 0x56, 0x1b, 0xdb, - 0xf8, 0xda, 0xd8, 0xc6, 0xc3, 0x65, 0x18, 0xcb, 0x28, 0x0f, 0xdc, 0x31, 0x72, 0xbd, 0x0d, 0x7d, - 0xb4, 0xc5, 0xe4, 0xd9, 0x9b, 0xea, 0xfd, 0xca, 0x59, 0x0a, 0x22, 0xf8, 0x5f, 0xbe, 0x77, 0xf3, - 0x1b, 0x00, 0x00, 0xff, 0xff, 0x62, 0x49, 0x9d, 0xc0, 0xfc, 0x01, 0x00, 0x00, + // 321 bytes of a gzipped FileDescriptorProto + 0x1f, 0x8b, 0x08, 0x00, 0x00, 0x00, 0x00, 0x00, 0x02, 0xff, 0xe2, 0x52, 0x48, 0xce, 0x2f, 0xce, + 0xcd, 0x2f, 0xd6, 0x4f, 0x2c, 0x2d, 0xc9, 0xa8, 0xd2, 0x2f, 0x33, 0x4c, 0x4a, 0x2d, 0x49, 0x34, + 0x84, 0xf0, 0xf4, 0x0a, 0x8a, 0xf2, 0x4b, 0xf2, 0x85, 0x44, 0x20, 0x2a, 0xf4, 0x20, 0x62, 0x50, + 0x15, 0x52, 0x92, 0x10, 0xd1, 0x78, 0xb0, 0x1a, 0x7d, 0xa8, 0x12, 0x30, 0x47, 0x4a, 0x3e, 0x3d, + 0x3f, 0x3f, 0x3d, 0x27, 0x55, 0x1f, 0xcc, 0x4b, 0x2a, 0x4d, 0xd3, 0x2f, 0xc9, 0xcc, 0x4d, 0x2d, + 0x2e, 0x49, 0xcc, 0x2d, 0x80, 0x2a, 0x10, 0x49, 0xcf, 0x4f, 0xcf, 0x87, 0x68, 0x04, 0xb1, 0xa0, + 0xa2, 0x92, 0xe8, 0xda, 0x12, 0xf3, 0x2a, 0x21, 0x52, 0x4a, 0xde, 0x5c, 0x22, 0xee, 0xa9, 0x79, + 0xa9, 0x45, 0x99, 0xc9, 0x8e, 0xa5, 0x25, 0x19, 0xf9, 0x45, 0x99, 0x55, 0x89, 0x25, 0x99, 0xf9, + 0x79, 0x42, 0x0a, 0x5c, 0x3c, 0xb9, 0xc5, 0xe9, 0xf1, 0x25, 0x95, 0x05, 0xa9, 0xf1, 0xa5, 0x45, + 0x39, 0x12, 0x8c, 0x0a, 0x8c, 0x1a, 0x9c, 0x41, 0x5c, 0xb9, 0xc5, 0xe9, 0x21, 0x95, 0x05, 0xa9, + 0xa1, 0x45, 0x39, 0x56, 0x82, 0x97, 0xb6, 0xe8, 0xf2, 0xa2, 0x68, 0x52, 0x9a, 0xc3, 0xc8, 0xc5, + 0xea, 0x5e, 0x94, 0x98, 0x57, 0x22, 0xe4, 0xcb, 0xc5, 0x9b, 0x88, 0x2c, 0x05, 0xd6, 0xcf, 0x6d, + 0x24, 0xa2, 0x07, 0x71, 0x89, 0x1e, 0xcc, 0x25, 0x7a, 0x8e, 0x79, 0x95, 0x4e, 0x82, 0xa7, 0xd0, + 0x4d, 0x0a, 0x42, 0xd5, 0x2d, 0xe4, 0xc2, 0xc5, 0x95, 0x5a, 0x51, 0x90, 0x59, 0x04, 0x31, 0x8b, + 0x09, 0x6c, 0x96, 0x14, 0x86, 0x59, 0x21, 0xb0, 0xc0, 0x70, 0xe2, 0x38, 0x71, 0x4f, 0x9e, 0x61, + 0xc2, 0x7d, 0x79, 0xc6, 0x20, 0x24, 0x7d, 0x4e, 0x2e, 0x27, 0x1e, 0xc9, 0x31, 0x5e, 0x78, 0x24, + 0xc7, 0xf8, 0xe0, 0x91, 0x1c, 0xe3, 0x84, 0xc7, 0x72, 0x0c, 0x17, 0x1e, 0xcb, 0x31, 0xdc, 0x78, + 0x2c, 0xc7, 0x10, 0xa5, 0x95, 0x9e, 0x59, 0x92, 0x51, 0x9a, 0xa4, 0x97, 0x9c, 0x9f, 0x0b, 0x0d, + 0x70, 0x28, 0xa5, 0x5b, 0x9c, 0x92, 0xad, 0x5f, 0x01, 0x8d, 0x42, 0x50, 0x60, 0x14, 0x27, 0xb1, + 0x81, 0xed, 0x33, 0x06, 0x04, 0x00, 0x00, 0xff, 0xff, 0x28, 0x5c, 0xf3, 0xb9, 0xdf, 0x01, 0x00, + 0x00, } func (m *GenericAuthorization) Marshal() (dAtA []byte, err error) { @@ -184,17 +182,17 @@ func (m *GenericAuthorization) MarshalToSizedBuffer(dAtA []byte) (int, error) { _ = i var l int _ = l - if len(m.MessageName) > 0 { - i -= len(m.MessageName) - copy(dAtA[i:], m.MessageName) - i = encodeVarintAuthz(dAtA, i, uint64(len(m.MessageName))) + if len(m.MsgTypeUrl) > 0 { + i -= len(m.MsgTypeUrl) + copy(dAtA[i:], m.MsgTypeUrl) + i = encodeVarintAuthz(dAtA, i, uint64(len(m.MsgTypeUrl))) i-- dAtA[i] = 0xa } return len(dAtA) - i, nil } -func (m *AuthorizationGrant) Marshal() (dAtA []byte, err error) { +func (m *Grant) Marshal() (dAtA []byte, err error) { size := m.Size() dAtA = make([]byte, size) n, err := m.MarshalToSizedBuffer(dAtA[:size]) @@ -204,12 +202,12 @@ func (m *AuthorizationGrant) Marshal() (dAtA []byte, err error) { return dAtA[:n], nil } -func (m *AuthorizationGrant) MarshalTo(dAtA []byte) (int, error) { +func (m *Grant) MarshalTo(dAtA []byte) (int, error) { size := m.Size() return m.MarshalToSizedBuffer(dAtA[:size]) } -func (m *AuthorizationGrant) MarshalToSizedBuffer(dAtA []byte) (int, error) { +func (m *Grant) MarshalToSizedBuffer(dAtA []byte) (int, error) { i := len(dAtA) _ = i var l int @@ -254,14 +252,14 @@ func (m *GenericAuthorization) Size() (n int) { } var l int _ = l - l = len(m.MessageName) + l = len(m.MsgTypeUrl) if l > 0 { n += 1 + l + sovAuthz(uint64(l)) } return n } -func (m *AuthorizationGrant) Size() (n int) { +func (m *Grant) Size() (n int) { if m == nil { return 0 } @@ -313,7 +311,7 @@ func (m *GenericAuthorization) Unmarshal(dAtA []byte) error { switch fieldNum { case 1: if wireType != 2 { - return fmt.Errorf("proto: wrong wireType = %d for field MessageName", wireType) + return fmt.Errorf("proto: wrong wireType = %d for field MsgTypeUrl", wireType) } var stringLen uint64 for shift := uint(0); ; shift += 7 { @@ -341,7 +339,7 @@ func (m *GenericAuthorization) Unmarshal(dAtA []byte) error { if postIndex > l { return io.ErrUnexpectedEOF } - m.MessageName = string(dAtA[iNdEx:postIndex]) + m.MsgTypeUrl = string(dAtA[iNdEx:postIndex]) iNdEx = postIndex default: iNdEx = preIndex @@ -364,7 +362,7 @@ func (m *GenericAuthorization) Unmarshal(dAtA []byte) error { } return nil } -func (m *AuthorizationGrant) Unmarshal(dAtA []byte) error { +func (m *Grant) Unmarshal(dAtA []byte) error { l := len(dAtA) iNdEx := 0 for iNdEx < l { @@ -387,10 +385,10 @@ func (m *AuthorizationGrant) Unmarshal(dAtA []byte) error { fieldNum := int32(wire >> 3) wireType := int(wire & 0x7) if wireType == 4 { - return fmt.Errorf("proto: AuthorizationGrant: wiretype end group for non-group") + return fmt.Errorf("proto: Grant: wiretype end group for non-group") } if fieldNum <= 0 { - return fmt.Errorf("proto: AuthorizationGrant: illegal tag %d (wire type %d)", fieldNum, wire) + return fmt.Errorf("proto: Grant: illegal tag %d (wire type %d)", fieldNum, wire) } switch fieldNum { case 1: diff --git a/x/authz/types/generic_authorization.go b/x/authz/types/generic_authorization.go index 6ecf9781417f..99fc72c1e84b 100644 --- a/x/authz/types/generic_authorization.go +++ b/x/authz/types/generic_authorization.go @@ -14,13 +14,13 @@ var ( // NewGenericAuthorization creates a new GenericAuthorization object. func NewGenericAuthorization(methodName string) *GenericAuthorization { return &GenericAuthorization{ - MessageName: methodName, + MsgTypeUrl: methodName, } } // MethodName implements Authorization.MethodName. func (a GenericAuthorization) MethodName() string { - return a.MessageName + return a.MsgTypeUrl } // Accept implements Authorization.Accept. @@ -30,8 +30,8 @@ func (a GenericAuthorization) Accept(ctx sdk.Context, msg sdk.ServiceMsg) (authz // ValidateBasic implements Authorization.ValidateBasic. func (a GenericAuthorization) ValidateBasic() error { - if !msgservice.IsServiceMsg(a.MessageName) { - return sdkerrors.Wrapf(sdkerrors.ErrInvalidType, " %s is not a valid service msg", a.MessageName) + if !msgservice.IsServiceMsg(a.MsgTypeUrl) { + return sdkerrors.Wrapf(sdkerrors.ErrInvalidType, " %s is not a valid service msg", a.MsgTypeUrl) } return nil } diff --git a/x/authz/types/generic_authorization_test.go b/x/authz/types/generic_authorization_test.go index 2dda401c693f..50bc9e01058d 100644 --- a/x/authz/types/generic_authorization_test.go +++ b/x/authz/types/generic_authorization_test.go @@ -17,5 +17,5 @@ func TestGenericAuthorization(t *testing.T) { t.Log("verify ValidateBasic returns nil for service msg") authorization = types.NewGenericAuthorization(banktypes.SendAuthorization{}.MethodName()) require.NoError(t, authorization.ValidateBasic()) - require.Equal(t, banktypes.SendAuthorization{}.MethodName(), authorization.MessageName) + require.Equal(t, banktypes.SendAuthorization{}.MethodName(), authorization.MsgTypeUrl) } diff --git a/x/authz/types/query.pb.go b/x/authz/types/query.pb.go index ccc5e5a8e820..ed8ecc394046 100644 --- a/x/authz/types/query.pb.go +++ b/x/authz/types/query.pb.go @@ -103,7 +103,7 @@ func (m *QueryGrantsRequest) GetPagination() *query.PageRequest { // QueryGrantsResponse is the response type for the Query/Authorizations RPC method. type QueryGrantsResponse struct { // authorizations is a list of grants granted for grantee by granter. - Grants []*AuthorizationGrant `protobuf:"bytes,1,rep,name=grants,proto3" json:"grants,omitempty"` + Grants []*Grant `protobuf:"bytes,1,rep,name=grants,proto3" json:"grants,omitempty"` // pagination defines an pagination for the response. Pagination *query.PageResponse `protobuf:"bytes,2,opt,name=pagination,proto3" json:"pagination,omitempty"` } @@ -141,7 +141,7 @@ func (m *QueryGrantsResponse) XXX_DiscardUnknown() { var xxx_messageInfo_QueryGrantsResponse proto.InternalMessageInfo -func (m *QueryGrantsResponse) GetGrants() []*AuthorizationGrant { +func (m *QueryGrantsResponse) GetGrants() []*Grant { if m != nil { return m.Grants } @@ -163,32 +163,32 @@ func init() { func init() { proto.RegisterFile("cosmos/authz/v1beta1/query.proto", fileDescriptor_376d714ffdeb1545) } var fileDescriptor_376d714ffdeb1545 = []byte{ - // 395 bytes of a gzipped FileDescriptorProto + // 385 bytes of a gzipped FileDescriptorProto 0x1f, 0x8b, 0x08, 0x00, 0x00, 0x00, 0x00, 0x00, 0x02, 0xff, 0x8c, 0x92, 0xc1, 0x4a, 0xeb, 0x40, - 0x14, 0x86, 0x3b, 0xed, 0xbd, 0xbd, 0xdc, 0xe9, 0x5d, 0xcd, 0x75, 0x11, 0x4a, 0x09, 0xa1, 0x88, - 0xc6, 0x82, 0x13, 0x5a, 0x5f, 0x40, 0x45, 0xec, 0x56, 0x83, 0x6e, 0xdc, 0x94, 0x49, 0x1d, 0xa6, - 0xc1, 0x26, 0x93, 0x66, 0x26, 0x62, 0xbb, 0xd4, 0xb5, 0x20, 0xf8, 0x02, 0x3e, 0x83, 0x4f, 0xe1, - 0xb2, 0xe0, 0xc6, 0xa5, 0xb4, 0x3e, 0x88, 0x64, 0x66, 0x6a, 0x5b, 0xac, 0xe8, 0x2a, 0x24, 0xe7, - 0x3f, 0xdf, 0xf9, 0xe6, 0x4c, 0xa0, 0xd3, 0xe5, 0x22, 0xe2, 0xc2, 0x23, 0x99, 0xec, 0x8d, 0xbc, - 0xcb, 0x66, 0x40, 0x25, 0x69, 0x7a, 0x83, 0x8c, 0xa6, 0x43, 0x9c, 0xa4, 0x5c, 0x72, 0xb4, 0xa6, - 0x13, 0x58, 0x25, 0xb0, 0x49, 0x54, 0x6b, 0x8c, 0x73, 0xd6, 0xa7, 0x1e, 0x49, 0x42, 0x8f, 0xc4, - 0x31, 0x97, 0x44, 0x86, 0x3c, 0x16, 0xba, 0xa7, 0xda, 0x30, 0xd4, 0x80, 0x08, 0xaa, 0x61, 0x1f, - 0xe8, 0x84, 0xb0, 0x30, 0x56, 0x61, 0x93, 0x5d, 0x6d, 0xa0, 0xa7, 0xa9, 0x44, 0xfd, 0x11, 0x40, - 0x74, 0x9c, 0x43, 0xda, 0x29, 0x89, 0xa5, 0xf0, 0xe9, 0x20, 0xa3, 0x42, 0x22, 0x0b, 0xfe, 0x61, - 0xf9, 0x07, 0x9a, 0x5a, 0xc0, 0x01, 0xee, 0x5f, 0x7f, 0xf6, 0x3a, 0xaf, 0x50, 0xab, 0xb8, 0x58, - 0xa1, 0xc8, 0x81, 0xff, 0x22, 0xc1, 0x3a, 0x72, 0x98, 0xd0, 0x4e, 0x96, 0xf6, 0xad, 0x92, 0x2a, - 0xc3, 0x48, 0xb0, 0x93, 0x61, 0x42, 0x4f, 0xd3, 0x3e, 0x3a, 0x84, 0x70, 0xae, 0x68, 0xfd, 0x72, - 0x80, 0x5b, 0x69, 0x6d, 0x60, 0xb3, 0x83, 0xfc, 0x3c, 0x58, 0x2f, 0xc7, 0x88, 0xe2, 0x23, 0xc2, - 0xa8, 0x31, 0xf2, 0x17, 0x3a, 0xeb, 0x0f, 0x00, 0xfe, 0x5f, 0x92, 0x16, 0x09, 0x8f, 0x05, 0x45, - 0xbb, 0xb0, 0xac, 0x64, 0x84, 0x05, 0x9c, 0x92, 0x5b, 0x69, 0xb9, 0x78, 0xd5, 0x7e, 0xf1, 0x5e, - 0x26, 0x7b, 0x3c, 0x0d, 0x47, 0x0a, 0xa6, 0x10, 0xbe, 0xe9, 0x43, 0xed, 0x25, 0xc3, 0xa2, 0x32, - 0xdc, 0xfc, 0xd6, 0x50, 0x8f, 0x5f, 0x54, 0x6c, 0xdd, 0x02, 0xf8, 0x5b, 0x29, 0xa2, 0x1b, 0x00, - 0xcb, 0xda, 0x13, 0x7d, 0xe1, 0xf3, 0x79, 0xff, 0xd5, 0xad, 0x1f, 0x24, 0xf5, 0xd4, 0xfa, 0xfa, - 0xf5, 0xf3, 0xdb, 0x7d, 0xd1, 0x46, 0x35, 0x6f, 0xe5, 0x65, 0xeb, 0x83, 0xed, 0x1f, 0x3c, 0x4d, - 0x6c, 0x30, 0x9e, 0xd8, 0xe0, 0x75, 0x62, 0x83, 0xbb, 0xa9, 0x5d, 0x18, 0x4f, 0xed, 0xc2, 0xcb, - 0xd4, 0x2e, 0x9c, 0x35, 0x58, 0x28, 0x7b, 0x59, 0x80, 0xbb, 0x3c, 0x9a, 0x11, 0xf4, 0x63, 0x5b, - 0x9c, 0x5f, 0x78, 0x57, 0x06, 0x97, 0xdf, 0xaa, 0x08, 0xca, 0xea, 0xa7, 0xd9, 0x79, 0x0f, 0x00, - 0x00, 0xff, 0xff, 0x77, 0xd6, 0x12, 0xe0, 0xda, 0x02, 0x00, 0x00, + 0x14, 0x86, 0x3b, 0xed, 0xbd, 0xbd, 0xdc, 0xe9, 0x5d, 0xcd, 0x75, 0x11, 0x6a, 0x09, 0xa1, 0x88, + 0xc6, 0x82, 0x13, 0xda, 0xbe, 0x81, 0x88, 0xdd, 0x6a, 0xd0, 0x8d, 0x9b, 0x32, 0xa9, 0xc3, 0x34, + 0xd8, 0x64, 0xd2, 0xcc, 0x44, 0xac, 0x4b, 0x5d, 0x0b, 0x42, 0xdf, 0xc4, 0xa7, 0x70, 0x59, 0x70, + 0xe3, 0x52, 0x5a, 0x1f, 0x44, 0x32, 0x33, 0xb5, 0x2d, 0x06, 0x74, 0x15, 0x92, 0xf3, 0x9d, 0xff, + 0x7c, 0x73, 0x26, 0xd0, 0x19, 0x70, 0x11, 0x71, 0xe1, 0x91, 0x4c, 0x0e, 0x6f, 0xbd, 0xeb, 0x76, + 0x40, 0x25, 0x69, 0x7b, 0xe3, 0x8c, 0xa6, 0x13, 0x9c, 0xa4, 0x5c, 0x72, 0xb4, 0xa5, 0x09, 0xac, + 0x08, 0x6c, 0x88, 0x7a, 0x83, 0x71, 0xce, 0x46, 0xd4, 0x23, 0x49, 0xe8, 0x91, 0x38, 0xe6, 0x92, + 0xc8, 0x90, 0xc7, 0x42, 0xf7, 0xd4, 0x5b, 0x26, 0x35, 0x20, 0x82, 0xea, 0xb0, 0xcf, 0xe8, 0x84, + 0xb0, 0x30, 0x56, 0xb0, 0x61, 0x8b, 0x0d, 0xf4, 0x34, 0x45, 0x34, 0x9f, 0x00, 0x44, 0xa7, 0x79, + 0x48, 0x2f, 0x25, 0xb1, 0x14, 0x3e, 0x1d, 0x67, 0x54, 0x48, 0x64, 0xc1, 0x3f, 0x2c, 0xff, 0x40, + 0x53, 0x0b, 0x38, 0xc0, 0xfd, 0xeb, 0x2f, 0x5f, 0x57, 0x15, 0x6a, 0x95, 0xd7, 0x2b, 0x14, 0x39, + 0xf0, 0x5f, 0x24, 0x58, 0x5f, 0x4e, 0x12, 0xda, 0xcf, 0xd2, 0x91, 0x55, 0x51, 0x65, 0x18, 0x09, + 0x76, 0x36, 0x49, 0xe8, 0x79, 0x3a, 0x42, 0xc7, 0x10, 0xae, 0x14, 0xad, 0x5f, 0x0e, 0x70, 0x6b, + 0x9d, 0x5d, 0x6c, 0x76, 0x90, 0x9f, 0x07, 0xeb, 0xe5, 0x18, 0x51, 0x7c, 0x42, 0x18, 0x35, 0x46, + 0xfe, 0x5a, 0x67, 0x73, 0x0a, 0xe0, 0xff, 0x0d, 0x69, 0x91, 0xf0, 0x58, 0x50, 0xd4, 0x85, 0x55, + 0x25, 0x23, 0x2c, 0xe0, 0x54, 0xdc, 0x5a, 0x67, 0x1b, 0x17, 0xed, 0x17, 0xab, 0x2e, 0xdf, 0xa0, + 0xa8, 0xb7, 0x21, 0x55, 0x56, 0x52, 0x7b, 0xdf, 0x4a, 0xe9, 0x89, 0xeb, 0x56, 0x9d, 0x07, 0x00, + 0x7f, 0x2b, 0x2b, 0x74, 0x0f, 0x60, 0x55, 0xab, 0x21, 0xb7, 0x58, 0xe1, 0xeb, 0xca, 0xeb, 0xfb, + 0x3f, 0x20, 0xf5, 0xd4, 0xe6, 0xce, 0xdd, 0xcb, 0xfb, 0xb4, 0x6c, 0xa3, 0x86, 0x57, 0x78, 0xbf, + 0xfa, 0x60, 0x87, 0x47, 0xcf, 0x73, 0x1b, 0xcc, 0xe6, 0x36, 0x78, 0x9b, 0xdb, 0xe0, 0x71, 0x61, + 0x97, 0x66, 0x0b, 0xbb, 0xf4, 0xba, 0xb0, 0x4b, 0x17, 0x2d, 0x16, 0xca, 0x61, 0x16, 0xe0, 0x01, + 0x8f, 0x96, 0x09, 0xfa, 0x71, 0x20, 0x2e, 0xaf, 0xbc, 0x1b, 0x13, 0x97, 0x5f, 0xa4, 0x08, 0xaa, + 0xea, 0x3f, 0xe9, 0x7e, 0x04, 0x00, 0x00, 0xff, 0xff, 0x99, 0xb7, 0x9e, 0x9d, 0xcd, 0x02, 0x00, + 0x00, } // Reference imports to suppress errors if they are not otherwise used. @@ -679,7 +679,7 @@ func (m *QueryGrantsResponse) Unmarshal(dAtA []byte) error { if postIndex > l { return io.ErrUnexpectedEOF } - m.Grants = append(m.Grants, &AuthorizationGrant{}) + m.Grants = append(m.Grants, &Grant{}) if err := m.Grants[len(m.Grants)-1].Unmarshal(dAtA[iNdEx:postIndex]); err != nil { return err } diff --git a/x/authz/types/tx.pb.go b/x/authz/types/tx.pb.go index a1f493ff2c53..6b3c48cf677e 100644 --- a/x/authz/types/tx.pb.go +++ b/x/authz/types/tx.pb.go @@ -35,27 +35,27 @@ var _ = time.Kitchen // proto package needs to be updated. const _ = proto.GoGoProtoPackageIsVersion3 // please upgrade the proto package -// MsgGrantAuthorizationRequest grants the provided authorization to the grantee on the granter's +// MsgGrantRequest grants the provided authorization to the grantee on the granter's // account with the provided expiration time. -type MsgGrantAuthorizationRequest struct { +type MsgGrantRequest struct { Granter string `protobuf:"bytes,1,opt,name=granter,proto3" json:"granter,omitempty"` Grantee string `protobuf:"bytes,2,opt,name=grantee,proto3" json:"grantee,omitempty"` Authorization *types.Any `protobuf:"bytes,3,opt,name=authorization,proto3" json:"authorization,omitempty"` Expiration time.Time `protobuf:"bytes,4,opt,name=expiration,proto3,stdtime" json:"expiration"` } -func (m *MsgGrantAuthorizationRequest) Reset() { *m = MsgGrantAuthorizationRequest{} } -func (m *MsgGrantAuthorizationRequest) String() string { return proto.CompactTextString(m) } -func (*MsgGrantAuthorizationRequest) ProtoMessage() {} -func (*MsgGrantAuthorizationRequest) Descriptor() ([]byte, []int) { +func (m *MsgGrantRequest) Reset() { *m = MsgGrantRequest{} } +func (m *MsgGrantRequest) String() string { return proto.CompactTextString(m) } +func (*MsgGrantRequest) ProtoMessage() {} +func (*MsgGrantRequest) Descriptor() ([]byte, []int) { return fileDescriptor_3ceddab7d8589ad1, []int{0} } -func (m *MsgGrantAuthorizationRequest) XXX_Unmarshal(b []byte) error { +func (m *MsgGrantRequest) XXX_Unmarshal(b []byte) error { return m.Unmarshal(b) } -func (m *MsgGrantAuthorizationRequest) XXX_Marshal(b []byte, deterministic bool) ([]byte, error) { +func (m *MsgGrantRequest) XXX_Marshal(b []byte, deterministic bool) ([]byte, error) { if deterministic { - return xxx_messageInfo_MsgGrantAuthorizationRequest.Marshal(b, m, deterministic) + return xxx_messageInfo_MsgGrantRequest.Marshal(b, m, deterministic) } else { b = b[:cap(b)] n, err := m.MarshalToSizedBuffer(b) @@ -65,40 +65,40 @@ func (m *MsgGrantAuthorizationRequest) XXX_Marshal(b []byte, deterministic bool) return b[:n], nil } } -func (m *MsgGrantAuthorizationRequest) XXX_Merge(src proto.Message) { - xxx_messageInfo_MsgGrantAuthorizationRequest.Merge(m, src) +func (m *MsgGrantRequest) XXX_Merge(src proto.Message) { + xxx_messageInfo_MsgGrantRequest.Merge(m, src) } -func (m *MsgGrantAuthorizationRequest) XXX_Size() int { +func (m *MsgGrantRequest) XXX_Size() int { return m.Size() } -func (m *MsgGrantAuthorizationRequest) XXX_DiscardUnknown() { - xxx_messageInfo_MsgGrantAuthorizationRequest.DiscardUnknown(m) +func (m *MsgGrantRequest) XXX_DiscardUnknown() { + xxx_messageInfo_MsgGrantRequest.DiscardUnknown(m) } -var xxx_messageInfo_MsgGrantAuthorizationRequest proto.InternalMessageInfo +var xxx_messageInfo_MsgGrantRequest proto.InternalMessageInfo -func (m *MsgGrantAuthorizationRequest) GetGranter() string { +func (m *MsgGrantRequest) GetGranter() string { if m != nil { return m.Granter } return "" } -func (m *MsgGrantAuthorizationRequest) GetGrantee() string { +func (m *MsgGrantRequest) GetGrantee() string { if m != nil { return m.Grantee } return "" } -func (m *MsgGrantAuthorizationRequest) GetAuthorization() *types.Any { +func (m *MsgGrantRequest) GetAuthorization() *types.Any { if m != nil { return m.Authorization } return nil } -func (m *MsgGrantAuthorizationRequest) GetExpiration() time.Time { +func (m *MsgGrantRequest) GetExpiration() time.Time { if m != nil { return m.Expiration } @@ -205,22 +205,22 @@ func (m *MsgExecAuthorizedRequest) GetMsgs() []*types.Any { return nil } -// MsgGrantAuthorizationResponse defines the Msg/MsgGrantAuthorization response type. -type MsgGrantAuthorizationResponse struct { +// MsgGrantResponse defines the Msg/MsgGrant response type. +type MsgGrantResponse struct { } -func (m *MsgGrantAuthorizationResponse) Reset() { *m = MsgGrantAuthorizationResponse{} } -func (m *MsgGrantAuthorizationResponse) String() string { return proto.CompactTextString(m) } -func (*MsgGrantAuthorizationResponse) ProtoMessage() {} -func (*MsgGrantAuthorizationResponse) Descriptor() ([]byte, []int) { +func (m *MsgGrantResponse) Reset() { *m = MsgGrantResponse{} } +func (m *MsgGrantResponse) String() string { return proto.CompactTextString(m) } +func (*MsgGrantResponse) ProtoMessage() {} +func (*MsgGrantResponse) Descriptor() ([]byte, []int) { return fileDescriptor_3ceddab7d8589ad1, []int{3} } -func (m *MsgGrantAuthorizationResponse) XXX_Unmarshal(b []byte) error { +func (m *MsgGrantResponse) XXX_Unmarshal(b []byte) error { return m.Unmarshal(b) } -func (m *MsgGrantAuthorizationResponse) XXX_Marshal(b []byte, deterministic bool) ([]byte, error) { +func (m *MsgGrantResponse) XXX_Marshal(b []byte, deterministic bool) ([]byte, error) { if deterministic { - return xxx_messageInfo_MsgGrantAuthorizationResponse.Marshal(b, m, deterministic) + return xxx_messageInfo_MsgGrantResponse.Marshal(b, m, deterministic) } else { b = b[:cap(b)] n, err := m.MarshalToSizedBuffer(b) @@ -230,38 +230,38 @@ func (m *MsgGrantAuthorizationResponse) XXX_Marshal(b []byte, deterministic bool return b[:n], nil } } -func (m *MsgGrantAuthorizationResponse) XXX_Merge(src proto.Message) { - xxx_messageInfo_MsgGrantAuthorizationResponse.Merge(m, src) +func (m *MsgGrantResponse) XXX_Merge(src proto.Message) { + xxx_messageInfo_MsgGrantResponse.Merge(m, src) } -func (m *MsgGrantAuthorizationResponse) XXX_Size() int { +func (m *MsgGrantResponse) XXX_Size() int { return m.Size() } -func (m *MsgGrantAuthorizationResponse) XXX_DiscardUnknown() { - xxx_messageInfo_MsgGrantAuthorizationResponse.DiscardUnknown(m) +func (m *MsgGrantResponse) XXX_DiscardUnknown() { + xxx_messageInfo_MsgGrantResponse.DiscardUnknown(m) } -var xxx_messageInfo_MsgGrantAuthorizationResponse proto.InternalMessageInfo +var xxx_messageInfo_MsgGrantResponse proto.InternalMessageInfo -// MsgRevokeAuthorizationRequest revokes any authorization with the provided sdk.Msg type on the +// MsgRevokeRequest revokes any authorization with the provided sdk.Msg type on the // granter's account with that has been granted to the grantee. -type MsgRevokeAuthorizationRequest struct { +type MsgRevokeRequest struct { Granter string `protobuf:"bytes,1,opt,name=granter,proto3" json:"granter,omitempty"` Grantee string `protobuf:"bytes,2,opt,name=grantee,proto3" json:"grantee,omitempty"` MethodName string `protobuf:"bytes,3,opt,name=method_name,json=methodName,proto3" json:"method_name,omitempty"` } -func (m *MsgRevokeAuthorizationRequest) Reset() { *m = MsgRevokeAuthorizationRequest{} } -func (m *MsgRevokeAuthorizationRequest) String() string { return proto.CompactTextString(m) } -func (*MsgRevokeAuthorizationRequest) ProtoMessage() {} -func (*MsgRevokeAuthorizationRequest) Descriptor() ([]byte, []int) { +func (m *MsgRevokeRequest) Reset() { *m = MsgRevokeRequest{} } +func (m *MsgRevokeRequest) String() string { return proto.CompactTextString(m) } +func (*MsgRevokeRequest) ProtoMessage() {} +func (*MsgRevokeRequest) Descriptor() ([]byte, []int) { return fileDescriptor_3ceddab7d8589ad1, []int{4} } -func (m *MsgRevokeAuthorizationRequest) XXX_Unmarshal(b []byte) error { +func (m *MsgRevokeRequest) XXX_Unmarshal(b []byte) error { return m.Unmarshal(b) } -func (m *MsgRevokeAuthorizationRequest) XXX_Marshal(b []byte, deterministic bool) ([]byte, error) { +func (m *MsgRevokeRequest) XXX_Marshal(b []byte, deterministic bool) ([]byte, error) { if deterministic { - return xxx_messageInfo_MsgRevokeAuthorizationRequest.Marshal(b, m, deterministic) + return xxx_messageInfo_MsgRevokeRequest.Marshal(b, m, deterministic) } else { b = b[:cap(b)] n, err := m.MarshalToSizedBuffer(b) @@ -271,55 +271,55 @@ func (m *MsgRevokeAuthorizationRequest) XXX_Marshal(b []byte, deterministic bool return b[:n], nil } } -func (m *MsgRevokeAuthorizationRequest) XXX_Merge(src proto.Message) { - xxx_messageInfo_MsgRevokeAuthorizationRequest.Merge(m, src) +func (m *MsgRevokeRequest) XXX_Merge(src proto.Message) { + xxx_messageInfo_MsgRevokeRequest.Merge(m, src) } -func (m *MsgRevokeAuthorizationRequest) XXX_Size() int { +func (m *MsgRevokeRequest) XXX_Size() int { return m.Size() } -func (m *MsgRevokeAuthorizationRequest) XXX_DiscardUnknown() { - xxx_messageInfo_MsgRevokeAuthorizationRequest.DiscardUnknown(m) +func (m *MsgRevokeRequest) XXX_DiscardUnknown() { + xxx_messageInfo_MsgRevokeRequest.DiscardUnknown(m) } -var xxx_messageInfo_MsgRevokeAuthorizationRequest proto.InternalMessageInfo +var xxx_messageInfo_MsgRevokeRequest proto.InternalMessageInfo -func (m *MsgRevokeAuthorizationRequest) GetGranter() string { +func (m *MsgRevokeRequest) GetGranter() string { if m != nil { return m.Granter } return "" } -func (m *MsgRevokeAuthorizationRequest) GetGrantee() string { +func (m *MsgRevokeRequest) GetGrantee() string { if m != nil { return m.Grantee } return "" } -func (m *MsgRevokeAuthorizationRequest) GetMethodName() string { +func (m *MsgRevokeRequest) GetMethodName() string { if m != nil { return m.MethodName } return "" } -// MsgRevokeAuthorizationResponse defines the Msg/MsgRevokeAuthorizationResponse response type. -type MsgRevokeAuthorizationResponse struct { +// MsgRevokeResponse defines the Msg/MsgRevokeResponse response type. +type MsgRevokeResponse struct { } -func (m *MsgRevokeAuthorizationResponse) Reset() { *m = MsgRevokeAuthorizationResponse{} } -func (m *MsgRevokeAuthorizationResponse) String() string { return proto.CompactTextString(m) } -func (*MsgRevokeAuthorizationResponse) ProtoMessage() {} -func (*MsgRevokeAuthorizationResponse) Descriptor() ([]byte, []int) { +func (m *MsgRevokeResponse) Reset() { *m = MsgRevokeResponse{} } +func (m *MsgRevokeResponse) String() string { return proto.CompactTextString(m) } +func (*MsgRevokeResponse) ProtoMessage() {} +func (*MsgRevokeResponse) Descriptor() ([]byte, []int) { return fileDescriptor_3ceddab7d8589ad1, []int{5} } -func (m *MsgRevokeAuthorizationResponse) XXX_Unmarshal(b []byte) error { +func (m *MsgRevokeResponse) XXX_Unmarshal(b []byte) error { return m.Unmarshal(b) } -func (m *MsgRevokeAuthorizationResponse) XXX_Marshal(b []byte, deterministic bool) ([]byte, error) { +func (m *MsgRevokeResponse) XXX_Marshal(b []byte, deterministic bool) ([]byte, error) { if deterministic { - return xxx_messageInfo_MsgRevokeAuthorizationResponse.Marshal(b, m, deterministic) + return xxx_messageInfo_MsgRevokeResponse.Marshal(b, m, deterministic) } else { b = b[:cap(b)] n, err := m.MarshalToSizedBuffer(b) @@ -329,64 +329,64 @@ func (m *MsgRevokeAuthorizationResponse) XXX_Marshal(b []byte, deterministic boo return b[:n], nil } } -func (m *MsgRevokeAuthorizationResponse) XXX_Merge(src proto.Message) { - xxx_messageInfo_MsgRevokeAuthorizationResponse.Merge(m, src) +func (m *MsgRevokeResponse) XXX_Merge(src proto.Message) { + xxx_messageInfo_MsgRevokeResponse.Merge(m, src) } -func (m *MsgRevokeAuthorizationResponse) XXX_Size() int { +func (m *MsgRevokeResponse) XXX_Size() int { return m.Size() } -func (m *MsgRevokeAuthorizationResponse) XXX_DiscardUnknown() { - xxx_messageInfo_MsgRevokeAuthorizationResponse.DiscardUnknown(m) +func (m *MsgRevokeResponse) XXX_DiscardUnknown() { + xxx_messageInfo_MsgRevokeResponse.DiscardUnknown(m) } -var xxx_messageInfo_MsgRevokeAuthorizationResponse proto.InternalMessageInfo +var xxx_messageInfo_MsgRevokeResponse proto.InternalMessageInfo func init() { - proto.RegisterType((*MsgGrantAuthorizationRequest)(nil), "cosmos.authz.v1beta1.MsgGrantAuthorizationRequest") + proto.RegisterType((*MsgGrantRequest)(nil), "cosmos.authz.v1beta1.MsgGrantRequest") proto.RegisterType((*MsgExecAuthorizedResponse)(nil), "cosmos.authz.v1beta1.MsgExecAuthorizedResponse") proto.RegisterType((*MsgExecAuthorizedRequest)(nil), "cosmos.authz.v1beta1.MsgExecAuthorizedRequest") - proto.RegisterType((*MsgGrantAuthorizationResponse)(nil), "cosmos.authz.v1beta1.MsgGrantAuthorizationResponse") - proto.RegisterType((*MsgRevokeAuthorizationRequest)(nil), "cosmos.authz.v1beta1.MsgRevokeAuthorizationRequest") - proto.RegisterType((*MsgRevokeAuthorizationResponse)(nil), "cosmos.authz.v1beta1.MsgRevokeAuthorizationResponse") + proto.RegisterType((*MsgGrantResponse)(nil), "cosmos.authz.v1beta1.MsgGrantResponse") + proto.RegisterType((*MsgRevokeRequest)(nil), "cosmos.authz.v1beta1.MsgRevokeRequest") + proto.RegisterType((*MsgRevokeResponse)(nil), "cosmos.authz.v1beta1.MsgRevokeResponse") } func init() { proto.RegisterFile("cosmos/authz/v1beta1/tx.proto", fileDescriptor_3ceddab7d8589ad1) } var fileDescriptor_3ceddab7d8589ad1 = []byte{ - // 521 bytes of a gzipped FileDescriptorProto - 0x1f, 0x8b, 0x08, 0x00, 0x00, 0x00, 0x00, 0x00, 0x02, 0xff, 0xac, 0x54, 0xc1, 0x6e, 0xd3, 0x40, - 0x10, 0x8d, 0x93, 0xaa, 0xd0, 0x8d, 0x8a, 0xc4, 0x92, 0x83, 0x63, 0x51, 0xdb, 0x32, 0x97, 0x08, - 0xa9, 0x6b, 0x35, 0xe5, 0xc0, 0xb5, 0x51, 0x11, 0xa7, 0x70, 0xb0, 0xe0, 0xc2, 0x81, 0x6a, 0x9d, - 0x0c, 0x1b, 0xab, 0xb5, 0xd7, 0xf5, 0xae, 0xab, 0xa4, 0x12, 0x12, 0x9f, 0xd0, 0x8f, 0xe1, 0x23, - 0x2a, 0x4e, 0x3d, 0x72, 0x02, 0x94, 0x1c, 0xf8, 0x07, 0x4e, 0x28, 0xbb, 0x1b, 0x48, 0xda, 0x18, - 0x11, 0x89, 0x93, 0x3d, 0x33, 0x6f, 0x66, 0x9e, 0xdf, 0x5b, 0x2f, 0xda, 0x1b, 0x70, 0x91, 0x72, - 0x11, 0xd2, 0x52, 0x8e, 0x2e, 0xc3, 0x8b, 0x83, 0x18, 0x24, 0x3d, 0x08, 0xe5, 0x98, 0xe4, 0x05, - 0x97, 0x1c, 0xb7, 0x74, 0x99, 0xa8, 0x32, 0x31, 0x65, 0xa7, 0xad, 0xb3, 0x27, 0x0a, 0x13, 0x1a, - 0x88, 0x0a, 0x9c, 0x16, 0xe3, 0x8c, 0xeb, 0xfc, 0xfc, 0xcd, 0x64, 0x3d, 0xc6, 0x39, 0x3b, 0x83, - 0x50, 0x45, 0x71, 0xf9, 0x3e, 0x94, 0x49, 0x0a, 0x42, 0xd2, 0x34, 0x37, 0x80, 0xf6, 0x6d, 0x00, - 0xcd, 0x26, 0xa6, 0xf4, 0xc4, 0x30, 0x8c, 0xa9, 0x80, 0x90, 0xc6, 0x83, 0xe4, 0x37, 0xcb, 0x79, - 0xa0, 0x41, 0xc1, 0x0f, 0x0b, 0x3d, 0xee, 0x0b, 0xf6, 0xb2, 0xa0, 0x99, 0x3c, 0x2a, 0xe5, 0x88, - 0x17, 0xc9, 0x25, 0x95, 0x09, 0xcf, 0x22, 0x38, 0x2f, 0x41, 0x48, 0x6c, 0xa3, 0x7b, 0x6c, 0x5e, - 0x84, 0xc2, 0xb6, 0x7c, 0xab, 0xb3, 0x13, 0x2d, 0xc2, 0x3f, 0x15, 0xb0, 0xeb, 0xcb, 0x15, 0xc0, - 0x7d, 0xb4, 0x4b, 0x97, 0x67, 0xd9, 0x0d, 0xdf, 0xea, 0x34, 0xbb, 0x2d, 0xa2, 0xc9, 0x92, 0x05, - 0x59, 0x72, 0x94, 0x4d, 0x7a, 0x0f, 0x3f, 0x7f, 0xda, 0xdf, 0x5d, 0x5d, 0xbd, 0xda, 0x8d, 0x8f, - 0x11, 0x82, 0x71, 0x9e, 0x14, 0x7a, 0xd6, 0x96, 0x9a, 0xe5, 0xdc, 0x99, 0xf5, 0x7a, 0xa1, 0x4c, - 0xef, 0xfe, 0xf5, 0x57, 0xaf, 0x76, 0xf5, 0xcd, 0xb3, 0xa2, 0xa5, 0xbe, 0xe0, 0x0d, 0x6a, 0xf7, - 0x05, 0x7b, 0x31, 0x86, 0xc1, 0x62, 0x19, 0x0c, 0x23, 0x10, 0x39, 0xcf, 0x04, 0xe0, 0xe7, 0x68, - 0xbb, 0x00, 0x51, 0x9e, 0x49, 0xf5, 0x91, 0xcd, 0xae, 0x4f, 0x8c, 0x39, 0x73, 0xf1, 0x88, 0xd2, - 0xcb, 0x88, 0x47, 0x22, 0x85, 0x8b, 0x0c, 0x3e, 0x78, 0x87, 0xec, 0x35, 0x63, 0x6f, 0x69, 0x07, - 0xab, 0xda, 0x01, 0xee, 0xa0, 0xad, 0x54, 0x30, 0x61, 0xd7, 0xfd, 0x46, 0x95, 0x30, 0x91, 0x42, - 0x04, 0x1e, 0xda, 0xab, 0xf0, 0x47, 0x53, 0x0f, 0xa4, 0x02, 0x44, 0x70, 0xc1, 0x4f, 0xe1, 0xbf, - 0x39, 0xe8, 0xa1, 0x66, 0x0a, 0x72, 0xc4, 0x87, 0x27, 0x19, 0x4d, 0x41, 0xf9, 0xb7, 0x13, 0x21, - 0x9d, 0x7a, 0x45, 0x53, 0x08, 0x7c, 0xe4, 0x56, 0x6d, 0xd5, 0xbc, 0xba, 0x3f, 0xeb, 0xa8, 0xd1, - 0x17, 0x0c, 0x7f, 0x40, 0xf8, 0x2e, 0x7b, 0xdc, 0x25, 0xeb, 0x7e, 0x10, 0xf2, 0xb7, 0xa3, 0xe8, - 0x1c, 0x6e, 0xd4, 0x63, 0x9c, 0x3d, 0x47, 0x0f, 0x56, 0xcd, 0xc1, 0xa4, 0x72, 0xcc, 0x5a, 0x17, - 0x9d, 0xf0, 0x9f, 0xf1, 0x66, 0xe5, 0x47, 0x0b, 0x3d, 0x5a, 0xa3, 0x0c, 0xae, 0xe6, 0x5f, 0xed, - 0x9e, 0xf3, 0x6c, 0xb3, 0x26, 0x4d, 0xa1, 0x77, 0x7c, 0x3d, 0x75, 0xad, 0x9b, 0xa9, 0x6b, 0x7d, - 0x9f, 0xba, 0xd6, 0xd5, 0xcc, 0xad, 0xdd, 0xcc, 0xdc, 0xda, 0x97, 0x99, 0x5b, 0x7b, 0xfb, 0x94, - 0x25, 0x72, 0x54, 0xc6, 0x64, 0xc0, 0x53, 0x73, 0x01, 0x99, 0xc7, 0xbe, 0x18, 0x9e, 0x86, 0x63, - 0x73, 0x9f, 0xc9, 0x49, 0x0e, 0x22, 0xde, 0x56, 0xe7, 0xf1, 0xf0, 0x57, 0x00, 0x00, 0x00, 0xff, - 0xff, 0xff, 0x9d, 0x19, 0xe1, 0xec, 0x04, 0x00, 0x00, + // 515 bytes of a gzipped FileDescriptorProto + 0x1f, 0x8b, 0x08, 0x00, 0x00, 0x00, 0x00, 0x00, 0x02, 0xff, 0xa4, 0x54, 0xc1, 0x6e, 0xd3, 0x40, + 0x10, 0x8d, 0x93, 0x2a, 0xa5, 0x1b, 0x15, 0xe8, 0x92, 0x83, 0x63, 0x09, 0x27, 0x32, 0x02, 0x22, + 0xa4, 0xae, 0xd5, 0x70, 0xe1, 0xda, 0xa8, 0x88, 0x53, 0x38, 0xac, 0x40, 0x02, 0x0e, 0x54, 0xeb, + 0x64, 0xd8, 0x58, 0xad, 0xbd, 0xa9, 0x77, 0x53, 0x39, 0xfd, 0x8a, 0xfe, 0x08, 0x37, 0x3e, 0xa2, + 0xe2, 0xd4, 0x23, 0xe2, 0x00, 0x28, 0xf9, 0x11, 0xe4, 0xdd, 0x0d, 0x4d, 0x42, 0xa2, 0x22, 0x71, + 0xb2, 0x67, 0xde, 0xdb, 0x99, 0xb7, 0x6f, 0xc6, 0x46, 0x0f, 0xfb, 0x42, 0x26, 0x42, 0x86, 0x6c, + 0xac, 0x86, 0x17, 0xe1, 0xf9, 0x41, 0x04, 0x8a, 0x1d, 0x84, 0x2a, 0x27, 0xa3, 0x4c, 0x28, 0x81, + 0xeb, 0x06, 0x26, 0x1a, 0x26, 0x16, 0xf6, 0x1a, 0x26, 0x7b, 0xac, 0x39, 0xa1, 0xa5, 0xe8, 0xc0, + 0xab, 0x73, 0xc1, 0x85, 0xc9, 0x17, 0x6f, 0x36, 0xdb, 0xe4, 0x42, 0xf0, 0x53, 0x08, 0x75, 0x14, + 0x8d, 0x3f, 0x85, 0x2a, 0x4e, 0x40, 0x2a, 0x96, 0x8c, 0x2c, 0xa1, 0xb1, 0x4a, 0x60, 0xe9, 0xc4, + 0x42, 0x8f, 0xac, 0xc2, 0x88, 0x49, 0x08, 0x59, 0xd4, 0x8f, 0xff, 0xa8, 0x2c, 0x02, 0x43, 0x0a, + 0xbe, 0x3b, 0xe8, 0x5e, 0x4f, 0xf2, 0x57, 0x19, 0x4b, 0x15, 0x85, 0xb3, 0x31, 0x48, 0x85, 0x5d, + 0xb4, 0xcd, 0x8b, 0x18, 0x32, 0xd7, 0x69, 0x39, 0xed, 0x1d, 0x3a, 0x0f, 0x6f, 0x10, 0x70, 0xcb, + 0x8b, 0x08, 0xe0, 0x1e, 0xda, 0x2d, 0xae, 0x2a, 0xb2, 0xf8, 0x82, 0xa9, 0x58, 0xa4, 0x6e, 0xa5, + 0xe5, 0xb4, 0x6b, 0x9d, 0x3a, 0x31, 0xfa, 0xc8, 0x5c, 0x1f, 0x39, 0x4c, 0x27, 0xdd, 0xbd, 0xaf, + 0x5f, 0xf6, 0x77, 0x0f, 0x17, 0xe9, 0x74, 0xf9, 0x34, 0x3e, 0x42, 0x08, 0xf2, 0x51, 0x9c, 0x99, + 0x5a, 0x5b, 0xba, 0x96, 0xf7, 0x57, 0xad, 0x37, 0x73, 0x33, 0xba, 0x77, 0xae, 0x7e, 0x34, 0x4b, + 0x97, 0x3f, 0x9b, 0x0e, 0x5d, 0x38, 0x17, 0xbc, 0x45, 0x8d, 0x9e, 0xe4, 0x2f, 0x73, 0xe8, 0xcf, + 0x9b, 0xc1, 0x80, 0x82, 0x1c, 0x89, 0x54, 0x02, 0x7e, 0x81, 0xaa, 0x19, 0xc8, 0xf1, 0xa9, 0xd2, + 0x97, 0xac, 0x75, 0x5a, 0xc4, 0xce, 0xa3, 0xf0, 0x8b, 0x68, 0x8b, 0xac, 0x5f, 0x84, 0x6a, 0x1e, + 0xb5, 0xfc, 0xe0, 0x23, 0x72, 0xd7, 0x94, 0x5d, 0xf1, 0x0e, 0x96, 0xbd, 0x03, 0xdc, 0x46, 0x5b, + 0x89, 0xe4, 0xd2, 0x2d, 0xb7, 0x2a, 0x9b, 0x8c, 0xa1, 0x9a, 0x11, 0x60, 0x74, 0xff, 0x66, 0x24, + 0x46, 0x6d, 0xc0, 0x75, 0x8e, 0xc2, 0xb9, 0x38, 0x81, 0xff, 0x99, 0x53, 0x13, 0xd5, 0x12, 0x50, + 0x43, 0x31, 0x38, 0x4e, 0x59, 0x02, 0x7a, 0x4a, 0x3b, 0x14, 0x99, 0xd4, 0x6b, 0x96, 0x40, 0xf0, + 0x00, 0xed, 0x2d, 0x34, 0x32, 0xdd, 0x3b, 0x9f, 0xcb, 0xa8, 0xd2, 0x93, 0x1c, 0xbf, 0x43, 0xdb, + 0x5a, 0x56, 0x9e, 0xe3, 0xc7, 0x64, 0xdd, 0x86, 0x93, 0x95, 0x5d, 0xf2, 0x9e, 0xdc, 0x46, 0xb3, + 0xd3, 0x38, 0x43, 0x77, 0x97, 0x0d, 0xc5, 0x64, 0xe3, 0xc9, 0xb5, 0xce, 0x7b, 0xe1, 0x3f, 0xf3, + 0x6d, 0xcb, 0xf7, 0xa8, 0x6a, 0xae, 0x89, 0x37, 0x8b, 0x5c, 0x32, 0xdc, 0x7b, 0x7a, 0x2b, 0xcf, + 0x94, 0xee, 0x1e, 0x5d, 0x4d, 0x7d, 0xe7, 0x7a, 0xea, 0x3b, 0xbf, 0xa6, 0xbe, 0x73, 0x39, 0xf3, + 0x4b, 0xd7, 0x33, 0xbf, 0xf4, 0x6d, 0xe6, 0x97, 0x3e, 0x3c, 0xe3, 0xb1, 0x1a, 0x8e, 0x23, 0xd2, + 0x17, 0x89, 0xfd, 0xfe, 0xed, 0x63, 0x5f, 0x0e, 0x4e, 0xc2, 0xdc, 0xfe, 0x4e, 0xd4, 0x64, 0x04, + 0x32, 0xaa, 0xea, 0xdd, 0x78, 0xfe, 0x3b, 0x00, 0x00, 0xff, 0xff, 0xa6, 0xf4, 0x13, 0x32, 0x6b, + 0x04, 0x00, 0x00, } // Reference imports to suppress errors if they are not otherwise used. @@ -401,16 +401,16 @@ const _ = grpc.SupportPackageIsVersion4 // // For semantics around ctx use and closing/ending streaming RPCs, please refer to https://godoc.org/google.golang.org/grpc#ClientConn.NewStream. type MsgClient interface { - // GrantAuthorization grants the provided authorization to the grantee on the granter's + // Grant grants the provided authorization to the grantee on the granter's // account with the provided expiration time. - GrantAuthorization(ctx context.Context, in *MsgGrantAuthorizationRequest, opts ...grpc.CallOption) (*MsgGrantAuthorizationResponse, error) + Grantxx(ctx context.Context, in *MsgGrantRequest, opts ...grpc.CallOption) (*MsgGrantResponse, error) // ExecAuthorized attempts to execute the provided messages using // authorizations granted to the grantee. Each message should have only // one signer corresponding to the granter of the authorization. ExecAuthorized(ctx context.Context, in *MsgExecAuthorizedRequest, opts ...grpc.CallOption) (*MsgExecAuthorizedResponse, error) - // RevokeAuthorization revokes any authorization corresponding to the provided method name on the + // Revoke revokes any authorization corresponding to the provided method name on the // granter's account that has been granted to the grantee. - RevokeAuthorization(ctx context.Context, in *MsgRevokeAuthorizationRequest, opts ...grpc.CallOption) (*MsgRevokeAuthorizationResponse, error) + Revoke(ctx context.Context, in *MsgRevokeRequest, opts ...grpc.CallOption) (*MsgRevokeResponse, error) } type msgClient struct { @@ -421,9 +421,9 @@ func NewMsgClient(cc grpc1.ClientConn) MsgClient { return &msgClient{cc} } -func (c *msgClient) GrantAuthorization(ctx context.Context, in *MsgGrantAuthorizationRequest, opts ...grpc.CallOption) (*MsgGrantAuthorizationResponse, error) { - out := new(MsgGrantAuthorizationResponse) - err := c.cc.Invoke(ctx, "/cosmos.authz.v1beta1.Msg/GrantAuthorization", in, out, opts...) +func (c *msgClient) Grantxx(ctx context.Context, in *MsgGrantRequest, opts ...grpc.CallOption) (*MsgGrantResponse, error) { + out := new(MsgGrantResponse) + err := c.cc.Invoke(ctx, "/cosmos.authz.v1beta1.Msg/Grantxx", in, out, opts...) if err != nil { return nil, err } @@ -439,9 +439,9 @@ func (c *msgClient) ExecAuthorized(ctx context.Context, in *MsgExecAuthorizedReq return out, nil } -func (c *msgClient) RevokeAuthorization(ctx context.Context, in *MsgRevokeAuthorizationRequest, opts ...grpc.CallOption) (*MsgRevokeAuthorizationResponse, error) { - out := new(MsgRevokeAuthorizationResponse) - err := c.cc.Invoke(ctx, "/cosmos.authz.v1beta1.Msg/RevokeAuthorization", in, out, opts...) +func (c *msgClient) Revoke(ctx context.Context, in *MsgRevokeRequest, opts ...grpc.CallOption) (*MsgRevokeResponse, error) { + out := new(MsgRevokeResponse) + err := c.cc.Invoke(ctx, "/cosmos.authz.v1beta1.Msg/Revoke", in, out, opts...) if err != nil { return nil, err } @@ -450,50 +450,50 @@ func (c *msgClient) RevokeAuthorization(ctx context.Context, in *MsgRevokeAuthor // MsgServer is the server API for Msg service. type MsgServer interface { - // GrantAuthorization grants the provided authorization to the grantee on the granter's + // Grant grants the provided authorization to the grantee on the granter's // account with the provided expiration time. - GrantAuthorization(context.Context, *MsgGrantAuthorizationRequest) (*MsgGrantAuthorizationResponse, error) + Grantxx(context.Context, *MsgGrantRequest) (*MsgGrantResponse, error) // ExecAuthorized attempts to execute the provided messages using // authorizations granted to the grantee. Each message should have only // one signer corresponding to the granter of the authorization. ExecAuthorized(context.Context, *MsgExecAuthorizedRequest) (*MsgExecAuthorizedResponse, error) - // RevokeAuthorization revokes any authorization corresponding to the provided method name on the + // Revoke revokes any authorization corresponding to the provided method name on the // granter's account that has been granted to the grantee. - RevokeAuthorization(context.Context, *MsgRevokeAuthorizationRequest) (*MsgRevokeAuthorizationResponse, error) + Revoke(context.Context, *MsgRevokeRequest) (*MsgRevokeResponse, error) } // UnimplementedMsgServer can be embedded to have forward compatible implementations. type UnimplementedMsgServer struct { } -func (*UnimplementedMsgServer) GrantAuthorization(ctx context.Context, req *MsgGrantAuthorizationRequest) (*MsgGrantAuthorizationResponse, error) { - return nil, status.Errorf(codes.Unimplemented, "method GrantAuthorization not implemented") +func (*UnimplementedMsgServer) Grantxx(ctx context.Context, req *MsgGrantRequest) (*MsgGrantResponse, error) { + return nil, status.Errorf(codes.Unimplemented, "method Grantxx not implemented") } func (*UnimplementedMsgServer) ExecAuthorized(ctx context.Context, req *MsgExecAuthorizedRequest) (*MsgExecAuthorizedResponse, error) { return nil, status.Errorf(codes.Unimplemented, "method ExecAuthorized not implemented") } -func (*UnimplementedMsgServer) RevokeAuthorization(ctx context.Context, req *MsgRevokeAuthorizationRequest) (*MsgRevokeAuthorizationResponse, error) { - return nil, status.Errorf(codes.Unimplemented, "method RevokeAuthorization not implemented") +func (*UnimplementedMsgServer) Revoke(ctx context.Context, req *MsgRevokeRequest) (*MsgRevokeResponse, error) { + return nil, status.Errorf(codes.Unimplemented, "method Revoke not implemented") } func RegisterMsgServer(s grpc1.Server, srv MsgServer) { s.RegisterService(&_Msg_serviceDesc, srv) } -func _Msg_GrantAuthorization_Handler(srv interface{}, ctx context.Context, dec func(interface{}) error, interceptor grpc.UnaryServerInterceptor) (interface{}, error) { - in := new(MsgGrantAuthorizationRequest) +func _Msg_Grantxx_Handler(srv interface{}, ctx context.Context, dec func(interface{}) error, interceptor grpc.UnaryServerInterceptor) (interface{}, error) { + in := new(MsgGrantRequest) if err := dec(in); err != nil { return nil, err } if interceptor == nil { - return srv.(MsgServer).GrantAuthorization(ctx, in) + return srv.(MsgServer).Grantxx(ctx, in) } info := &grpc.UnaryServerInfo{ Server: srv, - FullMethod: "/cosmos.authz.v1beta1.Msg/GrantAuthorization", + FullMethod: "/cosmos.authz.v1beta1.Msg/Grantxx", } handler := func(ctx context.Context, req interface{}) (interface{}, error) { - return srv.(MsgServer).GrantAuthorization(ctx, req.(*MsgGrantAuthorizationRequest)) + return srv.(MsgServer).Grantxx(ctx, req.(*MsgGrantRequest)) } return interceptor(ctx, in, info, handler) } @@ -516,20 +516,20 @@ func _Msg_ExecAuthorized_Handler(srv interface{}, ctx context.Context, dec func( return interceptor(ctx, in, info, handler) } -func _Msg_RevokeAuthorization_Handler(srv interface{}, ctx context.Context, dec func(interface{}) error, interceptor grpc.UnaryServerInterceptor) (interface{}, error) { - in := new(MsgRevokeAuthorizationRequest) +func _Msg_Revoke_Handler(srv interface{}, ctx context.Context, dec func(interface{}) error, interceptor grpc.UnaryServerInterceptor) (interface{}, error) { + in := new(MsgRevokeRequest) if err := dec(in); err != nil { return nil, err } if interceptor == nil { - return srv.(MsgServer).RevokeAuthorization(ctx, in) + return srv.(MsgServer).Revoke(ctx, in) } info := &grpc.UnaryServerInfo{ Server: srv, - FullMethod: "/cosmos.authz.v1beta1.Msg/RevokeAuthorization", + FullMethod: "/cosmos.authz.v1beta1.Msg/Revoke", } handler := func(ctx context.Context, req interface{}) (interface{}, error) { - return srv.(MsgServer).RevokeAuthorization(ctx, req.(*MsgRevokeAuthorizationRequest)) + return srv.(MsgServer).Revoke(ctx, req.(*MsgRevokeRequest)) } return interceptor(ctx, in, info, handler) } @@ -539,23 +539,23 @@ var _Msg_serviceDesc = grpc.ServiceDesc{ HandlerType: (*MsgServer)(nil), Methods: []grpc.MethodDesc{ { - MethodName: "GrantAuthorization", - Handler: _Msg_GrantAuthorization_Handler, + MethodName: "Grantxx", + Handler: _Msg_Grantxx_Handler, }, { MethodName: "ExecAuthorized", Handler: _Msg_ExecAuthorized_Handler, }, { - MethodName: "RevokeAuthorization", - Handler: _Msg_RevokeAuthorization_Handler, + MethodName: "Revoke", + Handler: _Msg_Revoke_Handler, }, }, Streams: []grpc.StreamDesc{}, Metadata: "cosmos/authz/v1beta1/tx.proto", } -func (m *MsgGrantAuthorizationRequest) Marshal() (dAtA []byte, err error) { +func (m *MsgGrantRequest) Marshal() (dAtA []byte, err error) { size := m.Size() dAtA = make([]byte, size) n, err := m.MarshalToSizedBuffer(dAtA[:size]) @@ -565,12 +565,12 @@ func (m *MsgGrantAuthorizationRequest) Marshal() (dAtA []byte, err error) { return dAtA[:n], nil } -func (m *MsgGrantAuthorizationRequest) MarshalTo(dAtA []byte) (int, error) { +func (m *MsgGrantRequest) MarshalTo(dAtA []byte) (int, error) { size := m.Size() return m.MarshalToSizedBuffer(dAtA[:size]) } -func (m *MsgGrantAuthorizationRequest) MarshalToSizedBuffer(dAtA []byte) (int, error) { +func (m *MsgGrantRequest) MarshalToSizedBuffer(dAtA []byte) (int, error) { i := len(dAtA) _ = i var l int @@ -691,7 +691,7 @@ func (m *MsgExecAuthorizedRequest) MarshalToSizedBuffer(dAtA []byte) (int, error return len(dAtA) - i, nil } -func (m *MsgGrantAuthorizationResponse) Marshal() (dAtA []byte, err error) { +func (m *MsgGrantResponse) Marshal() (dAtA []byte, err error) { size := m.Size() dAtA = make([]byte, size) n, err := m.MarshalToSizedBuffer(dAtA[:size]) @@ -701,12 +701,12 @@ func (m *MsgGrantAuthorizationResponse) Marshal() (dAtA []byte, err error) { return dAtA[:n], nil } -func (m *MsgGrantAuthorizationResponse) MarshalTo(dAtA []byte) (int, error) { +func (m *MsgGrantResponse) MarshalTo(dAtA []byte) (int, error) { size := m.Size() return m.MarshalToSizedBuffer(dAtA[:size]) } -func (m *MsgGrantAuthorizationResponse) MarshalToSizedBuffer(dAtA []byte) (int, error) { +func (m *MsgGrantResponse) MarshalToSizedBuffer(dAtA []byte) (int, error) { i := len(dAtA) _ = i var l int @@ -714,7 +714,7 @@ func (m *MsgGrantAuthorizationResponse) MarshalToSizedBuffer(dAtA []byte) (int, return len(dAtA) - i, nil } -func (m *MsgRevokeAuthorizationRequest) Marshal() (dAtA []byte, err error) { +func (m *MsgRevokeRequest) Marshal() (dAtA []byte, err error) { size := m.Size() dAtA = make([]byte, size) n, err := m.MarshalToSizedBuffer(dAtA[:size]) @@ -724,12 +724,12 @@ func (m *MsgRevokeAuthorizationRequest) Marshal() (dAtA []byte, err error) { return dAtA[:n], nil } -func (m *MsgRevokeAuthorizationRequest) MarshalTo(dAtA []byte) (int, error) { +func (m *MsgRevokeRequest) MarshalTo(dAtA []byte) (int, error) { size := m.Size() return m.MarshalToSizedBuffer(dAtA[:size]) } -func (m *MsgRevokeAuthorizationRequest) MarshalToSizedBuffer(dAtA []byte) (int, error) { +func (m *MsgRevokeRequest) MarshalToSizedBuffer(dAtA []byte) (int, error) { i := len(dAtA) _ = i var l int @@ -758,7 +758,7 @@ func (m *MsgRevokeAuthorizationRequest) MarshalToSizedBuffer(dAtA []byte) (int, return len(dAtA) - i, nil } -func (m *MsgRevokeAuthorizationResponse) Marshal() (dAtA []byte, err error) { +func (m *MsgRevokeResponse) Marshal() (dAtA []byte, err error) { size := m.Size() dAtA = make([]byte, size) n, err := m.MarshalToSizedBuffer(dAtA[:size]) @@ -768,12 +768,12 @@ func (m *MsgRevokeAuthorizationResponse) Marshal() (dAtA []byte, err error) { return dAtA[:n], nil } -func (m *MsgRevokeAuthorizationResponse) MarshalTo(dAtA []byte) (int, error) { +func (m *MsgRevokeResponse) MarshalTo(dAtA []byte) (int, error) { size := m.Size() return m.MarshalToSizedBuffer(dAtA[:size]) } -func (m *MsgRevokeAuthorizationResponse) MarshalToSizedBuffer(dAtA []byte) (int, error) { +func (m *MsgRevokeResponse) MarshalToSizedBuffer(dAtA []byte) (int, error) { i := len(dAtA) _ = i var l int @@ -792,7 +792,7 @@ func encodeVarintTx(dAtA []byte, offset int, v uint64) int { dAtA[offset] = uint8(v) return base } -func (m *MsgGrantAuthorizationRequest) Size() (n int) { +func (m *MsgGrantRequest) Size() (n int) { if m == nil { return 0 } @@ -847,7 +847,7 @@ func (m *MsgExecAuthorizedRequest) Size() (n int) { return n } -func (m *MsgGrantAuthorizationResponse) Size() (n int) { +func (m *MsgGrantResponse) Size() (n int) { if m == nil { return 0 } @@ -856,7 +856,7 @@ func (m *MsgGrantAuthorizationResponse) Size() (n int) { return n } -func (m *MsgRevokeAuthorizationRequest) Size() (n int) { +func (m *MsgRevokeRequest) Size() (n int) { if m == nil { return 0 } @@ -877,7 +877,7 @@ func (m *MsgRevokeAuthorizationRequest) Size() (n int) { return n } -func (m *MsgRevokeAuthorizationResponse) Size() (n int) { +func (m *MsgRevokeResponse) Size() (n int) { if m == nil { return 0 } @@ -892,7 +892,7 @@ func sovTx(x uint64) (n int) { func sozTx(x uint64) (n int) { return sovTx(uint64((x << 1) ^ uint64((int64(x) >> 63)))) } -func (m *MsgGrantAuthorizationRequest) Unmarshal(dAtA []byte) error { +func (m *MsgGrantRequest) Unmarshal(dAtA []byte) error { l := len(dAtA) iNdEx := 0 for iNdEx < l { @@ -915,10 +915,10 @@ func (m *MsgGrantAuthorizationRequest) Unmarshal(dAtA []byte) error { fieldNum := int32(wire >> 3) wireType := int(wire & 0x7) if wireType == 4 { - return fmt.Errorf("proto: MsgGrantAuthorizationRequest: wiretype end group for non-group") + return fmt.Errorf("proto: MsgGrantRequest: wiretype end group for non-group") } if fieldNum <= 0 { - return fmt.Errorf("proto: MsgGrantAuthorizationRequest: illegal tag %d (wire type %d)", fieldNum, wire) + return fmt.Errorf("proto: MsgGrantRequest: illegal tag %d (wire type %d)", fieldNum, wire) } switch fieldNum { case 1: @@ -1277,7 +1277,7 @@ func (m *MsgExecAuthorizedRequest) Unmarshal(dAtA []byte) error { } return nil } -func (m *MsgGrantAuthorizationResponse) Unmarshal(dAtA []byte) error { +func (m *MsgGrantResponse) Unmarshal(dAtA []byte) error { l := len(dAtA) iNdEx := 0 for iNdEx < l { @@ -1300,10 +1300,10 @@ func (m *MsgGrantAuthorizationResponse) Unmarshal(dAtA []byte) error { fieldNum := int32(wire >> 3) wireType := int(wire & 0x7) if wireType == 4 { - return fmt.Errorf("proto: MsgGrantAuthorizationResponse: wiretype end group for non-group") + return fmt.Errorf("proto: MsgGrantResponse: wiretype end group for non-group") } if fieldNum <= 0 { - return fmt.Errorf("proto: MsgGrantAuthorizationResponse: illegal tag %d (wire type %d)", fieldNum, wire) + return fmt.Errorf("proto: MsgGrantResponse: illegal tag %d (wire type %d)", fieldNum, wire) } switch fieldNum { default: @@ -1327,7 +1327,7 @@ func (m *MsgGrantAuthorizationResponse) Unmarshal(dAtA []byte) error { } return nil } -func (m *MsgRevokeAuthorizationRequest) Unmarshal(dAtA []byte) error { +func (m *MsgRevokeRequest) Unmarshal(dAtA []byte) error { l := len(dAtA) iNdEx := 0 for iNdEx < l { @@ -1350,10 +1350,10 @@ func (m *MsgRevokeAuthorizationRequest) Unmarshal(dAtA []byte) error { fieldNum := int32(wire >> 3) wireType := int(wire & 0x7) if wireType == 4 { - return fmt.Errorf("proto: MsgRevokeAuthorizationRequest: wiretype end group for non-group") + return fmt.Errorf("proto: MsgRevokeRequest: wiretype end group for non-group") } if fieldNum <= 0 { - return fmt.Errorf("proto: MsgRevokeAuthorizationRequest: illegal tag %d (wire type %d)", fieldNum, wire) + return fmt.Errorf("proto: MsgRevokeRequest: illegal tag %d (wire type %d)", fieldNum, wire) } switch fieldNum { case 1: @@ -1473,7 +1473,7 @@ func (m *MsgRevokeAuthorizationRequest) Unmarshal(dAtA []byte) error { } return nil } -func (m *MsgRevokeAuthorizationResponse) Unmarshal(dAtA []byte) error { +func (m *MsgRevokeResponse) Unmarshal(dAtA []byte) error { l := len(dAtA) iNdEx := 0 for iNdEx < l { @@ -1496,10 +1496,10 @@ func (m *MsgRevokeAuthorizationResponse) Unmarshal(dAtA []byte) error { fieldNum := int32(wire >> 3) wireType := int(wire & 0x7) if wireType == 4 { - return fmt.Errorf("proto: MsgRevokeAuthorizationResponse: wiretype end group for non-group") + return fmt.Errorf("proto: MsgRevokeResponse: wiretype end group for non-group") } if fieldNum <= 0 { - return fmt.Errorf("proto: MsgRevokeAuthorizationResponse: illegal tag %d (wire type %d)", fieldNum, wire) + return fmt.Errorf("proto: MsgRevokeResponse: illegal tag %d (wire type %d)", fieldNum, wire) } switch fieldNum { default: From 424af8fb44ed6dea0ae400469ff6fc861ca48310 Mon Sep 17 00:00:00 2001 From: Robert Zaremba Date: Tue, 20 Apr 2021 02:25:34 +0200 Subject: [PATCH 09/44] renames wip --- Makefile | 2 +- docs/core/proto-docs.md | 2 +- proto/cosmos/authz/v1beta1/tx.proto | 2 +- x/authz/client/cli/tx.go | 13 ++-- x/authz/genesis.go | 4 +- x/authz/genesis_test.go | 4 +- x/authz/keeper/grpc_query.go | 4 +- x/authz/keeper/grpc_query_test.go | 53 ++++++++-------- x/authz/keeper/keeper.go | 15 ++--- x/authz/keeper/keeper_test.go | 12 ++-- x/authz/keeper/msg_server.go | 18 +++--- x/authz/simulation/decoder_test.go | 2 +- x/authz/simulation/operations.go | 30 ++++----- x/authz/simulation/operations_test.go | 8 +-- x/authz/types/authorization_grant.go | 18 +++--- x/authz/types/codec.go | 4 +- x/authz/types/msgs.go | 38 +++++------ x/authz/types/msgs_test.go | 4 +- x/authz/types/tx.pb.go | 90 +++++++++++++-------------- 19 files changed, 161 insertions(+), 162 deletions(-) diff --git a/Makefile b/Makefile index 630a2a528fb1..812e72696085 100644 --- a/Makefile +++ b/Makefile @@ -374,7 +374,7 @@ proto-all: proto-format proto-lint proto-gen protoContainer=cosmos-proto-gen proto-gen: @echo "Generating Protobuf files" - if docker ps -a --format '{{.Names}}' | grep -Eq "^${protoContainer}"; then docker start $(protoContainer); else docker run --name $(protoContainer) -v $(CURDIR):/workspace --workdir /workspace tendermintdev/sdk-proto-gen:v0.1 sh ./scripts/protocgen.sh; fi + if docker ps -a --format '{{.Names}}' | grep -Eq "^${protoContainer}$$"; then docker start $(protoContainer); else docker run --name $(protoContainer) -v $(CURDIR):/workspace --workdir /workspace tendermintdev/sdk-proto-gen:v0.1 sh ./scripts/protocgen.sh; fi # $(DOCKER) run --rm -v $(CURDIR):/workspace --workdir /workspace tendermintdev/sdk-proto-gen:v0.1 sh ./scripts/protocgen.sh proto-format: diff --git a/docs/core/proto-docs.md b/docs/core/proto-docs.md index b7cb860955e8..7b3d4aa17b5a 100644 --- a/docs/core/proto-docs.md +++ b/docs/core/proto-docs.md @@ -1386,7 +1386,7 @@ Msg defines the authz Msg service. | Method Name | Request Type | Response Type | Description | HTTP Verb | Endpoint | | ----------- | ------------ | ------------- | ------------| ------- | -------- | -| `Grantxx` | [MsgGrantRequest](#cosmos.authz.v1beta1.MsgGrantRequest) | [MsgGrantResponse](#cosmos.authz.v1beta1.MsgGrantResponse) | Grant grants the provided authorization to the grantee on the granter's account with the provided expiration time. | | +| `Grant` | [MsgGrantRequest](#cosmos.authz.v1beta1.MsgGrantRequest) | [MsgGrantResponse](#cosmos.authz.v1beta1.MsgGrantResponse) | Grant grants the provided authorization to the grantee on the granter's account with the provided expiration time. | | | `ExecAuthorized` | [MsgExecAuthorizedRequest](#cosmos.authz.v1beta1.MsgExecAuthorizedRequest) | [MsgExecAuthorizedResponse](#cosmos.authz.v1beta1.MsgExecAuthorizedResponse) | ExecAuthorized attempts to execute the provided messages using authorizations granted to the grantee. Each message should have only one signer corresponding to the granter of the authorization. | | | `Revoke` | [MsgRevokeRequest](#cosmos.authz.v1beta1.MsgRevokeRequest) | [MsgRevokeResponse](#cosmos.authz.v1beta1.MsgRevokeResponse) | Revoke revokes any authorization corresponding to the provided method name on the granter's account that has been granted to the grantee. | | diff --git a/proto/cosmos/authz/v1beta1/tx.proto b/proto/cosmos/authz/v1beta1/tx.proto index bd75ab6a801c..f88bae47e226 100644 --- a/proto/cosmos/authz/v1beta1/tx.proto +++ b/proto/cosmos/authz/v1beta1/tx.proto @@ -12,7 +12,7 @@ option go_package = "github.com/cosmos/cosmos-sdk/x/authz/types"; service Msg { // Grant grants the provided authorization to the grantee on the granter's // account with the provided expiration time. - rpc Grantxx(MsgGrantRequest) returns (MsgGrantResponse); + rpc Grant(MsgGrantRequest) returns (MsgGrantResponse); // ExecAuthorized attempts to execute the provided messages using // authorizations granted to the grantee. Each message should have only diff --git a/x/authz/client/cli/tx.go b/x/authz/client/cli/tx.go index 44df6f5e9aa4..e94a45b442af 100644 --- a/x/authz/client/cli/tx.go +++ b/x/authz/client/cli/tx.go @@ -1,7 +1,6 @@ package cli import ( - "context" "errors" "fmt" "strings" @@ -160,14 +159,14 @@ Examples: return fmt.Errorf("invalid authorization type, %s", args[1]) } - msg, err := types.NewMsgGrantAuthorization(clientCtx.GetFromAddress(), grantee, authorization, time.Unix(exp, 0)) + msg, err := types.NewMsgGrant(clientCtx.GetFromAddress(), grantee, authorization, time.Unix(exp, 0)) if err != nil { return err } svcMsgClientConn := &msgservice.ServiceMsgClientConn{} msgClient := types.NewMsgClient(svcMsgClientConn) - _, err = msgClient.GrantAuthorization(context.Background(), msg) + _, err = msgClient.Grant(cmd.Context(), msg) if err != nil { return err } @@ -207,14 +206,12 @@ Example: } granter := clientCtx.GetFromAddress() - msgAuthorized := args[1] - - msg := types.NewMsgRevokeAuthorization(granter, grantee, msgAuthorized) + msg := types.NewMsgRevoke(granter, grantee, msgAuthorized) svcMsgClientConn := &msgservice.ServiceMsgClientConn{} msgClient := types.NewMsgClient(svcMsgClientConn) - _, err = msgClient.RevokeAuthorization(context.Background(), &msg) + _, err = msgClient.Revoke(cmd.Context(), &msg) if err != nil { return err } @@ -267,7 +264,7 @@ Example: msg := types.NewMsgExecAuthorized(grantee, serviceMsgs) svcMsgClientConn := &msgservice.ServiceMsgClientConn{} msgClient := types.NewMsgClient(svcMsgClientConn) - _, err = msgClient.ExecAuthorized(context.Background(), &msg) + _, err = msgClient.ExecAuthorized(cmd.Context(), &msg) if err != nil { return err } diff --git a/x/authz/genesis.go b/x/authz/genesis.go index 8cce4973b9b4..a2b1cfd3ceb0 100644 --- a/x/authz/genesis.go +++ b/x/authz/genesis.go @@ -23,7 +23,7 @@ func InitGenesis(ctx sdk.Context, keeper keeper.Keeper, data *types.GenesisState panic("expected authorization") } - err = keeper.Grant(ctx, grantee, granter, authorization, entry.Expiration) + err = keeper.GrantX(ctx, grantee, granter, authorization, entry.Expiration) if err != nil { panic(err) } @@ -33,7 +33,7 @@ func InitGenesis(ctx sdk.Context, keeper keeper.Keeper, data *types.GenesisState // ExportGenesis returns a GenesisState for a given context and keeper. func ExportGenesis(ctx sdk.Context, keeper keeper.Keeper) *types.GenesisState { var entries []types.GrantAuthorization - keeper.IterateGrants(ctx, func(granter, grantee sdk.AccAddress, grant types.AuthorizationGrant) bool { + keeper.IterateGrants(ctx, func(granter, grantee sdk.AccAddress, grant types.Grant) bool { exp := grant.Expiration entries = append(entries, types.GrantAuthorization{ Granter: granter.String(), diff --git a/x/authz/genesis_test.go b/x/authz/genesis_test.go index 5e623a60604b..a99ad60b938f 100644 --- a/x/authz/genesis_test.go +++ b/x/authz/genesis_test.go @@ -42,12 +42,12 @@ func (suite *GenesisTestSuite) TestImportExportGenesis() { now := suite.ctx.BlockHeader().Time grant := &bank.SendAuthorization{SpendLimit: coins} - err := suite.keeper.Grant(suite.ctx, granteeAddr, granterAddr, grant, now.Add(time.Hour)) + err := suite.keeper.GrantX(suite.ctx, granteeAddr, granterAddr, grant, now.Add(time.Hour)) suite.Require().NoError(err) genesis := authz.ExportGenesis(suite.ctx, suite.keeper) // Clear keeper - suite.keeper.Revoke(suite.ctx, granteeAddr, granterAddr, grant.MethodName()) + suite.keeper.RevokeX(suite.ctx, granteeAddr, granterAddr, grant.MethodName()) authz.InitGenesis(suite.ctx, suite.keeper, genesis) newGenesis := authz.ExportGenesis(suite.ctx, suite.keeper) diff --git a/x/authz/keeper/grpc_query.go b/x/authz/keeper/grpc_query.go index 0e38b560ac65..9203ab017e7f 100644 --- a/x/authz/keeper/grpc_query.go +++ b/x/authz/keeper/grpc_query.go @@ -18,7 +18,7 @@ import ( var _ types.QueryServer = Keeper{} -// Authorizations implements the Query/Authorizations gRPC method. +// Authorizations implements the Query/Grants gRPC method. func (k Keeper) Grants(c context.Context, req *types.QueryGrantsRequest) (*types.QueryGrantsResponse, error) { if req == nil { return nil, status.Errorf(codes.InvalidArgument, "empty request") @@ -62,7 +62,7 @@ func (k Keeper) Grants(c context.Context, req *types.QueryGrantsRequest) (*types if err != nil { return false, err } - auth1 := auth.GetAuthorizationGrant() + auth1 := auth.GetGrant() if accumulate { msg, ok := auth1.(proto.Message) if !ok { diff --git a/x/authz/keeper/grpc_query_test.go b/x/authz/keeper/grpc_query_test.go index 568cdd4afea0..9a0f42a988b1 100644 --- a/x/authz/keeper/grpc_query_test.go +++ b/x/authz/keeper/grpc_query_test.go @@ -14,43 +14,43 @@ import ( func (suite *TestSuite) TestGRPCQueryAuthorization() { app, ctx, queryClient, addrs := suite.app, suite.ctx, suite.queryClient, suite.addrs var ( - req *types.QueryAuthorizationRequest + req *types.QueryGrantsRequest expAuthorization exported.Authorization ) testCases := []struct { msg string malleate func() expPass bool - postTest func(res *types.QueryAuthorizationResponse) + postTest func(res *types.QueryGrantsResponse) }{ { "fail invalid granter addr", func() { - req = &types.QueryAuthorizationRequest{} + req = &types.QueryGrantsRequest{} }, false, - func(res *types.QueryAuthorizationResponse) {}, + func(res *types.QueryGrantsResponse) {}, }, { "fail invalid grantee addr", func() { - req = &types.QueryAuthorizationRequest{ + req = &types.QueryGrantsRequest{ Granter: addrs[0].String(), } }, false, - func(res *types.QueryAuthorizationResponse) {}, + func(res *types.QueryGrantsResponse) {}, }, { "fail invalid msg-type", func() { - req = &types.QueryAuthorizationRequest{ + req = &types.QueryGrantsRequest{ Granter: addrs[0].String(), Grantee: addrs[1].String(), } }, false, - func(res *types.QueryAuthorizationResponse) {}, + func(res *types.QueryGrantsResponse) {}, }, { "Success", @@ -58,18 +58,19 @@ func (suite *TestSuite) TestGRPCQueryAuthorization() { now := ctx.BlockHeader().Time newCoins := sdk.NewCoins(sdk.NewInt64Coin("steak", 100)) expAuthorization = &banktypes.SendAuthorization{SpendLimit: newCoins} - err := app.AuthzKeeper.Grant(ctx, addrs[0], addrs[1], expAuthorization, now.Add(time.Hour)) + err := app.AuthzKeeper.GrantX(ctx, addrs[0], addrs[1], expAuthorization, now.Add(time.Hour)) suite.Require().NoError(err) - req = &types.QueryAuthorizationRequest{ + req = &types.QueryGrantsRequest{ Granter: addrs[1].String(), Grantee: addrs[0].String(), - MethodName: expAuthorization.MethodName(), + MsgTypeUrl: expAuthorization.MethodName(), } }, true, - func(res *types.QueryAuthorizationResponse) { + func(res *types.QueryGrantsResponse) { var auth exported.Authorization - err := suite.app.InterfaceRegistry().UnpackAny(res.Authorization.Authorization, &auth) + suite.Require().Equal(1, len(res.Grants)) + err := suite.app.InterfaceRegistry().UnpackAny(res.Grants[0].Authorization, &auth) suite.Require().NoError(err) suite.Require().NotNil(auth) suite.Require().Equal(auth.String(), expAuthorization.String()) @@ -79,7 +80,7 @@ func (suite *TestSuite) TestGRPCQueryAuthorization() { for _, testCase := range testCases { suite.Run(fmt.Sprintf("Case %s", testCase.msg), func() { testCase.malleate() - result, err := queryClient.Authorization(gocontext.Background(), req) + result, err := queryClient.Grants(gocontext.Background(), req) if testCase.expPass { suite.Require().NoError(err) } else { @@ -93,32 +94,32 @@ func (suite *TestSuite) TestGRPCQueryAuthorization() { func (suite *TestSuite) TestGRPCQueryAuthorizations() { app, ctx, queryClient, addrs := suite.app, suite.ctx, suite.queryClient, suite.addrs var ( - req *types.QueryAuthorizationsRequest + req *types.QueryGrantsRequest expAuthorization exported.Authorization ) testCases := []struct { msg string malleate func() expPass bool - postTest func(res *types.QueryAuthorizationsResponse) + postTest func(res *types.QueryGrantsResponse) }{ { "fail invalid granter addr", func() { - req = &types.QueryAuthorizationsRequest{} + req = &types.QueryGrantsRequest{} }, false, - func(res *types.QueryAuthorizationsResponse) {}, + func(res *types.QueryGrantsResponse) {}, }, { "fail invalid grantee addr", func() { - req = &types.QueryAuthorizationsRequest{ + req = &types.QueryGrantsRequest{ Granter: addrs[0].String(), } }, false, - func(res *types.QueryAuthorizationsResponse) {}, + func(res *types.QueryGrantsResponse) {}, }, { "Success", @@ -126,18 +127,18 @@ func (suite *TestSuite) TestGRPCQueryAuthorizations() { now := ctx.BlockHeader().Time newCoins := sdk.NewCoins(sdk.NewInt64Coin("steak", 100)) expAuthorization = &banktypes.SendAuthorization{SpendLimit: newCoins} - err := app.AuthzKeeper.Grant(ctx, addrs[0], addrs[1], expAuthorization, now.Add(time.Hour)) + err := app.AuthzKeeper.GrantX(ctx, addrs[0], addrs[1], expAuthorization, now.Add(time.Hour)) suite.Require().NoError(err) - req = &types.QueryAuthorizationsRequest{ + req = &types.QueryGrantsRequest{ Granter: addrs[1].String(), Grantee: addrs[0].String(), } }, true, - func(res *types.QueryAuthorizationsResponse) { + func(res *types.QueryGrantsResponse) { var auth exported.Authorization - suite.Require().Equal(1, len(res.Authorizations)) - err := suite.app.InterfaceRegistry().UnpackAny(res.Authorizations[0].Authorization, &auth) + suite.Require().Equal(1, len(res.Grants)) + err := suite.app.InterfaceRegistry().UnpackAny(res.Grants[0].Authorization, &auth) suite.Require().NoError(err) suite.Require().NotNil(auth) suite.Require().Equal(auth.String(), expAuthorization.String()) @@ -147,7 +148,7 @@ func (suite *TestSuite) TestGRPCQueryAuthorizations() { for _, testCase := range testCases { suite.Run(fmt.Sprintf("Case %s", testCase.msg), func() { testCase.malleate() - result, err := queryClient.Authorizations(gocontext.Background(), req) + result, err := queryClient.Grants(gocontext.Background(), req) if testCase.expPass { suite.Require().NoError(err) } else { diff --git a/x/authz/keeper/keeper.go b/x/authz/keeper/keeper.go index 119c59945614..edabab068d7f 100644 --- a/x/authz/keeper/keeper.go +++ b/x/authz/keeper/keeper.go @@ -93,7 +93,7 @@ func (k Keeper) DispatchActions(ctx sdk.Context, grantee sdk.AccAddress, service return nil, err } if resp.Delete { - k.Revoke(ctx, grantee, granter, serviceMsg.Type()) + k.RevokeX(ctx, grantee, granter, serviceMsg.Type()) } else if resp.Updated != nil { err = k.update(ctx, grantee, granter, resp.Updated) if err != nil { @@ -122,10 +122,11 @@ func (k Keeper) DispatchActions(ctx sdk.Context, grantee sdk.AccAddress, service // Grant method grants the provided authorization to the grantee on the granter's account with the provided expiration // time. If there is an existing authorization grant for the same `sdk.Msg` type, this grant // overwrites that. -func (k Keeper) Grant(ctx sdk.Context, grantee, granter sdk.AccAddress, authorization exported.Authorization, expiration time.Time) error { +// TODO: rename +func (k Keeper) GrantX(ctx sdk.Context, grantee, granter sdk.AccAddress, authorization exported.Authorization, expiration time.Time) error { store := ctx.KVStore(k.storeKey) - grant, err := types.NewAuthorizationGrant(authorization, expiration) + grant, err := types.NewGrant(authorization, expiration) if err != nil { return err } @@ -142,7 +143,7 @@ func (k Keeper) Grant(ctx sdk.Context, grantee, granter sdk.AccAddress, authoriz } // Revoke method revokes any authorization for the provided message type granted to the grantee by the granter. -func (k Keeper) Revoke(ctx sdk.Context, grantee sdk.AccAddress, granter sdk.AccAddress, msgType string) error { +func (k Keeper) RevokeX(ctx sdk.Context, grantee sdk.AccAddress, granter sdk.AccAddress, msgType string) error { store := ctx.KVStore(k.storeKey) grantStoreKey := types.GetAuthorizationStoreKey(grantee, granter, msgType) _, found := k.getAuthorizationGrant(ctx, grantStoreKey) @@ -167,7 +168,7 @@ func (k Keeper) GetAuthorizations(ctx sdk.Context, grantee sdk.AccAddress, grant var authorization types.Grant for ; iter.Valid(); iter.Next() { k.cdc.MustUnmarshalBinaryBare(iter.Value(), &authorization) - authorizations = append(authorizations, authorization.GetAuthorizationGrant()) + authorizations = append(authorizations, authorization.GetGrant()) } return authorizations } @@ -181,11 +182,11 @@ func (k Keeper) GetOrRevokeAuthorization(ctx sdk.Context, grantee sdk.AccAddress return nil, time.Time{} } if grant.Expiration.Before(ctx.BlockHeader().Time) { - k.Revoke(ctx, grantee, granter, msgType) + k.RevokeX(ctx, grantee, granter, msgType) return nil, time.Time{} } - return grant.GetAuthorizationGrant(), grant.Expiration + return grant.GetGrant(), grant.Expiration } // IterateGrants iterates over all authorization grants diff --git a/x/authz/keeper/keeper_test.go b/x/authz/keeper/keeper_test.go index 9c8e0f86db0d..a91d8251a6a6 100644 --- a/x/authz/keeper/keeper_test.go +++ b/x/authz/keeper/keeper_test.go @@ -62,14 +62,14 @@ func (s *TestSuite) TestKeeper() { newCoins := sdk.NewCoins(sdk.NewInt64Coin("steak", 100)) s.T().Log("verify if expired authorization is rejected") x := &banktypes.SendAuthorization{SpendLimit: newCoins} - err := app.AuthzKeeper.Grant(ctx, granterAddr, granteeAddr, x, now.Add(-1*time.Hour)) + err := app.AuthzKeeper.GrantX(ctx, granterAddr, granteeAddr, x, now.Add(-1*time.Hour)) s.Require().NoError(err) authorization, _ = app.AuthzKeeper.GetOrRevokeAuthorization(ctx, granteeAddr, granterAddr, banktypes.SendAuthorization{}.MethodName()) s.Require().Nil(authorization) s.T().Log("verify if authorization is accepted") x = &banktypes.SendAuthorization{SpendLimit: newCoins} - err = app.AuthzKeeper.Grant(ctx, granteeAddr, granterAddr, x, now.Add(time.Hour)) + err = app.AuthzKeeper.GrantX(ctx, granteeAddr, granterAddr, x, now.Add(time.Hour)) s.Require().NoError(err) authorization, _ = app.AuthzKeeper.GetOrRevokeAuthorization(ctx, granteeAddr, granterAddr, banktypes.SendAuthorization{}.MethodName()) s.Require().NotNil(authorization) @@ -84,13 +84,13 @@ func (s *TestSuite) TestKeeper() { s.Require().Nil(authorization) s.T().Log("verify revoke fails with wrong information") - err = app.AuthzKeeper.Revoke(ctx, recipientAddr, granterAddr, banktypes.SendAuthorization{}.MethodName()) + err = app.AuthzKeeper.RevokeX(ctx, recipientAddr, granterAddr, banktypes.SendAuthorization{}.MethodName()) s.Require().Error(err) authorization, _ = app.AuthzKeeper.GetOrRevokeAuthorization(ctx, recipientAddr, granterAddr, banktypes.SendAuthorization{}.MethodName()) s.Require().Nil(authorization) s.T().Log("verify revoke executes with correct information") - err = app.AuthzKeeper.Revoke(ctx, granteeAddr, granterAddr, banktypes.SendAuthorization{}.MethodName()) + err = app.AuthzKeeper.RevokeX(ctx, granteeAddr, granterAddr, banktypes.SendAuthorization{}.MethodName()) s.Require().NoError(err) authorization, _ = app.AuthzKeeper.GetOrRevokeAuthorization(ctx, granteeAddr, granterAddr, banktypes.SendAuthorization{}.MethodName()) s.Require().Nil(authorization) @@ -113,7 +113,7 @@ func (s *TestSuite) TestKeeperIter() { newCoins := sdk.NewCoins(sdk.NewInt64Coin("steak", 100)) s.T().Log("verify if expired authorization is rejected") x := &banktypes.SendAuthorization{SpendLimit: newCoins} - err := app.AuthzKeeper.Grant(ctx, granteeAddr, granterAddr, x, now.Add(-1*time.Hour)) + err := app.AuthzKeeper.GrantX(ctx, granteeAddr, granterAddr, x, now.Add(-1*time.Hour)) s.Require().NoError(err) authorization, _ = app.AuthzKeeper.GetOrRevokeAuthorization(ctx, granteeAddr, granterAddr, "abcd") s.Require().Nil(authorization) @@ -162,7 +162,7 @@ func (s *TestSuite) TestKeeperFees() { s.T().Log("verify dispatch executes with correct information") // grant authorization - err = app.AuthzKeeper.Grant(s.ctx, granteeAddr, granterAddr, &banktypes.SendAuthorization{SpendLimit: smallCoin}, now) + err = app.AuthzKeeper.GrantX(s.ctx, granteeAddr, granterAddr, &banktypes.SendAuthorization{SpendLimit: smallCoin}, now) s.Require().NoError(err) authorization, _ := app.AuthzKeeper.GetOrRevokeAuthorization(s.ctx, granteeAddr, granterAddr, banktypes.SendAuthorization{}.MethodName()) s.Require().NotNil(authorization) diff --git a/x/authz/keeper/msg_server.go b/x/authz/keeper/msg_server.go index 53beb129dfaa..76d34ca2cab8 100644 --- a/x/authz/keeper/msg_server.go +++ b/x/authz/keeper/msg_server.go @@ -10,8 +10,8 @@ import ( var _ types.MsgServer = Keeper{} -// GrantAuthorization implements the MsgServer.GrantAuthorization method. -func (k Keeper) GrantAuthorization(goCtx context.Context, msg *types.MsgGrantAuthorizationRequest) (*types.MsgGrantAuthorizationResponse, error) { +// GrantAuthorization implements the MsgServer.Grant method. +func (k Keeper) Grant(goCtx context.Context, msg *types.MsgGrantRequest) (*types.MsgGrantResponse, error) { ctx := sdk.UnwrapSDKContext(goCtx) grantee, err := sdk.AccAddressFromBech32(msg.Grantee) if err != nil { @@ -22,22 +22,22 @@ func (k Keeper) GrantAuthorization(goCtx context.Context, msg *types.MsgGrantAut return nil, err } - authorization := msg.GetGrantAuthorization() + authorization := msg.GetGrant() // If the granted service Msg doesn't exist, we throw an error. if k.router.Handler(authorization.MethodName()) == nil { return nil, sdkerrors.Wrapf(sdkerrors.ErrInvalidType, "%s doesn't exist.", authorization.MethodName()) } - err = k.Grant(ctx, grantee, granter, authorization, msg.Expiration) + err = k.GrantX(ctx, grantee, granter, authorization, msg.Expiration) if err != nil { return nil, err } - return &types.MsgGrantAuthorizationResponse{}, nil + return &types.MsgGrantResponse{}, nil } -// RevokeAuthorization implements the MsgServer.RevokeAuthorization method. -func (k Keeper) RevokeAuthorization(goCtx context.Context, msg *types.MsgRevokeAuthorizationRequest) (*types.MsgRevokeAuthorizationResponse, error) { +// RevokeAuthorization implements the MsgServer.Revoke method. +func (k Keeper) Revoke(goCtx context.Context, msg *types.MsgRevokeRequest) (*types.MsgRevokeResponse, error) { ctx := sdk.UnwrapSDKContext(goCtx) grantee, err := sdk.AccAddressFromBech32(msg.Grantee) if err != nil { @@ -48,12 +48,12 @@ func (k Keeper) RevokeAuthorization(goCtx context.Context, msg *types.MsgRevokeA return nil, err } - err = k.Revoke(ctx, grantee, granter, msg.MethodName) + err = k.RevokeX(ctx, grantee, granter, msg.MethodName) if err != nil { return nil, err } - return &types.MsgRevokeAuthorizationResponse{}, nil + return &types.MsgRevokeResponse{}, nil } // ExecAuthorized implements the MsgServer.ExecAuthorized method. diff --git a/x/authz/simulation/decoder_test.go b/x/authz/simulation/decoder_test.go index 8b5e71cfbdd7..f7d664b9a823 100644 --- a/x/authz/simulation/decoder_test.go +++ b/x/authz/simulation/decoder_test.go @@ -19,7 +19,7 @@ func TestDecodeStore(t *testing.T) { cdc := simapp.MakeTestEncodingConfig().Marshaler dec := simulation.NewDecodeStore(cdc) - grant, _ := types.NewAuthorizationGrant(banktypes.NewSendAuthorization(sdk.NewCoins(sdk.NewInt64Coin("foo", 123))), time.Now().UTC()) + grant, _ := types.NewGrant(banktypes.NewSendAuthorization(sdk.NewCoins(sdk.NewInt64Coin("foo", 123))), time.Now().UTC()) grantBz, err := cdc.MarshalBinaryBare(&grant) require.NoError(t, err) kvPairs := kv.Pairs{ diff --git a/x/authz/simulation/operations.go b/x/authz/simulation/operations.go index cb368b8afbc0..3be0fc6b9348 100644 --- a/x/authz/simulation/operations.go +++ b/x/authz/simulation/operations.go @@ -21,16 +21,16 @@ import ( // authz message types const ( - TypeMsgGrantAuthorization = "/cosmos.authz.v1beta1.Msg/GrantAuthorization" - TypeMsgRevokeAuthorization = "/cosmos.authz.v1beta1.Msg/RevokeAuthorization" - TypeMsgExecDelegated = "/cosmos.authz.v1beta1.Msg/ExecAuthorized" + TypeMsgGrantAuthorization = "/cosmos.authz.v1beta1.Msg/Grant" + TypeMsgRevokeAuthorization = "/cosmos.authz.v1beta1.Msg/Revoke" + TypeMsgExecDelegated = "/cosmos.authz.v1beta1.Msg/Exec" ) // Simulation operation weights constants const ( - OpWeightMsgGrantAuthorization = "op_weight_msg_grant_authorization" - OpWeightRevokeAuthorization = "op_weight_msg_revoke_authorization" - OpWeightExecAuthorized = "op_weight_msg_execute_authorized" + OpWeightMsgGrantAuthorization = "op_weight_msg_grant" + OpWeightRevokeAuthorization = "op_weight_msg_revoke" + OpWeightExecAuthorized = "op_weight_msg_execute" ) // WeightedOperations returns all the operations from the module with their respective weights @@ -100,7 +100,7 @@ func SimulateMsgGrantAuthorization(ak types.AccountKeeper, bk types.BankKeeper, if spendLimit == nil { return simtypes.NoOpMsg(types.ModuleName, TypeMsgGrantAuthorization, "spend limit is nil"), nil, nil } - msg, err := types.NewMsgGrantAuthorization(granter.Address, grantee.Address, + msg, err := types.NewMsgGrant(granter.Address, grantee.Address, banktype.NewSendAuthorization(spendLimit), blockTime.AddDate(1, 0, 0)) if err != nil { @@ -109,7 +109,7 @@ func SimulateMsgGrantAuthorization(ak types.AccountKeeper, bk types.BankKeeper, txGen := simappparams.MakeTestEncodingConfig().TxConfig svcMsgClientConn := &msgservice.ServiceMsgClientConn{} authzMsgClient := types.NewMsgClient(svcMsgClientConn) - _, err = authzMsgClient.GrantAuthorization(context.Background(), msg) + _, err = authzMsgClient.Grant(context.Background(), msg) if err != nil { return simtypes.NoOpMsg(types.ModuleName, TypeMsgGrantAuthorization, err.Error()), nil, err } @@ -143,10 +143,10 @@ func SimulateMsgRevokeAuthorization(ak types.AccountKeeper, bk types.BankKeeper, r *rand.Rand, app *baseapp.BaseApp, ctx sdk.Context, accs []simtypes.Account, chainID string, ) (simtypes.OperationMsg, []simtypes.FutureOperation, error) { hasGrant := false - var targetGrant types.AuthorizationGrant + var targetGrant types.Grant var granterAddr sdk.AccAddress var granteeAddr sdk.AccAddress - k.IterateGrants(ctx, func(granter, grantee sdk.AccAddress, grant types.AuthorizationGrant) bool { + k.IterateGrants(ctx, func(granter, grantee sdk.AccAddress, grant types.Grant) bool { targetGrant = grant granterAddr = granter granteeAddr = grantee @@ -169,13 +169,13 @@ func SimulateMsgRevokeAuthorization(ak types.AccountKeeper, bk types.BankKeeper, if err != nil { return simtypes.NoOpMsg(types.ModuleName, TypeMsgRevokeAuthorization, "fee error"), nil, err } - auth := targetGrant.GetAuthorizationGrant() - msg := types.NewMsgRevokeAuthorization(granterAddr, granteeAddr, auth.MethodName()) + auth := targetGrant.GetAuthorization() + msg := types.NewMsgRevoke(granterAddr, granteeAddr, auth.GetTypeUrl()) txGen := simappparams.MakeTestEncodingConfig().TxConfig svcMsgClientConn := &msgservice.ServiceMsgClientConn{} authzMsgClient := types.NewMsgClient(svcMsgClientConn) - _, err = authzMsgClient.RevokeAuthorization(context.Background(), &msg) + _, err = authzMsgClient.Revoke(context.Background(), &msg) if err != nil { return simtypes.NoOpMsg(types.ModuleName, TypeMsgRevokeAuthorization, err.Error()), nil, err } @@ -207,10 +207,10 @@ func SimulateMsgExecuteAuthorized(ak types.AccountKeeper, bk types.BankKeeper, k ) (simtypes.OperationMsg, []simtypes.FutureOperation, error) { hasGrant := false - var targetGrant types.AuthorizationGrant + var targetGrant types.Grant var granterAddr sdk.AccAddress var granteeAddr sdk.AccAddress - k.IterateGrants(ctx, func(granter, grantee sdk.AccAddress, grant types.AuthorizationGrant) bool { + k.IterateGrants(ctx, func(granter, grantee sdk.AccAddress, grant types.Grant) bool { targetGrant = grant granterAddr = granter granteeAddr = grantee diff --git a/x/authz/simulation/operations_test.go b/x/authz/simulation/operations_test.go index 92679307352e..7a2cd5e0d462 100644 --- a/x/authz/simulation/operations_test.go +++ b/x/authz/simulation/operations_test.go @@ -110,7 +110,7 @@ func (suite *SimTestSuite) TestSimulateGrantAuthorization() { operationMsg, futureOperations, err := op(r, suite.app.BaseApp, ctx, accounts, "") suite.Require().NoError(err) - var msg types.MsgGrantAuthorizationRequest + var msg types.MsgGrantRequest suite.app.AppCodec().UnmarshalJSON(operationMsg.Msg, &msg) suite.Require().True(operationMsg.OK) suite.Require().Equal(granter.Address.String(), msg.Granter) @@ -139,7 +139,7 @@ func (suite *SimTestSuite) TestSimulateRevokeAuthorization() { grantee := accounts[1] authorization := banktypes.NewSendAuthorization(initCoins) - err := suite.app.AuthzKeeper.Grant(suite.ctx, grantee.Address, granter.Address, authorization, time.Now().Add(30*time.Hour)) + err := suite.app.AuthzKeeper.GrantX(suite.ctx, grantee.Address, granter.Address, authorization, time.Now().Add(30*time.Hour)) suite.Require().NoError(err) // execute operation @@ -147,7 +147,7 @@ func (suite *SimTestSuite) TestSimulateRevokeAuthorization() { operationMsg, futureOperations, err := op(r, suite.app.BaseApp, suite.ctx, accounts, "") suite.Require().NoError(err) - var msg types.MsgRevokeAuthorizationRequest + var msg types.MsgRevokeRequest suite.app.AppCodec().UnmarshalJSON(operationMsg.Msg, &msg) suite.Require().True(operationMsg.OK) @@ -174,7 +174,7 @@ func (suite *SimTestSuite) TestSimulateExecAuthorization() { grantee := accounts[1] authorization := banktypes.NewSendAuthorization(initCoins) - err := suite.app.AuthzKeeper.Grant(suite.ctx, grantee.Address, granter.Address, authorization, time.Now().Add(30*time.Hour)) + err := suite.app.AuthzKeeper.GrantX(suite.ctx, grantee.Address, granter.Address, authorization, time.Now().Add(30*time.Hour)) suite.Require().NoError(err) // execute operation diff --git a/x/authz/types/authorization_grant.go b/x/authz/types/authorization_grant.go index 03a83bdefd5c..a9c013f7ea57 100644 --- a/x/authz/types/authorization_grant.go +++ b/x/authz/types/authorization_grant.go @@ -10,19 +10,19 @@ import ( "github.com/cosmos/cosmos-sdk/x/authz/exported" ) -// NewAuthorizationGrant returns new AuthrizationGrant -func NewAuthorizationGrant(authorization exported.Authorization, expiration time.Time) (AuthorizationGrant, error) { - auth := AuthorizationGrant{ +// NewGrant returns new AuthrizationGrant +func NewGrant(authorization exported.Authorization, expiration time.Time) (Grant, error) { + auth := Grant{ Expiration: expiration, } msg, ok := authorization.(proto.Message) if !ok { - return AuthorizationGrant{}, sdkerrors.Wrapf(sdkerrors.ErrPackAny, "cannot proto marshal %T", authorization) + return Grant{}, sdkerrors.Wrapf(sdkerrors.ErrPackAny, "cannot proto marshal %T", authorization) } any, err := types.NewAnyWithValue(msg) if err != nil { - return AuthorizationGrant{}, err + return Grant{}, err } auth.Authorization = any @@ -31,17 +31,17 @@ func NewAuthorizationGrant(authorization exported.Authorization, expiration time } var ( - _ types.UnpackInterfacesMessage = &AuthorizationGrant{} + _ types.UnpackInterfacesMessage = &Grant{} ) // UnpackInterfaces implements UnpackInterfacesMessage.UnpackInterfaces -func (auth AuthorizationGrant) UnpackInterfaces(unpacker types.AnyUnpacker) error { +func (auth Grant) UnpackInterfaces(unpacker types.AnyUnpacker) error { var authorization exported.Authorization return unpacker.UnpackAny(auth.Authorization, &authorization) } -// GetAuthorizationGrant returns the cached value from the AuthorizationGrant.Authorization if present. -func (auth AuthorizationGrant) GetAuthorizationGrant() exported.Authorization { +// GetGrant returns the cached value from the Grant.Authorization if present. +func (auth Grant) GetGrant() exported.Authorization { authorization, ok := auth.Authorization.GetCachedValue().(exported.Authorization) if !ok { return nil diff --git a/x/authz/types/codec.go b/x/authz/types/codec.go index c6119f2a0bbb..d10382c336a7 100644 --- a/x/authz/types/codec.go +++ b/x/authz/types/codec.go @@ -12,8 +12,8 @@ import ( // RegisterInterfaces registers the interfaces types with the interface registry func RegisterInterfaces(registry types.InterfaceRegistry) { registry.RegisterImplementations((*sdk.MsgRequest)(nil), - &MsgGrantAuthorizationRequest{}, - &MsgRevokeAuthorizationRequest{}, + &MsgGrantRequest{}, + &MsgRevokeRequest{}, &MsgExecAuthorizedRequest{}, ) diff --git a/x/authz/types/msgs.go b/x/authz/types/msgs.go index 0b72d1a7e869..48319ea0d649 100644 --- a/x/authz/types/msgs.go +++ b/x/authz/types/msgs.go @@ -12,18 +12,18 @@ import ( ) var ( - _ sdk.MsgRequest = &MsgGrantAuthorizationRequest{} - _ sdk.MsgRequest = &MsgRevokeAuthorizationRequest{} + _ sdk.MsgRequest = &MsgGrantRequest{} + _ sdk.MsgRequest = &MsgRevokeRequest{} _ sdk.MsgRequest = &MsgExecAuthorizedRequest{} - _ types.UnpackInterfacesMessage = &MsgGrantAuthorizationRequest{} + _ types.UnpackInterfacesMessage = &MsgGrantRequest{} _ types.UnpackInterfacesMessage = &MsgExecAuthorizedRequest{} ) -// NewMsgGrantAuthorization creates a new MsgGrantAuthorization +// NewMsgGrant creates a new MsgGrant //nolint:interfacer -func NewMsgGrantAuthorization(granter sdk.AccAddress, grantee sdk.AccAddress, authorization exported.Authorization, expiration time.Time) (*MsgGrantAuthorizationRequest, error) { - m := &MsgGrantAuthorizationRequest{ +func NewMsgGrant(granter sdk.AccAddress, grantee sdk.AccAddress, authorization exported.Authorization, expiration time.Time) (*MsgGrantRequest, error) { + m := &MsgGrantRequest{ Granter: granter.String(), Grantee: grantee.String(), Expiration: expiration, @@ -36,7 +36,7 @@ func NewMsgGrantAuthorization(granter sdk.AccAddress, grantee sdk.AccAddress, au } // GetSigners implements Msg -func (msg MsgGrantAuthorizationRequest) GetSigners() []sdk.AccAddress { +func (msg MsgGrantRequest) GetSigners() []sdk.AccAddress { granter, err := sdk.AccAddressFromBech32(msg.Granter) if err != nil { panic(err) @@ -45,7 +45,7 @@ func (msg MsgGrantAuthorizationRequest) GetSigners() []sdk.AccAddress { } // ValidateBasic implements Msg -func (msg MsgGrantAuthorizationRequest) ValidateBasic() error { +func (msg MsgGrantRequest) ValidateBasic() error { granter, err := sdk.AccAddressFromBech32(msg.Granter) if err != nil { return sdkerrors.Wrap(sdkerrors.ErrInvalidAddress, "invalid granter address") @@ -70,8 +70,8 @@ func (msg MsgGrantAuthorizationRequest) ValidateBasic() error { return authorization.ValidateBasic() } -// GetGrantAuthorization returns the cache value from the MsgGrantAuthorization.Authorization if present. -func (msg *MsgGrantAuthorizationRequest) GetGrantAuthorization() exported.Authorization { +// GetGrant returns the cache value from the MsgGrant.Authorization if present. +func (msg *MsgGrantRequest) GetGrant() exported.Authorization { authorization, ok := msg.Authorization.GetCachedValue().(exported.Authorization) if !ok { return nil @@ -79,8 +79,8 @@ func (msg *MsgGrantAuthorizationRequest) GetGrantAuthorization() exported.Author return authorization } -// SetAuthorization converts Authorization to any and adds it to MsgGrantAuthorization.Authorization. -func (msg *MsgGrantAuthorizationRequest) SetAuthorization(authorization exported.Authorization) error { +// SetAuthorization converts Authorization to any and adds it to MsgGrant.Authorization. +func (msg *MsgGrantRequest) SetAuthorization(authorization exported.Authorization) error { m, ok := authorization.(proto.Message) if !ok { return sdkerrors.Wrapf(sdkerrors.ErrPackAny, "can't proto marshal %T", m) @@ -107,23 +107,23 @@ func (msg MsgExecAuthorizedRequest) UnpackInterfaces(unpacker types.AnyUnpacker) } // UnpackInterfaces implements UnpackInterfacesMessage.UnpackInterfaces -func (msg MsgGrantAuthorizationRequest) UnpackInterfaces(unpacker types.AnyUnpacker) error { +func (msg MsgGrantRequest) UnpackInterfaces(unpacker types.AnyUnpacker) error { var authorization exported.Authorization return unpacker.UnpackAny(msg.Authorization, &authorization) } -// NewMsgRevokeAuthorization creates a new MsgRevokeAuthorization +// NewMsgRevoke creates a new MsgRevoke //nolint:interfacer -func NewMsgRevokeAuthorization(granter sdk.AccAddress, grantee sdk.AccAddress, methodName string) MsgRevokeAuthorizationRequest { - return MsgRevokeAuthorizationRequest{ +func NewMsgRevoke(granter sdk.AccAddress, grantee sdk.AccAddress, msgTypeURL string) MsgRevokeRequest { + return MsgRevokeRequest{ Granter: granter.String(), Grantee: grantee.String(), - MethodName: methodName, + MethodName: msgTypeURL, } } // GetSigners implements Msg -func (msg MsgRevokeAuthorizationRequest) GetSigners() []sdk.AccAddress { +func (msg MsgRevokeRequest) GetSigners() []sdk.AccAddress { granter, err := sdk.AccAddressFromBech32(msg.Granter) if err != nil { panic(err) @@ -132,7 +132,7 @@ func (msg MsgRevokeAuthorizationRequest) GetSigners() []sdk.AccAddress { } // ValidateBasic implements MsgRequest.ValidateBasic -func (msg MsgRevokeAuthorizationRequest) ValidateBasic() error { +func (msg MsgRevokeRequest) ValidateBasic() error { granter, err := sdk.AccAddressFromBech32(msg.Granter) if err != nil { return sdkerrors.Wrap(sdkerrors.ErrInvalidAddress, "invalid granter address") diff --git a/x/authz/types/msgs_test.go b/x/authz/types/msgs_test.go index c27c750b0d93..fcb875e60625 100644 --- a/x/authz/types/msgs_test.go +++ b/x/authz/types/msgs_test.go @@ -61,7 +61,7 @@ func TestMsgRevokeAuthorization(t *testing.T) { {"valid test case", granter, grantee, "hello", true}, } for i, tc := range tests { - msg := types.NewMsgRevokeAuthorization(tc.granter, tc.grantee, tc.msgType) + msg := types.NewMsgRevoke(tc.granter, tc.grantee, tc.msgType) if tc.expectPass { require.NoError(t, msg.ValidateBasic(), "test: %v", i) } else { @@ -87,7 +87,7 @@ func TestMsgGrantAuthorization(t *testing.T) { {"past time", granter, grantee, &banktypes.SendAuthorization{SpendLimit: coinsPos}, time.Now().AddDate(0, 0, -1), false, false}, } for i, tc := range tests { - msg, err := types.NewMsgGrantAuthorization( + msg, err := types.NewMsgGrant( tc.granter, tc.grantee, tc.authorization, tc.expiration, ) if !tc.expectErr { diff --git a/x/authz/types/tx.pb.go b/x/authz/types/tx.pb.go index 6b3c48cf677e..58ece2f87614 100644 --- a/x/authz/types/tx.pb.go +++ b/x/authz/types/tx.pb.go @@ -353,40 +353,40 @@ func init() { func init() { proto.RegisterFile("cosmos/authz/v1beta1/tx.proto", fileDescriptor_3ceddab7d8589ad1) } var fileDescriptor_3ceddab7d8589ad1 = []byte{ - // 515 bytes of a gzipped FileDescriptorProto + // 514 bytes of a gzipped FileDescriptorProto 0x1f, 0x8b, 0x08, 0x00, 0x00, 0x00, 0x00, 0x00, 0x02, 0xff, 0xa4, 0x54, 0xc1, 0x6e, 0xd3, 0x40, - 0x10, 0x8d, 0x93, 0x2a, 0xa5, 0x1b, 0x15, 0xe8, 0x92, 0x83, 0x63, 0x09, 0x27, 0x32, 0x02, 0x22, - 0xa4, 0xae, 0xd5, 0x70, 0xe1, 0xda, 0xa8, 0x88, 0x53, 0x38, 0xac, 0x40, 0x02, 0x0e, 0x54, 0xeb, - 0x64, 0xd8, 0x58, 0xad, 0xbd, 0xa9, 0x77, 0x53, 0x39, 0xfd, 0x8a, 0xfe, 0x08, 0x37, 0x3e, 0xa2, - 0xe2, 0xd4, 0x23, 0xe2, 0x00, 0x28, 0xf9, 0x11, 0xe4, 0xdd, 0x0d, 0x4d, 0x42, 0xa2, 0x22, 0x71, - 0xb2, 0x67, 0xde, 0xdb, 0x99, 0xb7, 0x6f, 0xc6, 0x46, 0x0f, 0xfb, 0x42, 0x26, 0x42, 0x86, 0x6c, - 0xac, 0x86, 0x17, 0xe1, 0xf9, 0x41, 0x04, 0x8a, 0x1d, 0x84, 0x2a, 0x27, 0xa3, 0x4c, 0x28, 0x81, - 0xeb, 0x06, 0x26, 0x1a, 0x26, 0x16, 0xf6, 0x1a, 0x26, 0x7b, 0xac, 0x39, 0xa1, 0xa5, 0xe8, 0xc0, - 0xab, 0x73, 0xc1, 0x85, 0xc9, 0x17, 0x6f, 0x36, 0xdb, 0xe4, 0x42, 0xf0, 0x53, 0x08, 0x75, 0x14, - 0x8d, 0x3f, 0x85, 0x2a, 0x4e, 0x40, 0x2a, 0x96, 0x8c, 0x2c, 0xa1, 0xb1, 0x4a, 0x60, 0xe9, 0xc4, - 0x42, 0x8f, 0xac, 0xc2, 0x88, 0x49, 0x08, 0x59, 0xd4, 0x8f, 0xff, 0xa8, 0x2c, 0x02, 0x43, 0x0a, - 0xbe, 0x3b, 0xe8, 0x5e, 0x4f, 0xf2, 0x57, 0x19, 0x4b, 0x15, 0x85, 0xb3, 0x31, 0x48, 0x85, 0x5d, - 0xb4, 0xcd, 0x8b, 0x18, 0x32, 0xd7, 0x69, 0x39, 0xed, 0x1d, 0x3a, 0x0f, 0x6f, 0x10, 0x70, 0xcb, - 0x8b, 0x08, 0xe0, 0x1e, 0xda, 0x2d, 0xae, 0x2a, 0xb2, 0xf8, 0x82, 0xa9, 0x58, 0xa4, 0x6e, 0xa5, - 0xe5, 0xb4, 0x6b, 0x9d, 0x3a, 0x31, 0xfa, 0xc8, 0x5c, 0x1f, 0x39, 0x4c, 0x27, 0xdd, 0xbd, 0xaf, - 0x5f, 0xf6, 0x77, 0x0f, 0x17, 0xe9, 0x74, 0xf9, 0x34, 0x3e, 0x42, 0x08, 0xf2, 0x51, 0x9c, 0x99, - 0x5a, 0x5b, 0xba, 0x96, 0xf7, 0x57, 0xad, 0x37, 0x73, 0x33, 0xba, 0x77, 0xae, 0x7e, 0x34, 0x4b, - 0x97, 0x3f, 0x9b, 0x0e, 0x5d, 0x38, 0x17, 0xbc, 0x45, 0x8d, 0x9e, 0xe4, 0x2f, 0x73, 0xe8, 0xcf, - 0x9b, 0xc1, 0x80, 0x82, 0x1c, 0x89, 0x54, 0x02, 0x7e, 0x81, 0xaa, 0x19, 0xc8, 0xf1, 0xa9, 0xd2, - 0x97, 0xac, 0x75, 0x5a, 0xc4, 0xce, 0xa3, 0xf0, 0x8b, 0x68, 0x8b, 0xac, 0x5f, 0x84, 0x6a, 0x1e, - 0xb5, 0xfc, 0xe0, 0x23, 0x72, 0xd7, 0x94, 0x5d, 0xf1, 0x0e, 0x96, 0xbd, 0x03, 0xdc, 0x46, 0x5b, - 0x89, 0xe4, 0xd2, 0x2d, 0xb7, 0x2a, 0x9b, 0x8c, 0xa1, 0x9a, 0x11, 0x60, 0x74, 0xff, 0x66, 0x24, - 0x46, 0x6d, 0xc0, 0x75, 0x8e, 0xc2, 0xb9, 0x38, 0x81, 0xff, 0x99, 0x53, 0x13, 0xd5, 0x12, 0x50, - 0x43, 0x31, 0x38, 0x4e, 0x59, 0x02, 0x7a, 0x4a, 0x3b, 0x14, 0x99, 0xd4, 0x6b, 0x96, 0x40, 0xf0, - 0x00, 0xed, 0x2d, 0x34, 0x32, 0xdd, 0x3b, 0x9f, 0xcb, 0xa8, 0xd2, 0x93, 0x1c, 0xbf, 0x43, 0xdb, - 0x5a, 0x56, 0x9e, 0xe3, 0xc7, 0x64, 0xdd, 0x86, 0x93, 0x95, 0x5d, 0xf2, 0x9e, 0xdc, 0x46, 0xb3, - 0xd3, 0x38, 0x43, 0x77, 0x97, 0x0d, 0xc5, 0x64, 0xe3, 0xc9, 0xb5, 0xce, 0x7b, 0xe1, 0x3f, 0xf3, - 0x6d, 0xcb, 0xf7, 0xa8, 0x6a, 0xae, 0x89, 0x37, 0x8b, 0x5c, 0x32, 0xdc, 0x7b, 0x7a, 0x2b, 0xcf, - 0x94, 0xee, 0x1e, 0x5d, 0x4d, 0x7d, 0xe7, 0x7a, 0xea, 0x3b, 0xbf, 0xa6, 0xbe, 0x73, 0x39, 0xf3, - 0x4b, 0xd7, 0x33, 0xbf, 0xf4, 0x6d, 0xe6, 0x97, 0x3e, 0x3c, 0xe3, 0xb1, 0x1a, 0x8e, 0x23, 0xd2, - 0x17, 0x89, 0xfd, 0xfe, 0xed, 0x63, 0x5f, 0x0e, 0x4e, 0xc2, 0xdc, 0xfe, 0x4e, 0xd4, 0x64, 0x04, - 0x32, 0xaa, 0xea, 0xdd, 0x78, 0xfe, 0x3b, 0x00, 0x00, 0xff, 0xff, 0xa6, 0xf4, 0x13, 0x32, 0x6b, - 0x04, 0x00, 0x00, + 0x10, 0x8d, 0x93, 0x12, 0xe8, 0x46, 0x05, 0xba, 0xe4, 0xe0, 0x58, 0xc2, 0x89, 0x8c, 0x80, 0x08, + 0xa9, 0x6b, 0x35, 0x5c, 0xb8, 0x36, 0x2a, 0xe2, 0x14, 0x0e, 0x2b, 0x40, 0x82, 0x03, 0xd5, 0x3a, + 0x19, 0x36, 0x56, 0x6b, 0x6f, 0xea, 0x5d, 0x57, 0x49, 0xbf, 0xa2, 0xff, 0xc1, 0x95, 0x8f, 0xa8, + 0x38, 0xf5, 0x88, 0x38, 0x00, 0x4a, 0x7e, 0x04, 0x79, 0x77, 0x43, 0x93, 0x90, 0xa8, 0x48, 0x9c, + 0xec, 0x99, 0xf7, 0x76, 0xe6, 0xed, 0x9b, 0xb1, 0xd1, 0xc3, 0xbe, 0x90, 0x89, 0x90, 0x21, 0xcb, + 0xd5, 0xf0, 0x3c, 0x3c, 0xdb, 0x8f, 0x40, 0xb1, 0xfd, 0x50, 0x8d, 0xc9, 0x28, 0x13, 0x4a, 0xe0, + 0xba, 0x81, 0x89, 0x86, 0x89, 0x85, 0xbd, 0x86, 0xc9, 0x1e, 0x69, 0x4e, 0x68, 0x29, 0x3a, 0xf0, + 0xea, 0x5c, 0x70, 0x61, 0xf2, 0xc5, 0x9b, 0xcd, 0x36, 0xb9, 0x10, 0xfc, 0x04, 0x42, 0x1d, 0x45, + 0xf9, 0xa7, 0x50, 0xc5, 0x09, 0x48, 0xc5, 0x92, 0x91, 0x25, 0x34, 0x56, 0x09, 0x2c, 0x9d, 0x58, + 0xe8, 0x91, 0x55, 0x18, 0x31, 0x09, 0x21, 0x8b, 0xfa, 0xf1, 0x1f, 0x95, 0x45, 0x60, 0x48, 0xc1, + 0x77, 0x07, 0xdd, 0xeb, 0x49, 0xfe, 0x2a, 0x63, 0xa9, 0xa2, 0x70, 0x9a, 0x83, 0x54, 0xd8, 0x45, + 0xb7, 0x79, 0x11, 0x43, 0xe6, 0x3a, 0x2d, 0xa7, 0xbd, 0x4d, 0xe7, 0xe1, 0x35, 0x02, 0x6e, 0x79, + 0x11, 0x01, 0xdc, 0x43, 0x3b, 0xc5, 0x55, 0x45, 0x16, 0x9f, 0x33, 0x15, 0x8b, 0xd4, 0xad, 0xb4, + 0x9c, 0x76, 0xad, 0x53, 0x27, 0x46, 0x1f, 0x99, 0xeb, 0x23, 0x07, 0xe9, 0xa4, 0xbb, 0xfb, 0xf5, + 0xcb, 0xde, 0xce, 0xc1, 0x22, 0x9d, 0x2e, 0x9f, 0xc6, 0x87, 0x08, 0xc1, 0x78, 0x14, 0x67, 0xa6, + 0xd6, 0x96, 0xae, 0xe5, 0xfd, 0x55, 0xeb, 0xcd, 0xdc, 0x8c, 0xee, 0x9d, 0xcb, 0x1f, 0xcd, 0xd2, + 0xc5, 0xcf, 0xa6, 0x43, 0x17, 0xce, 0x05, 0x6f, 0x51, 0xa3, 0x27, 0xf9, 0xcb, 0x31, 0xf4, 0xe7, + 0xcd, 0x60, 0x40, 0x41, 0x8e, 0x44, 0x2a, 0x01, 0xbf, 0x40, 0xd5, 0x0c, 0x64, 0x7e, 0xa2, 0xf4, + 0x25, 0x6b, 0x9d, 0x16, 0xb1, 0xf3, 0x28, 0xfc, 0x22, 0xda, 0x22, 0xeb, 0x17, 0xa1, 0x9a, 0x47, + 0x2d, 0x3f, 0xf8, 0x88, 0xdc, 0x35, 0x65, 0x57, 0xbc, 0x83, 0x65, 0xef, 0x00, 0xb7, 0xd1, 0x56, + 0x22, 0xb9, 0x74, 0xcb, 0xad, 0xca, 0x26, 0x63, 0xa8, 0x66, 0x04, 0x18, 0xdd, 0xbf, 0x1e, 0x89, + 0x51, 0x1b, 0x70, 0x9d, 0xa3, 0x70, 0x26, 0x8e, 0xe1, 0x7f, 0xe6, 0xd4, 0x44, 0xb5, 0x04, 0xd4, + 0x50, 0x0c, 0x8e, 0x52, 0x96, 0x80, 0x9e, 0xd2, 0x36, 0x45, 0x26, 0xf5, 0x9a, 0x25, 0x10, 0x3c, + 0x40, 0xbb, 0x0b, 0x8d, 0x4c, 0xf7, 0xce, 0xe7, 0x32, 0xaa, 0xf4, 0x24, 0xc7, 0xef, 0xd0, 0x2d, + 0x2d, 0x0b, 0x3f, 0x26, 0xeb, 0xf6, 0x9b, 0xac, 0x6c, 0x92, 0xf7, 0xe4, 0x26, 0x9a, 0x9d, 0xc5, + 0x29, 0xba, 0xbb, 0x6c, 0x27, 0x26, 0x1b, 0x4f, 0xae, 0xf5, 0xdd, 0x0b, 0xff, 0x99, 0x6f, 0x5b, + 0xbe, 0x47, 0x55, 0x73, 0x49, 0xbc, 0x59, 0xe4, 0x92, 0xdd, 0xde, 0xd3, 0x1b, 0x79, 0xa6, 0x74, + 0xf7, 0xf0, 0x72, 0xea, 0x3b, 0x57, 0x53, 0xdf, 0xf9, 0x35, 0xf5, 0x9d, 0x8b, 0x99, 0x5f, 0xba, + 0x9a, 0xf9, 0xa5, 0x6f, 0x33, 0xbf, 0xf4, 0xe1, 0x19, 0x8f, 0xd5, 0x30, 0x8f, 0x48, 0x5f, 0x24, + 0xf6, 0xeb, 0xb7, 0x8f, 0x3d, 0x39, 0x38, 0x0e, 0xc7, 0xf6, 0x67, 0xa2, 0x26, 0x23, 0x90, 0x51, + 0x55, 0x6f, 0xc6, 0xf3, 0xdf, 0x01, 0x00, 0x00, 0xff, 0xff, 0xe8, 0x5f, 0x9e, 0x5c, 0x69, 0x04, + 0x00, 0x00, } // Reference imports to suppress errors if they are not otherwise used. @@ -403,7 +403,7 @@ const _ = grpc.SupportPackageIsVersion4 type MsgClient interface { // Grant grants the provided authorization to the grantee on the granter's // account with the provided expiration time. - Grantxx(ctx context.Context, in *MsgGrantRequest, opts ...grpc.CallOption) (*MsgGrantResponse, error) + Grant(ctx context.Context, in *MsgGrantRequest, opts ...grpc.CallOption) (*MsgGrantResponse, error) // ExecAuthorized attempts to execute the provided messages using // authorizations granted to the grantee. Each message should have only // one signer corresponding to the granter of the authorization. @@ -421,9 +421,9 @@ func NewMsgClient(cc grpc1.ClientConn) MsgClient { return &msgClient{cc} } -func (c *msgClient) Grantxx(ctx context.Context, in *MsgGrantRequest, opts ...grpc.CallOption) (*MsgGrantResponse, error) { +func (c *msgClient) Grant(ctx context.Context, in *MsgGrantRequest, opts ...grpc.CallOption) (*MsgGrantResponse, error) { out := new(MsgGrantResponse) - err := c.cc.Invoke(ctx, "/cosmos.authz.v1beta1.Msg/Grantxx", in, out, opts...) + err := c.cc.Invoke(ctx, "/cosmos.authz.v1beta1.Msg/Grant", in, out, opts...) if err != nil { return nil, err } @@ -452,7 +452,7 @@ func (c *msgClient) Revoke(ctx context.Context, in *MsgRevokeRequest, opts ...gr type MsgServer interface { // Grant grants the provided authorization to the grantee on the granter's // account with the provided expiration time. - Grantxx(context.Context, *MsgGrantRequest) (*MsgGrantResponse, error) + Grant(context.Context, *MsgGrantRequest) (*MsgGrantResponse, error) // ExecAuthorized attempts to execute the provided messages using // authorizations granted to the grantee. Each message should have only // one signer corresponding to the granter of the authorization. @@ -466,8 +466,8 @@ type MsgServer interface { type UnimplementedMsgServer struct { } -func (*UnimplementedMsgServer) Grantxx(ctx context.Context, req *MsgGrantRequest) (*MsgGrantResponse, error) { - return nil, status.Errorf(codes.Unimplemented, "method Grantxx not implemented") +func (*UnimplementedMsgServer) Grant(ctx context.Context, req *MsgGrantRequest) (*MsgGrantResponse, error) { + return nil, status.Errorf(codes.Unimplemented, "method Grant not implemented") } func (*UnimplementedMsgServer) ExecAuthorized(ctx context.Context, req *MsgExecAuthorizedRequest) (*MsgExecAuthorizedResponse, error) { return nil, status.Errorf(codes.Unimplemented, "method ExecAuthorized not implemented") @@ -480,20 +480,20 @@ func RegisterMsgServer(s grpc1.Server, srv MsgServer) { s.RegisterService(&_Msg_serviceDesc, srv) } -func _Msg_Grantxx_Handler(srv interface{}, ctx context.Context, dec func(interface{}) error, interceptor grpc.UnaryServerInterceptor) (interface{}, error) { +func _Msg_Grant_Handler(srv interface{}, ctx context.Context, dec func(interface{}) error, interceptor grpc.UnaryServerInterceptor) (interface{}, error) { in := new(MsgGrantRequest) if err := dec(in); err != nil { return nil, err } if interceptor == nil { - return srv.(MsgServer).Grantxx(ctx, in) + return srv.(MsgServer).Grant(ctx, in) } info := &grpc.UnaryServerInfo{ Server: srv, - FullMethod: "/cosmos.authz.v1beta1.Msg/Grantxx", + FullMethod: "/cosmos.authz.v1beta1.Msg/Grant", } handler := func(ctx context.Context, req interface{}) (interface{}, error) { - return srv.(MsgServer).Grantxx(ctx, req.(*MsgGrantRequest)) + return srv.(MsgServer).Grant(ctx, req.(*MsgGrantRequest)) } return interceptor(ctx, in, info, handler) } @@ -539,8 +539,8 @@ var _Msg_serviceDesc = grpc.ServiceDesc{ HandlerType: (*MsgServer)(nil), Methods: []grpc.MethodDesc{ { - MethodName: "Grantxx", - Handler: _Msg_Grantxx_Handler, + MethodName: "Grant", + Handler: _Msg_Grant_Handler, }, { MethodName: "ExecAuthorized", From 3876db212d7ec0d2983703c8797690ccbd0802b8 Mon Sep 17 00:00:00 2001 From: Robert Zaremba Date: Tue, 20 Apr 2021 03:25:14 +0200 Subject: [PATCH 10/44] refactoring --- proto/cosmos/authz/v1beta1/tx.proto | 14 +-- x/authz/client/cli/tx.go | 2 +- x/authz/keeper/keeper_test.go | 4 +- x/authz/keeper/msg_server.go | 8 +- x/authz/simulation/operations.go | 2 +- x/authz/simulation/operations_test.go | 4 +- x/authz/types/codec.go | 2 +- x/authz/types/msgs.go | 22 ++--- x/authz/types/msgs_test.go | 2 +- x/authz/types/tx.pb.go | 120 +++++++++++++------------- 10 files changed, 89 insertions(+), 91 deletions(-) diff --git a/proto/cosmos/authz/v1beta1/tx.proto b/proto/cosmos/authz/v1beta1/tx.proto index f88bae47e226..59e02127e8dc 100644 --- a/proto/cosmos/authz/v1beta1/tx.proto +++ b/proto/cosmos/authz/v1beta1/tx.proto @@ -14,10 +14,10 @@ service Msg { // account with the provided expiration time. rpc Grant(MsgGrantRequest) returns (MsgGrantResponse); - // ExecAuthorized attempts to execute the provided messages using + // Exec attempts to execute the provided messages using // authorizations granted to the grantee. Each message should have only // one signer corresponding to the granter of the authorization. - rpc ExecAuthorized(MsgExecAuthorizedRequest) returns (MsgExecAuthorizedResponse); + rpc Exec(MsgExecRequest) returns (MsgExecResponse); // Revoke revokes any authorization corresponding to the provided method name on the // granter's account that has been granted to the grantee. @@ -34,15 +34,15 @@ message MsgGrantRequest { google.protobuf.Timestamp expiration = 4 [(gogoproto.nullable) = false, (gogoproto.stdtime) = true]; } -// MsgExecAuthorizedResponse defines the Msg/MsgExecAuthorizedResponse response type. -message MsgExecAuthorizedResponse { +// MsgExecResponse defines the Msg/MsgExecResponse response type. +message MsgExecResponse { cosmos.base.abci.v1beta1.Result result = 1; } -// MsgExecAuthorizedRequest attempts to execute the provided messages using +// MsgExecRequest attempts to execute the provided messages using // authorizations granted to the grantee. Each message should have only // one signer corresponding to the granter of the authorization. -message MsgExecAuthorizedRequest { +message MsgExecRequest { string grantee = 1; repeated google.protobuf.Any msgs = 2; } @@ -55,7 +55,7 @@ message MsgGrantResponse {} message MsgRevokeRequest { string granter = 1; string grantee = 2; - string method_name = 3; + string msg_type_url = 3; } // MsgRevokeResponse defines the Msg/MsgRevokeResponse response type. diff --git a/x/authz/client/cli/tx.go b/x/authz/client/cli/tx.go index e94a45b442af..001bdcefcd9e 100644 --- a/x/authz/client/cli/tx.go +++ b/x/authz/client/cli/tx.go @@ -261,7 +261,7 @@ Example: serviceMsgs[i] = srvMsg } - msg := types.NewMsgExecAuthorized(grantee, serviceMsgs) + msg := types.NewMsgExec(grantee, serviceMsgs) svcMsgClientConn := &msgservice.ServiceMsgClientConn{} msgClient := types.NewMsgClient(svcMsgClientConn) _, err = msgClient.ExecAuthorized(cmd.Context(), &msg) diff --git a/x/authz/keeper/keeper_test.go b/x/authz/keeper/keeper_test.go index a91d8251a6a6..d545a7bac601 100644 --- a/x/authz/keeper/keeper_test.go +++ b/x/authz/keeper/keeper_test.go @@ -139,7 +139,7 @@ func (s *TestSuite) TestKeeperFees() { smallCoin := sdk.NewCoins(sdk.NewInt64Coin("steak", 20)) someCoin := sdk.NewCoins(sdk.NewInt64Coin("steak", 123)) - msgs := types.NewMsgExecAuthorized(granteeAddr, []sdk.ServiceMsg{ + msgs := types.NewMsgExec(granteeAddr, []sdk.ServiceMsg{ { MethodName: banktypes.SendAuthorization{}.MethodName(), Request: &banktypes.MsgSend{ @@ -182,7 +182,7 @@ func (s *TestSuite) TestKeeperFees() { s.T().Log("verify dispatch fails with overlimit") // grant authorization - msgs = types.NewMsgExecAuthorized(granteeAddr, []sdk.ServiceMsg{ + msgs = types.NewMsgExec(granteeAddr, []sdk.ServiceMsg{ { MethodName: banktypes.SendAuthorization{}.MethodName(), Request: &banktypes.MsgSend{ diff --git a/x/authz/keeper/msg_server.go b/x/authz/keeper/msg_server.go index 76d34ca2cab8..fa746a8170f3 100644 --- a/x/authz/keeper/msg_server.go +++ b/x/authz/keeper/msg_server.go @@ -48,7 +48,7 @@ func (k Keeper) Revoke(goCtx context.Context, msg *types.MsgRevokeRequest) (*typ return nil, err } - err = k.RevokeX(ctx, grantee, granter, msg.MethodName) + err = k.RevokeX(ctx, grantee, granter, msg.MsgTypeUrl) if err != nil { return nil, err } @@ -56,8 +56,8 @@ func (k Keeper) Revoke(goCtx context.Context, msg *types.MsgRevokeRequest) (*typ return &types.MsgRevokeResponse{}, nil } -// ExecAuthorized implements the MsgServer.ExecAuthorized method. -func (k Keeper) ExecAuthorized(goCtx context.Context, msg *types.MsgExecAuthorizedRequest) (*types.MsgExecAuthorizedResponse, error) { +// Exec implements the MsgServer.Exec method. +func (k Keeper) Exec(goCtx context.Context, msg *types.MsgExecRequest) (*types.MsgExecResponse, error) { ctx := sdk.UnwrapSDKContext(goCtx) grantee, err := sdk.AccAddressFromBech32(msg.Grantee) if err != nil { @@ -71,5 +71,5 @@ func (k Keeper) ExecAuthorized(goCtx context.Context, msg *types.MsgExecAuthoriz if err != nil { return nil, err } - return &types.MsgExecAuthorizedResponse{Result: result}, nil + return &types.MsgExecResponse{Result: result}, nil } diff --git a/x/authz/simulation/operations.go b/x/authz/simulation/operations.go index 3be0fc6b9348..416bd970ccc8 100644 --- a/x/authz/simulation/operations.go +++ b/x/authz/simulation/operations.go @@ -251,7 +251,7 @@ func SimulateMsgExecuteAuthorized(ak types.AccountKeeper, bk types.BankKeeper, k ), } - msg := types.NewMsgExecAuthorized(grantee.Address, []sdk.ServiceMsg{execMsg}) + msg := types.NewMsgExec(grantee.Address, []sdk.ServiceMsg{execMsg}) sendGrant := targetGrant.Authorization.GetCachedValue().(*banktype.SendAuthorization) _, err = sendGrant.Accept(ctx, execMsg) if err != nil { diff --git a/x/authz/simulation/operations_test.go b/x/authz/simulation/operations_test.go index 7a2cd5e0d462..527f0ede8b7b 100644 --- a/x/authz/simulation/operations_test.go +++ b/x/authz/simulation/operations_test.go @@ -153,7 +153,7 @@ func (suite *SimTestSuite) TestSimulateRevokeAuthorization() { suite.Require().True(operationMsg.OK) suite.Require().Equal(granter.Address.String(), msg.Granter) suite.Require().Equal(grantee.Address.String(), msg.Grantee) - suite.Require().Equal(banktypes.SendAuthorization{}.MethodName(), msg.MethodName) + suite.Require().Equal(banktypes.SendAuthorization{}.MethodName(), msg.MsgTypeUrl) suite.Require().Len(futureOperations, 0) } @@ -182,7 +182,7 @@ func (suite *SimTestSuite) TestSimulateExecAuthorization() { operationMsg, futureOperations, err := op(r, suite.app.BaseApp, suite.ctx, accounts, "") suite.Require().NoError(err) - var msg types.MsgExecAuthorizedRequest + var msg types.MsgExecRequest suite.app.AppCodec().UnmarshalJSON(operationMsg.Msg, &msg) diff --git a/x/authz/types/codec.go b/x/authz/types/codec.go index d10382c336a7..c9f735446094 100644 --- a/x/authz/types/codec.go +++ b/x/authz/types/codec.go @@ -14,7 +14,7 @@ func RegisterInterfaces(registry types.InterfaceRegistry) { registry.RegisterImplementations((*sdk.MsgRequest)(nil), &MsgGrantRequest{}, &MsgRevokeRequest{}, - &MsgExecAuthorizedRequest{}, + &MsgExecRequest{}, ) registry.RegisterInterface( diff --git a/x/authz/types/msgs.go b/x/authz/types/msgs.go index 48319ea0d649..82a5122efa88 100644 --- a/x/authz/types/msgs.go +++ b/x/authz/types/msgs.go @@ -14,10 +14,10 @@ import ( var ( _ sdk.MsgRequest = &MsgGrantRequest{} _ sdk.MsgRequest = &MsgRevokeRequest{} - _ sdk.MsgRequest = &MsgExecAuthorizedRequest{} + _ sdk.MsgRequest = &MsgExecRequest{} _ types.UnpackInterfacesMessage = &MsgGrantRequest{} - _ types.UnpackInterfacesMessage = &MsgExecAuthorizedRequest{} + _ types.UnpackInterfacesMessage = &MsgExecRequest{} ) // NewMsgGrant creates a new MsgGrant @@ -94,7 +94,7 @@ func (msg *MsgGrantRequest) SetAuthorization(authorization exported.Authorizatio } // UnpackInterfaces implements UnpackInterfacesMessage.UnpackInterfaces -func (msg MsgExecAuthorizedRequest) UnpackInterfaces(unpacker types.AnyUnpacker) error { +func (msg MsgExecRequest) UnpackInterfaces(unpacker types.AnyUnpacker) error { for _, x := range msg.Msgs { var msgExecAuthorized sdk.MsgRequest err := unpacker.UnpackAny(x, &msgExecAuthorized) @@ -118,7 +118,7 @@ func NewMsgRevoke(granter sdk.AccAddress, grantee sdk.AccAddress, msgTypeURL str return MsgRevokeRequest{ Granter: granter.String(), Grantee: grantee.String(), - MethodName: msgTypeURL, + MsgTypeUrl: msgTypeURL, } } @@ -146,16 +146,16 @@ func (msg MsgRevokeRequest) ValidateBasic() error { return sdkerrors.Wrap(sdkerrors.ErrInvalidRequest, "granter and grantee cannot be same") } - if msg.MethodName == "" { + if msg.MsgTypeUrl == "" { return sdkerrors.Wrap(sdkerrors.ErrInvalidRequest, "missing method name") } return nil } -// NewMsgExecAuthorized creates a new MsgExecAuthorized +// NewMsgExec creates a new MsgExecAuthorized //nolint:interfacer -func NewMsgExecAuthorized(grantee sdk.AccAddress, msgs []sdk.ServiceMsg) MsgExecAuthorizedRequest { +func NewMsgExec(grantee sdk.AccAddress, msgs []sdk.ServiceMsg) MsgExecRequest { msgsAny := make([]*types.Any, len(msgs)) for i, msg := range msgs { bz, err := proto.Marshal(msg.Request) @@ -171,14 +171,14 @@ func NewMsgExecAuthorized(grantee sdk.AccAddress, msgs []sdk.ServiceMsg) MsgExec msgsAny[i] = anyMsg } - return MsgExecAuthorizedRequest{ + return MsgExecRequest{ Grantee: grantee.String(), Msgs: msgsAny, } } // GetServiceMsgs returns the cache values from the MsgExecAuthorized.Msgs if present. -func (msg MsgExecAuthorizedRequest) GetServiceMsgs() ([]sdk.ServiceMsg, error) { +func (msg MsgExecRequest) GetServiceMsgs() ([]sdk.ServiceMsg, error) { msgs := make([]sdk.ServiceMsg, len(msg.Msgs)) for i, msgAny := range msg.Msgs { msgReq, ok := msgAny.GetCachedValue().(sdk.MsgRequest) @@ -197,7 +197,7 @@ func (msg MsgExecAuthorizedRequest) GetServiceMsgs() ([]sdk.ServiceMsg, error) { } // GetSigners implements Msg -func (msg MsgExecAuthorizedRequest) GetSigners() []sdk.AccAddress { +func (msg MsgExecRequest) GetSigners() []sdk.AccAddress { grantee, err := sdk.AccAddressFromBech32(msg.Grantee) if err != nil { panic(err) @@ -206,7 +206,7 @@ func (msg MsgExecAuthorizedRequest) GetSigners() []sdk.AccAddress { } // ValidateBasic implements Msg -func (msg MsgExecAuthorizedRequest) ValidateBasic() error { +func (msg MsgExecRequest) ValidateBasic() error { _, err := sdk.AccAddressFromBech32(msg.Grantee) if err != nil { return sdkerrors.Wrap(sdkerrors.ErrInvalidAddress, "invalid grantee address") diff --git a/x/authz/types/msgs_test.go b/x/authz/types/msgs_test.go index fcb875e60625..ce9ce7231af0 100644 --- a/x/authz/types/msgs_test.go +++ b/x/authz/types/msgs_test.go @@ -40,7 +40,7 @@ func TestMsgExecAuthorized(t *testing.T) { }, true}, } for i, tc := range tests { - msg := types.NewMsgExecAuthorized(tc.grantee, tc.msgs) + msg := types.NewMsgExec(tc.grantee, tc.msgs) if tc.expectPass { require.NoError(t, msg.ValidateBasic(), "test: %v", i) } else { diff --git a/x/authz/types/tx.pb.go b/x/authz/types/tx.pb.go index 58ece2f87614..1c5b8a466714 100644 --- a/x/authz/types/tx.pb.go +++ b/x/authz/types/tx.pb.go @@ -1,11 +1,13 @@ -// Code generated by protoc-gen-gogo. DO NOT EDIT. -// source: cosmos/authz/v1beta1/tx.proto - package types import ( context "context" fmt "fmt" + io "io" + math "math" + math_bits "math/bits" + time "time" + types "github.com/cosmos/cosmos-sdk/codec/types" types1 "github.com/cosmos/cosmos-sdk/types" _ "github.com/gogo/protobuf/gogoproto" @@ -17,10 +19,6 @@ import ( codes "google.golang.org/grpc/codes" status "google.golang.org/grpc/status" _ "google.golang.org/protobuf/types/known/timestamppb" - io "io" - math "math" - math_bits "math/bits" - time "time" ) // Reference imports to suppress errors if they are not otherwise used. @@ -105,21 +103,21 @@ func (m *MsgGrantRequest) GetExpiration() time.Time { return time.Time{} } -// MsgExecAuthorizedResponse defines the Msg/MsgExecAuthorizedResponse response type. -type MsgExecAuthorizedResponse struct { +// MsgExecResponse defines the Msg/MsgExecResponse response type. +type MsgExecResponse struct { Result *types1.Result `protobuf:"bytes,1,opt,name=result,proto3" json:"result,omitempty"` } -func (m *MsgExecAuthorizedResponse) Reset() { *m = MsgExecAuthorizedResponse{} } -func (m *MsgExecAuthorizedResponse) String() string { return proto.CompactTextString(m) } -func (*MsgExecAuthorizedResponse) ProtoMessage() {} -func (*MsgExecAuthorizedResponse) Descriptor() ([]byte, []int) { +func (m *MsgExecResponse) Reset() { *m = MsgExecResponse{} } +func (m *MsgExecResponse) String() string { return proto.CompactTextString(m) } +func (*MsgExecResponse) ProtoMessage() {} +func (*MsgExecResponse) Descriptor() ([]byte, []int) { return fileDescriptor_3ceddab7d8589ad1, []int{1} } -func (m *MsgExecAuthorizedResponse) XXX_Unmarshal(b []byte) error { +func (m *MsgExecResponse) XXX_Unmarshal(b []byte) error { return m.Unmarshal(b) } -func (m *MsgExecAuthorizedResponse) XXX_Marshal(b []byte, deterministic bool) ([]byte, error) { +func (m *MsgExecResponse) XXX_Marshal(b []byte, deterministic bool) ([]byte, error) { if deterministic { return xxx_messageInfo_MsgExecAuthorizedResponse.Marshal(b, m, deterministic) } else { @@ -131,43 +129,43 @@ func (m *MsgExecAuthorizedResponse) XXX_Marshal(b []byte, deterministic bool) ([ return b[:n], nil } } -func (m *MsgExecAuthorizedResponse) XXX_Merge(src proto.Message) { +func (m *MsgExecResponse) XXX_Merge(src proto.Message) { xxx_messageInfo_MsgExecAuthorizedResponse.Merge(m, src) } -func (m *MsgExecAuthorizedResponse) XXX_Size() int { +func (m *MsgExecResponse) XXX_Size() int { return m.Size() } -func (m *MsgExecAuthorizedResponse) XXX_DiscardUnknown() { +func (m *MsgExecResponse) XXX_DiscardUnknown() { xxx_messageInfo_MsgExecAuthorizedResponse.DiscardUnknown(m) } var xxx_messageInfo_MsgExecAuthorizedResponse proto.InternalMessageInfo -func (m *MsgExecAuthorizedResponse) GetResult() *types1.Result { +func (m *MsgExecResponse) GetResult() *types1.Result { if m != nil { return m.Result } return nil } -// MsgExecAuthorizedRequest attempts to execute the provided messages using +// MsgExecRequest attempts to execute the provided messages using // authorizations granted to the grantee. Each message should have only // one signer corresponding to the granter of the authorization. -type MsgExecAuthorizedRequest struct { +type MsgExecRequest struct { Grantee string `protobuf:"bytes,1,opt,name=grantee,proto3" json:"grantee,omitempty"` Msgs []*types.Any `protobuf:"bytes,2,rep,name=msgs,proto3" json:"msgs,omitempty"` } -func (m *MsgExecAuthorizedRequest) Reset() { *m = MsgExecAuthorizedRequest{} } -func (m *MsgExecAuthorizedRequest) String() string { return proto.CompactTextString(m) } -func (*MsgExecAuthorizedRequest) ProtoMessage() {} -func (*MsgExecAuthorizedRequest) Descriptor() ([]byte, []int) { +func (m *MsgExecRequest) Reset() { *m = MsgExecRequest{} } +func (m *MsgExecRequest) String() string { return proto.CompactTextString(m) } +func (*MsgExecRequest) ProtoMessage() {} +func (*MsgExecRequest) Descriptor() ([]byte, []int) { return fileDescriptor_3ceddab7d8589ad1, []int{2} } -func (m *MsgExecAuthorizedRequest) XXX_Unmarshal(b []byte) error { +func (m *MsgExecRequest) XXX_Unmarshal(b []byte) error { return m.Unmarshal(b) } -func (m *MsgExecAuthorizedRequest) XXX_Marshal(b []byte, deterministic bool) ([]byte, error) { +func (m *MsgExecRequest) XXX_Marshal(b []byte, deterministic bool) ([]byte, error) { if deterministic { return xxx_messageInfo_MsgExecAuthorizedRequest.Marshal(b, m, deterministic) } else { @@ -179,26 +177,26 @@ func (m *MsgExecAuthorizedRequest) XXX_Marshal(b []byte, deterministic bool) ([] return b[:n], nil } } -func (m *MsgExecAuthorizedRequest) XXX_Merge(src proto.Message) { +func (m *MsgExecRequest) XXX_Merge(src proto.Message) { xxx_messageInfo_MsgExecAuthorizedRequest.Merge(m, src) } -func (m *MsgExecAuthorizedRequest) XXX_Size() int { +func (m *MsgExecRequest) XXX_Size() int { return m.Size() } -func (m *MsgExecAuthorizedRequest) XXX_DiscardUnknown() { +func (m *MsgExecRequest) XXX_DiscardUnknown() { xxx_messageInfo_MsgExecAuthorizedRequest.DiscardUnknown(m) } var xxx_messageInfo_MsgExecAuthorizedRequest proto.InternalMessageInfo -func (m *MsgExecAuthorizedRequest) GetGrantee() string { +func (m *MsgExecRequest) GetGrantee() string { if m != nil { return m.Grantee } return "" } -func (m *MsgExecAuthorizedRequest) GetMsgs() []*types.Any { +func (m *MsgExecRequest) GetMsgs() []*types.Any { if m != nil { return m.Msgs } @@ -247,7 +245,7 @@ var xxx_messageInfo_MsgGrantResponse proto.InternalMessageInfo type MsgRevokeRequest struct { Granter string `protobuf:"bytes,1,opt,name=granter,proto3" json:"granter,omitempty"` Grantee string `protobuf:"bytes,2,opt,name=grantee,proto3" json:"grantee,omitempty"` - MethodName string `protobuf:"bytes,3,opt,name=method_name,json=methodName,proto3" json:"method_name,omitempty"` + MsgTypeUrl string `protobuf:"bytes,3,opt,name=method_name,json=methodName,proto3" json:"method_name,omitempty"` } func (m *MsgRevokeRequest) Reset() { *m = MsgRevokeRequest{} } @@ -299,7 +297,7 @@ func (m *MsgRevokeRequest) GetGrantee() string { func (m *MsgRevokeRequest) GetMethodName() string { if m != nil { - return m.MethodName + return m.MsgTypeUrl } return "" } @@ -343,8 +341,8 @@ var xxx_messageInfo_MsgRevokeResponse proto.InternalMessageInfo func init() { proto.RegisterType((*MsgGrantRequest)(nil), "cosmos.authz.v1beta1.MsgGrantRequest") - proto.RegisterType((*MsgExecAuthorizedResponse)(nil), "cosmos.authz.v1beta1.MsgExecAuthorizedResponse") - proto.RegisterType((*MsgExecAuthorizedRequest)(nil), "cosmos.authz.v1beta1.MsgExecAuthorizedRequest") + proto.RegisterType((*MsgExecResponse)(nil), "cosmos.authz.v1beta1.MsgExecAuthorizedResponse") + proto.RegisterType((*MsgExecRequest)(nil), "cosmos.authz.v1beta1.MsgExecAuthorizedRequest") proto.RegisterType((*MsgGrantResponse)(nil), "cosmos.authz.v1beta1.MsgGrantResponse") proto.RegisterType((*MsgRevokeRequest)(nil), "cosmos.authz.v1beta1.MsgRevokeRequest") proto.RegisterType((*MsgRevokeResponse)(nil), "cosmos.authz.v1beta1.MsgRevokeResponse") @@ -407,7 +405,7 @@ type MsgClient interface { // ExecAuthorized attempts to execute the provided messages using // authorizations granted to the grantee. Each message should have only // one signer corresponding to the granter of the authorization. - ExecAuthorized(ctx context.Context, in *MsgExecAuthorizedRequest, opts ...grpc.CallOption) (*MsgExecAuthorizedResponse, error) + ExecAuthorized(ctx context.Context, in *MsgExecRequest, opts ...grpc.CallOption) (*MsgExecResponse, error) // Revoke revokes any authorization corresponding to the provided method name on the // granter's account that has been granted to the grantee. Revoke(ctx context.Context, in *MsgRevokeRequest, opts ...grpc.CallOption) (*MsgRevokeResponse, error) @@ -430,8 +428,8 @@ func (c *msgClient) Grant(ctx context.Context, in *MsgGrantRequest, opts ...grpc return out, nil } -func (c *msgClient) ExecAuthorized(ctx context.Context, in *MsgExecAuthorizedRequest, opts ...grpc.CallOption) (*MsgExecAuthorizedResponse, error) { - out := new(MsgExecAuthorizedResponse) +func (c *msgClient) ExecAuthorized(ctx context.Context, in *MsgExecRequest, opts ...grpc.CallOption) (*MsgExecResponse, error) { + out := new(MsgExecResponse) err := c.cc.Invoke(ctx, "/cosmos.authz.v1beta1.Msg/ExecAuthorized", in, out, opts...) if err != nil { return nil, err @@ -453,10 +451,10 @@ type MsgServer interface { // Grant grants the provided authorization to the grantee on the granter's // account with the provided expiration time. Grant(context.Context, *MsgGrantRequest) (*MsgGrantResponse, error) - // ExecAuthorized attempts to execute the provided messages using + // Exec attempts to execute the provided messages using // authorizations granted to the grantee. Each message should have only // one signer corresponding to the granter of the authorization. - ExecAuthorized(context.Context, *MsgExecAuthorizedRequest) (*MsgExecAuthorizedResponse, error) + Exec(context.Context, *MsgExecRequest) (*MsgExecResponse, error) // Revoke revokes any authorization corresponding to the provided method name on the // granter's account that has been granted to the grantee. Revoke(context.Context, *MsgRevokeRequest) (*MsgRevokeResponse, error) @@ -469,7 +467,7 @@ type UnimplementedMsgServer struct { func (*UnimplementedMsgServer) Grant(ctx context.Context, req *MsgGrantRequest) (*MsgGrantResponse, error) { return nil, status.Errorf(codes.Unimplemented, "method Grant not implemented") } -func (*UnimplementedMsgServer) ExecAuthorized(ctx context.Context, req *MsgExecAuthorizedRequest) (*MsgExecAuthorizedResponse, error) { +func (*UnimplementedMsgServer) ExecAuthorized(ctx context.Context, req *MsgExecRequest) (*MsgExecResponse, error) { return nil, status.Errorf(codes.Unimplemented, "method ExecAuthorized not implemented") } func (*UnimplementedMsgServer) Revoke(ctx context.Context, req *MsgRevokeRequest) (*MsgRevokeResponse, error) { @@ -499,19 +497,19 @@ func _Msg_Grant_Handler(srv interface{}, ctx context.Context, dec func(interface } func _Msg_ExecAuthorized_Handler(srv interface{}, ctx context.Context, dec func(interface{}) error, interceptor grpc.UnaryServerInterceptor) (interface{}, error) { - in := new(MsgExecAuthorizedRequest) + in := new(MsgExecRequest) if err := dec(in); err != nil { return nil, err } if interceptor == nil { - return srv.(MsgServer).ExecAuthorized(ctx, in) + return srv.(MsgServer).Exec(ctx, in) } info := &grpc.UnaryServerInfo{ Server: srv, FullMethod: "/cosmos.authz.v1beta1.Msg/ExecAuthorized", } handler := func(ctx context.Context, req interface{}) (interface{}, error) { - return srv.(MsgServer).ExecAuthorized(ctx, req.(*MsgExecAuthorizedRequest)) + return srv.(MsgServer).Exec(ctx, req.(*MsgExecRequest)) } return interceptor(ctx, in, info, handler) } @@ -612,7 +610,7 @@ func (m *MsgGrantRequest) MarshalToSizedBuffer(dAtA []byte) (int, error) { return len(dAtA) - i, nil } -func (m *MsgExecAuthorizedResponse) Marshal() (dAtA []byte, err error) { +func (m *MsgExecResponse) Marshal() (dAtA []byte, err error) { size := m.Size() dAtA = make([]byte, size) n, err := m.MarshalToSizedBuffer(dAtA[:size]) @@ -622,12 +620,12 @@ func (m *MsgExecAuthorizedResponse) Marshal() (dAtA []byte, err error) { return dAtA[:n], nil } -func (m *MsgExecAuthorizedResponse) MarshalTo(dAtA []byte) (int, error) { +func (m *MsgExecResponse) MarshalTo(dAtA []byte) (int, error) { size := m.Size() return m.MarshalToSizedBuffer(dAtA[:size]) } -func (m *MsgExecAuthorizedResponse) MarshalToSizedBuffer(dAtA []byte) (int, error) { +func (m *MsgExecResponse) MarshalToSizedBuffer(dAtA []byte) (int, error) { i := len(dAtA) _ = i var l int @@ -647,7 +645,7 @@ func (m *MsgExecAuthorizedResponse) MarshalToSizedBuffer(dAtA []byte) (int, erro return len(dAtA) - i, nil } -func (m *MsgExecAuthorizedRequest) Marshal() (dAtA []byte, err error) { +func (m *MsgExecRequest) Marshal() (dAtA []byte, err error) { size := m.Size() dAtA = make([]byte, size) n, err := m.MarshalToSizedBuffer(dAtA[:size]) @@ -657,12 +655,12 @@ func (m *MsgExecAuthorizedRequest) Marshal() (dAtA []byte, err error) { return dAtA[:n], nil } -func (m *MsgExecAuthorizedRequest) MarshalTo(dAtA []byte) (int, error) { +func (m *MsgExecRequest) MarshalTo(dAtA []byte) (int, error) { size := m.Size() return m.MarshalToSizedBuffer(dAtA[:size]) } -func (m *MsgExecAuthorizedRequest) MarshalToSizedBuffer(dAtA []byte) (int, error) { +func (m *MsgExecRequest) MarshalToSizedBuffer(dAtA []byte) (int, error) { i := len(dAtA) _ = i var l int @@ -734,10 +732,10 @@ func (m *MsgRevokeRequest) MarshalToSizedBuffer(dAtA []byte) (int, error) { _ = i var l int _ = l - if len(m.MethodName) > 0 { - i -= len(m.MethodName) - copy(dAtA[i:], m.MethodName) - i = encodeVarintTx(dAtA, i, uint64(len(m.MethodName))) + if len(m.MsgTypeUrl) > 0 { + i -= len(m.MsgTypeUrl) + copy(dAtA[i:], m.MsgTypeUrl) + i = encodeVarintTx(dAtA, i, uint64(len(m.MsgTypeUrl))) i-- dAtA[i] = 0x1a } @@ -815,7 +813,7 @@ func (m *MsgGrantRequest) Size() (n int) { return n } -func (m *MsgExecAuthorizedResponse) Size() (n int) { +func (m *MsgExecResponse) Size() (n int) { if m == nil { return 0 } @@ -828,7 +826,7 @@ func (m *MsgExecAuthorizedResponse) Size() (n int) { return n } -func (m *MsgExecAuthorizedRequest) Size() (n int) { +func (m *MsgExecRequest) Size() (n int) { if m == nil { return 0 } @@ -870,7 +868,7 @@ func (m *MsgRevokeRequest) Size() (n int) { if l > 0 { n += 1 + l + sovTx(uint64(l)) } - l = len(m.MethodName) + l = len(m.MsgTypeUrl) if l > 0 { n += 1 + l + sovTx(uint64(l)) } @@ -1075,7 +1073,7 @@ func (m *MsgGrantRequest) Unmarshal(dAtA []byte) error { } return nil } -func (m *MsgExecAuthorizedResponse) Unmarshal(dAtA []byte) error { +func (m *MsgExecResponse) Unmarshal(dAtA []byte) error { l := len(dAtA) iNdEx := 0 for iNdEx < l { @@ -1161,7 +1159,7 @@ func (m *MsgExecAuthorizedResponse) Unmarshal(dAtA []byte) error { } return nil } -func (m *MsgExecAuthorizedRequest) Unmarshal(dAtA []byte) error { +func (m *MsgExecRequest) Unmarshal(dAtA []byte) error { l := len(dAtA) iNdEx := 0 for iNdEx < l { @@ -1450,7 +1448,7 @@ func (m *MsgRevokeRequest) Unmarshal(dAtA []byte) error { if postIndex > l { return io.ErrUnexpectedEOF } - m.MethodName = string(dAtA[iNdEx:postIndex]) + m.MsgTypeUrl = string(dAtA[iNdEx:postIndex]) iNdEx = postIndex default: iNdEx = preIndex From c85574b0a512f0c03d7d6ea6e5d5b6267611e4e2 Mon Sep 17 00:00:00 2001 From: Robert Zaremba Date: Thu, 22 Apr 2021 16:38:21 +0200 Subject: [PATCH 11/44] update tests --- Makefile | 2 +- docs/core/proto-docs.md | 20 ++--- x/authz/types/tx.pb.go | 133 +++++++++++++++++----------------- x/staking/types/authz_test.go | 6 +- 4 files changed, 81 insertions(+), 80 deletions(-) diff --git a/Makefile b/Makefile index 812e72696085..cc5783ce8bc6 100644 --- a/Makefile +++ b/Makefile @@ -374,7 +374,7 @@ proto-all: proto-format proto-lint proto-gen protoContainer=cosmos-proto-gen proto-gen: @echo "Generating Protobuf files" - if docker ps -a --format '{{.Names}}' | grep -Eq "^${protoContainer}$$"; then docker start $(protoContainer); else docker run --name $(protoContainer) -v $(CURDIR):/workspace --workdir /workspace tendermintdev/sdk-proto-gen:v0.1 sh ./scripts/protocgen.sh; fi + if docker ps -a --format '{{.Names}}' | grep -Eq "^${protoContainer}$$"; then docker start $(protoContainer); else docker run -a --name $(protoContainer) -v $(CURDIR):/workspace --workdir /workspace tendermintdev/sdk-proto-gen:v0.1 sh ./scripts/protocgen.sh; fi # $(DOCKER) run --rm -v $(CURDIR):/workspace --workdir /workspace tendermintdev/sdk-proto-gen:v0.1 sh ./scripts/protocgen.sh proto-format: diff --git a/docs/core/proto-docs.md b/docs/core/proto-docs.md index 7b3d4aa17b5a..7d30389c8d1c 100644 --- a/docs/core/proto-docs.md +++ b/docs/core/proto-docs.md @@ -57,8 +57,8 @@ - [TxResponse](#cosmos.base.abci.v1beta1.TxResponse) - [cosmos/authz/v1beta1/tx.proto](#cosmos/authz/v1beta1/tx.proto) - - [MsgExecAuthorizedRequest](#cosmos.authz.v1beta1.MsgExecAuthorizedRequest) - - [MsgExecAuthorizedResponse](#cosmos.authz.v1beta1.MsgExecAuthorizedResponse) + - [MsgExecRequest](#cosmos.authz.v1beta1.MsgExecRequest) + - [MsgExecResponse](#cosmos.authz.v1beta1.MsgExecResponse) - [MsgGrantRequest](#cosmos.authz.v1beta1.MsgGrantRequest) - [MsgGrantResponse](#cosmos.authz.v1beta1.MsgGrantResponse) - [MsgRevokeRequest](#cosmos.authz.v1beta1.MsgRevokeRequest) @@ -1283,10 +1283,10 @@ tags are stringified and the log is JSON decoded. - + -### MsgExecAuthorizedRequest -MsgExecAuthorizedRequest attempts to execute the provided messages using +### MsgExecRequest +MsgExecRequest attempts to execute the provided messages using authorizations granted to the grantee. Each message should have only one signer corresponding to the granter of the authorization. @@ -1301,10 +1301,10 @@ one signer corresponding to the granter of the authorization. - + -### MsgExecAuthorizedResponse -MsgExecAuthorizedResponse defines the Msg/MsgExecAuthorizedResponse response type. +### MsgExecResponse +MsgExecResponse defines the Msg/MsgExecResponse response type. | Field | Type | Label | Description | @@ -1356,7 +1356,7 @@ granter's account with that has been granted to the grantee. | ----- | ---- | ----- | ----------- | | `granter` | [string](#string) | | | | `grantee` | [string](#string) | | | -| `method_name` | [string](#string) | | | +| `msg_type_url` | [string](#string) | | | @@ -1387,7 +1387,7 @@ Msg defines the authz Msg service. | Method Name | Request Type | Response Type | Description | HTTP Verb | Endpoint | | ----------- | ------------ | ------------- | ------------| ------- | -------- | | `Grant` | [MsgGrantRequest](#cosmos.authz.v1beta1.MsgGrantRequest) | [MsgGrantResponse](#cosmos.authz.v1beta1.MsgGrantResponse) | Grant grants the provided authorization to the grantee on the granter's account with the provided expiration time. | | -| `ExecAuthorized` | [MsgExecAuthorizedRequest](#cosmos.authz.v1beta1.MsgExecAuthorizedRequest) | [MsgExecAuthorizedResponse](#cosmos.authz.v1beta1.MsgExecAuthorizedResponse) | ExecAuthorized attempts to execute the provided messages using authorizations granted to the grantee. Each message should have only one signer corresponding to the granter of the authorization. | | +| `Exec` | [MsgExecRequest](#cosmos.authz.v1beta1.MsgExecRequest) | [MsgExecResponse](#cosmos.authz.v1beta1.MsgExecResponse) | Exec attempts to execute the provided messages using authorizations granted to the grantee. Each message should have only one signer corresponding to the granter of the authorization. | | | `Revoke` | [MsgRevokeRequest](#cosmos.authz.v1beta1.MsgRevokeRequest) | [MsgRevokeResponse](#cosmos.authz.v1beta1.MsgRevokeResponse) | Revoke revokes any authorization corresponding to the provided method name on the granter's account that has been granted to the grantee. | | diff --git a/x/authz/types/tx.pb.go b/x/authz/types/tx.pb.go index 1c5b8a466714..ecff063438d9 100644 --- a/x/authz/types/tx.pb.go +++ b/x/authz/types/tx.pb.go @@ -1,13 +1,11 @@ +// Code generated by protoc-gen-gogo. DO NOT EDIT. +// source: cosmos/authz/v1beta1/tx.proto + package types import ( context "context" fmt "fmt" - io "io" - math "math" - math_bits "math/bits" - time "time" - types "github.com/cosmos/cosmos-sdk/codec/types" types1 "github.com/cosmos/cosmos-sdk/types" _ "github.com/gogo/protobuf/gogoproto" @@ -19,6 +17,10 @@ import ( codes "google.golang.org/grpc/codes" status "google.golang.org/grpc/status" _ "google.golang.org/protobuf/types/known/timestamppb" + io "io" + math "math" + math_bits "math/bits" + time "time" ) // Reference imports to suppress errors if they are not otherwise used. @@ -119,7 +121,7 @@ func (m *MsgExecResponse) XXX_Unmarshal(b []byte) error { } func (m *MsgExecResponse) XXX_Marshal(b []byte, deterministic bool) ([]byte, error) { if deterministic { - return xxx_messageInfo_MsgExecAuthorizedResponse.Marshal(b, m, deterministic) + return xxx_messageInfo_MsgExecResponse.Marshal(b, m, deterministic) } else { b = b[:cap(b)] n, err := m.MarshalToSizedBuffer(b) @@ -130,16 +132,16 @@ func (m *MsgExecResponse) XXX_Marshal(b []byte, deterministic bool) ([]byte, err } } func (m *MsgExecResponse) XXX_Merge(src proto.Message) { - xxx_messageInfo_MsgExecAuthorizedResponse.Merge(m, src) + xxx_messageInfo_MsgExecResponse.Merge(m, src) } func (m *MsgExecResponse) XXX_Size() int { return m.Size() } func (m *MsgExecResponse) XXX_DiscardUnknown() { - xxx_messageInfo_MsgExecAuthorizedResponse.DiscardUnknown(m) + xxx_messageInfo_MsgExecResponse.DiscardUnknown(m) } -var xxx_messageInfo_MsgExecAuthorizedResponse proto.InternalMessageInfo +var xxx_messageInfo_MsgExecResponse proto.InternalMessageInfo func (m *MsgExecResponse) GetResult() *types1.Result { if m != nil { @@ -167,7 +169,7 @@ func (m *MsgExecRequest) XXX_Unmarshal(b []byte) error { } func (m *MsgExecRequest) XXX_Marshal(b []byte, deterministic bool) ([]byte, error) { if deterministic { - return xxx_messageInfo_MsgExecAuthorizedRequest.Marshal(b, m, deterministic) + return xxx_messageInfo_MsgExecRequest.Marshal(b, m, deterministic) } else { b = b[:cap(b)] n, err := m.MarshalToSizedBuffer(b) @@ -178,16 +180,16 @@ func (m *MsgExecRequest) XXX_Marshal(b []byte, deterministic bool) ([]byte, erro } } func (m *MsgExecRequest) XXX_Merge(src proto.Message) { - xxx_messageInfo_MsgExecAuthorizedRequest.Merge(m, src) + xxx_messageInfo_MsgExecRequest.Merge(m, src) } func (m *MsgExecRequest) XXX_Size() int { return m.Size() } func (m *MsgExecRequest) XXX_DiscardUnknown() { - xxx_messageInfo_MsgExecAuthorizedRequest.DiscardUnknown(m) + xxx_messageInfo_MsgExecRequest.DiscardUnknown(m) } -var xxx_messageInfo_MsgExecAuthorizedRequest proto.InternalMessageInfo +var xxx_messageInfo_MsgExecRequest proto.InternalMessageInfo func (m *MsgExecRequest) GetGrantee() string { if m != nil { @@ -245,7 +247,7 @@ var xxx_messageInfo_MsgGrantResponse proto.InternalMessageInfo type MsgRevokeRequest struct { Granter string `protobuf:"bytes,1,opt,name=granter,proto3" json:"granter,omitempty"` Grantee string `protobuf:"bytes,2,opt,name=grantee,proto3" json:"grantee,omitempty"` - MsgTypeUrl string `protobuf:"bytes,3,opt,name=method_name,json=methodName,proto3" json:"method_name,omitempty"` + MsgTypeUrl string `protobuf:"bytes,3,opt,name=msg_type_url,json=msgTypeUrl,proto3" json:"msg_type_url,omitempty"` } func (m *MsgRevokeRequest) Reset() { *m = MsgRevokeRequest{} } @@ -295,7 +297,7 @@ func (m *MsgRevokeRequest) GetGrantee() string { return "" } -func (m *MsgRevokeRequest) GetMethodName() string { +func (m *MsgRevokeRequest) GetMsgTypeUrl() string { if m != nil { return m.MsgTypeUrl } @@ -341,8 +343,8 @@ var xxx_messageInfo_MsgRevokeResponse proto.InternalMessageInfo func init() { proto.RegisterType((*MsgGrantRequest)(nil), "cosmos.authz.v1beta1.MsgGrantRequest") - proto.RegisterType((*MsgExecResponse)(nil), "cosmos.authz.v1beta1.MsgExecAuthorizedResponse") - proto.RegisterType((*MsgExecRequest)(nil), "cosmos.authz.v1beta1.MsgExecAuthorizedRequest") + proto.RegisterType((*MsgExecResponse)(nil), "cosmos.authz.v1beta1.MsgExecResponse") + proto.RegisterType((*MsgExecRequest)(nil), "cosmos.authz.v1beta1.MsgExecRequest") proto.RegisterType((*MsgGrantResponse)(nil), "cosmos.authz.v1beta1.MsgGrantResponse") proto.RegisterType((*MsgRevokeRequest)(nil), "cosmos.authz.v1beta1.MsgRevokeRequest") proto.RegisterType((*MsgRevokeResponse)(nil), "cosmos.authz.v1beta1.MsgRevokeResponse") @@ -351,40 +353,39 @@ func init() { func init() { proto.RegisterFile("cosmos/authz/v1beta1/tx.proto", fileDescriptor_3ceddab7d8589ad1) } var fileDescriptor_3ceddab7d8589ad1 = []byte{ - // 514 bytes of a gzipped FileDescriptorProto - 0x1f, 0x8b, 0x08, 0x00, 0x00, 0x00, 0x00, 0x00, 0x02, 0xff, 0xa4, 0x54, 0xc1, 0x6e, 0xd3, 0x40, - 0x10, 0x8d, 0x93, 0x12, 0xe8, 0x46, 0x05, 0xba, 0xe4, 0xe0, 0x58, 0xc2, 0x89, 0x8c, 0x80, 0x08, - 0xa9, 0x6b, 0x35, 0x5c, 0xb8, 0x36, 0x2a, 0xe2, 0x14, 0x0e, 0x2b, 0x40, 0x82, 0x03, 0xd5, 0x3a, - 0x19, 0x36, 0x56, 0x6b, 0x6f, 0xea, 0x5d, 0x57, 0x49, 0xbf, 0xa2, 0xff, 0xc1, 0x95, 0x8f, 0xa8, - 0x38, 0xf5, 0x88, 0x38, 0x00, 0x4a, 0x7e, 0x04, 0x79, 0x77, 0x43, 0x93, 0x90, 0xa8, 0x48, 0x9c, - 0xec, 0x99, 0xf7, 0x76, 0xe6, 0xed, 0x9b, 0xb1, 0xd1, 0xc3, 0xbe, 0x90, 0x89, 0x90, 0x21, 0xcb, - 0xd5, 0xf0, 0x3c, 0x3c, 0xdb, 0x8f, 0x40, 0xb1, 0xfd, 0x50, 0x8d, 0xc9, 0x28, 0x13, 0x4a, 0xe0, - 0xba, 0x81, 0x89, 0x86, 0x89, 0x85, 0xbd, 0x86, 0xc9, 0x1e, 0x69, 0x4e, 0x68, 0x29, 0x3a, 0xf0, - 0xea, 0x5c, 0x70, 0x61, 0xf2, 0xc5, 0x9b, 0xcd, 0x36, 0xb9, 0x10, 0xfc, 0x04, 0x42, 0x1d, 0x45, - 0xf9, 0xa7, 0x50, 0xc5, 0x09, 0x48, 0xc5, 0x92, 0x91, 0x25, 0x34, 0x56, 0x09, 0x2c, 0x9d, 0x58, - 0xe8, 0x91, 0x55, 0x18, 0x31, 0x09, 0x21, 0x8b, 0xfa, 0xf1, 0x1f, 0x95, 0x45, 0x60, 0x48, 0xc1, - 0x77, 0x07, 0xdd, 0xeb, 0x49, 0xfe, 0x2a, 0x63, 0xa9, 0xa2, 0x70, 0x9a, 0x83, 0x54, 0xd8, 0x45, - 0xb7, 0x79, 0x11, 0x43, 0xe6, 0x3a, 0x2d, 0xa7, 0xbd, 0x4d, 0xe7, 0xe1, 0x35, 0x02, 0x6e, 0x79, - 0x11, 0x01, 0xdc, 0x43, 0x3b, 0xc5, 0x55, 0x45, 0x16, 0x9f, 0x33, 0x15, 0x8b, 0xd4, 0xad, 0xb4, - 0x9c, 0x76, 0xad, 0x53, 0x27, 0x46, 0x1f, 0x99, 0xeb, 0x23, 0x07, 0xe9, 0xa4, 0xbb, 0xfb, 0xf5, - 0xcb, 0xde, 0xce, 0xc1, 0x22, 0x9d, 0x2e, 0x9f, 0xc6, 0x87, 0x08, 0xc1, 0x78, 0x14, 0x67, 0xa6, - 0xd6, 0x96, 0xae, 0xe5, 0xfd, 0x55, 0xeb, 0xcd, 0xdc, 0x8c, 0xee, 0x9d, 0xcb, 0x1f, 0xcd, 0xd2, - 0xc5, 0xcf, 0xa6, 0x43, 0x17, 0xce, 0x05, 0x6f, 0x51, 0xa3, 0x27, 0xf9, 0xcb, 0x31, 0xf4, 0xe7, - 0xcd, 0x60, 0x40, 0x41, 0x8e, 0x44, 0x2a, 0x01, 0xbf, 0x40, 0xd5, 0x0c, 0x64, 0x7e, 0xa2, 0xf4, - 0x25, 0x6b, 0x9d, 0x16, 0xb1, 0xf3, 0x28, 0xfc, 0x22, 0xda, 0x22, 0xeb, 0x17, 0xa1, 0x9a, 0x47, - 0x2d, 0x3f, 0xf8, 0x88, 0xdc, 0x35, 0x65, 0x57, 0xbc, 0x83, 0x65, 0xef, 0x00, 0xb7, 0xd1, 0x56, - 0x22, 0xb9, 0x74, 0xcb, 0xad, 0xca, 0x26, 0x63, 0xa8, 0x66, 0x04, 0x18, 0xdd, 0xbf, 0x1e, 0x89, - 0x51, 0x1b, 0x70, 0x9d, 0xa3, 0x70, 0x26, 0x8e, 0xe1, 0x7f, 0xe6, 0xd4, 0x44, 0xb5, 0x04, 0xd4, - 0x50, 0x0c, 0x8e, 0x52, 0x96, 0x80, 0x9e, 0xd2, 0x36, 0x45, 0x26, 0xf5, 0x9a, 0x25, 0x10, 0x3c, - 0x40, 0xbb, 0x0b, 0x8d, 0x4c, 0xf7, 0xce, 0xe7, 0x32, 0xaa, 0xf4, 0x24, 0xc7, 0xef, 0xd0, 0x2d, - 0x2d, 0x0b, 0x3f, 0x26, 0xeb, 0xf6, 0x9b, 0xac, 0x6c, 0x92, 0xf7, 0xe4, 0x26, 0x9a, 0x9d, 0xc5, - 0x29, 0xba, 0xbb, 0x6c, 0x27, 0x26, 0x1b, 0x4f, 0xae, 0xf5, 0xdd, 0x0b, 0xff, 0x99, 0x6f, 0x5b, - 0xbe, 0x47, 0x55, 0x73, 0x49, 0xbc, 0x59, 0xe4, 0x92, 0xdd, 0xde, 0xd3, 0x1b, 0x79, 0xa6, 0x74, - 0xf7, 0xf0, 0x72, 0xea, 0x3b, 0x57, 0x53, 0xdf, 0xf9, 0x35, 0xf5, 0x9d, 0x8b, 0x99, 0x5f, 0xba, - 0x9a, 0xf9, 0xa5, 0x6f, 0x33, 0xbf, 0xf4, 0xe1, 0x19, 0x8f, 0xd5, 0x30, 0x8f, 0x48, 0x5f, 0x24, - 0xf6, 0xeb, 0xb7, 0x8f, 0x3d, 0x39, 0x38, 0x0e, 0xc7, 0xf6, 0x67, 0xa2, 0x26, 0x23, 0x90, 0x51, - 0x55, 0x6f, 0xc6, 0xf3, 0xdf, 0x01, 0x00, 0x00, 0xff, 0xff, 0xe8, 0x5f, 0x9e, 0x5c, 0x69, 0x04, - 0x00, 0x00, + // 512 bytes of a gzipped FileDescriptorProto + 0x1f, 0x8b, 0x08, 0x00, 0x00, 0x00, 0x00, 0x00, 0x02, 0xff, 0xa4, 0x94, 0x41, 0x6f, 0x12, 0x41, + 0x14, 0xc7, 0x59, 0x40, 0xb4, 0x53, 0xab, 0x76, 0xe4, 0x40, 0x37, 0x71, 0x21, 0xab, 0x55, 0x62, + 0xd2, 0xd9, 0x14, 0x2f, 0x5e, 0x4b, 0x6a, 0x3c, 0x18, 0x2e, 0x23, 0x9a, 0xe8, 0x85, 0xec, 0xe2, + 0x73, 0xd8, 0x94, 0xdd, 0x59, 0x77, 0x66, 0x1b, 0xe8, 0x77, 0x30, 0xe9, 0x87, 0xf1, 0x43, 0x34, + 0x9e, 0x7a, 0x34, 0x1e, 0xd4, 0xc0, 0x17, 0x31, 0x3b, 0x33, 0xb4, 0x0b, 0x4a, 0x38, 0xf4, 0x04, + 0xef, 0xbd, 0xdf, 0xbc, 0xf9, 0xbf, 0xff, 0x1b, 0x40, 0x8f, 0x86, 0x5c, 0x44, 0x5c, 0x78, 0x7e, + 0x26, 0x47, 0x67, 0xde, 0xe9, 0x61, 0x00, 0xd2, 0x3f, 0xf4, 0xe4, 0x84, 0x24, 0x29, 0x97, 0x1c, + 0xd7, 0x75, 0x99, 0xa8, 0x32, 0x31, 0x65, 0x7b, 0x4f, 0x67, 0x07, 0x8a, 0xf1, 0x0c, 0xa2, 0x02, + 0xbb, 0xce, 0x38, 0xe3, 0x3a, 0x9f, 0x7f, 0x33, 0xd9, 0x26, 0xe3, 0x9c, 0x8d, 0xc1, 0x53, 0x51, + 0x90, 0x7d, 0xf6, 0x64, 0x18, 0x81, 0x90, 0x7e, 0x94, 0x18, 0x60, 0x6f, 0x15, 0xf0, 0xe3, 0xa9, + 0x29, 0x3d, 0x36, 0x0a, 0x03, 0x5f, 0x80, 0xe7, 0x07, 0xc3, 0xf0, 0x4a, 0x65, 0x1e, 0x68, 0xc8, + 0xfd, 0x69, 0xa1, 0xfb, 0x3d, 0xc1, 0x5e, 0xa7, 0x7e, 0x2c, 0x29, 0x7c, 0xc9, 0x40, 0x48, 0xdc, + 0x40, 0xb7, 0x59, 0x1e, 0x43, 0xda, 0xb0, 0x5a, 0x56, 0x7b, 0x8b, 0x2e, 0xc2, 0xeb, 0x0a, 0x34, + 0xca, 0xc5, 0x0a, 0xe0, 0x1e, 0xda, 0xc9, 0x47, 0xe5, 0x69, 0x78, 0xe6, 0xcb, 0x90, 0xc7, 0x8d, + 0x4a, 0xcb, 0x6a, 0x6f, 0x77, 0xea, 0x44, 0xeb, 0x23, 0x0b, 0x7d, 0xe4, 0x28, 0x9e, 0x76, 0x77, + 0xbf, 0x7f, 0x3b, 0xd8, 0x39, 0x2a, 0xe2, 0x74, 0xf9, 0x34, 0x3e, 0x46, 0x08, 0x26, 0x49, 0x98, + 0xea, 0x5e, 0x55, 0xd5, 0xcb, 0xfe, 0xa7, 0x57, 0x7f, 0x61, 0x46, 0xf7, 0xce, 0xc5, 0xaf, 0x66, + 0xe9, 0xfc, 0x77, 0xd3, 0xa2, 0x85, 0x73, 0xee, 0x1b, 0x35, 0xdb, 0xab, 0x09, 0x0c, 0x29, 0x88, + 0x84, 0xc7, 0x02, 0xf0, 0x4b, 0x54, 0x4b, 0x41, 0x64, 0x63, 0xa9, 0x46, 0xdb, 0xee, 0xb4, 0x88, + 0xd9, 0x42, 0xee, 0x12, 0x51, 0xc6, 0x18, 0x97, 0x08, 0x55, 0x1c, 0x35, 0xbc, 0xdb, 0x47, 0xf7, + 0xae, 0x9a, 0xad, 0xf8, 0x04, 0xcb, 0x3e, 0x01, 0x6e, 0xa3, 0x6a, 0x24, 0x98, 0x68, 0x94, 0x5b, + 0x95, 0x75, 0x26, 0x50, 0x45, 0xb8, 0x18, 0x3d, 0xb8, 0xb6, 0x5f, 0x6b, 0x74, 0x47, 0x2a, 0x47, + 0xe1, 0x94, 0x9f, 0xc0, 0x4d, 0x76, 0xd2, 0x42, 0x77, 0x23, 0xc1, 0x06, 0x72, 0x9a, 0xc0, 0x20, + 0x4b, 0xc7, 0x6a, 0x25, 0x5b, 0x14, 0x45, 0x82, 0xf5, 0xa7, 0x09, 0xbc, 0x4b, 0xc7, 0xee, 0x43, + 0xb4, 0x5b, 0xb8, 0x49, 0x5f, 0xdf, 0xf9, 0x5a, 0x46, 0x95, 0x9e, 0x60, 0xf8, 0x3d, 0xba, 0xa5, + 0x74, 0xe1, 0x7d, 0xf2, 0xbf, 0xc7, 0x4c, 0x56, 0x9e, 0x8d, 0xfd, 0x74, 0x13, 0x66, 0x56, 0xf0, + 0x16, 0x55, 0x73, 0x17, 0xf1, 0x93, 0xb5, 0x7c, 0xc1, 0x64, 0x7b, 0x7f, 0x03, 0x65, 0x9a, 0x7e, + 0x40, 0x35, 0x3d, 0x06, 0x5e, 0x2f, 0x63, 0xc9, 0x51, 0xfb, 0xd9, 0x46, 0x4e, 0xb7, 0xee, 0x1e, + 0x5f, 0xcc, 0x1c, 0xeb, 0x72, 0xe6, 0x58, 0x7f, 0x66, 0x8e, 0x75, 0x3e, 0x77, 0x4a, 0x97, 0x73, + 0xa7, 0xf4, 0x63, 0xee, 0x94, 0x3e, 0x3e, 0x67, 0xa1, 0x1c, 0x65, 0x01, 0x19, 0xf2, 0xc8, 0xfc, + 0x98, 0xcd, 0xc7, 0x81, 0xf8, 0x74, 0xe2, 0x4d, 0xcc, 0x7f, 0x43, 0xee, 0xbf, 0x08, 0x6a, 0x6a, + 0xf9, 0x2f, 0xfe, 0x06, 0x00, 0x00, 0xff, 0xff, 0xe9, 0x04, 0xe2, 0x34, 0x38, 0x04, 0x00, 0x00, } // Reference imports to suppress errors if they are not otherwise used. @@ -402,10 +403,10 @@ type MsgClient interface { // Grant grants the provided authorization to the grantee on the granter's // account with the provided expiration time. Grant(ctx context.Context, in *MsgGrantRequest, opts ...grpc.CallOption) (*MsgGrantResponse, error) - // ExecAuthorized attempts to execute the provided messages using + // Exec attempts to execute the provided messages using // authorizations granted to the grantee. Each message should have only // one signer corresponding to the granter of the authorization. - ExecAuthorized(ctx context.Context, in *MsgExecRequest, opts ...grpc.CallOption) (*MsgExecResponse, error) + Exec(ctx context.Context, in *MsgExecRequest, opts ...grpc.CallOption) (*MsgExecResponse, error) // Revoke revokes any authorization corresponding to the provided method name on the // granter's account that has been granted to the grantee. Revoke(ctx context.Context, in *MsgRevokeRequest, opts ...grpc.CallOption) (*MsgRevokeResponse, error) @@ -428,9 +429,9 @@ func (c *msgClient) Grant(ctx context.Context, in *MsgGrantRequest, opts ...grpc return out, nil } -func (c *msgClient) ExecAuthorized(ctx context.Context, in *MsgExecRequest, opts ...grpc.CallOption) (*MsgExecResponse, error) { +func (c *msgClient) Exec(ctx context.Context, in *MsgExecRequest, opts ...grpc.CallOption) (*MsgExecResponse, error) { out := new(MsgExecResponse) - err := c.cc.Invoke(ctx, "/cosmos.authz.v1beta1.Msg/ExecAuthorized", in, out, opts...) + err := c.cc.Invoke(ctx, "/cosmos.authz.v1beta1.Msg/Exec", in, out, opts...) if err != nil { return nil, err } @@ -467,8 +468,8 @@ type UnimplementedMsgServer struct { func (*UnimplementedMsgServer) Grant(ctx context.Context, req *MsgGrantRequest) (*MsgGrantResponse, error) { return nil, status.Errorf(codes.Unimplemented, "method Grant not implemented") } -func (*UnimplementedMsgServer) ExecAuthorized(ctx context.Context, req *MsgExecRequest) (*MsgExecResponse, error) { - return nil, status.Errorf(codes.Unimplemented, "method ExecAuthorized not implemented") +func (*UnimplementedMsgServer) Exec(ctx context.Context, req *MsgExecRequest) (*MsgExecResponse, error) { + return nil, status.Errorf(codes.Unimplemented, "method Exec not implemented") } func (*UnimplementedMsgServer) Revoke(ctx context.Context, req *MsgRevokeRequest) (*MsgRevokeResponse, error) { return nil, status.Errorf(codes.Unimplemented, "method Revoke not implemented") @@ -496,7 +497,7 @@ func _Msg_Grant_Handler(srv interface{}, ctx context.Context, dec func(interface return interceptor(ctx, in, info, handler) } -func _Msg_ExecAuthorized_Handler(srv interface{}, ctx context.Context, dec func(interface{}) error, interceptor grpc.UnaryServerInterceptor) (interface{}, error) { +func _Msg_Exec_Handler(srv interface{}, ctx context.Context, dec func(interface{}) error, interceptor grpc.UnaryServerInterceptor) (interface{}, error) { in := new(MsgExecRequest) if err := dec(in); err != nil { return nil, err @@ -506,7 +507,7 @@ func _Msg_ExecAuthorized_Handler(srv interface{}, ctx context.Context, dec func( } info := &grpc.UnaryServerInfo{ Server: srv, - FullMethod: "/cosmos.authz.v1beta1.Msg/ExecAuthorized", + FullMethod: "/cosmos.authz.v1beta1.Msg/Exec", } handler := func(ctx context.Context, req interface{}) (interface{}, error) { return srv.(MsgServer).Exec(ctx, req.(*MsgExecRequest)) @@ -541,8 +542,8 @@ var _Msg_serviceDesc = grpc.ServiceDesc{ Handler: _Msg_Grant_Handler, }, { - MethodName: "ExecAuthorized", - Handler: _Msg_ExecAuthorized_Handler, + MethodName: "Exec", + Handler: _Msg_Exec_Handler, }, { MethodName: "Revoke", @@ -1096,10 +1097,10 @@ func (m *MsgExecResponse) Unmarshal(dAtA []byte) error { fieldNum := int32(wire >> 3) wireType := int(wire & 0x7) if wireType == 4 { - return fmt.Errorf("proto: MsgExecAuthorizedResponse: wiretype end group for non-group") + return fmt.Errorf("proto: MsgExecResponse: wiretype end group for non-group") } if fieldNum <= 0 { - return fmt.Errorf("proto: MsgExecAuthorizedResponse: illegal tag %d (wire type %d)", fieldNum, wire) + return fmt.Errorf("proto: MsgExecResponse: illegal tag %d (wire type %d)", fieldNum, wire) } switch fieldNum { case 1: @@ -1182,10 +1183,10 @@ func (m *MsgExecRequest) Unmarshal(dAtA []byte) error { fieldNum := int32(wire >> 3) wireType := int(wire & 0x7) if wireType == 4 { - return fmt.Errorf("proto: MsgExecAuthorizedRequest: wiretype end group for non-group") + return fmt.Errorf("proto: MsgExecRequest: wiretype end group for non-group") } if fieldNum <= 0 { - return fmt.Errorf("proto: MsgExecAuthorizedRequest: illegal tag %d (wire type %d)", fieldNum, wire) + return fmt.Errorf("proto: MsgExecRequest: illegal tag %d (wire type %d)", fieldNum, wire) } switch fieldNum { case 1: @@ -1420,7 +1421,7 @@ func (m *MsgRevokeRequest) Unmarshal(dAtA []byte) error { iNdEx = postIndex case 3: if wireType != 2 { - return fmt.Errorf("proto: wrong wireType = %d for field MethodName", wireType) + return fmt.Errorf("proto: wrong wireType = %d for field MsgTypeUrl", wireType) } var stringLen uint64 for shift := uint(0); ; shift += 7 { diff --git a/x/staking/types/authz_test.go b/x/staking/types/authz_test.go index c43ef9e1fb48..282f2beb83c7 100644 --- a/x/staking/types/authz_test.go +++ b/x/staking/types/authz_test.go @@ -252,15 +252,15 @@ func TestAuthzAuthorizations(t *testing.T) { t.Run(tc.msg, func(t *testing.T) { delAuth, err := stakingtypes.NewStakeAuthorization(tc.allowed, tc.denied, tc.msgType, tc.limit) require.NoError(t, err) - updated, del, err := delAuth.Accept(ctx, tc.srvMsg) + resp, err := delAuth.Accept(ctx, tc.srvMsg) if tc.expectErr { require.Error(t, err) require.Equal(t, tc.isDelete, del) } else { require.NoError(t, err) - require.Equal(t, tc.isDelete, del) + require.Equal(t, tc.isDelete, resp.Delete) if tc.updatedAuthorization != nil { - require.Equal(t, tc.updatedAuthorization.String(), updated.String()) + require.Equal(t, tc.updatedAuthorization.String(), resp.Updated.String()) } } }) From 55ce5b8274a958f72df9e7ddbbf486715f7ad899 Mon Sep 17 00:00:00 2001 From: Robert Zaremba Date: Thu, 22 Apr 2021 16:39:55 +0200 Subject: [PATCH 12/44] fix compilation --- x/authz/client/cli/tx.go | 2 +- x/authz/simulation/operations.go | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/x/authz/client/cli/tx.go b/x/authz/client/cli/tx.go index 001bdcefcd9e..564025e2859f 100644 --- a/x/authz/client/cli/tx.go +++ b/x/authz/client/cli/tx.go @@ -264,7 +264,7 @@ Example: msg := types.NewMsgExec(grantee, serviceMsgs) svcMsgClientConn := &msgservice.ServiceMsgClientConn{} msgClient := types.NewMsgClient(svcMsgClientConn) - _, err = msgClient.ExecAuthorized(cmd.Context(), &msg) + _, err = msgClient.Exec(cmd.Context(), &msg) if err != nil { return err } diff --git a/x/authz/simulation/operations.go b/x/authz/simulation/operations.go index 416bd970ccc8..aa776c2706cb 100644 --- a/x/authz/simulation/operations.go +++ b/x/authz/simulation/operations.go @@ -261,7 +261,7 @@ func SimulateMsgExecuteAuthorized(ak types.AccountKeeper, bk types.BankKeeper, k txGen := simappparams.MakeTestEncodingConfig().TxConfig svcMsgClientConn := &msgservice.ServiceMsgClientConn{} authzMsgClient := types.NewMsgClient(svcMsgClientConn) - _, err = authzMsgClient.ExecAuthorized(context.Background(), &msg) + _, err = authzMsgClient.Exec(context.Background(), &msg) if err != nil { return simtypes.NoOpMsg(types.ModuleName, TypeMsgExecDelegated, err.Error()), nil, err } From 385205a1bc3b5f1046d13ac8b2851841c91fd151 Mon Sep 17 00:00:00 2001 From: Robert Zaremba Date: Thu, 22 Apr 2021 16:56:21 +0200 Subject: [PATCH 13/44] fixing gRPC query tests --- x/authz/keeper/grpc_query_test.go | 62 ++++++++++++++++--------------- 1 file changed, 33 insertions(+), 29 deletions(-) diff --git a/x/authz/keeper/grpc_query_test.go b/x/authz/keeper/grpc_query_test.go index 9a0f42a988b1..46bed7747dca 100644 --- a/x/authz/keeper/grpc_query_test.go +++ b/x/authz/keeper/grpc_query_test.go @@ -9,6 +9,7 @@ import ( "github.com/cosmos/cosmos-sdk/x/authz/exported" "github.com/cosmos/cosmos-sdk/x/authz/types" banktypes "github.com/cosmos/cosmos-sdk/x/bank/types" + "github.com/stretchr/testify/require" ) func (suite *TestSuite) TestGRPCQueryAuthorization() { @@ -19,74 +20,77 @@ func (suite *TestSuite) TestGRPCQueryAuthorization() { ) testCases := []struct { msg string - malleate func() - expPass bool - postTest func(res *types.QueryGrantsResponse) + malleate func(require *require.Assertions) + expError string + postTest func(require *require.Assertions, res *types.QueryGrantsResponse) }{ { "fail invalid granter addr", - func() { + func(require *require.Assertions) { req = &types.QueryGrantsRequest{} }, - false, - func(res *types.QueryGrantsResponse) {}, + "empty address string is not allowed", + func(require *require.Assertions, res *types.QueryGrantsResponse) {}, }, { "fail invalid grantee addr", - func() { + func(require *require.Assertions) { req = &types.QueryGrantsRequest{ Granter: addrs[0].String(), } }, - false, - func(res *types.QueryGrantsResponse) {}, + "empty address string is not allowed", + func(require *require.Assertions, res *types.QueryGrantsResponse) {}, }, { "fail invalid msg-type", - func() { + func(require *require.Assertions) { req = &types.QueryGrantsRequest{ - Granter: addrs[0].String(), - Grantee: addrs[1].String(), + Granter: addrs[0].String(), + Grantee: addrs[1].String(), + MsgTypeUrl: "unknown", } }, - false, - func(res *types.QueryGrantsResponse) {}, + "no authorization found for unknown type", + func(require *require.Assertions, res *types.QueryGrantsResponse) {}, }, { "Success", - func() { + func(require *require.Assertions) { now := ctx.BlockHeader().Time newCoins := sdk.NewCoins(sdk.NewInt64Coin("steak", 100)) expAuthorization = &banktypes.SendAuthorization{SpendLimit: newCoins} err := app.AuthzKeeper.GrantX(ctx, addrs[0], addrs[1], expAuthorization, now.Add(time.Hour)) - suite.Require().NoError(err) + require.NoError(err) req = &types.QueryGrantsRequest{ Granter: addrs[1].String(), Grantee: addrs[0].String(), MsgTypeUrl: expAuthorization.MethodName(), } }, - true, - func(res *types.QueryGrantsResponse) { + "", + func(require *require.Assertions, res *types.QueryGrantsResponse) { var auth exported.Authorization - suite.Require().Equal(1, len(res.Grants)) + require.Equal(1, len(res.Grants)) err := suite.app.InterfaceRegistry().UnpackAny(res.Grants[0].Authorization, &auth) - suite.Require().NoError(err) - suite.Require().NotNil(auth) - suite.Require().Equal(auth.String(), expAuthorization.String()) + require.NoError(err) + require.NotNil(auth) + require.Equal(auth.String(), expAuthorization.String()) }, }, } - for _, testCase := range testCases { - suite.Run(fmt.Sprintf("Case %s", testCase.msg), func() { - testCase.malleate() + for _, tc := range testCases { + suite.Run(fmt.Sprintf("Case %s", tc.msg), func() { + require := suite.Require() + tc.malleate(require) result, err := queryClient.Grants(gocontext.Background(), req) - if testCase.expPass { - suite.Require().NoError(err) + if tc.expError == "" { + require.NoError(err) } else { - suite.Require().Error(err) + require.Error(err) + require.Contains(err.Error(), tc.expError) } - testCase.postTest(result) + tc.postTest(require, result) }) } } From 90da7b6785507f04d80aade2b2afc2d5b6a3ec99 Mon Sep 17 00:00:00 2001 From: Robert Zaremba Date: Fri, 23 Apr 2021 10:24:54 +0200 Subject: [PATCH 14/44] fix simulation tests --- proto/cosmos/authz/v1beta1/authz.proto | 1 + proto/cosmos/authz/v1beta1/tx.proto | 2 + x/authz/keeper/grpc_query.go | 2 +- x/authz/keeper/keeper.go | 4 +- x/authz/simulation/operations.go | 4 +- x/authz/types/authorization_grant.go | 4 +- x/authz/types/authz.pb.go | 35 ++----- x/authz/types/tx.pb.go | 137 ++++++------------------- 8 files changed, 51 insertions(+), 138 deletions(-) diff --git a/proto/cosmos/authz/v1beta1/authz.proto b/proto/cosmos/authz/v1beta1/authz.proto index 1cc8c18e28c8..08d7c514749e 100644 --- a/proto/cosmos/authz/v1beta1/authz.proto +++ b/proto/cosmos/authz/v1beta1/authz.proto @@ -7,6 +7,7 @@ import "gogoproto/gogo.proto"; import "google/protobuf/any.proto"; option go_package = "github.com/cosmos/cosmos-sdk/x/authz/types"; +option (gogoproto.goproto_getters_all) = false; // GenericAuthorization gives the grantee unrestricted permissions to execute // the provided method on behalf of the granter's account. diff --git a/proto/cosmos/authz/v1beta1/tx.proto b/proto/cosmos/authz/v1beta1/tx.proto index 59e02127e8dc..c15cde0749a7 100644 --- a/proto/cosmos/authz/v1beta1/tx.proto +++ b/proto/cosmos/authz/v1beta1/tx.proto @@ -6,7 +6,9 @@ import "gogoproto/gogo.proto"; import "google/protobuf/timestamp.proto"; import "google/protobuf/any.proto"; import "cosmos/base/abci/v1beta1/abci.proto"; + option go_package = "github.com/cosmos/cosmos-sdk/x/authz/types"; +option (gogoproto.goproto_getters_all) = false; // Msg defines the authz Msg service. service Msg { diff --git a/x/authz/keeper/grpc_query.go b/x/authz/keeper/grpc_query.go index 9203ab017e7f..69a9d68d2909 100644 --- a/x/authz/keeper/grpc_query.go +++ b/x/authz/keeper/grpc_query.go @@ -62,7 +62,7 @@ func (k Keeper) Grants(c context.Context, req *types.QueryGrantsRequest) (*types if err != nil { return false, err } - auth1 := auth.GetGrant() + auth1 := auth.GetAuthorization() if accumulate { msg, ok := auth1.(proto.Message) if !ok { diff --git a/x/authz/keeper/keeper.go b/x/authz/keeper/keeper.go index edabab068d7f..78faf749352b 100644 --- a/x/authz/keeper/keeper.go +++ b/x/authz/keeper/keeper.go @@ -168,7 +168,7 @@ func (k Keeper) GetAuthorizations(ctx sdk.Context, grantee sdk.AccAddress, grant var authorization types.Grant for ; iter.Valid(); iter.Next() { k.cdc.MustUnmarshalBinaryBare(iter.Value(), &authorization) - authorizations = append(authorizations, authorization.GetGrant()) + authorizations = append(authorizations, authorization.GetAuthorization()) } return authorizations } @@ -186,7 +186,7 @@ func (k Keeper) GetOrRevokeAuthorization(ctx sdk.Context, grantee sdk.AccAddress return nil, time.Time{} } - return grant.GetGrant(), grant.Expiration + return grant.GetAuthorization(), grant.Expiration } // IterateGrants iterates over all authorization grants diff --git a/x/authz/simulation/operations.go b/x/authz/simulation/operations.go index aa776c2706cb..5a17080c0633 100644 --- a/x/authz/simulation/operations.go +++ b/x/authz/simulation/operations.go @@ -169,9 +169,9 @@ func SimulateMsgRevokeAuthorization(ak types.AccountKeeper, bk types.BankKeeper, if err != nil { return simtypes.NoOpMsg(types.ModuleName, TypeMsgRevokeAuthorization, "fee error"), nil, err } - auth := targetGrant.GetAuthorization() - msg := types.NewMsgRevoke(granterAddr, granteeAddr, auth.GetTypeUrl()) + auth := targetGrant.GetAuthorization() + msg := types.NewMsgRevoke(granterAddr, granteeAddr, auth.MethodName()) txGen := simappparams.MakeTestEncodingConfig().TxConfig svcMsgClientConn := &msgservice.ServiceMsgClientConn{} authzMsgClient := types.NewMsgClient(svcMsgClientConn) diff --git a/x/authz/types/authorization_grant.go b/x/authz/types/authorization_grant.go index a9c013f7ea57..77d0c2a74838 100644 --- a/x/authz/types/authorization_grant.go +++ b/x/authz/types/authorization_grant.go @@ -40,8 +40,8 @@ func (auth Grant) UnpackInterfaces(unpacker types.AnyUnpacker) error { return unpacker.UnpackAny(auth.Authorization, &authorization) } -// GetGrant returns the cached value from the Grant.Authorization if present. -func (auth Grant) GetGrant() exported.Authorization { +// GetAuthorization returns the cached value from the Grant.Authorization if present. +func (auth Grant) GetAuthorization() exported.Authorization { authorization, ok := auth.Authorization.GetCachedValue().(exported.Authorization) if !ok { return nil diff --git a/x/authz/types/authz.pb.go b/x/authz/types/authz.pb.go index 3872e85b775a..b782ea57134d 100644 --- a/x/authz/types/authz.pb.go +++ b/x/authz/types/authz.pb.go @@ -69,13 +69,6 @@ func (m *GenericAuthorization) XXX_DiscardUnknown() { var xxx_messageInfo_GenericAuthorization proto.InternalMessageInfo -func (m *GenericAuthorization) GetMsgTypeUrl() string { - if m != nil { - return m.MsgTypeUrl - } - return "" -} - // AuthorizationGrant gives permissions to execute // the provide method with expiration time. type Grant struct { @@ -116,20 +109,6 @@ func (m *Grant) XXX_DiscardUnknown() { var xxx_messageInfo_Grant proto.InternalMessageInfo -func (m *Grant) GetAuthorization() *types.Any { - if m != nil { - return m.Authorization - } - return nil -} - -func (m *Grant) GetExpiration() time.Time { - if m != nil { - return m.Expiration - } - return time.Time{} -} - func init() { proto.RegisterType((*GenericAuthorization)(nil), "cosmos.authz.v1beta1.GenericAuthorization") proto.RegisterType((*Grant)(nil), "cosmos.authz.v1beta1.Grant") @@ -138,7 +117,7 @@ func init() { func init() { proto.RegisterFile("cosmos/authz/v1beta1/authz.proto", fileDescriptor_544dc2e84b61c637) } var fileDescriptor_544dc2e84b61c637 = []byte{ - // 321 bytes of a gzipped FileDescriptorProto + // 325 bytes of a gzipped FileDescriptorProto 0x1f, 0x8b, 0x08, 0x00, 0x00, 0x00, 0x00, 0x00, 0x02, 0xff, 0xe2, 0x52, 0x48, 0xce, 0x2f, 0xce, 0xcd, 0x2f, 0xd6, 0x4f, 0x2c, 0x2d, 0xc9, 0xa8, 0xd2, 0x2f, 0x33, 0x4c, 0x4a, 0x2d, 0x49, 0x34, 0x84, 0xf0, 0xf4, 0x0a, 0x8a, 0xf2, 0x4b, 0xf2, 0x85, 0x44, 0x20, 0x2a, 0xf4, 0x20, 0x62, 0x50, @@ -154,12 +133,12 @@ var fileDescriptor_544dc2e84b61c637 = []byte{ 0x24, 0xa2, 0x07, 0x71, 0x89, 0x1e, 0xcc, 0x25, 0x7a, 0x8e, 0x79, 0x95, 0x4e, 0x82, 0xa7, 0xd0, 0x4d, 0x0a, 0x42, 0xd5, 0x2d, 0xe4, 0xc2, 0xc5, 0x95, 0x5a, 0x51, 0x90, 0x59, 0x04, 0x31, 0x8b, 0x09, 0x6c, 0x96, 0x14, 0x86, 0x59, 0x21, 0xb0, 0xc0, 0x70, 0xe2, 0x38, 0x71, 0x4f, 0x9e, 0x61, - 0xc2, 0x7d, 0x79, 0xc6, 0x20, 0x24, 0x7d, 0x4e, 0x2e, 0x27, 0x1e, 0xc9, 0x31, 0x5e, 0x78, 0x24, - 0xc7, 0xf8, 0xe0, 0x91, 0x1c, 0xe3, 0x84, 0xc7, 0x72, 0x0c, 0x17, 0x1e, 0xcb, 0x31, 0xdc, 0x78, - 0x2c, 0xc7, 0x10, 0xa5, 0x95, 0x9e, 0x59, 0x92, 0x51, 0x9a, 0xa4, 0x97, 0x9c, 0x9f, 0x0b, 0x0d, - 0x70, 0x28, 0xa5, 0x5b, 0x9c, 0x92, 0xad, 0x5f, 0x01, 0x8d, 0x42, 0x50, 0x60, 0x14, 0x27, 0xb1, - 0x81, 0xed, 0x33, 0x06, 0x04, 0x00, 0x00, 0xff, 0xff, 0x28, 0x5c, 0xf3, 0xb9, 0xdf, 0x01, 0x00, - 0x00, + 0xc2, 0x7d, 0x79, 0xc6, 0x20, 0x24, 0x7d, 0x4e, 0x1e, 0x27, 0x1e, 0xca, 0x31, 0x9c, 0x78, 0x24, + 0xc7, 0x78, 0xe1, 0x91, 0x1c, 0xe3, 0x83, 0x47, 0x72, 0x8c, 0x13, 0x1e, 0xcb, 0x31, 0x5c, 0x78, + 0x2c, 0xc7, 0x70, 0xe3, 0xb1, 0x1c, 0x43, 0x94, 0x56, 0x7a, 0x66, 0x49, 0x46, 0x69, 0x92, 0x5e, + 0x72, 0x7e, 0x2e, 0x34, 0xd0, 0xa1, 0x94, 0x6e, 0x71, 0x4a, 0xb6, 0x7e, 0x05, 0x34, 0x1a, 0x41, + 0x01, 0x52, 0x9c, 0xc4, 0x06, 0xb6, 0xd3, 0x18, 0x10, 0x00, 0x00, 0xff, 0xff, 0xc9, 0xea, 0x09, + 0xba, 0xe3, 0x01, 0x00, 0x00, } func (m *GenericAuthorization) Marshal() (dAtA []byte, err error) { diff --git a/x/authz/types/tx.pb.go b/x/authz/types/tx.pb.go index ecff063438d9..f180edf24776 100644 --- a/x/authz/types/tx.pb.go +++ b/x/authz/types/tx.pb.go @@ -77,34 +77,6 @@ func (m *MsgGrantRequest) XXX_DiscardUnknown() { var xxx_messageInfo_MsgGrantRequest proto.InternalMessageInfo -func (m *MsgGrantRequest) GetGranter() string { - if m != nil { - return m.Granter - } - return "" -} - -func (m *MsgGrantRequest) GetGrantee() string { - if m != nil { - return m.Grantee - } - return "" -} - -func (m *MsgGrantRequest) GetAuthorization() *types.Any { - if m != nil { - return m.Authorization - } - return nil -} - -func (m *MsgGrantRequest) GetExpiration() time.Time { - if m != nil { - return m.Expiration - } - return time.Time{} -} - // MsgExecResponse defines the Msg/MsgExecResponse response type. type MsgExecResponse struct { Result *types1.Result `protobuf:"bytes,1,opt,name=result,proto3" json:"result,omitempty"` @@ -143,13 +115,6 @@ func (m *MsgExecResponse) XXX_DiscardUnknown() { var xxx_messageInfo_MsgExecResponse proto.InternalMessageInfo -func (m *MsgExecResponse) GetResult() *types1.Result { - if m != nil { - return m.Result - } - return nil -} - // MsgExecRequest attempts to execute the provided messages using // authorizations granted to the grantee. Each message should have only // one signer corresponding to the granter of the authorization. @@ -191,20 +156,6 @@ func (m *MsgExecRequest) XXX_DiscardUnknown() { var xxx_messageInfo_MsgExecRequest proto.InternalMessageInfo -func (m *MsgExecRequest) GetGrantee() string { - if m != nil { - return m.Grantee - } - return "" -} - -func (m *MsgExecRequest) GetMsgs() []*types.Any { - if m != nil { - return m.Msgs - } - return nil -} - // MsgGrantResponse defines the Msg/MsgGrant response type. type MsgGrantResponse struct { } @@ -283,27 +234,6 @@ func (m *MsgRevokeRequest) XXX_DiscardUnknown() { var xxx_messageInfo_MsgRevokeRequest proto.InternalMessageInfo -func (m *MsgRevokeRequest) GetGranter() string { - if m != nil { - return m.Granter - } - return "" -} - -func (m *MsgRevokeRequest) GetGrantee() string { - if m != nil { - return m.Grantee - } - return "" -} - -func (m *MsgRevokeRequest) GetMsgTypeUrl() string { - if m != nil { - return m.MsgTypeUrl - } - return "" -} - // MsgRevokeResponse defines the Msg/MsgRevokeResponse response type. type MsgRevokeResponse struct { } @@ -353,39 +283,40 @@ func init() { func init() { proto.RegisterFile("cosmos/authz/v1beta1/tx.proto", fileDescriptor_3ceddab7d8589ad1) } var fileDescriptor_3ceddab7d8589ad1 = []byte{ - // 512 bytes of a gzipped FileDescriptorProto - 0x1f, 0x8b, 0x08, 0x00, 0x00, 0x00, 0x00, 0x00, 0x02, 0xff, 0xa4, 0x94, 0x41, 0x6f, 0x12, 0x41, - 0x14, 0xc7, 0x59, 0x40, 0xb4, 0x53, 0xab, 0x76, 0xe4, 0x40, 0x37, 0x71, 0x21, 0xab, 0x55, 0x62, - 0xd2, 0xd9, 0x14, 0x2f, 0x5e, 0x4b, 0x6a, 0x3c, 0x18, 0x2e, 0x23, 0x9a, 0xe8, 0x85, 0xec, 0xe2, - 0x73, 0xd8, 0x94, 0xdd, 0x59, 0x77, 0x66, 0x1b, 0xe8, 0x77, 0x30, 0xe9, 0x87, 0xf1, 0x43, 0x34, - 0x9e, 0x7a, 0x34, 0x1e, 0xd4, 0xc0, 0x17, 0x31, 0x3b, 0x33, 0xb4, 0x0b, 0x4a, 0x38, 0xf4, 0x04, - 0xef, 0xbd, 0xdf, 0xbc, 0xf9, 0xbf, 0xff, 0x1b, 0x40, 0x8f, 0x86, 0x5c, 0x44, 0x5c, 0x78, 0x7e, - 0x26, 0x47, 0x67, 0xde, 0xe9, 0x61, 0x00, 0xd2, 0x3f, 0xf4, 0xe4, 0x84, 0x24, 0x29, 0x97, 0x1c, - 0xd7, 0x75, 0x99, 0xa8, 0x32, 0x31, 0x65, 0x7b, 0x4f, 0x67, 0x07, 0x8a, 0xf1, 0x0c, 0xa2, 0x02, - 0xbb, 0xce, 0x38, 0xe3, 0x3a, 0x9f, 0x7f, 0x33, 0xd9, 0x26, 0xe3, 0x9c, 0x8d, 0xc1, 0x53, 0x51, - 0x90, 0x7d, 0xf6, 0x64, 0x18, 0x81, 0x90, 0x7e, 0x94, 0x18, 0x60, 0x6f, 0x15, 0xf0, 0xe3, 0xa9, - 0x29, 0x3d, 0x36, 0x0a, 0x03, 0x5f, 0x80, 0xe7, 0x07, 0xc3, 0xf0, 0x4a, 0x65, 0x1e, 0x68, 0xc8, - 0xfd, 0x69, 0xa1, 0xfb, 0x3d, 0xc1, 0x5e, 0xa7, 0x7e, 0x2c, 0x29, 0x7c, 0xc9, 0x40, 0x48, 0xdc, - 0x40, 0xb7, 0x59, 0x1e, 0x43, 0xda, 0xb0, 0x5a, 0x56, 0x7b, 0x8b, 0x2e, 0xc2, 0xeb, 0x0a, 0x34, - 0xca, 0xc5, 0x0a, 0xe0, 0x1e, 0xda, 0xc9, 0x47, 0xe5, 0x69, 0x78, 0xe6, 0xcb, 0x90, 0xc7, 0x8d, - 0x4a, 0xcb, 0x6a, 0x6f, 0x77, 0xea, 0x44, 0xeb, 0x23, 0x0b, 0x7d, 0xe4, 0x28, 0x9e, 0x76, 0x77, - 0xbf, 0x7f, 0x3b, 0xd8, 0x39, 0x2a, 0xe2, 0x74, 0xf9, 0x34, 0x3e, 0x46, 0x08, 0x26, 0x49, 0x98, - 0xea, 0x5e, 0x55, 0xd5, 0xcb, 0xfe, 0xa7, 0x57, 0x7f, 0x61, 0x46, 0xf7, 0xce, 0xc5, 0xaf, 0x66, - 0xe9, 0xfc, 0x77, 0xd3, 0xa2, 0x85, 0x73, 0xee, 0x1b, 0x35, 0xdb, 0xab, 0x09, 0x0c, 0x29, 0x88, - 0x84, 0xc7, 0x02, 0xf0, 0x4b, 0x54, 0x4b, 0x41, 0x64, 0x63, 0xa9, 0x46, 0xdb, 0xee, 0xb4, 0x88, - 0xd9, 0x42, 0xee, 0x12, 0x51, 0xc6, 0x18, 0x97, 0x08, 0x55, 0x1c, 0x35, 0xbc, 0xdb, 0x47, 0xf7, - 0xae, 0x9a, 0xad, 0xf8, 0x04, 0xcb, 0x3e, 0x01, 0x6e, 0xa3, 0x6a, 0x24, 0x98, 0x68, 0x94, 0x5b, - 0x95, 0x75, 0x26, 0x50, 0x45, 0xb8, 0x18, 0x3d, 0xb8, 0xb6, 0x5f, 0x6b, 0x74, 0x47, 0x2a, 0x47, - 0xe1, 0x94, 0x9f, 0xc0, 0x4d, 0x76, 0xd2, 0x42, 0x77, 0x23, 0xc1, 0x06, 0x72, 0x9a, 0xc0, 0x20, - 0x4b, 0xc7, 0x6a, 0x25, 0x5b, 0x14, 0x45, 0x82, 0xf5, 0xa7, 0x09, 0xbc, 0x4b, 0xc7, 0xee, 0x43, - 0xb4, 0x5b, 0xb8, 0x49, 0x5f, 0xdf, 0xf9, 0x5a, 0x46, 0x95, 0x9e, 0x60, 0xf8, 0x3d, 0xba, 0xa5, - 0x74, 0xe1, 0x7d, 0xf2, 0xbf, 0xc7, 0x4c, 0x56, 0x9e, 0x8d, 0xfd, 0x74, 0x13, 0x66, 0x56, 0xf0, - 0x16, 0x55, 0x73, 0x17, 0xf1, 0x93, 0xb5, 0x7c, 0xc1, 0x64, 0x7b, 0x7f, 0x03, 0x65, 0x9a, 0x7e, - 0x40, 0x35, 0x3d, 0x06, 0x5e, 0x2f, 0x63, 0xc9, 0x51, 0xfb, 0xd9, 0x46, 0x4e, 0xb7, 0xee, 0x1e, - 0x5f, 0xcc, 0x1c, 0xeb, 0x72, 0xe6, 0x58, 0x7f, 0x66, 0x8e, 0x75, 0x3e, 0x77, 0x4a, 0x97, 0x73, - 0xa7, 0xf4, 0x63, 0xee, 0x94, 0x3e, 0x3e, 0x67, 0xa1, 0x1c, 0x65, 0x01, 0x19, 0xf2, 0xc8, 0xfc, - 0x98, 0xcd, 0xc7, 0x81, 0xf8, 0x74, 0xe2, 0x4d, 0xcc, 0x7f, 0x43, 0xee, 0xbf, 0x08, 0x6a, 0x6a, - 0xf9, 0x2f, 0xfe, 0x06, 0x00, 0x00, 0xff, 0xff, 0xe9, 0x04, 0xe2, 0x34, 0x38, 0x04, 0x00, 0x00, + // 517 bytes of a gzipped FileDescriptorProto + 0x1f, 0x8b, 0x08, 0x00, 0x00, 0x00, 0x00, 0x00, 0x02, 0xff, 0xa4, 0x94, 0xcf, 0x6e, 0xd3, 0x40, + 0x10, 0xc6, 0xe3, 0x26, 0x04, 0xba, 0xa5, 0x40, 0x97, 0x1c, 0x52, 0x4b, 0x38, 0x91, 0xa1, 0x10, + 0x21, 0x75, 0xad, 0x86, 0x0b, 0xd7, 0x46, 0x20, 0x90, 0x50, 0x2e, 0x4b, 0x40, 0x82, 0x4b, 0x64, + 0x87, 0x61, 0x63, 0x35, 0xf6, 0x1a, 0xef, 0xba, 0x4a, 0xfa, 0x0e, 0x48, 0x7d, 0x18, 0x1e, 0x22, + 0xe2, 0xd4, 0x23, 0xe2, 0xc0, 0x9f, 0xe4, 0x45, 0x90, 0x77, 0x37, 0xad, 0x13, 0x88, 0x72, 0xe0, + 0x94, 0xcc, 0xcc, 0x6f, 0x67, 0xbf, 0xf9, 0x66, 0x13, 0x74, 0x6f, 0xc0, 0x45, 0xc4, 0x85, 0xe7, + 0x67, 0x72, 0x78, 0xe6, 0x9d, 0x1e, 0x05, 0x20, 0xfd, 0x23, 0x4f, 0x8e, 0x49, 0x92, 0x72, 0xc9, + 0x71, 0x4d, 0x97, 0x89, 0x2a, 0x13, 0x53, 0xb6, 0xf7, 0x75, 0xb6, 0xaf, 0x18, 0xcf, 0x20, 0x2a, + 0xb0, 0x6b, 0x8c, 0x33, 0xae, 0xf3, 0xf9, 0x37, 0x93, 0x6d, 0x30, 0xce, 0xd9, 0x08, 0x3c, 0x15, + 0x05, 0xd9, 0x47, 0x4f, 0x86, 0x11, 0x08, 0xe9, 0x47, 0x89, 0x01, 0xf6, 0x57, 0x01, 0x3f, 0x9e, + 0x98, 0xd2, 0x7d, 0xa3, 0x30, 0xf0, 0x05, 0x78, 0x7e, 0x30, 0x08, 0x2f, 0x55, 0xe6, 0x81, 0x86, + 0xdc, 0xef, 0x16, 0xba, 0xdd, 0x15, 0xec, 0x45, 0xea, 0xc7, 0x92, 0xc2, 0xa7, 0x0c, 0x84, 0xc4, + 0x75, 0x74, 0x9d, 0xe5, 0x31, 0xa4, 0x75, 0xab, 0x69, 0xb5, 0xb6, 0xe9, 0x22, 0xbc, 0xaa, 0x40, + 0x7d, 0xab, 0x58, 0x01, 0xdc, 0x45, 0xbb, 0xf9, 0xa8, 0x3c, 0x0d, 0xcf, 0x7c, 0x19, 0xf2, 0xb8, + 0x5e, 0x6e, 0x5a, 0xad, 0x9d, 0x76, 0x8d, 0x68, 0x7d, 0x64, 0xa1, 0x8f, 0x1c, 0xc7, 0x93, 0xce, + 0xde, 0xd7, 0x2f, 0x87, 0xbb, 0xc7, 0x45, 0x9c, 0x2e, 0x9f, 0xc6, 0xcf, 0x10, 0x82, 0x71, 0x12, + 0xa6, 0xba, 0x57, 0x45, 0xf5, 0xb2, 0xff, 0xea, 0xd5, 0x5b, 0x98, 0xd1, 0xb9, 0x31, 0xfd, 0xd1, + 0x28, 0x9d, 0xff, 0x6c, 0x58, 0xb4, 0x70, 0xce, 0x7d, 0xa5, 0x66, 0x7b, 0x3e, 0x86, 0x01, 0x05, + 0x91, 0xf0, 0x58, 0x00, 0x7e, 0x8a, 0xaa, 0x29, 0x88, 0x6c, 0x24, 0xd5, 0x68, 0x3b, 0xed, 0x26, + 0x31, 0x5b, 0xc8, 0x5d, 0x22, 0xca, 0x18, 0xe3, 0x12, 0xa1, 0x8a, 0xa3, 0x86, 0x77, 0x7b, 0xe8, + 0xd6, 0x65, 0xb3, 0x15, 0x9f, 0x60, 0xd9, 0x27, 0xc0, 0x2d, 0x54, 0x89, 0x04, 0x13, 0xf5, 0xad, + 0x66, 0x79, 0x9d, 0x09, 0x54, 0x11, 0x2e, 0x46, 0x77, 0xae, 0xec, 0xd7, 0x1a, 0xdd, 0xa1, 0xca, + 0x51, 0x38, 0xe5, 0x27, 0xf0, 0x3f, 0x3b, 0x69, 0xa2, 0x9b, 0x91, 0x60, 0x7d, 0x39, 0x49, 0xa0, + 0x9f, 0xa5, 0x23, 0xb5, 0x92, 0x6d, 0x8a, 0x22, 0xc1, 0x7a, 0x93, 0x04, 0xde, 0xa4, 0x23, 0xf7, + 0x2e, 0xda, 0x2b, 0xdc, 0xa4, 0xaf, 0x6f, 0x7f, 0xde, 0x42, 0xe5, 0xae, 0x60, 0xf8, 0x2d, 0xba, + 0xa6, 0x74, 0xe1, 0x03, 0xf2, 0xaf, 0xc7, 0x4c, 0x56, 0x9e, 0x8d, 0xfd, 0x70, 0x13, 0x66, 0x56, + 0xf0, 0x1a, 0x55, 0x72, 0x17, 0xf1, 0x83, 0xb5, 0x7c, 0xc1, 0x64, 0xfb, 0x60, 0x03, 0x65, 0x9a, + 0xbe, 0x43, 0x55, 0x3d, 0x06, 0x5e, 0x2f, 0x63, 0xc9, 0x51, 0xfb, 0xd1, 0x46, 0x4e, 0xb7, 0xee, + 0xbc, 0x9c, 0xfe, 0x76, 0x4a, 0xd3, 0x99, 0x63, 0x5d, 0xcc, 0x1c, 0xeb, 0xd7, 0xcc, 0xb1, 0xce, + 0xe7, 0x4e, 0xe9, 0x62, 0xee, 0x94, 0xbe, 0xcd, 0x9d, 0xd2, 0xfb, 0xc7, 0x2c, 0x94, 0xc3, 0x2c, + 0x20, 0x03, 0x1e, 0x99, 0x1f, 0xb4, 0xf9, 0x38, 0x14, 0x1f, 0x4e, 0xbc, 0xb1, 0xf9, 0x7f, 0xc8, + 0x77, 0x20, 0x82, 0xaa, 0x7a, 0x00, 0x4f, 0xfe, 0x04, 0x00, 0x00, 0xff, 0xff, 0x2f, 0xc0, 0x87, + 0xd6, 0x3c, 0x04, 0x00, 0x00, } // Reference imports to suppress errors if they are not otherwise used. From bf42888d67f89003c4c786dbaf648e7a4d415b1d Mon Sep 17 00:00:00 2001 From: Robert Zaremba Date: Fri, 23 Apr 2021 10:36:01 +0200 Subject: [PATCH 15/44] few renames --- Makefile | 5 +++-- docs/core/proto-docs.md | 2 +- proto/cosmos/authz/v1beta1/event.proto | 2 +- x/authz/genesis.go | 2 +- x/authz/genesis_test.go | 4 ++-- x/authz/keeper/grpc_query_test.go | 4 ++-- x/authz/keeper/keeper.go | 18 +++++++++--------- x/authz/keeper/keeper_test.go | 12 ++++++------ x/authz/keeper/msg_server.go | 4 ++-- x/authz/simulation/operations_test.go | 4 ++-- x/authz/types/event.pb.go | 2 +- 11 files changed, 30 insertions(+), 29 deletions(-) diff --git a/Makefile b/Makefile index cc5783ce8bc6..e3bb9d08c7a3 100644 --- a/Makefile +++ b/Makefile @@ -371,10 +371,11 @@ devdoc-update: proto-all: proto-format proto-lint proto-gen -protoContainer=cosmos-proto-gen +protoContainerVer=v0.1 +protoContainer=cosmos-proto-gen-$(protoContainerVer) proto-gen: @echo "Generating Protobuf files" - if docker ps -a --format '{{.Names}}' | grep -Eq "^${protoContainer}$$"; then docker start $(protoContainer); else docker run -a --name $(protoContainer) -v $(CURDIR):/workspace --workdir /workspace tendermintdev/sdk-proto-gen:v0.1 sh ./scripts/protocgen.sh; fi + @if docker ps -a --format '{{.Names}}' | grep -Eq "^${protoContainer}$$"; then docker start -a $(protoContainer); else docker run --name $(protoContainer) -v $(CURDIR):/workspace --workdir /workspace tendermintdev/sdk-proto-gen:$(protoContainerVer) sh ./scripts/protocgen.sh; fi # $(DOCKER) run --rm -v $(CURDIR):/workspace --workdir /workspace tendermintdev/sdk-proto-gen:v0.1 sh ./scripts/protocgen.sh proto-format: diff --git a/docs/core/proto-docs.md b/docs/core/proto-docs.md index 26ebea766dac..3063180f51f7 100644 --- a/docs/core/proto-docs.md +++ b/docs/core/proto-docs.md @@ -934,7 +934,7 @@ EventGrant is emitted on Msg/Grant | Field | Type | Label | Description | | ----- | ---- | ----- | ----------- | -| `module` | [string](#string) | | Module which invokes the authorizaiton grant TODO: not sure if this is needed. It's always have the same value | +| `module` | [string](#string) | | Module which invokes the authorizaiton grant TODO: not sure if this is needed. It always has the same value | | `msg` | [string](#string) | | Msg type for which an autorization is granted | | `granter` | [string](#string) | | Granter account address | | `grantee` | [string](#string) | | Grantee account address | diff --git a/proto/cosmos/authz/v1beta1/event.proto b/proto/cosmos/authz/v1beta1/event.proto index 10c189231733..3d9c9cb02b63 100644 --- a/proto/cosmos/authz/v1beta1/event.proto +++ b/proto/cosmos/authz/v1beta1/event.proto @@ -12,7 +12,7 @@ option go_package = "github.com/cosmos/cosmos-sdk/x/authz/types"; // EventGrant is emitted on Msg/Grant message EventGrant { // Module which invokes the authorizaiton grant - // TODO: not sure if this is needed. It's always have the same value + // TODO: not sure if this is needed. It always has the same value string module = 1; // Msg type for which an autorization is granted string msg = 2; diff --git a/x/authz/genesis.go b/x/authz/genesis.go index a2b1cfd3ceb0..d3341d320e59 100644 --- a/x/authz/genesis.go +++ b/x/authz/genesis.go @@ -23,7 +23,7 @@ func InitGenesis(ctx sdk.Context, keeper keeper.Keeper, data *types.GenesisState panic("expected authorization") } - err = keeper.GrantX(ctx, grantee, granter, authorization, entry.Expiration) + err = keeper.SaveGrant(ctx, grantee, granter, authorization, entry.Expiration) if err != nil { panic(err) } diff --git a/x/authz/genesis_test.go b/x/authz/genesis_test.go index a99ad60b938f..e12514fd8c9e 100644 --- a/x/authz/genesis_test.go +++ b/x/authz/genesis_test.go @@ -42,12 +42,12 @@ func (suite *GenesisTestSuite) TestImportExportGenesis() { now := suite.ctx.BlockHeader().Time grant := &bank.SendAuthorization{SpendLimit: coins} - err := suite.keeper.GrantX(suite.ctx, granteeAddr, granterAddr, grant, now.Add(time.Hour)) + err := suite.keeper.SaveGrant(suite.ctx, granteeAddr, granterAddr, grant, now.Add(time.Hour)) suite.Require().NoError(err) genesis := authz.ExportGenesis(suite.ctx, suite.keeper) // Clear keeper - suite.keeper.RevokeX(suite.ctx, granteeAddr, granterAddr, grant.MethodName()) + suite.keeper.DeleteGrant(suite.ctx, granteeAddr, granterAddr, grant.MethodName()) authz.InitGenesis(suite.ctx, suite.keeper, genesis) newGenesis := authz.ExportGenesis(suite.ctx, suite.keeper) diff --git a/x/authz/keeper/grpc_query_test.go b/x/authz/keeper/grpc_query_test.go index 46bed7747dca..125c02672cec 100644 --- a/x/authz/keeper/grpc_query_test.go +++ b/x/authz/keeper/grpc_query_test.go @@ -60,7 +60,7 @@ func (suite *TestSuite) TestGRPCQueryAuthorization() { now := ctx.BlockHeader().Time newCoins := sdk.NewCoins(sdk.NewInt64Coin("steak", 100)) expAuthorization = &banktypes.SendAuthorization{SpendLimit: newCoins} - err := app.AuthzKeeper.GrantX(ctx, addrs[0], addrs[1], expAuthorization, now.Add(time.Hour)) + err := app.AuthzKeeper.SaveGrant(ctx, addrs[0], addrs[1], expAuthorization, now.Add(time.Hour)) require.NoError(err) req = &types.QueryGrantsRequest{ Granter: addrs[1].String(), @@ -131,7 +131,7 @@ func (suite *TestSuite) TestGRPCQueryAuthorizations() { now := ctx.BlockHeader().Time newCoins := sdk.NewCoins(sdk.NewInt64Coin("steak", 100)) expAuthorization = &banktypes.SendAuthorization{SpendLimit: newCoins} - err := app.AuthzKeeper.GrantX(ctx, addrs[0], addrs[1], expAuthorization, now.Add(time.Hour)) + err := app.AuthzKeeper.SaveGrant(ctx, addrs[0], addrs[1], expAuthorization, now.Add(time.Hour)) suite.Require().NoError(err) req = &types.QueryGrantsRequest{ Granter: addrs[1].String(), diff --git a/x/authz/keeper/keeper.go b/x/authz/keeper/keeper.go index 78faf749352b..0b4c430df629 100644 --- a/x/authz/keeper/keeper.go +++ b/x/authz/keeper/keeper.go @@ -93,7 +93,7 @@ func (k Keeper) DispatchActions(ctx sdk.Context, grantee sdk.AccAddress, service return nil, err } if resp.Delete { - k.RevokeX(ctx, grantee, granter, serviceMsg.Type()) + k.DeleteGrant(ctx, grantee, granter, serviceMsg.Type()) } else if resp.Updated != nil { err = k.update(ctx, grantee, granter, resp.Updated) if err != nil { @@ -119,11 +119,10 @@ func (k Keeper) DispatchActions(ctx sdk.Context, grantee sdk.AccAddress, service return msgResult, nil } -// Grant method grants the provided authorization to the grantee on the granter's account with the provided expiration -// time. If there is an existing authorization grant for the same `sdk.Msg` type, this grant -// overwrites that. -// TODO: rename -func (k Keeper) GrantX(ctx sdk.Context, grantee, granter sdk.AccAddress, authorization exported.Authorization, expiration time.Time) error { +// SaveGrant method grants the provided authorization to the grantee on the granter's account +// with the provided expiration time. If there is an existing authorization grant for the +// same `sdk.Msg` type, this grant overwrites that. +func (k Keeper) SaveGrant(ctx sdk.Context, grantee, granter sdk.AccAddress, authorization exported.Authorization, expiration time.Time) error { store := ctx.KVStore(k.storeKey) grant, err := types.NewGrant(authorization, expiration) @@ -142,8 +141,9 @@ func (k Keeper) GrantX(ctx sdk.Context, grantee, granter sdk.AccAddress, authori }) } -// Revoke method revokes any authorization for the provided message type granted to the grantee by the granter. -func (k Keeper) RevokeX(ctx sdk.Context, grantee sdk.AccAddress, granter sdk.AccAddress, msgType string) error { +// DeleteGrant revokes any authorization for the provided message type granted to the grantee +// by the granter. +func (k Keeper) DeleteGrant(ctx sdk.Context, grantee sdk.AccAddress, granter sdk.AccAddress, msgType string) error { store := ctx.KVStore(k.storeKey) grantStoreKey := types.GetAuthorizationStoreKey(grantee, granter, msgType) _, found := k.getAuthorizationGrant(ctx, grantStoreKey) @@ -182,7 +182,7 @@ func (k Keeper) GetOrRevokeAuthorization(ctx sdk.Context, grantee sdk.AccAddress return nil, time.Time{} } if grant.Expiration.Before(ctx.BlockHeader().Time) { - k.RevokeX(ctx, grantee, granter, msgType) + k.DeleteGrant(ctx, grantee, granter, msgType) return nil, time.Time{} } diff --git a/x/authz/keeper/keeper_test.go b/x/authz/keeper/keeper_test.go index d545a7bac601..a5e9782a9ff7 100644 --- a/x/authz/keeper/keeper_test.go +++ b/x/authz/keeper/keeper_test.go @@ -62,14 +62,14 @@ func (s *TestSuite) TestKeeper() { newCoins := sdk.NewCoins(sdk.NewInt64Coin("steak", 100)) s.T().Log("verify if expired authorization is rejected") x := &banktypes.SendAuthorization{SpendLimit: newCoins} - err := app.AuthzKeeper.GrantX(ctx, granterAddr, granteeAddr, x, now.Add(-1*time.Hour)) + err := app.AuthzKeeper.SaveGrant(ctx, granterAddr, granteeAddr, x, now.Add(-1*time.Hour)) s.Require().NoError(err) authorization, _ = app.AuthzKeeper.GetOrRevokeAuthorization(ctx, granteeAddr, granterAddr, banktypes.SendAuthorization{}.MethodName()) s.Require().Nil(authorization) s.T().Log("verify if authorization is accepted") x = &banktypes.SendAuthorization{SpendLimit: newCoins} - err = app.AuthzKeeper.GrantX(ctx, granteeAddr, granterAddr, x, now.Add(time.Hour)) + err = app.AuthzKeeper.SaveGrant(ctx, granteeAddr, granterAddr, x, now.Add(time.Hour)) s.Require().NoError(err) authorization, _ = app.AuthzKeeper.GetOrRevokeAuthorization(ctx, granteeAddr, granterAddr, banktypes.SendAuthorization{}.MethodName()) s.Require().NotNil(authorization) @@ -84,13 +84,13 @@ func (s *TestSuite) TestKeeper() { s.Require().Nil(authorization) s.T().Log("verify revoke fails with wrong information") - err = app.AuthzKeeper.RevokeX(ctx, recipientAddr, granterAddr, banktypes.SendAuthorization{}.MethodName()) + err = app.AuthzKeeper.DeleteGrant(ctx, recipientAddr, granterAddr, banktypes.SendAuthorization{}.MethodName()) s.Require().Error(err) authorization, _ = app.AuthzKeeper.GetOrRevokeAuthorization(ctx, recipientAddr, granterAddr, banktypes.SendAuthorization{}.MethodName()) s.Require().Nil(authorization) s.T().Log("verify revoke executes with correct information") - err = app.AuthzKeeper.RevokeX(ctx, granteeAddr, granterAddr, banktypes.SendAuthorization{}.MethodName()) + err = app.AuthzKeeper.DeleteGrant(ctx, granteeAddr, granterAddr, banktypes.SendAuthorization{}.MethodName()) s.Require().NoError(err) authorization, _ = app.AuthzKeeper.GetOrRevokeAuthorization(ctx, granteeAddr, granterAddr, banktypes.SendAuthorization{}.MethodName()) s.Require().Nil(authorization) @@ -113,7 +113,7 @@ func (s *TestSuite) TestKeeperIter() { newCoins := sdk.NewCoins(sdk.NewInt64Coin("steak", 100)) s.T().Log("verify if expired authorization is rejected") x := &banktypes.SendAuthorization{SpendLimit: newCoins} - err := app.AuthzKeeper.GrantX(ctx, granteeAddr, granterAddr, x, now.Add(-1*time.Hour)) + err := app.AuthzKeeper.SaveGrant(ctx, granteeAddr, granterAddr, x, now.Add(-1*time.Hour)) s.Require().NoError(err) authorization, _ = app.AuthzKeeper.GetOrRevokeAuthorization(ctx, granteeAddr, granterAddr, "abcd") s.Require().Nil(authorization) @@ -162,7 +162,7 @@ func (s *TestSuite) TestKeeperFees() { s.T().Log("verify dispatch executes with correct information") // grant authorization - err = app.AuthzKeeper.GrantX(s.ctx, granteeAddr, granterAddr, &banktypes.SendAuthorization{SpendLimit: smallCoin}, now) + err = app.AuthzKeeper.SaveGrant(s.ctx, granteeAddr, granterAddr, &banktypes.SendAuthorization{SpendLimit: smallCoin}, now) s.Require().NoError(err) authorization, _ := app.AuthzKeeper.GetOrRevokeAuthorization(s.ctx, granteeAddr, granterAddr, banktypes.SendAuthorization{}.MethodName()) s.Require().NotNil(authorization) diff --git a/x/authz/keeper/msg_server.go b/x/authz/keeper/msg_server.go index fa746a8170f3..3a89f88e1c2a 100644 --- a/x/authz/keeper/msg_server.go +++ b/x/authz/keeper/msg_server.go @@ -28,7 +28,7 @@ func (k Keeper) Grant(goCtx context.Context, msg *types.MsgGrantRequest) (*types return nil, sdkerrors.Wrapf(sdkerrors.ErrInvalidType, "%s doesn't exist.", authorization.MethodName()) } - err = k.GrantX(ctx, grantee, granter, authorization, msg.Expiration) + err = k.SaveGrant(ctx, grantee, granter, authorization, msg.Expiration) if err != nil { return nil, err } @@ -48,7 +48,7 @@ func (k Keeper) Revoke(goCtx context.Context, msg *types.MsgRevokeRequest) (*typ return nil, err } - err = k.RevokeX(ctx, grantee, granter, msg.MsgTypeUrl) + err = k.DeleteGrant(ctx, grantee, granter, msg.MsgTypeUrl) if err != nil { return nil, err } diff --git a/x/authz/simulation/operations_test.go b/x/authz/simulation/operations_test.go index 527f0ede8b7b..4e9b30e7d6b8 100644 --- a/x/authz/simulation/operations_test.go +++ b/x/authz/simulation/operations_test.go @@ -139,7 +139,7 @@ func (suite *SimTestSuite) TestSimulateRevokeAuthorization() { grantee := accounts[1] authorization := banktypes.NewSendAuthorization(initCoins) - err := suite.app.AuthzKeeper.GrantX(suite.ctx, grantee.Address, granter.Address, authorization, time.Now().Add(30*time.Hour)) + err := suite.app.AuthzKeeper.SaveGrant(suite.ctx, grantee.Address, granter.Address, authorization, time.Now().Add(30*time.Hour)) suite.Require().NoError(err) // execute operation @@ -174,7 +174,7 @@ func (suite *SimTestSuite) TestSimulateExecAuthorization() { grantee := accounts[1] authorization := banktypes.NewSendAuthorization(initCoins) - err := suite.app.AuthzKeeper.GrantX(suite.ctx, grantee.Address, granter.Address, authorization, time.Now().Add(30*time.Hour)) + err := suite.app.AuthzKeeper.SaveGrant(suite.ctx, grantee.Address, granter.Address, authorization, time.Now().Add(30*time.Hour)) suite.Require().NoError(err) // execute operation diff --git a/x/authz/types/event.pb.go b/x/authz/types/event.pb.go index 6c48acea40f8..200a6aff3449 100644 --- a/x/authz/types/event.pb.go +++ b/x/authz/types/event.pb.go @@ -25,7 +25,7 @@ const _ = proto.GoGoProtoPackageIsVersion3 // please upgrade the proto package // EventGrant is emitted on Msg/Grant type EventGrant struct { // Module which invokes the authorizaiton grant - // TODO: not sure if this is needed. It's always have the same value + // TODO: not sure if this is needed. It always has the same value Module string `protobuf:"bytes,1,opt,name=module,proto3" json:"module,omitempty"` // Msg type for which an autorization is granted Msg string `protobuf:"bytes,2,opt,name=msg,proto3" json:"msg,omitempty"` From afb9e8f89c689046bf8ce5c43cc7e8b6b491b0ed Mon Sep 17 00:00:00 2001 From: Robert Zaremba Date: Fri, 23 Apr 2021 11:00:33 +0200 Subject: [PATCH 16/44] more refactore --- x/authz/keeper/grpc_query.go | 2 +- x/authz/keeper/keeper.go | 32 +++++++++++++------------- x/authz/{types => keeper}/keys_test.go | 4 ++-- x/authz/keeper/msg_server.go | 5 +++- x/authz/types/keys.go | 27 ---------------------- x/authz/types/msgs.go | 4 ++-- 6 files changed, 25 insertions(+), 49 deletions(-) rename x/authz/{types => keeper}/keys_test.go (81%) diff --git a/x/authz/keeper/grpc_query.go b/x/authz/keeper/grpc_query.go index 69a9d68d2909..49065574f6f1 100644 --- a/x/authz/keeper/grpc_query.go +++ b/x/authz/keeper/grpc_query.go @@ -36,7 +36,7 @@ func (k Keeper) Grants(c context.Context, req *types.QueryGrantsRequest) (*types ctx := sdk.UnwrapSDKContext(c) store := ctx.KVStore(k.storeKey) - key := types.GetAuthorizationStoreKey(grantee, granter, "") + key := grantStoreKey(grantee, granter, "") authStore := prefix.NewStore(store, key) if req.MsgTypeUrl != "" { diff --git a/x/authz/keeper/keeper.go b/x/authz/keeper/keeper.go index 0b4c430df629..d47212c98de2 100644 --- a/x/authz/keeper/keeper.go +++ b/x/authz/keeper/keeper.go @@ -37,10 +37,10 @@ func (k Keeper) Logger(ctx sdk.Context) log.Logger { return ctx.Logger().With("module", fmt.Sprintf("x/%s", types.ModuleName)) } -// getAuthorizationGrant returns grant between granter and grantee for the given msg type -func (k Keeper) getAuthorizationGrant(ctx sdk.Context, grantStoreKey []byte) (grant types.Grant, found bool) { +// getGrant returns grant stored at skey. +func (k Keeper) getGrant(ctx sdk.Context, skey []byte) (grant types.Grant, found bool) { store := ctx.KVStore(k.storeKey) - bz := store.Get(grantStoreKey) + bz := store.Get(skey) if bz == nil { return grant, false } @@ -49,8 +49,8 @@ func (k Keeper) getAuthorizationGrant(ctx sdk.Context, grantStoreKey []byte) (gr } func (k Keeper) update(ctx sdk.Context, grantee sdk.AccAddress, granter sdk.AccAddress, updated exported.Authorization) error { - grantStoreKey := types.GetAuthorizationStoreKey(grantee, granter, updated.MethodName()) - grant, found := k.getAuthorizationGrant(ctx, grantStoreKey) + skey := grantStoreKey(grantee, granter, updated.MethodName()) + grant, found := k.getGrant(ctx, skey) if !found { return sdkerrors.ErrNotFound.Wrap("authorization not found") } @@ -67,7 +67,7 @@ func (k Keeper) update(ctx sdk.Context, grantee sdk.AccAddress, granter sdk.AccA grant.Authorization = any store := ctx.KVStore(k.storeKey) - store.Set(grantStoreKey, k.cdc.MustMarshalBinaryBare(&grant)) + store.Set(skey, k.cdc.MustMarshalBinaryBare(&grant)) return nil } @@ -131,8 +131,8 @@ func (k Keeper) SaveGrant(ctx sdk.Context, grantee, granter sdk.AccAddress, auth } bz := k.cdc.MustMarshalBinaryBare(&grant) - grantStoreKey := types.GetAuthorizationStoreKey(grantee, granter, authorization.MethodName()) - store.Set(grantStoreKey, bz) + skey := grantStoreKey(grantee, granter, authorization.MethodName()) + store.Set(skey, bz) return ctx.EventManager().EmitTypedEvent(&types.EventGrant{ Module: types.ModuleName, Msg: authorization.MethodName(), @@ -145,12 +145,12 @@ func (k Keeper) SaveGrant(ctx sdk.Context, grantee, granter sdk.AccAddress, auth // by the granter. func (k Keeper) DeleteGrant(ctx sdk.Context, grantee sdk.AccAddress, granter sdk.AccAddress, msgType string) error { store := ctx.KVStore(k.storeKey) - grantStoreKey := types.GetAuthorizationStoreKey(grantee, granter, msgType) - _, found := k.getAuthorizationGrant(ctx, grantStoreKey) + skey := grantStoreKey(grantee, granter, msgType) + _, found := k.getGrant(ctx, skey) if !found { return sdkerrors.ErrNotFound.Wrap("authorization not found") } - store.Delete(grantStoreKey) + store.Delete(skey) return ctx.EventManager().EmitTypedEvent(&types.EventRevoke{ Module: types.ModuleName, Msg: msgType, @@ -162,7 +162,7 @@ func (k Keeper) DeleteGrant(ctx sdk.Context, grantee sdk.AccAddress, granter sdk // GetAuthorizations Returns list of `Authorizations` granted to the grantee by the granter. func (k Keeper) GetAuthorizations(ctx sdk.Context, grantee sdk.AccAddress, granter sdk.AccAddress) (authorizations []exported.Authorization) { store := ctx.KVStore(k.storeKey) - key := types.GetAuthorizationStoreKey(grantee, granter, "") + key := grantStoreKey(grantee, granter, "") iter := sdk.KVStorePrefixIterator(store, key) defer iter.Close() var authorization types.Grant @@ -173,11 +173,11 @@ func (k Keeper) GetAuthorizations(ctx sdk.Context, grantee sdk.AccAddress, grant return authorizations } -// GetOrRevokeAuthorization returns an `Authorization` and it's expiration time if the granter -// has a grant for (granter, message name) pair. If there is no grant `nil` is returned. +// GetOrRevokeAuthorization returns an `Authorization` and it's expiration time for +// (grantee, granter, message name) grant. If there is no grant `nil` is returned. // If the grant is expired, the grant is revoked, removed from the storage, and `nil` is returned. func (k Keeper) GetOrRevokeAuthorization(ctx sdk.Context, grantee sdk.AccAddress, granter sdk.AccAddress, msgType string) (cap exported.Authorization, expiration time.Time) { - grant, found := k.getAuthorizationGrant(ctx, types.GetAuthorizationStoreKey(grantee, granter, msgType)) + grant, found := k.getGrant(ctx, grantStoreKey(grantee, granter, msgType)) if !found { return nil, time.Time{} } @@ -197,7 +197,7 @@ func (k Keeper) IterateGrants(ctx sdk.Context, defer iter.Close() for ; iter.Valid(); iter.Next() { var grant types.Grant - granterAddr, granteeAddr := types.ExtractAddressesFromGrantKey(iter.Key()) + granterAddr, granteeAddr := addressesFromGrantStoreKey(iter.Key()) k.cdc.MustUnmarshalBinaryBare(iter.Value(), &grant) if handler(granterAddr, granteeAddr, grant) { break diff --git a/x/authz/types/keys_test.go b/x/authz/keeper/keys_test.go similarity index 81% rename from x/authz/types/keys_test.go rename to x/authz/keeper/keys_test.go index caad7ba5cf1c..2959c6bdc17f 100644 --- a/x/authz/types/keys_test.go +++ b/x/authz/keeper/keys_test.go @@ -1,4 +1,4 @@ -package types +package keeper import ( "testing" @@ -15,7 +15,7 @@ var grantee = sdk.AccAddress(ed25519.GenPrivKey().PubKey().Address()) var msgType = bank.SendAuthorization{}.MethodName() func TestGrantkey(t *testing.T) { - granter1, grantee1 := ExtractAddressesFromGrantKey(GetAuthorizationStoreKey(grantee, granter, msgType)) + granter1, grantee1 := addressesFromGrantStoreKey(grantStoreKey(grantee, granter, msgType)) require.Equal(t, granter, granter1) require.Equal(t, grantee, grantee1) } diff --git a/x/authz/keeper/msg_server.go b/x/authz/keeper/msg_server.go index 3a89f88e1c2a..d4a0b17c1c68 100644 --- a/x/authz/keeper/msg_server.go +++ b/x/authz/keeper/msg_server.go @@ -22,7 +22,10 @@ func (k Keeper) Grant(goCtx context.Context, msg *types.MsgGrantRequest) (*types return nil, err } - authorization := msg.GetGrant() + authorization := msg.GetAuthorization() + if authorization == nil { + return nil, sdkerrors.ErrUnpackAny.Wrap("Authorization is not present in the msg") + } // If the granted service Msg doesn't exist, we throw an error. if k.router.Handler(authorization.MethodName()) == nil { return nil, sdkerrors.Wrapf(sdkerrors.ErrInvalidType, "%s doesn't exist.", authorization.MethodName()) diff --git a/x/authz/types/keys.go b/x/authz/types/keys.go index 7ee571b27f74..be75dc045cdc 100644 --- a/x/authz/types/keys.go +++ b/x/authz/types/keys.go @@ -1,10 +1,5 @@ package types -import ( - sdk "github.com/cosmos/cosmos-sdk/types" - "github.com/cosmos/cosmos-sdk/types/address" -) - const ( // ModuleName is the module name constant used in many places ModuleName = "authz" @@ -28,25 +23,3 @@ var ( // Keys for store prefixes GrantKey = []byte{0x01} // prefix for each key ) - -// GetAuthorizationStoreKey - return authorization store key -func GetAuthorizationStoreKey(grantee sdk.AccAddress, granter sdk.AccAddress, msgType string) []byte { - return append(append(append( - GrantKey, - address.MustLengthPrefix(granter)...), - address.MustLengthPrefix(grantee)...), - []byte(msgType)..., - ) -} - -// ExtractAddressesFromGrantKey - split granter & grantee address from the authorization key -func ExtractAddressesFromGrantKey(key []byte) (granterAddr, granteeAddr sdk.AccAddress) { - // key if of format: - // 0x01 - granterAddrLen := key[1] // remove prefix key - granterAddr = sdk.AccAddress(key[2 : 2+granterAddrLen]) - granteeAddrLen := int(key[2+granterAddrLen]) - granteeAddr = sdk.AccAddress(key[3+granterAddrLen : 3+granterAddrLen+byte(granteeAddrLen)]) - - return granterAddr, granteeAddr -} diff --git a/x/authz/types/msgs.go b/x/authz/types/msgs.go index 82a5122efa88..d3bae106c1ac 100644 --- a/x/authz/types/msgs.go +++ b/x/authz/types/msgs.go @@ -70,8 +70,8 @@ func (msg MsgGrantRequest) ValidateBasic() error { return authorization.ValidateBasic() } -// GetGrant returns the cache value from the MsgGrant.Authorization if present. -func (msg *MsgGrantRequest) GetGrant() exported.Authorization { +// GetAuthorization returns the cache value from the MsgGrant.Authorization if present. +func (msg *MsgGrantRequest) GetAuthorization() exported.Authorization { authorization, ok := msg.Authorization.GetCachedValue().(exported.Authorization) if !ok { return nil From 46d547d5ac68802870b76e3832d45920c080dd5a Mon Sep 17 00:00:00 2001 From: Robert Zaremba Date: Fri, 23 Apr 2021 11:00:49 +0200 Subject: [PATCH 17/44] add missing file --- x/authz/keeper/keys.go | 29 +++++++++++++++++++++++++++++ 1 file changed, 29 insertions(+) create mode 100644 x/authz/keeper/keys.go diff --git a/x/authz/keeper/keys.go b/x/authz/keeper/keys.go new file mode 100644 index 000000000000..9c44c0f03292 --- /dev/null +++ b/x/authz/keeper/keys.go @@ -0,0 +1,29 @@ +package keeper + +import ( + sdk "github.com/cosmos/cosmos-sdk/types" + "github.com/cosmos/cosmos-sdk/types/address" + "github.com/cosmos/cosmos-sdk/x/authz/types" +) + +// grantStoreKey - return authorization store key +func grantStoreKey(grantee sdk.AccAddress, granter sdk.AccAddress, msgType string) []byte { + return append(append(append( + types.GrantKey, + address.MustLengthPrefix(granter)...), + address.MustLengthPrefix(grantee)...), + []byte(msgType)..., + ) +} + +// addressesFromGrantStoreKey - split granter & grantee address from the authorization key +func addressesFromGrantStoreKey(key []byte) (granterAddr, granteeAddr sdk.AccAddress) { + // key if of format: + // 0x01 + granterAddrLen := key[1] // remove prefix key + granterAddr = sdk.AccAddress(key[2 : 2+granterAddrLen]) + granteeAddrLen := int(key[2+granterAddrLen]) + granteeAddr = sdk.AccAddress(key[3+granterAddrLen : 3+granterAddrLen+byte(granteeAddrLen)]) + + return granterAddr, granteeAddr +} From 7e9e32582b030009667b182d9f616cb0eeaafb05 Mon Sep 17 00:00:00 2001 From: Robert Zaremba Date: Fri, 23 Apr 2021 11:12:38 +0200 Subject: [PATCH 18/44] moving export genesis to keeper --- x/authz/genesis.go | 17 ----------------- x/authz/keeper/grpc_query.go | 2 +- x/authz/keeper/keeper.go | 25 ++++++++++++++++++++++--- x/authz/keeper/keeper_test.go | 24 ++++++++++++------------ x/authz/module.go | 2 +- 5 files changed, 36 insertions(+), 34 deletions(-) diff --git a/x/authz/genesis.go b/x/authz/genesis.go index d3341d320e59..0f9081fafad1 100644 --- a/x/authz/genesis.go +++ b/x/authz/genesis.go @@ -29,20 +29,3 @@ func InitGenesis(ctx sdk.Context, keeper keeper.Keeper, data *types.GenesisState } } } - -// ExportGenesis returns a GenesisState for a given context and keeper. -func ExportGenesis(ctx sdk.Context, keeper keeper.Keeper) *types.GenesisState { - var entries []types.GrantAuthorization - keeper.IterateGrants(ctx, func(granter, grantee sdk.AccAddress, grant types.Grant) bool { - exp := grant.Expiration - entries = append(entries, types.GrantAuthorization{ - Granter: granter.String(), - Grantee: grantee.String(), - Expiration: exp, - Authorization: grant.Authorization, - }) - return false - }) - - return types.NewGenesisState(entries) -} diff --git a/x/authz/keeper/grpc_query.go b/x/authz/keeper/grpc_query.go index 49065574f6f1..adb2dbf2586b 100644 --- a/x/authz/keeper/grpc_query.go +++ b/x/authz/keeper/grpc_query.go @@ -40,7 +40,7 @@ func (k Keeper) Grants(c context.Context, req *types.QueryGrantsRequest) (*types authStore := prefix.NewStore(store, key) if req.MsgTypeUrl != "" { - authorization, expiration := k.GetOrRevokeAuthorization(ctx, grantee, granter, req.MsgTypeUrl) + authorization, expiration := k.GetCleanAuthorization(ctx, grantee, granter, req.MsgTypeUrl) if authorization == nil { return nil, status.Errorf(codes.NotFound, "no authorization found for %s type", req.MsgTypeUrl) } diff --git a/x/authz/keeper/keeper.go b/x/authz/keeper/keeper.go index d47212c98de2..3c20e079add1 100644 --- a/x/authz/keeper/keeper.go +++ b/x/authz/keeper/keeper.go @@ -84,7 +84,7 @@ func (k Keeper) DispatchActions(ctx sdk.Context, grantee sdk.AccAddress, service granter := signers[0] // if granter != grantee then check authorization.Accept, otherwise we implicitly accept. if !granter.Equals(grantee) { - authorization, _ := k.GetOrRevokeAuthorization(ctx, grantee, granter, serviceMsg.MethodName) + authorization, _ := k.GetCleanAuthorization(ctx, grantee, granter, serviceMsg.MethodName) if authorization == nil { return nil, sdkerrors.ErrUnauthorized.Wrap("authorization not found") } @@ -173,10 +173,10 @@ func (k Keeper) GetAuthorizations(ctx sdk.Context, grantee sdk.AccAddress, grant return authorizations } -// GetOrRevokeAuthorization returns an `Authorization` and it's expiration time for +// GetCleanAuthorization returns an `Authorization` and it's expiration time for // (grantee, granter, message name) grant. If there is no grant `nil` is returned. // If the grant is expired, the grant is revoked, removed from the storage, and `nil` is returned. -func (k Keeper) GetOrRevokeAuthorization(ctx sdk.Context, grantee sdk.AccAddress, granter sdk.AccAddress, msgType string) (cap exported.Authorization, expiration time.Time) { +func (k Keeper) GetCleanAuthorization(ctx sdk.Context, grantee sdk.AccAddress, granter sdk.AccAddress, msgType string) (cap exported.Authorization, expiration time.Time) { grant, found := k.getGrant(ctx, grantStoreKey(grantee, granter, msgType)) if !found { return nil, time.Time{} @@ -190,6 +190,8 @@ func (k Keeper) GetOrRevokeAuthorization(ctx sdk.Context, grantee sdk.AccAddress } // IterateGrants iterates over all authorization grants +// This function should be used with caution because it can involve significant IO operations. +// It should not be used in query or msg services without charging additional gas. func (k Keeper) IterateGrants(ctx sdk.Context, handler func(granterAddr sdk.AccAddress, granteeAddr sdk.AccAddress, grant types.Grant) bool) { store := ctx.KVStore(k.storeKey) @@ -204,3 +206,20 @@ func (k Keeper) IterateGrants(ctx sdk.Context, } } } + +// ExportGenesis returns a GenesisState for a given context. +func (k Keeper) ExportGenesis(ctx sdk.Context) *types.GenesisState { + var entries []types.GrantAuthorization + k.IterateGrants(ctx, func(granter, grantee sdk.AccAddress, grant types.Grant) bool { + exp := grant.Expiration + entries = append(entries, types.GrantAuthorization{ + Granter: granter.String(), + Grantee: grantee.String(), + Expiration: exp, + Authorization: grant.Authorization, + }) + return false + }) + + return types.NewGenesisState(entries) +} diff --git a/x/authz/keeper/keeper_test.go b/x/authz/keeper/keeper_test.go index a5e9782a9ff7..c4c6a151140c 100644 --- a/x/authz/keeper/keeper_test.go +++ b/x/authz/keeper/keeper_test.go @@ -53,7 +53,7 @@ func (s *TestSuite) TestKeeper() { recipientAddr := addrs[2] s.T().Log("verify that no authorization returns nil") - authorization, expiration := app.AuthzKeeper.GetOrRevokeAuthorization(ctx, granteeAddr, granterAddr, banktypes.SendAuthorization{}.MethodName()) + authorization, expiration := app.AuthzKeeper.GetCleanAuthorization(ctx, granteeAddr, granterAddr, banktypes.SendAuthorization{}.MethodName()) s.Require().Nil(authorization) s.Require().Equal(expiration, time.Time{}) now := s.ctx.BlockHeader().Time @@ -64,35 +64,35 @@ func (s *TestSuite) TestKeeper() { x := &banktypes.SendAuthorization{SpendLimit: newCoins} err := app.AuthzKeeper.SaveGrant(ctx, granterAddr, granteeAddr, x, now.Add(-1*time.Hour)) s.Require().NoError(err) - authorization, _ = app.AuthzKeeper.GetOrRevokeAuthorization(ctx, granteeAddr, granterAddr, banktypes.SendAuthorization{}.MethodName()) + authorization, _ = app.AuthzKeeper.GetCleanAuthorization(ctx, granteeAddr, granterAddr, banktypes.SendAuthorization{}.MethodName()) s.Require().Nil(authorization) s.T().Log("verify if authorization is accepted") x = &banktypes.SendAuthorization{SpendLimit: newCoins} err = app.AuthzKeeper.SaveGrant(ctx, granteeAddr, granterAddr, x, now.Add(time.Hour)) s.Require().NoError(err) - authorization, _ = app.AuthzKeeper.GetOrRevokeAuthorization(ctx, granteeAddr, granterAddr, banktypes.SendAuthorization{}.MethodName()) + authorization, _ = app.AuthzKeeper.GetCleanAuthorization(ctx, granteeAddr, granterAddr, banktypes.SendAuthorization{}.MethodName()) s.Require().NotNil(authorization) s.Require().Equal(authorization.MethodName(), banktypes.SendAuthorization{}.MethodName()) s.T().Log("verify fetching authorization with wrong msg type fails") - authorization, _ = app.AuthzKeeper.GetOrRevokeAuthorization(ctx, granteeAddr, granterAddr, proto.MessageName(&banktypes.MsgMultiSend{})) + authorization, _ = app.AuthzKeeper.GetCleanAuthorization(ctx, granteeAddr, granterAddr, proto.MessageName(&banktypes.MsgMultiSend{})) s.Require().Nil(authorization) s.T().Log("verify fetching authorization with wrong grantee fails") - authorization, _ = app.AuthzKeeper.GetOrRevokeAuthorization(ctx, recipientAddr, granterAddr, banktypes.SendAuthorization{}.MethodName()) + authorization, _ = app.AuthzKeeper.GetCleanAuthorization(ctx, recipientAddr, granterAddr, banktypes.SendAuthorization{}.MethodName()) s.Require().Nil(authorization) s.T().Log("verify revoke fails with wrong information") err = app.AuthzKeeper.DeleteGrant(ctx, recipientAddr, granterAddr, banktypes.SendAuthorization{}.MethodName()) s.Require().Error(err) - authorization, _ = app.AuthzKeeper.GetOrRevokeAuthorization(ctx, recipientAddr, granterAddr, banktypes.SendAuthorization{}.MethodName()) + authorization, _ = app.AuthzKeeper.GetCleanAuthorization(ctx, recipientAddr, granterAddr, banktypes.SendAuthorization{}.MethodName()) s.Require().Nil(authorization) s.T().Log("verify revoke executes with correct information") err = app.AuthzKeeper.DeleteGrant(ctx, granteeAddr, granterAddr, banktypes.SendAuthorization{}.MethodName()) s.Require().NoError(err) - authorization, _ = app.AuthzKeeper.GetOrRevokeAuthorization(ctx, granteeAddr, granterAddr, banktypes.SendAuthorization{}.MethodName()) + authorization, _ = app.AuthzKeeper.GetCleanAuthorization(ctx, granteeAddr, granterAddr, banktypes.SendAuthorization{}.MethodName()) s.Require().Nil(authorization) } @@ -104,7 +104,7 @@ func (s *TestSuite) TestKeeperIter() { granteeAddr := addrs[1] s.T().Log("verify that no authorization returns nil") - authorization, expiration := app.AuthzKeeper.GetOrRevokeAuthorization(ctx, granteeAddr, granterAddr, "Abcd") + authorization, expiration := app.AuthzKeeper.GetCleanAuthorization(ctx, granteeAddr, granterAddr, "Abcd") s.Require().Nil(authorization) s.Require().Equal(time.Time{}, expiration) now := s.ctx.BlockHeader().Time @@ -115,7 +115,7 @@ func (s *TestSuite) TestKeeperIter() { x := &banktypes.SendAuthorization{SpendLimit: newCoins} err := app.AuthzKeeper.SaveGrant(ctx, granteeAddr, granterAddr, x, now.Add(-1*time.Hour)) s.Require().NoError(err) - authorization, _ = app.AuthzKeeper.GetOrRevokeAuthorization(ctx, granteeAddr, granterAddr, "abcd") + authorization, _ = app.AuthzKeeper.GetCleanAuthorization(ctx, granteeAddr, granterAddr, "abcd") s.Require().Nil(authorization) app.AuthzKeeper.IterateGrants(ctx, func(granter, grantee sdk.AccAddress, grant types.Grant) bool { @@ -164,7 +164,7 @@ func (s *TestSuite) TestKeeperFees() { // grant authorization err = app.AuthzKeeper.SaveGrant(s.ctx, granteeAddr, granterAddr, &banktypes.SendAuthorization{SpendLimit: smallCoin}, now) s.Require().NoError(err) - authorization, _ := app.AuthzKeeper.GetOrRevokeAuthorization(s.ctx, granteeAddr, granterAddr, banktypes.SendAuthorization{}.MethodName()) + authorization, _ := app.AuthzKeeper.GetCleanAuthorization(s.ctx, granteeAddr, granterAddr, banktypes.SendAuthorization{}.MethodName()) s.Require().NotNil(authorization) s.Require().Equal(authorization.MethodName(), banktypes.SendAuthorization{}.MethodName()) @@ -176,7 +176,7 @@ func (s *TestSuite) TestKeeperFees() { s.Require().NoError(err) s.Require().NotNil(result) - authorization, _ = app.AuthzKeeper.GetOrRevokeAuthorization(s.ctx, granteeAddr, granterAddr, banktypes.SendAuthorization{}.MethodName()) + authorization, _ = app.AuthzKeeper.GetCleanAuthorization(s.ctx, granteeAddr, granterAddr, banktypes.SendAuthorization{}.MethodName()) s.Require().NotNil(authorization) s.T().Log("verify dispatch fails with overlimit") @@ -201,7 +201,7 @@ func (s *TestSuite) TestKeeperFees() { s.Require().Nil(result) s.Require().NotNil(err) - authorization, _ = app.AuthzKeeper.GetOrRevokeAuthorization(s.ctx, granteeAddr, granterAddr, banktypes.SendAuthorization{}.MethodName()) + authorization, _ = app.AuthzKeeper.GetCleanAuthorization(s.ctx, granteeAddr, granterAddr, banktypes.SendAuthorization{}.MethodName()) s.Require().NotNil(authorization) } diff --git a/x/authz/module.go b/x/authz/module.go index b39c02487fe0..7eea3f56a1b2 100644 --- a/x/authz/module.go +++ b/x/authz/module.go @@ -148,7 +148,7 @@ func (am AppModule) InitGenesis(ctx sdk.Context, cdc codec.JSONMarshaler, data j // ExportGenesis returns the exported genesis state as raw bytes for the authz // module. func (am AppModule) ExportGenesis(ctx sdk.Context, cdc codec.JSONMarshaler) json.RawMessage { - gs := ExportGenesis(ctx, am.keeper) + gs := am.keeper.ExportGenesis(ctx) return cdc.MustMarshalJSON(gs) } From 2d5b037a4e047be279b6decd56142cadc3c69bfa Mon Sep 17 00:00:00 2001 From: Robert Zaremba Date: Fri, 23 Apr 2021 11:32:58 +0200 Subject: [PATCH 19/44] Update docs --- x/authz/spec/01_concepts.md | 19 +++++++++++++------ x/authz/spec/02_state.md | 2 +- x/authz/spec/03_messages.md | 19 ++++++++++--------- x/authz/spec/04_events.md | 23 +---------------------- 4 files changed, 25 insertions(+), 38 deletions(-) diff --git a/x/authz/spec/01_concepts.md b/x/authz/spec/01_concepts.md index 8be3333e62ff..7a2c3b33a149 100644 --- a/x/authz/spec/01_concepts.md +++ b/x/authz/spec/01_concepts.md @@ -4,8 +4,14 @@ order: 1 # Concepts -## Authorization -Any concrete type of authorization defined in the `x/authz` module must fulfill the `Authorization` interface outlined below. Authorizations determine exactly what privileges are granted. They are extensible and can be defined for any Msg service method even outside of the module where the Msg method is defined. Authorizations use the new `ServiceMsg` type from [ADR 031](../../../architecture/adr-031-msg-service.md). +## Authorization and Grant +`x/authz` module defines interfaces and messages grant authorizations to perform actions +on behalf of one account to other accounts. The design is defined in the [ADR 030](../../../architecture/adr-030-authz-module.md). + +Grant is an allowance to execute an Msg by grantee address on behalf of the granter. +Authorization is an interface which must be implemented by a concrete authorization logic to validate and execute grants. They are extensible and can be defined for any Msg service method even outside of the module where the Msg method is defined. See the `SendAuthorization` example below for more details. + +Authorizations use the new `Msg` type from [ADR 031](../../../architecture/adr-031-msg-service.md). +++ https://github.com/cosmos/cosmos-sdk/blob/c95de9c4177442dee4c69d96917efc955b5d19d9/x/authz/types/authorizations.go#L15-L24 @@ -17,7 +23,7 @@ Cosmos-SDK `x/authz` module comes with following authorization types ### SendAuthorization -`SendAuthorization` implements `Authorization` interface for the `cosmos.bank.v1beta1.Msg/Send` ServiceMsg, that takes a `SpendLimit` and updates it down to zero. +`SendAuthorization` implements `Authorization` interface for the `cosmos.bank.v1beta1.Msg/Send` Msg, that takes a `SpendLimit` and updates it down to zero. +++ https://github.com/cosmos/cosmos-sdk/blob/c95de9c4177442dee4c69d96917efc955b5d19d9/proto/cosmos/authz/v1beta1/authz.proto#L12-L19 @@ -28,13 +34,14 @@ Cosmos-SDK `x/authz` module comes with following authorization types ### GenericAuthorization -`GenericAuthorization` implements the `Authorization` interface, that gives unrestricted permission to execute the provided ServiceMsg on behalf of granter's account. +`GenericAuthorization` implements the `Authorization` interface, that gives unrestricted permission to execute the provided Msg on behalf of granter's account. +++ https://github.com/cosmos/cosmos-sdk/blob/c95de9c4177442dee4c69d96917efc955b5d19d9/proto/cosmos/authz/v1beta1/authz.proto#L21-L30 +++ https://github.com/cosmos/cosmos-sdk/blob/c95de9c4177442dee4c69d96917efc955b5d19d9/x/authz/types/generic_authorization.go#L20-L28 -- `method_name` holds ServiceMsg type. +- `method_name` stores Msg type URL. ## Gas -In order to prevent DoS attacks, granting `StakeAuthorizaiton`s with `x/authz` incur gas. `StakeAuthorizaiton` allows you to authorize another account to delegate, undelegate, or redelegate to validators. The authorizer can define a list of validators they will allow and/or deny delegations to. The SDK will iterate over these lists and charge 10 gas for each validator in both of the lists. \ No newline at end of file + +In order to prevent DoS attacks, granting `StakeAuthorizaiton`s with `x/authz` incur gas. `StakeAuthorizaiton` allows you to authorize another account to delegate, undelegate, or redelegate to validators. The authorizer can define a list of validators they will allow and/or deny delegations to. The SDK will iterate over these lists and charge 10 gas for each validator in both of the lists. diff --git a/x/authz/spec/02_state.md b/x/authz/spec/02_state.md index 3afc5eddbafb..ea2b6cac2e64 100644 --- a/x/authz/spec/02_state.md +++ b/x/authz/spec/02_state.md @@ -6,7 +6,7 @@ order: 2 ## AuthorizationGrant -Authorizations are identified by combining granter address (the address bytes of the granter), grantee address (the address bytes of the grantee) and ServiceMsg type (its method name). +Grants are identified by combining granter address (the address bytes of the granter), grantee address (the address bytes of the grantee) and Msg type (its URL). Hence we only allow one grant for the (granter, grantee, msg type) triple. - AuthorizationGrant: `0x01 | granter_address_len (1 byte) | granter_address_bytes | grantee_address_len (1 byte) | grantee_address_bytes | msgType_bytes-> ProtocolBuffer(AuthorizationGrant)` diff --git a/x/authz/spec/03_messages.md b/x/authz/spec/03_messages.md index 9b3cffa35c24..86d6150644fa 100644 --- a/x/authz/spec/03_messages.md +++ b/x/authz/spec/03_messages.md @@ -6,32 +6,33 @@ order: 3 In this section we describe the processing of messages for the authz module. -## Msg/GrantAuthorization +## Msg/Grant -An authorization-grant is created using the `MsgGrantAuthorization` message. +An authorization-grant is created using the `MsgGrant` message. +++ https://github.com/cosmos/cosmos-sdk/blob/c95de9c4177442dee4c69d96917efc955b5d19d9/proto/cosmos/authz/v1beta1/tx.proto#L27-L35 This message is expected to fail if: - + - both granter & grantee have same address. - provided `Expiration` time less than current unix timestamp. - provided `Authorization` is not implemented. +- Authorization Method doesn't exist (there is no defined handler in the app router to handle that Msg types) -## Msg/RevokeAuthorization +## Msg/Revoke -An allowed authorization can be removed with `MsgRevokeAuthorization` message. +An allowed authorization can be removed with `MsgRevoke` message. +++ https://github.com/cosmos/cosmos-sdk/blob/c95de9c4177442dee4c69d96917efc955b5d19d9/proto/cosmos/authz/v1beta1/tx.proto#L53-L59 This message is expected to fail if: - both granter & grantee have same address. -- provided `MethodName` is empty. +- provided `MsgTypeUrl` is empty. -## Msg/ExecAuthorizedRequest +## Msg/Exec -When a grantee wants to execute transaction on behalf of a granter, it must send MsgExecAuthorizedRequest. +When a grantee wants to execute transaction on behalf of a granter, it must send MsgExecRequest. +++ https://github.com/cosmos/cosmos-sdk/blob/c95de9c4177442dee4c69d96917efc955b5d19d9/proto/cosmos/authz/v1beta1/tx.proto#L42-L48 @@ -39,4 +40,4 @@ This message is expected to fail if: - authorization not implemented for the provided msg. - grantee don't have permission to run transaction. -- if granted authorization is expired. \ No newline at end of file +- if granted authorization is expired. diff --git a/x/authz/spec/04_events.md b/x/authz/spec/04_events.md index 4d0a9858af7f..1094105a79c8 100644 --- a/x/authz/spec/04_events.md +++ b/x/authz/spec/04_events.md @@ -4,25 +4,4 @@ order: 4 # Events -The authz module emits the following events: - -## Keeper - -### GrantAuthorization - -| Type | Attribute Key | Attribute Value | -|----------------------|-------------------|--------------------| -| grant-authorization | module | authz | -| grant-authorization | grant-type | {msgType} | -| grant-authorization | granter | {granterAddress} | -| grant-authorization | grantee | {granteeAddress} | - - -### RevokeAuthorization - -| Type | Attribute Key | Attribute Value | -|----------------------|-------------------|--------------------| -| revoke-authorization | module | authz | -| revoke-authorization | grant-type | {msgType} | -| revoke-authorization | granter | {granterAddress} | -| revoke-authorization | grantee | {granteeAddress} | +The authz module emits proto eevents defined in [](../../../docs/core/proto-docs.md#cosmos/authz/v1beta1/event.proto) From 5639620ab3be030250bb96b6d64f628aea70074d Mon Sep 17 00:00:00 2001 From: Robert Zaremba Date: Fri, 23 Apr 2021 13:12:10 +0200 Subject: [PATCH 20/44] update tests --- x/authz/client/cli/query_test.go | 6 +++--- x/authz/genesis_test.go | 4 ++-- x/authz/keeper/keeper.go | 1 + x/bank/types/send_authorization_test.go | 20 ++++++++++---------- x/staking/types/authz_test.go | 3 +-- 5 files changed, 17 insertions(+), 17 deletions(-) diff --git a/x/authz/client/cli/query_test.go b/x/authz/client/cli/query_test.go index e011d990d70b..80df52545126 100644 --- a/x/authz/client/cli/query_test.go +++ b/x/authz/client/cli/query_test.go @@ -80,7 +80,7 @@ func (s *IntegrationTestSuite) TestQueryAuthorizations() { tc := tc s.Run(tc.name, func() { - cmd := cli.GetCmdQueryAuthorizations() + cmd := cli.GetCmdQueryGrants() clientCtx := val.ClientCtx resp, err := clitestutil.ExecTestCLICmd(clientCtx, cmd, tc.args) if tc.expectErr { @@ -88,7 +88,7 @@ func (s *IntegrationTestSuite) TestQueryAuthorizations() { s.Require().Contains(string(resp.Bytes()), tc.expErrMsg) } else { s.Require().NoError(err) - var grants types.QueryAuthorizationsResponse + var grants types.QueryGrantsResponse err = val.ClientCtx.JSONMarshaler.UnmarshalJSON(resp.Bytes(), &grants) s.Require().NoError(err) } @@ -172,7 +172,7 @@ func (s *IntegrationTestSuite) TestQueryAuthorization() { tc := tc s.Run(tc.name, func() { - cmd := cli.GetCmdQueryAuthorization() + cmd := cli.GetCmdQueryGrants() clientCtx := val.ClientCtx out, err := clitestutil.ExecTestCLICmd(clientCtx, cmd, tc.args) if tc.expectErr { diff --git a/x/authz/genesis_test.go b/x/authz/genesis_test.go index e12514fd8c9e..bdde7d957cd6 100644 --- a/x/authz/genesis_test.go +++ b/x/authz/genesis_test.go @@ -44,13 +44,13 @@ func (suite *GenesisTestSuite) TestImportExportGenesis() { grant := &bank.SendAuthorization{SpendLimit: coins} err := suite.keeper.SaveGrant(suite.ctx, granteeAddr, granterAddr, grant, now.Add(time.Hour)) suite.Require().NoError(err) - genesis := authz.ExportGenesis(suite.ctx, suite.keeper) + genesis := suite.keeper.ExportGenesis(suite.ctx) // Clear keeper suite.keeper.DeleteGrant(suite.ctx, granteeAddr, granterAddr, grant.MethodName()) authz.InitGenesis(suite.ctx, suite.keeper, genesis) - newGenesis := authz.ExportGenesis(suite.ctx, suite.keeper) + newGenesis := suite.keeper.ExportGenesis(suite.ctx) suite.Require().Equal(genesis, newGenesis) } diff --git a/x/authz/keeper/keeper.go b/x/authz/keeper/keeper.go index 3c20e079add1..bd51e014b0bb 100644 --- a/x/authz/keeper/keeper.go +++ b/x/authz/keeper/keeper.go @@ -130,6 +130,7 @@ func (k Keeper) SaveGrant(ctx sdk.Context, grantee, granter sdk.AccAddress, auth return err } + fmt.Println("granting authorization: ", granter, grantee, authorization.MethodName()) bz := k.cdc.MustMarshalBinaryBare(&grant) skey := grantStoreKey(grantee, granter, authorization.MethodName()) store.Set(skey, bz) diff --git a/x/bank/types/send_authorization_test.go b/x/bank/types/send_authorization_test.go index 45bb718cd847..d2ed356c253e 100644 --- a/x/bank/types/send_authorization_test.go +++ b/x/bank/types/send_authorization_test.go @@ -34,10 +34,10 @@ func TestSendAuthorization(t *testing.T) { require.NoError(t, authorization.ValidateBasic()) t.Log("verify updated authorization returns nil") - updated, del, err := authorization.Accept(ctx, srvMsg) + resp, err := authorization.Accept(ctx, srvMsg) require.NoError(t, err) - require.True(t, del) - require.Nil(t, updated) + require.True(t, resp.Delete) + require.Nil(t, resp.Updated) authorization = types.NewSendAuthorization(coins1000) require.Equal(t, authorization.MethodName(), "/cosmos.bank.v1beta1.Msg/Send") @@ -48,18 +48,18 @@ func TestSendAuthorization(t *testing.T) { Request: send, } require.NoError(t, authorization.ValidateBasic()) - updated, del, err = authorization.Accept(ctx, srvMsg) + resp, err = authorization.Accept(ctx, srvMsg) t.Log("verify updated authorization returns remaining spent limit") require.NoError(t, err) - require.False(t, del) - require.NotNil(t, updated) + require.False(t, resp.Delete) + require.NotNil(t, resp.Updated) sendAuth := types.NewSendAuthorization(coins500) - require.Equal(t, sendAuth.String(), updated.String()) + require.Equal(t, sendAuth.String(), resp.Updated.String()) t.Log("expect updated authorization nil after spending remaining amount") - updated, del, err = updated.Accept(ctx, srvMsg) + resp, err = resp.Updated.Accept(ctx, srvMsg) require.NoError(t, err) - require.True(t, del) - require.Nil(t, updated) + require.True(t, resp.Delete) + require.Nil(t, resp.Updated) } diff --git a/x/staking/types/authz_test.go b/x/staking/types/authz_test.go index 282f2beb83c7..6bbb414b564c 100644 --- a/x/staking/types/authz_test.go +++ b/x/staking/types/authz_test.go @@ -253,12 +253,11 @@ func TestAuthzAuthorizations(t *testing.T) { delAuth, err := stakingtypes.NewStakeAuthorization(tc.allowed, tc.denied, tc.msgType, tc.limit) require.NoError(t, err) resp, err := delAuth.Accept(ctx, tc.srvMsg) + require.Equal(t, tc.isDelete, resp.Delete) if tc.expectErr { require.Error(t, err) - require.Equal(t, tc.isDelete, del) } else { require.NoError(t, err) - require.Equal(t, tc.isDelete, resp.Delete) if tc.updatedAuthorization != nil { require.Equal(t, tc.updatedAuthorization.String(), resp.Updated.String()) } From fc048d046abe84baa6e1722f392c89619d93c5d0 Mon Sep 17 00:00:00 2001 From: Robert Zaremba Date: Fri, 23 Apr 2021 13:28:02 +0200 Subject: [PATCH 21/44] rename event Msg attribute to MsgTypeURL --- docs/core/proto-docs.md | 4 +- proto/cosmos/authz/v1beta1/event.proto | 8 +-- x/authz/keeper/keeper.go | 16 +++--- x/authz/types/event.pb.go | 67 +++++++++++++------------- 4 files changed, 48 insertions(+), 47 deletions(-) diff --git a/docs/core/proto-docs.md b/docs/core/proto-docs.md index 3063180f51f7..ffeb4a80925b 100644 --- a/docs/core/proto-docs.md +++ b/docs/core/proto-docs.md @@ -935,7 +935,7 @@ EventGrant is emitted on Msg/Grant | Field | Type | Label | Description | | ----- | ---- | ----- | ----------- | | `module` | [string](#string) | | Module which invokes the authorizaiton grant TODO: not sure if this is needed. It always has the same value | -| `msg` | [string](#string) | | Msg type for which an autorization is granted | +| `msg_type_url` | [string](#string) | | Msg type URL for which an autorization is granted | | `granter` | [string](#string) | | Granter account address | | `grantee` | [string](#string) | | Grantee account address | @@ -953,7 +953,7 @@ EventRevoke is emitted on Msg/Revoke | Field | Type | Label | Description | | ----- | ---- | ----- | ----------- | | `module` | [string](#string) | | Module which invokes the authorizaiton revokation | -| `msg` | [string](#string) | | Msg type for which an autorization is revoked | +| `msg_type_url` | [string](#string) | | Msg type URL for which an autorization is revoked | | `granter` | [string](#string) | | Granter account address | | `grantee` | [string](#string) | | Grantee account address | diff --git a/proto/cosmos/authz/v1beta1/event.proto b/proto/cosmos/authz/v1beta1/event.proto index 3d9c9cb02b63..4fd77ac0cf20 100644 --- a/proto/cosmos/authz/v1beta1/event.proto +++ b/proto/cosmos/authz/v1beta1/event.proto @@ -14,8 +14,8 @@ message EventGrant { // Module which invokes the authorizaiton grant // TODO: not sure if this is needed. It always has the same value string module = 1; - // Msg type for which an autorization is granted - string msg = 2; + // Msg type URL for which an autorization is granted + string msg_type_url = 2; // Granter account address string granter = 3; // Grantee account address @@ -26,8 +26,8 @@ message EventGrant { message EventRevoke { // Module which invokes the authorizaiton revokation string module = 1; - // Msg type for which an autorization is revoked - string msg = 2; + // Msg type URL for which an autorization is revoked + string msg_type_url = 2; // Granter account address string granter = 3; // Grantee account address diff --git a/x/authz/keeper/keeper.go b/x/authz/keeper/keeper.go index bd51e014b0bb..603566798e9a 100644 --- a/x/authz/keeper/keeper.go +++ b/x/authz/keeper/keeper.go @@ -135,10 +135,10 @@ func (k Keeper) SaveGrant(ctx sdk.Context, grantee, granter sdk.AccAddress, auth skey := grantStoreKey(grantee, granter, authorization.MethodName()) store.Set(skey, bz) return ctx.EventManager().EmitTypedEvent(&types.EventGrant{ - Module: types.ModuleName, - Msg: authorization.MethodName(), - Granter: granter.String(), - Grantee: grantee.String(), + Module: types.ModuleName, + MsgTypeUrl: authorization.MethodName(), + Granter: granter.String(), + Grantee: grantee.String(), }) } @@ -153,10 +153,10 @@ func (k Keeper) DeleteGrant(ctx sdk.Context, grantee sdk.AccAddress, granter sdk } store.Delete(skey) return ctx.EventManager().EmitTypedEvent(&types.EventRevoke{ - Module: types.ModuleName, - Msg: msgType, - Granter: granter.String(), - Grantee: grantee.String(), + Module: types.ModuleName, + MsgTypeUrl: msgType, + Granter: granter.String(), + Grantee: grantee.String(), }) } diff --git a/x/authz/types/event.pb.go b/x/authz/types/event.pb.go index 200a6aff3449..5cfc19612ed7 100644 --- a/x/authz/types/event.pb.go +++ b/x/authz/types/event.pb.go @@ -27,8 +27,8 @@ type EventGrant struct { // Module which invokes the authorizaiton grant // TODO: not sure if this is needed. It always has the same value Module string `protobuf:"bytes,1,opt,name=module,proto3" json:"module,omitempty"` - // Msg type for which an autorization is granted - Msg string `protobuf:"bytes,2,opt,name=msg,proto3" json:"msg,omitempty"` + // Msg type URL for which an autorization is granted + MsgTypeUrl string `protobuf:"bytes,2,opt,name=msg_type_url,json=msgTypeUrl,proto3" json:"msg_type_url,omitempty"` // Granter account address Granter string `protobuf:"bytes,3,opt,name=granter,proto3" json:"granter,omitempty"` // Grantee account address @@ -75,9 +75,9 @@ func (m *EventGrant) GetModule() string { return "" } -func (m *EventGrant) GetMsg() string { +func (m *EventGrant) GetMsgTypeUrl() string { if m != nil { - return m.Msg + return m.MsgTypeUrl } return "" } @@ -100,8 +100,8 @@ func (m *EventGrant) GetGrantee() string { type EventRevoke struct { // Module which invokes the authorizaiton revokation Module string `protobuf:"bytes,1,opt,name=module,proto3" json:"module,omitempty"` - // Msg type for which an autorization is revoked - Msg string `protobuf:"bytes,2,opt,name=msg,proto3" json:"msg,omitempty"` + // Msg type URL for which an autorization is revoked + MsgTypeUrl string `protobuf:"bytes,2,opt,name=msg_type_url,json=msgTypeUrl,proto3" json:"msg_type_url,omitempty"` // Granter account address Granter string `protobuf:"bytes,3,opt,name=granter,proto3" json:"granter,omitempty"` // Grantee account address @@ -148,9 +148,9 @@ func (m *EventRevoke) GetModule() string { return "" } -func (m *EventRevoke) GetMsg() string { +func (m *EventRevoke) GetMsgTypeUrl() string { if m != nil { - return m.Msg + return m.MsgTypeUrl } return "" } @@ -177,21 +177,22 @@ func init() { func init() { proto.RegisterFile("cosmos/authz/v1beta1/event.proto", fileDescriptor_1f88cbc71a8baf1f) } var fileDescriptor_1f88cbc71a8baf1f = []byte{ - // 212 bytes of a gzipped FileDescriptorProto + // 229 bytes of a gzipped FileDescriptorProto 0x1f, 0x8b, 0x08, 0x00, 0x00, 0x00, 0x00, 0x00, 0x02, 0xff, 0xe2, 0x52, 0x48, 0xce, 0x2f, 0xce, 0xcd, 0x2f, 0xd6, 0x4f, 0x2c, 0x2d, 0xc9, 0xa8, 0xd2, 0x2f, 0x33, 0x4c, 0x4a, 0x2d, 0x49, 0x34, 0xd4, 0x4f, 0x2d, 0x4b, 0xcd, 0x2b, 0xd1, 0x2b, 0x28, 0xca, 0x2f, 0xc9, 0x17, 0x12, 0x81, 0xa8, - 0xd0, 0x03, 0xab, 0xd0, 0x83, 0xaa, 0x50, 0xca, 0xe2, 0xe2, 0x72, 0x05, 0x29, 0x72, 0x2f, 0x4a, + 0xd0, 0x03, 0xab, 0xd0, 0x83, 0xaa, 0x50, 0xaa, 0xe2, 0xe2, 0x72, 0x05, 0x29, 0x72, 0x2f, 0x4a, 0xcc, 0x2b, 0x11, 0x12, 0xe3, 0x62, 0xcb, 0xcd, 0x4f, 0x29, 0xcd, 0x49, 0x95, 0x60, 0x54, 0x60, - 0xd4, 0xe0, 0x0c, 0x82, 0xf2, 0x84, 0x04, 0xb8, 0x98, 0x73, 0x8b, 0xd3, 0x25, 0x98, 0xc0, 0x82, - 0x20, 0xa6, 0x90, 0x04, 0x17, 0x7b, 0x3a, 0x48, 0x4b, 0x6a, 0x91, 0x04, 0x33, 0x58, 0x14, 0xc6, - 0x45, 0xc8, 0xa4, 0x4a, 0xb0, 0x20, 0xcb, 0xa4, 0x2a, 0x65, 0x73, 0x71, 0x83, 0xed, 0x0a, 0x4a, - 0x2d, 0xcb, 0xcf, 0x4e, 0xa5, 0xad, 0x65, 0x4e, 0x2e, 0x27, 0x1e, 0xc9, 0x31, 0x5e, 0x78, 0x24, - 0xc7, 0xf8, 0xe0, 0x91, 0x1c, 0xe3, 0x84, 0xc7, 0x72, 0x0c, 0x17, 0x1e, 0xcb, 0x31, 0xdc, 0x78, - 0x2c, 0xc7, 0x10, 0xa5, 0x95, 0x9e, 0x59, 0x92, 0x51, 0x9a, 0xa4, 0x97, 0x9c, 0x9f, 0xab, 0x0f, - 0x0d, 0x35, 0x08, 0xa5, 0x5b, 0x9c, 0x92, 0xad, 0x5f, 0x01, 0x0d, 0xc2, 0x92, 0xca, 0x82, 0xd4, - 0xe2, 0x24, 0x36, 0x70, 0xd8, 0x19, 0x03, 0x02, 0x00, 0x00, 0xff, 0xff, 0x6c, 0x04, 0x6b, 0x5a, - 0x5f, 0x01, 0x00, 0x00, + 0xd4, 0xe0, 0x0c, 0x82, 0xf2, 0x84, 0x14, 0xb8, 0x78, 0x72, 0x8b, 0xd3, 0xe3, 0x4b, 0x2a, 0x0b, + 0x52, 0xe3, 0x4b, 0x8b, 0x72, 0x24, 0x98, 0xc0, 0xb2, 0x5c, 0xb9, 0xc5, 0xe9, 0x21, 0x95, 0x05, + 0xa9, 0xa1, 0x45, 0x39, 0x42, 0x12, 0x5c, 0xec, 0xe9, 0x20, 0x23, 0x52, 0x8b, 0x24, 0x98, 0xc1, + 0x92, 0x30, 0x2e, 0x42, 0x26, 0x55, 0x82, 0x05, 0x59, 0x26, 0x55, 0xa9, 0x9a, 0x8b, 0x1b, 0x6c, + 0x77, 0x50, 0x6a, 0x59, 0x7e, 0x76, 0x2a, 0x7d, 0x2d, 0x77, 0x72, 0x39, 0xf1, 0x48, 0x8e, 0xf1, + 0xc2, 0x23, 0x39, 0xc6, 0x07, 0x8f, 0xe4, 0x18, 0x27, 0x3c, 0x96, 0x63, 0xb8, 0xf0, 0x58, 0x8e, + 0xe1, 0xc6, 0x63, 0x39, 0x86, 0x28, 0xad, 0xf4, 0xcc, 0x92, 0x8c, 0xd2, 0x24, 0xbd, 0xe4, 0xfc, + 0x5c, 0x7d, 0x68, 0xa8, 0x42, 0x28, 0xdd, 0xe2, 0x94, 0x6c, 0xfd, 0x0a, 0x68, 0x10, 0x83, 0x9c, + 0x53, 0x9c, 0xc4, 0x06, 0x0e, 0x5b, 0x63, 0x40, 0x00, 0x00, 0x00, 0xff, 0xff, 0x97, 0x7a, 0x04, + 0x1c, 0x7f, 0x01, 0x00, 0x00, } func (m *EventGrant) Marshal() (dAtA []byte, err error) { @@ -228,10 +229,10 @@ func (m *EventGrant) MarshalToSizedBuffer(dAtA []byte) (int, error) { i-- dAtA[i] = 0x1a } - if len(m.Msg) > 0 { - i -= len(m.Msg) - copy(dAtA[i:], m.Msg) - i = encodeVarintEvent(dAtA, i, uint64(len(m.Msg))) + if len(m.MsgTypeUrl) > 0 { + i -= len(m.MsgTypeUrl) + copy(dAtA[i:], m.MsgTypeUrl) + i = encodeVarintEvent(dAtA, i, uint64(len(m.MsgTypeUrl))) i-- dAtA[i] = 0x12 } @@ -279,10 +280,10 @@ func (m *EventRevoke) MarshalToSizedBuffer(dAtA []byte) (int, error) { i-- dAtA[i] = 0x1a } - if len(m.Msg) > 0 { - i -= len(m.Msg) - copy(dAtA[i:], m.Msg) - i = encodeVarintEvent(dAtA, i, uint64(len(m.Msg))) + if len(m.MsgTypeUrl) > 0 { + i -= len(m.MsgTypeUrl) + copy(dAtA[i:], m.MsgTypeUrl) + i = encodeVarintEvent(dAtA, i, uint64(len(m.MsgTypeUrl))) i-- dAtA[i] = 0x12 } @@ -317,7 +318,7 @@ func (m *EventGrant) Size() (n int) { if l > 0 { n += 1 + l + sovEvent(uint64(l)) } - l = len(m.Msg) + l = len(m.MsgTypeUrl) if l > 0 { n += 1 + l + sovEvent(uint64(l)) } @@ -342,7 +343,7 @@ func (m *EventRevoke) Size() (n int) { if l > 0 { n += 1 + l + sovEvent(uint64(l)) } - l = len(m.Msg) + l = len(m.MsgTypeUrl) if l > 0 { n += 1 + l + sovEvent(uint64(l)) } @@ -426,7 +427,7 @@ func (m *EventGrant) Unmarshal(dAtA []byte) error { iNdEx = postIndex case 2: if wireType != 2 { - return fmt.Errorf("proto: wrong wireType = %d for field Msg", wireType) + return fmt.Errorf("proto: wrong wireType = %d for field MsgTypeUrl", wireType) } var stringLen uint64 for shift := uint(0); ; shift += 7 { @@ -454,7 +455,7 @@ func (m *EventGrant) Unmarshal(dAtA []byte) error { if postIndex > l { return io.ErrUnexpectedEOF } - m.Msg = string(dAtA[iNdEx:postIndex]) + m.MsgTypeUrl = string(dAtA[iNdEx:postIndex]) iNdEx = postIndex case 3: if wireType != 2 { @@ -604,7 +605,7 @@ func (m *EventRevoke) Unmarshal(dAtA []byte) error { iNdEx = postIndex case 2: if wireType != 2 { - return fmt.Errorf("proto: wrong wireType = %d for field Msg", wireType) + return fmt.Errorf("proto: wrong wireType = %d for field MsgTypeUrl", wireType) } var stringLen uint64 for shift := uint(0); ; shift += 7 { @@ -632,7 +633,7 @@ func (m *EventRevoke) Unmarshal(dAtA []byte) error { if postIndex > l { return io.ErrUnexpectedEOF } - m.Msg = string(dAtA[iNdEx:postIndex]) + m.MsgTypeUrl = string(dAtA[iNdEx:postIndex]) iNdEx = postIndex case 3: if wireType != 2 { From 155913e73d94376701420cd61b80ee82e4e9c322 Mon Sep 17 00:00:00 2001 From: Robert Zaremba Date: Fri, 23 Apr 2021 13:45:39 +0200 Subject: [PATCH 22/44] Upate Authorization interface --- docs/core/proto-docs.md | 2 +- proto/cosmos/authz/v1beta1/authz.proto | 4 +- x/authz/client/cli/query.go | 2 +- x/authz/client/cli/tx.go | 4 +- x/authz/exported/authorizations.go | 4 +- x/authz/genesis_test.go | 2 +- x/authz/keeper/grpc_query_test.go | 2 +- x/authz/keeper/keeper.go | 8 ++-- x/authz/keeper/keeper_test.go | 32 +++++++------- x/authz/keeper/keys_test.go | 2 +- x/authz/keeper/msg_server.go | 4 +- x/authz/simulation/operations.go | 4 +- x/authz/simulation/operations_test.go | 2 +- x/authz/types/authz.pb.go | 47 ++++++++++----------- x/authz/types/generic_authorization.go | 12 +++--- x/authz/types/generic_authorization_test.go | 4 +- x/authz/types/msgs_test.go | 2 +- x/bank/types/send_authorization.go | 4 +- x/staking/types/authz.go | 4 +- 19 files changed, 73 insertions(+), 72 deletions(-) diff --git a/docs/core/proto-docs.md b/docs/core/proto-docs.md index ffeb4a80925b..73bd0aea802c 100644 --- a/docs/core/proto-docs.md +++ b/docs/core/proto-docs.md @@ -886,7 +886,7 @@ the provided method on behalf of the granter's account. | Field | Type | Label | Description | | ----- | ---- | ----- | ----------- | -| `msg_type_url` | [string](#string) | | Msg method to grant unrestricted permissions to execute | +| `msg` | [string](#string) | | Msg, identified by it's type URL, to grant unrestricted permissions to execute | diff --git a/proto/cosmos/authz/v1beta1/authz.proto b/proto/cosmos/authz/v1beta1/authz.proto index 08d7c514749e..bdd06cc928cd 100644 --- a/proto/cosmos/authz/v1beta1/authz.proto +++ b/proto/cosmos/authz/v1beta1/authz.proto @@ -14,8 +14,8 @@ option (gogoproto.goproto_getters_all) = false; message GenericAuthorization { option (cosmos_proto.implements_interface) = "Authorization"; - // Msg method to grant unrestricted permissions to execute - string msg_type_url = 1; + // Msg, identified by it's type URL, to grant unrestricted permissions to execute + string msg = 1; } // AuthorizationGrant gives permissions to execute diff --git a/x/authz/client/cli/query.go b/x/authz/client/cli/query.go index 297a8f695cb7..f1a5869650e0 100644 --- a/x/authz/client/cli/query.go +++ b/x/authz/client/cli/query.go @@ -46,7 +46,7 @@ $ %s query %s grants cosmos1skj.. cosmos1skjwj.. $ %s query %s grants cosmos1skjw.. cosmos1skjwj.. %s `, version.AppName, types.ModuleName, - version.AppName, types.ModuleName, bank.SendAuthorization{}.MethodName()), + version.AppName, types.ModuleName, bank.SendAuthorization{}.MsgTypeURL()), ), RunE: func(cmd *cobra.Command, args []string) error { clientCtx, err := client.GetClientQueryContext(cmd) diff --git a/x/authz/client/cli/tx.go b/x/authz/client/cli/tx.go index 564025e2859f..63dccf5d3053 100644 --- a/x/authz/client/cli/tx.go +++ b/x/authz/client/cli/tx.go @@ -60,7 +60,7 @@ func NewCmdGrantAuthorization() *cobra.Command { Examples: $ %s tx %s grant cosmos1skjw.. send %s --spend-limit=1000stake --from=cosmos1skl.. $ %s tx %s grant cosmos1skjw.. generic --msg-type=/cosmos.gov.v1beta1.Msg/Vote --from=cosmos1sk.. - `, version.AppName, types.ModuleName, bank.SendAuthorization{}.MethodName(), version.AppName, types.ModuleName), + `, version.AppName, types.ModuleName, bank.SendAuthorization{}.MsgTypeURL(), version.AppName, types.ModuleName), ), Args: cobra.ExactArgs(2), RunE: func(cmd *cobra.Command, args []string) error { @@ -191,7 +191,7 @@ func NewCmdRevokeAuthorization() *cobra.Command { fmt.Sprintf(`revoke authorization from a granter to a grantee: Example: $ %s tx %s revoke cosmos1skj.. %s --from=cosmos1skj.. - `, version.AppName, types.ModuleName, bank.SendAuthorization{}.MethodName()), + `, version.AppName, types.ModuleName, bank.SendAuthorization{}.MsgTypeURL()), ), Args: cobra.ExactArgs(2), RunE: func(cmd *cobra.Command, args []string) error { diff --git a/x/authz/exported/authorizations.go b/x/authz/exported/authorizations.go index fc671ee4f986..76497a862b4a 100644 --- a/x/authz/exported/authorizations.go +++ b/x/authz/exported/authorizations.go @@ -10,8 +10,8 @@ import ( type Authorization interface { proto.Message - // MethodName returns the fully-qualified Msg service method name as described in ADR 031. - MethodName() string + // MsgTypeURL returns the fully-qualified Msg service method name as described in ADR 031. + MsgTypeURL() string // Accept determines whether this grant permits the provided sdk.ServiceMsg to be performed, and if // so provides an upgraded authorization instance. diff --git a/x/authz/genesis_test.go b/x/authz/genesis_test.go index bdde7d957cd6..d5992a350a5c 100644 --- a/x/authz/genesis_test.go +++ b/x/authz/genesis_test.go @@ -47,7 +47,7 @@ func (suite *GenesisTestSuite) TestImportExportGenesis() { genesis := suite.keeper.ExportGenesis(suite.ctx) // Clear keeper - suite.keeper.DeleteGrant(suite.ctx, granteeAddr, granterAddr, grant.MethodName()) + suite.keeper.DeleteGrant(suite.ctx, granteeAddr, granterAddr, grant.MsgTypeURL()) authz.InitGenesis(suite.ctx, suite.keeper, genesis) newGenesis := suite.keeper.ExportGenesis(suite.ctx) diff --git a/x/authz/keeper/grpc_query_test.go b/x/authz/keeper/grpc_query_test.go index 125c02672cec..16708ff5a112 100644 --- a/x/authz/keeper/grpc_query_test.go +++ b/x/authz/keeper/grpc_query_test.go @@ -65,7 +65,7 @@ func (suite *TestSuite) TestGRPCQueryAuthorization() { req = &types.QueryGrantsRequest{ Granter: addrs[1].String(), Grantee: addrs[0].String(), - MsgTypeUrl: expAuthorization.MethodName(), + MsgTypeUrl: expAuthorization.MsgTypeURL(), } }, "", diff --git a/x/authz/keeper/keeper.go b/x/authz/keeper/keeper.go index 603566798e9a..ed9cf206b1c8 100644 --- a/x/authz/keeper/keeper.go +++ b/x/authz/keeper/keeper.go @@ -49,7 +49,7 @@ func (k Keeper) getGrant(ctx sdk.Context, skey []byte) (grant types.Grant, found } func (k Keeper) update(ctx sdk.Context, grantee sdk.AccAddress, granter sdk.AccAddress, updated exported.Authorization) error { - skey := grantStoreKey(grantee, granter, updated.MethodName()) + skey := grantStoreKey(grantee, granter, updated.MsgTypeURL()) grant, found := k.getGrant(ctx, skey) if !found { return sdkerrors.ErrNotFound.Wrap("authorization not found") @@ -130,13 +130,13 @@ func (k Keeper) SaveGrant(ctx sdk.Context, grantee, granter sdk.AccAddress, auth return err } - fmt.Println("granting authorization: ", granter, grantee, authorization.MethodName()) + fmt.Println("granting authorization: ", granter, grantee, authorization.MsgTypeURL()) bz := k.cdc.MustMarshalBinaryBare(&grant) - skey := grantStoreKey(grantee, granter, authorization.MethodName()) + skey := grantStoreKey(grantee, granter, authorization.MsgTypeURL()) store.Set(skey, bz) return ctx.EventManager().EmitTypedEvent(&types.EventGrant{ Module: types.ModuleName, - MsgTypeUrl: authorization.MethodName(), + MsgTypeUrl: authorization.MsgTypeURL(), Granter: granter.String(), Grantee: grantee.String(), }) diff --git a/x/authz/keeper/keeper_test.go b/x/authz/keeper/keeper_test.go index c4c6a151140c..85bf91e19447 100644 --- a/x/authz/keeper/keeper_test.go +++ b/x/authz/keeper/keeper_test.go @@ -19,6 +19,8 @@ import ( banktypes "github.com/cosmos/cosmos-sdk/x/bank/types" ) +var bankSendAuthMsgType = banktypes.SendAuthorization{}.MsgTypeURL() + type TestSuite struct { suite.Suite @@ -53,7 +55,7 @@ func (s *TestSuite) TestKeeper() { recipientAddr := addrs[2] s.T().Log("verify that no authorization returns nil") - authorization, expiration := app.AuthzKeeper.GetCleanAuthorization(ctx, granteeAddr, granterAddr, banktypes.SendAuthorization{}.MethodName()) + authorization, expiration := app.AuthzKeeper.GetCleanAuthorization(ctx, granteeAddr, granterAddr, bankSendAuthMsgType) s.Require().Nil(authorization) s.Require().Equal(expiration, time.Time{}) now := s.ctx.BlockHeader().Time @@ -64,35 +66,35 @@ func (s *TestSuite) TestKeeper() { x := &banktypes.SendAuthorization{SpendLimit: newCoins} err := app.AuthzKeeper.SaveGrant(ctx, granterAddr, granteeAddr, x, now.Add(-1*time.Hour)) s.Require().NoError(err) - authorization, _ = app.AuthzKeeper.GetCleanAuthorization(ctx, granteeAddr, granterAddr, banktypes.SendAuthorization{}.MethodName()) + authorization, _ = app.AuthzKeeper.GetCleanAuthorization(ctx, granteeAddr, granterAddr, bankSendAuthMsgType) s.Require().Nil(authorization) s.T().Log("verify if authorization is accepted") x = &banktypes.SendAuthorization{SpendLimit: newCoins} err = app.AuthzKeeper.SaveGrant(ctx, granteeAddr, granterAddr, x, now.Add(time.Hour)) s.Require().NoError(err) - authorization, _ = app.AuthzKeeper.GetCleanAuthorization(ctx, granteeAddr, granterAddr, banktypes.SendAuthorization{}.MethodName()) + authorization, _ = app.AuthzKeeper.GetCleanAuthorization(ctx, granteeAddr, granterAddr, bankSendAuthMsgType) s.Require().NotNil(authorization) - s.Require().Equal(authorization.MethodName(), banktypes.SendAuthorization{}.MethodName()) + s.Require().Equal(authorization.MsgTypeURL(), bankSendAuthMsgType) s.T().Log("verify fetching authorization with wrong msg type fails") authorization, _ = app.AuthzKeeper.GetCleanAuthorization(ctx, granteeAddr, granterAddr, proto.MessageName(&banktypes.MsgMultiSend{})) s.Require().Nil(authorization) s.T().Log("verify fetching authorization with wrong grantee fails") - authorization, _ = app.AuthzKeeper.GetCleanAuthorization(ctx, recipientAddr, granterAddr, banktypes.SendAuthorization{}.MethodName()) + authorization, _ = app.AuthzKeeper.GetCleanAuthorization(ctx, recipientAddr, granterAddr, bankSendAuthMsgType) s.Require().Nil(authorization) s.T().Log("verify revoke fails with wrong information") - err = app.AuthzKeeper.DeleteGrant(ctx, recipientAddr, granterAddr, banktypes.SendAuthorization{}.MethodName()) + err = app.AuthzKeeper.DeleteGrant(ctx, recipientAddr, granterAddr, bankSendAuthMsgType) s.Require().Error(err) - authorization, _ = app.AuthzKeeper.GetCleanAuthorization(ctx, recipientAddr, granterAddr, banktypes.SendAuthorization{}.MethodName()) + authorization, _ = app.AuthzKeeper.GetCleanAuthorization(ctx, recipientAddr, granterAddr, bankSendAuthMsgType) s.Require().Nil(authorization) s.T().Log("verify revoke executes with correct information") - err = app.AuthzKeeper.DeleteGrant(ctx, granteeAddr, granterAddr, banktypes.SendAuthorization{}.MethodName()) + err = app.AuthzKeeper.DeleteGrant(ctx, granteeAddr, granterAddr, bankSendAuthMsgType) s.Require().NoError(err) - authorization, _ = app.AuthzKeeper.GetCleanAuthorization(ctx, granteeAddr, granterAddr, banktypes.SendAuthorization{}.MethodName()) + authorization, _ = app.AuthzKeeper.GetCleanAuthorization(ctx, granteeAddr, granterAddr, bankSendAuthMsgType) s.Require().Nil(authorization) } @@ -141,7 +143,7 @@ func (s *TestSuite) TestKeeperFees() { msgs := types.NewMsgExec(granteeAddr, []sdk.ServiceMsg{ { - MethodName: banktypes.SendAuthorization{}.MethodName(), + MethodName: bankSendAuthMsgType, Request: &banktypes.MsgSend{ Amount: sdk.NewCoins(sdk.NewInt64Coin("steak", 2)), FromAddress: granterAddr.String(), @@ -164,10 +166,10 @@ func (s *TestSuite) TestKeeperFees() { // grant authorization err = app.AuthzKeeper.SaveGrant(s.ctx, granteeAddr, granterAddr, &banktypes.SendAuthorization{SpendLimit: smallCoin}, now) s.Require().NoError(err) - authorization, _ := app.AuthzKeeper.GetCleanAuthorization(s.ctx, granteeAddr, granterAddr, banktypes.SendAuthorization{}.MethodName()) + authorization, _ := app.AuthzKeeper.GetCleanAuthorization(s.ctx, granteeAddr, granterAddr, bankSendAuthMsgType) s.Require().NotNil(authorization) - s.Require().Equal(authorization.MethodName(), banktypes.SendAuthorization{}.MethodName()) + s.Require().Equal(authorization.MsgTypeURL(), bankSendAuthMsgType) executeMsgs, err = msgs.GetServiceMsgs() s.Require().NoError(err) @@ -176,7 +178,7 @@ func (s *TestSuite) TestKeeperFees() { s.Require().NoError(err) s.Require().NotNil(result) - authorization, _ = app.AuthzKeeper.GetCleanAuthorization(s.ctx, granteeAddr, granterAddr, banktypes.SendAuthorization{}.MethodName()) + authorization, _ = app.AuthzKeeper.GetCleanAuthorization(s.ctx, granteeAddr, granterAddr, bankSendAuthMsgType) s.Require().NotNil(authorization) s.T().Log("verify dispatch fails with overlimit") @@ -184,7 +186,7 @@ func (s *TestSuite) TestKeeperFees() { msgs = types.NewMsgExec(granteeAddr, []sdk.ServiceMsg{ { - MethodName: banktypes.SendAuthorization{}.MethodName(), + MethodName: bankSendAuthMsgType, Request: &banktypes.MsgSend{ Amount: someCoin, FromAddress: granterAddr.String(), @@ -201,7 +203,7 @@ func (s *TestSuite) TestKeeperFees() { s.Require().Nil(result) s.Require().NotNil(err) - authorization, _ = app.AuthzKeeper.GetCleanAuthorization(s.ctx, granteeAddr, granterAddr, banktypes.SendAuthorization{}.MethodName()) + authorization, _ = app.AuthzKeeper.GetCleanAuthorization(s.ctx, granteeAddr, granterAddr, bankSendAuthMsgType) s.Require().NotNil(authorization) } diff --git a/x/authz/keeper/keys_test.go b/x/authz/keeper/keys_test.go index 2959c6bdc17f..f643474565c6 100644 --- a/x/authz/keeper/keys_test.go +++ b/x/authz/keeper/keys_test.go @@ -12,7 +12,7 @@ import ( var granter = sdk.AccAddress(ed25519.GenPrivKey().PubKey().Address()) var grantee = sdk.AccAddress(ed25519.GenPrivKey().PubKey().Address()) -var msgType = bank.SendAuthorization{}.MethodName() +var msgType = bank.SendAuthorization{}.MsgTypeURL() func TestGrantkey(t *testing.T) { granter1, grantee1 := addressesFromGrantStoreKey(grantStoreKey(grantee, granter, msgType)) diff --git a/x/authz/keeper/msg_server.go b/x/authz/keeper/msg_server.go index d4a0b17c1c68..b31fee07648e 100644 --- a/x/authz/keeper/msg_server.go +++ b/x/authz/keeper/msg_server.go @@ -27,8 +27,8 @@ func (k Keeper) Grant(goCtx context.Context, msg *types.MsgGrantRequest) (*types return nil, sdkerrors.ErrUnpackAny.Wrap("Authorization is not present in the msg") } // If the granted service Msg doesn't exist, we throw an error. - if k.router.Handler(authorization.MethodName()) == nil { - return nil, sdkerrors.Wrapf(sdkerrors.ErrInvalidType, "%s doesn't exist.", authorization.MethodName()) + if k.router.Handler(authorization.MsgTypeURL()) == nil { + return nil, sdkerrors.Wrapf(sdkerrors.ErrInvalidType, "%s doesn't exist.", authorization.MsgTypeURL()) } err = k.SaveGrant(ctx, grantee, granter, authorization, msg.Expiration) diff --git a/x/authz/simulation/operations.go b/x/authz/simulation/operations.go index 5a17080c0633..10e9b094260a 100644 --- a/x/authz/simulation/operations.go +++ b/x/authz/simulation/operations.go @@ -171,7 +171,7 @@ func SimulateMsgRevokeAuthorization(ak types.AccountKeeper, bk types.BankKeeper, } auth := targetGrant.GetAuthorization() - msg := types.NewMsgRevoke(granterAddr, granteeAddr, auth.MethodName()) + msg := types.NewMsgRevoke(granterAddr, granteeAddr, auth.MsgTypeURL()) txGen := simappparams.MakeTestEncodingConfig().TxConfig svcMsgClientConn := &msgservice.ServiceMsgClientConn{} authzMsgClient := types.NewMsgClient(svcMsgClientConn) @@ -243,7 +243,7 @@ func SimulateMsgExecuteAuthorized(ak types.AccountKeeper, bk types.BankKeeper, k sendCoins := sdk.NewCoins(sdk.NewCoin("foo", sdk.NewInt(10))) execMsg := sdk.ServiceMsg{ - MethodName: banktype.SendAuthorization{}.MethodName(), + MethodName: banktype.SendAuthorization{}.MsgTypeURL(), Request: banktype.NewMsgSend( granterAddr, granteeAddr, diff --git a/x/authz/simulation/operations_test.go b/x/authz/simulation/operations_test.go index 4e9b30e7d6b8..86367ef4c5d8 100644 --- a/x/authz/simulation/operations_test.go +++ b/x/authz/simulation/operations_test.go @@ -153,7 +153,7 @@ func (suite *SimTestSuite) TestSimulateRevokeAuthorization() { suite.Require().True(operationMsg.OK) suite.Require().Equal(granter.Address.String(), msg.Granter) suite.Require().Equal(grantee.Address.String(), msg.Grantee) - suite.Require().Equal(banktypes.SendAuthorization{}.MethodName(), msg.MsgTypeUrl) + suite.Require().Equal(banktypes.SendAuthorization{}.MsgTypeURL(), msg.MsgTypeUrl) suite.Require().Len(futureOperations, 0) } diff --git a/x/authz/types/authz.pb.go b/x/authz/types/authz.pb.go index b782ea57134d..0529619c44bf 100644 --- a/x/authz/types/authz.pb.go +++ b/x/authz/types/authz.pb.go @@ -32,8 +32,8 @@ const _ = proto.GoGoProtoPackageIsVersion3 // please upgrade the proto package // GenericAuthorization gives the grantee unrestricted permissions to execute // the provided method on behalf of the granter's account. type GenericAuthorization struct { - // Msg method to grant unrestricted permissions to execute - MsgTypeUrl string `protobuf:"bytes,1,opt,name=msg_type_url,json=msgTypeUrl,proto3" json:"msg_type_url,omitempty"` + // Msg, identified by it's type URL, to grant unrestricted permissions to execute + Msg string `protobuf:"bytes,1,opt,name=msg,proto3" json:"msg,omitempty"` } func (m *GenericAuthorization) Reset() { *m = GenericAuthorization{} } @@ -117,28 +117,27 @@ func init() { func init() { proto.RegisterFile("cosmos/authz/v1beta1/authz.proto", fileDescriptor_544dc2e84b61c637) } var fileDescriptor_544dc2e84b61c637 = []byte{ - // 325 bytes of a gzipped FileDescriptorProto + // 308 bytes of a gzipped FileDescriptorProto 0x1f, 0x8b, 0x08, 0x00, 0x00, 0x00, 0x00, 0x00, 0x02, 0xff, 0xe2, 0x52, 0x48, 0xce, 0x2f, 0xce, 0xcd, 0x2f, 0xd6, 0x4f, 0x2c, 0x2d, 0xc9, 0xa8, 0xd2, 0x2f, 0x33, 0x4c, 0x4a, 0x2d, 0x49, 0x34, 0x84, 0xf0, 0xf4, 0x0a, 0x8a, 0xf2, 0x4b, 0xf2, 0x85, 0x44, 0x20, 0x2a, 0xf4, 0x20, 0x62, 0x50, 0x15, 0x52, 0x92, 0x10, 0xd1, 0x78, 0xb0, 0x1a, 0x7d, 0xa8, 0x12, 0x30, 0x47, 0x4a, 0x3e, 0x3d, 0x3f, 0x3f, 0x3d, 0x27, 0x55, 0x1f, 0xcc, 0x4b, 0x2a, 0x4d, 0xd3, 0x2f, 0xc9, 0xcc, 0x4d, 0x2d, 0x2e, 0x49, 0xcc, 0x2d, 0x80, 0x2a, 0x10, 0x49, 0xcf, 0x4f, 0xcf, 0x87, 0x68, 0x04, 0xb1, 0xa0, - 0xa2, 0x92, 0xe8, 0xda, 0x12, 0xf3, 0x2a, 0x21, 0x52, 0x4a, 0xde, 0x5c, 0x22, 0xee, 0xa9, 0x79, + 0xa2, 0x92, 0xe8, 0xda, 0x12, 0xf3, 0x2a, 0x21, 0x52, 0x4a, 0xd6, 0x5c, 0x22, 0xee, 0xa9, 0x79, 0xa9, 0x45, 0x99, 0xc9, 0x8e, 0xa5, 0x25, 0x19, 0xf9, 0x45, 0x99, 0x55, 0x89, 0x25, 0x99, 0xf9, - 0x79, 0x42, 0x0a, 0x5c, 0x3c, 0xb9, 0xc5, 0xe9, 0xf1, 0x25, 0x95, 0x05, 0xa9, 0xf1, 0xa5, 0x45, - 0x39, 0x12, 0x8c, 0x0a, 0x8c, 0x1a, 0x9c, 0x41, 0x5c, 0xb9, 0xc5, 0xe9, 0x21, 0x95, 0x05, 0xa9, - 0xa1, 0x45, 0x39, 0x56, 0x82, 0x97, 0xb6, 0xe8, 0xf2, 0xa2, 0x68, 0x52, 0x9a, 0xc3, 0xc8, 0xc5, - 0xea, 0x5e, 0x94, 0x98, 0x57, 0x22, 0xe4, 0xcb, 0xc5, 0x9b, 0x88, 0x2c, 0x05, 0xd6, 0xcf, 0x6d, - 0x24, 0xa2, 0x07, 0x71, 0x89, 0x1e, 0xcc, 0x25, 0x7a, 0x8e, 0x79, 0x95, 0x4e, 0x82, 0xa7, 0xd0, - 0x4d, 0x0a, 0x42, 0xd5, 0x2d, 0xe4, 0xc2, 0xc5, 0x95, 0x5a, 0x51, 0x90, 0x59, 0x04, 0x31, 0x8b, - 0x09, 0x6c, 0x96, 0x14, 0x86, 0x59, 0x21, 0xb0, 0xc0, 0x70, 0xe2, 0x38, 0x71, 0x4f, 0x9e, 0x61, - 0xc2, 0x7d, 0x79, 0xc6, 0x20, 0x24, 0x7d, 0x4e, 0x1e, 0x27, 0x1e, 0xca, 0x31, 0x9c, 0x78, 0x24, - 0xc7, 0x78, 0xe1, 0x91, 0x1c, 0xe3, 0x83, 0x47, 0x72, 0x8c, 0x13, 0x1e, 0xcb, 0x31, 0x5c, 0x78, - 0x2c, 0xc7, 0x70, 0xe3, 0xb1, 0x1c, 0x43, 0x94, 0x56, 0x7a, 0x66, 0x49, 0x46, 0x69, 0x92, 0x5e, - 0x72, 0x7e, 0x2e, 0x34, 0xd0, 0xa1, 0x94, 0x6e, 0x71, 0x4a, 0xb6, 0x7e, 0x05, 0x34, 0x1a, 0x41, - 0x01, 0x52, 0x9c, 0xc4, 0x06, 0xb6, 0xd3, 0x18, 0x10, 0x00, 0x00, 0xff, 0xff, 0xc9, 0xea, 0x09, - 0xba, 0xe3, 0x01, 0x00, 0x00, + 0x79, 0x42, 0x02, 0x5c, 0xcc, 0xb9, 0xc5, 0xe9, 0x12, 0x8c, 0x0a, 0x8c, 0x1a, 0x9c, 0x41, 0x20, + 0xa6, 0x95, 0xe0, 0xa5, 0x2d, 0xba, 0xbc, 0x28, 0x8a, 0x94, 0xe6, 0x30, 0x72, 0xb1, 0xba, 0x17, + 0x25, 0xe6, 0x95, 0x08, 0xf9, 0x72, 0xf1, 0x26, 0x22, 0x4b, 0x81, 0x35, 0x72, 0x1b, 0x89, 0xe8, + 0x41, 0x6c, 0xd6, 0x83, 0xd9, 0xac, 0xe7, 0x98, 0x57, 0xe9, 0x24, 0x78, 0x0a, 0xdd, 0xa4, 0x20, + 0x54, 0xdd, 0x42, 0x2e, 0x5c, 0x5c, 0xa9, 0x15, 0x05, 0x99, 0x45, 0x10, 0xb3, 0x98, 0xc0, 0x66, + 0x49, 0x61, 0x98, 0x15, 0x02, 0xf3, 0xbc, 0x13, 0xc7, 0x89, 0x7b, 0xf2, 0x0c, 0x13, 0xee, 0xcb, + 0x33, 0x06, 0x21, 0xe9, 0x73, 0xf2, 0x38, 0xf1, 0x50, 0x8e, 0xe1, 0xc4, 0x23, 0x39, 0xc6, 0x0b, + 0x8f, 0xe4, 0x18, 0x1f, 0x3c, 0x92, 0x63, 0x9c, 0xf0, 0x58, 0x8e, 0xe1, 0xc2, 0x63, 0x39, 0x86, + 0x1b, 0x8f, 0xe5, 0x18, 0xa2, 0xb4, 0xd2, 0x33, 0x4b, 0x32, 0x4a, 0x93, 0xf4, 0x92, 0xf3, 0x73, + 0xa1, 0x81, 0x0c, 0xa5, 0x74, 0x8b, 0x53, 0xb2, 0xf5, 0x2b, 0xa0, 0xd1, 0x56, 0x52, 0x59, 0x90, + 0x5a, 0x9c, 0xc4, 0x06, 0xb6, 0xd3, 0x18, 0x10, 0x00, 0x00, 0xff, 0xff, 0x08, 0xb2, 0x09, 0x58, + 0xd3, 0x01, 0x00, 0x00, } func (m *GenericAuthorization) Marshal() (dAtA []byte, err error) { @@ -161,10 +160,10 @@ func (m *GenericAuthorization) MarshalToSizedBuffer(dAtA []byte) (int, error) { _ = i var l int _ = l - if len(m.MsgTypeUrl) > 0 { - i -= len(m.MsgTypeUrl) - copy(dAtA[i:], m.MsgTypeUrl) - i = encodeVarintAuthz(dAtA, i, uint64(len(m.MsgTypeUrl))) + if len(m.Msg) > 0 { + i -= len(m.Msg) + copy(dAtA[i:], m.Msg) + i = encodeVarintAuthz(dAtA, i, uint64(len(m.Msg))) i-- dAtA[i] = 0xa } @@ -231,7 +230,7 @@ func (m *GenericAuthorization) Size() (n int) { } var l int _ = l - l = len(m.MsgTypeUrl) + l = len(m.Msg) if l > 0 { n += 1 + l + sovAuthz(uint64(l)) } @@ -290,7 +289,7 @@ func (m *GenericAuthorization) Unmarshal(dAtA []byte) error { switch fieldNum { case 1: if wireType != 2 { - return fmt.Errorf("proto: wrong wireType = %d for field MsgTypeUrl", wireType) + return fmt.Errorf("proto: wrong wireType = %d for field Msg", wireType) } var stringLen uint64 for shift := uint(0); ; shift += 7 { @@ -318,7 +317,7 @@ func (m *GenericAuthorization) Unmarshal(dAtA []byte) error { if postIndex > l { return io.ErrUnexpectedEOF } - m.MsgTypeUrl = string(dAtA[iNdEx:postIndex]) + m.Msg = string(dAtA[iNdEx:postIndex]) iNdEx = postIndex default: iNdEx = preIndex diff --git a/x/authz/types/generic_authorization.go b/x/authz/types/generic_authorization.go index 99fc72c1e84b..769a353de800 100644 --- a/x/authz/types/generic_authorization.go +++ b/x/authz/types/generic_authorization.go @@ -14,13 +14,13 @@ var ( // NewGenericAuthorization creates a new GenericAuthorization object. func NewGenericAuthorization(methodName string) *GenericAuthorization { return &GenericAuthorization{ - MsgTypeUrl: methodName, + Msg: methodName, } } -// MethodName implements Authorization.MethodName. -func (a GenericAuthorization) MethodName() string { - return a.MsgTypeUrl +// MsgTypeURL implements Authorization.MsgTypeURL. +func (a GenericAuthorization) MsgTypeURL() string { + return a.Msg } // Accept implements Authorization.Accept. @@ -30,8 +30,8 @@ func (a GenericAuthorization) Accept(ctx sdk.Context, msg sdk.ServiceMsg) (authz // ValidateBasic implements Authorization.ValidateBasic. func (a GenericAuthorization) ValidateBasic() error { - if !msgservice.IsServiceMsg(a.MsgTypeUrl) { - return sdkerrors.Wrapf(sdkerrors.ErrInvalidType, " %s is not a valid service msg", a.MsgTypeUrl) + if !msgservice.IsServiceMsg(a.Msg) { + return sdkerrors.Wrapf(sdkerrors.ErrInvalidType, " %s is not a valid service msg", a.Msg) } return nil } diff --git a/x/authz/types/generic_authorization_test.go b/x/authz/types/generic_authorization_test.go index 50bc9e01058d..f13c927bc007 100644 --- a/x/authz/types/generic_authorization_test.go +++ b/x/authz/types/generic_authorization_test.go @@ -15,7 +15,7 @@ func TestGenericAuthorization(t *testing.T) { require.Error(t, authorization.ValidateBasic()) t.Log("verify ValidateBasic returns nil for service msg") - authorization = types.NewGenericAuthorization(banktypes.SendAuthorization{}.MethodName()) + authorization = types.NewGenericAuthorization(banktypes.SendAuthorization{}.MsgTypeURL()) require.NoError(t, authorization.ValidateBasic()) - require.Equal(t, banktypes.SendAuthorization{}.MethodName(), authorization.MsgTypeUrl) + require.Equal(t, banktypes.SendAuthorization{}.MsgTypeURL(), authorization.Msg) } diff --git a/x/authz/types/msgs_test.go b/x/authz/types/msgs_test.go index ce9ce7231af0..0ec5372a9fbd 100644 --- a/x/authz/types/msgs_test.go +++ b/x/authz/types/msgs_test.go @@ -30,7 +30,7 @@ func TestMsgExecAuthorized(t *testing.T) { {"zero-messages test: should fail", grantee, []sdk.ServiceMsg{}, false}, {"valid test: msg type", grantee, []sdk.ServiceMsg{ { - MethodName: banktypes.SendAuthorization{}.MethodName(), + MethodName: banktypes.SendAuthorization{}.MsgTypeURL(), Request: &banktypes.MsgSend{ Amount: sdk.NewCoins(sdk.NewInt64Coin("steak", 2)), FromAddress: granter.String(), diff --git a/x/bank/types/send_authorization.go b/x/bank/types/send_authorization.go index 586d58fcbde7..bba77b126a72 100644 --- a/x/bank/types/send_authorization.go +++ b/x/bank/types/send_authorization.go @@ -17,8 +17,8 @@ func NewSendAuthorization(spendLimit sdk.Coins) *SendAuthorization { } } -// MethodName implements Authorization.MethodName. -func (a SendAuthorization) MethodName() string { +// MsgTypeURL implements Authorization.MsgTypeURL. +func (a SendAuthorization) MsgTypeURL() string { return "/cosmos.bank.v1beta1.Msg/Send" } diff --git a/x/staking/types/authz.go b/x/staking/types/authz.go index 8058a024bbd8..459d8860bcd2 100644 --- a/x/staking/types/authz.go +++ b/x/staking/types/authz.go @@ -40,8 +40,8 @@ func NewStakeAuthorization(allowed []sdk.ValAddress, denied []sdk.ValAddress, au return &authorization, nil } -// MethodName implements Authorization.MethodName. -func (a StakeAuthorization) MethodName() string { +// MsgTypeURL implements Authorization.MsgTypeURL. +func (a StakeAuthorization) MsgTypeURL() string { authzType, err := normalizeAuthzType(a.AuthorizationType) if err != nil { panic(err) From c1b077c7501264725433cb624b3477a879c5b02e Mon Sep 17 00:00:00 2001 From: Robert Zaremba Date: Fri, 23 Apr 2021 13:50:57 +0200 Subject: [PATCH 23/44] rollback Makefile changes --- Makefile | 5 +---- 1 file changed, 1 insertion(+), 4 deletions(-) diff --git a/Makefile b/Makefile index e3bb9d08c7a3..a26681ea8e5f 100644 --- a/Makefile +++ b/Makefile @@ -371,12 +371,9 @@ devdoc-update: proto-all: proto-format proto-lint proto-gen -protoContainerVer=v0.1 -protoContainer=cosmos-proto-gen-$(protoContainerVer) proto-gen: @echo "Generating Protobuf files" - @if docker ps -a --format '{{.Names}}' | grep -Eq "^${protoContainer}$$"; then docker start -a $(protoContainer); else docker run --name $(protoContainer) -v $(CURDIR):/workspace --workdir /workspace tendermintdev/sdk-proto-gen:$(protoContainerVer) sh ./scripts/protocgen.sh; fi -# $(DOCKER) run --rm -v $(CURDIR):/workspace --workdir /workspace tendermintdev/sdk-proto-gen:v0.1 sh ./scripts/protocgen.sh + $(DOCKER) run --rm -v $(CURDIR):/workspace --workdir /workspace tendermintdev/sdk-proto-gen:v0.1 sh ./scripts/protocgen.sh proto-format: @echo "Formatting Protobuf files" From 3ca0a988bc655da912ba3fc8f410f654714dc034 Mon Sep 17 00:00:00 2001 From: Robert Zaremba Date: Fri, 23 Apr 2021 13:55:35 +0200 Subject: [PATCH 24/44] fix tests --- x/authz/client/cli/tx_test.go | 2 +- x/bank/types/send_authorization_test.go | 4 +-- x/staking/types/authz_test.go | 36 ++++++++++++------------- 3 files changed, 21 insertions(+), 21 deletions(-) diff --git a/x/authz/client/cli/tx_test.go b/x/authz/client/cli/tx_test.go index b7dad15e65b2..0c236c3ba70c 100644 --- a/x/authz/client/cli/tx_test.go +++ b/x/authz/client/cli/tx_test.go @@ -85,7 +85,7 @@ func (s *IntegrationTestSuite) TearDownSuite() { s.network.Cleanup() } -var typeMsgSend = bank.SendAuthorization{}.MethodName() +var typeMsgSend = bank.SendAuthorization{}.MsgTypeURL() var typeMsgVote = "/cosmos.gov.v1beta1.Msg/Vote" var commonFlags = []string{} diff --git a/x/bank/types/send_authorization_test.go b/x/bank/types/send_authorization_test.go index d2ed356c253e..ae575aa8dbb9 100644 --- a/x/bank/types/send_authorization_test.go +++ b/x/bank/types/send_authorization_test.go @@ -24,7 +24,7 @@ func TestSendAuthorization(t *testing.T) { authorization := types.NewSendAuthorization(coins1000) t.Log("verify authorization returns valid method name") - require.Equal(t, authorization.MethodName(), "/cosmos.bank.v1beta1.Msg/Send") + require.Equal(t, authorization.MsgTypeURL(), "/cosmos.bank.v1beta1.Msg/Send") require.NoError(t, authorization.ValidateBasic()) send := types.NewMsgSend(fromAddr, toAddr, coins1000) srvMsg := sdk.ServiceMsg{ @@ -40,7 +40,7 @@ func TestSendAuthorization(t *testing.T) { require.Nil(t, resp.Updated) authorization = types.NewSendAuthorization(coins1000) - require.Equal(t, authorization.MethodName(), "/cosmos.bank.v1beta1.Msg/Send") + require.Equal(t, authorization.MsgTypeURL(), "/cosmos.bank.v1beta1.Msg/Send") require.NoError(t, authorization.ValidateBasic()) send = types.NewMsgSend(fromAddr, toAddr, coins500) srvMsg = sdk.ServiceMsg{ diff --git a/x/staking/types/authz_test.go b/x/staking/types/authz_test.go index 6bbb414b564c..cfd0ae2d079d 100644 --- a/x/staking/types/authz_test.go +++ b/x/staking/types/authz_test.go @@ -33,7 +33,7 @@ func TestAuthzAuthorizations(t *testing.T) { // verify MethodName delAuth, err = stakingtypes.NewStakeAuthorization([]sdk.ValAddress{val1, val2}, []sdk.ValAddress{}, stakingtypes.AuthorizationType_AUTHORIZATION_TYPE_DELEGATE, &coin100) require.NoError(t, err) - require.Equal(t, delAuth.MethodName(), stakingtypes.TypeDelegate) + require.Equal(t, delAuth.MsgTypeURL(), stakingtypes.TypeDelegate) // error both allow & deny list _, err = stakingtypes.NewStakeAuthorization([]sdk.ValAddress{val1, val2}, []sdk.ValAddress{val1}, stakingtypes.AuthorizationType_AUTHORIZATION_TYPE_DELEGATE, &coin100) @@ -41,11 +41,11 @@ func TestAuthzAuthorizations(t *testing.T) { // verify MethodName undelAuth, _ := stakingtypes.NewStakeAuthorization([]sdk.ValAddress{val1, val2}, []sdk.ValAddress{}, stakingtypes.AuthorizationType_AUTHORIZATION_TYPE_UNDELEGATE, &coin100) - require.Equal(t, undelAuth.MethodName(), stakingtypes.TypeUndelegate) + require.Equal(t, undelAuth.MsgTypeURL(), stakingtypes.TypeUndelegate) // verify MethodName beginRedelAuth, _ := stakingtypes.NewStakeAuthorization([]sdk.ValAddress{val1, val2}, []sdk.ValAddress{}, stakingtypes.AuthorizationType_AUTHORIZATION_TYPE_REDELEGATE, &coin100) - require.Equal(t, beginRedelAuth.MethodName(), stakingtypes.TypeBeginRedelegate) + require.Equal(t, beginRedelAuth.MsgTypeURL(), stakingtypes.TypeBeginRedelegate) validators1_2 := []string{val1.String(), val2.String()} @@ -66,7 +66,7 @@ func TestAuthzAuthorizations(t *testing.T) { []sdk.ValAddress{}, stakingtypes.AuthorizationType_AUTHORIZATION_TYPE_DELEGATE, &coin100, - createSrvMsgDelegate(delAuth.MethodName(), delAddr, val1, coin100), + createSrvMsgDelegate(delAuth.MsgTypeURL(), delAddr, val1, coin100), false, true, nil, @@ -77,7 +77,7 @@ func TestAuthzAuthorizations(t *testing.T) { []sdk.ValAddress{}, stakingtypes.AuthorizationType_AUTHORIZATION_TYPE_DELEGATE, &coin100, - createSrvMsgDelegate(delAuth.MethodName(), delAddr, val1, coin50), + createSrvMsgDelegate(delAuth.MsgTypeURL(), delAddr, val1, coin50), false, false, &stakingtypes.StakeAuthorization{ @@ -91,7 +91,7 @@ func TestAuthzAuthorizations(t *testing.T) { []sdk.ValAddress{}, stakingtypes.AuthorizationType_AUTHORIZATION_TYPE_DELEGATE, &coin100, - createSrvMsgDelegate(delAuth.MethodName(), delAddr, val3, coin100), + createSrvMsgDelegate(delAuth.MsgTypeURL(), delAddr, val3, coin100), true, false, nil, @@ -102,7 +102,7 @@ func TestAuthzAuthorizations(t *testing.T) { []sdk.ValAddress{}, stakingtypes.AuthorizationType_AUTHORIZATION_TYPE_DELEGATE, nil, - createSrvMsgDelegate(delAuth.MethodName(), delAddr, val2, coin100), + createSrvMsgDelegate(delAuth.MsgTypeURL(), delAddr, val2, coin100), false, false, &stakingtypes.StakeAuthorization{ @@ -116,7 +116,7 @@ func TestAuthzAuthorizations(t *testing.T) { []sdk.ValAddress{val1}, stakingtypes.AuthorizationType_AUTHORIZATION_TYPE_DELEGATE, nil, - createSrvMsgDelegate(delAuth.MethodName(), delAddr, val1, coin100), + createSrvMsgDelegate(delAuth.MsgTypeURL(), delAddr, val1, coin100), true, false, nil, @@ -128,7 +128,7 @@ func TestAuthzAuthorizations(t *testing.T) { []sdk.ValAddress{}, stakingtypes.AuthorizationType_AUTHORIZATION_TYPE_UNDELEGATE, &coin100, - createSrvMsgUndelegate(undelAuth.MethodName(), delAddr, val1, coin100), + createSrvMsgUndelegate(undelAuth.MsgTypeURL(), delAddr, val1, coin100), false, true, nil, @@ -139,7 +139,7 @@ func TestAuthzAuthorizations(t *testing.T) { []sdk.ValAddress{}, stakingtypes.AuthorizationType_AUTHORIZATION_TYPE_UNDELEGATE, &coin100, - createSrvMsgUndelegate(undelAuth.MethodName(), delAddr, val1, coin50), + createSrvMsgUndelegate(undelAuth.MsgTypeURL(), delAddr, val1, coin50), false, false, &stakingtypes.StakeAuthorization{ @@ -153,7 +153,7 @@ func TestAuthzAuthorizations(t *testing.T) { []sdk.ValAddress{}, stakingtypes.AuthorizationType_AUTHORIZATION_TYPE_UNDELEGATE, &coin100, - createSrvMsgUndelegate(undelAuth.MethodName(), delAddr, val3, coin100), + createSrvMsgUndelegate(undelAuth.MsgTypeURL(), delAddr, val3, coin100), true, false, nil, @@ -164,7 +164,7 @@ func TestAuthzAuthorizations(t *testing.T) { []sdk.ValAddress{}, stakingtypes.AuthorizationType_AUTHORIZATION_TYPE_UNDELEGATE, nil, - createSrvMsgUndelegate(undelAuth.MethodName(), delAddr, val2, coin100), + createSrvMsgUndelegate(undelAuth.MsgTypeURL(), delAddr, val2, coin100), false, false, &stakingtypes.StakeAuthorization{ @@ -178,7 +178,7 @@ func TestAuthzAuthorizations(t *testing.T) { []sdk.ValAddress{val1}, stakingtypes.AuthorizationType_AUTHORIZATION_TYPE_UNDELEGATE, &coin100, - createSrvMsgUndelegate(undelAuth.MethodName(), delAddr, val1, coin100), + createSrvMsgUndelegate(undelAuth.MsgTypeURL(), delAddr, val1, coin100), true, false, nil, @@ -190,7 +190,7 @@ func TestAuthzAuthorizations(t *testing.T) { []sdk.ValAddress{}, stakingtypes.AuthorizationType_AUTHORIZATION_TYPE_REDELEGATE, &coin100, - createSrvMsgUndelegate(undelAuth.MethodName(), delAddr, val1, coin100), + createSrvMsgUndelegate(undelAuth.MsgTypeURL(), delAddr, val1, coin100), false, true, nil, @@ -201,7 +201,7 @@ func TestAuthzAuthorizations(t *testing.T) { []sdk.ValAddress{}, stakingtypes.AuthorizationType_AUTHORIZATION_TYPE_REDELEGATE, &coin100, - createSrvMsgReDelegate(undelAuth.MethodName(), delAddr, val1, coin50), + createSrvMsgReDelegate(undelAuth.MsgTypeURL(), delAddr, val1, coin50), false, false, &stakingtypes.StakeAuthorization{ @@ -215,7 +215,7 @@ func TestAuthzAuthorizations(t *testing.T) { []sdk.ValAddress{}, stakingtypes.AuthorizationType_AUTHORIZATION_TYPE_REDELEGATE, &coin100, - createSrvMsgReDelegate(undelAuth.MethodName(), delAddr, val3, coin100), + createSrvMsgReDelegate(undelAuth.MsgTypeURL(), delAddr, val3, coin100), true, false, nil, @@ -226,7 +226,7 @@ func TestAuthzAuthorizations(t *testing.T) { []sdk.ValAddress{}, stakingtypes.AuthorizationType_AUTHORIZATION_TYPE_REDELEGATE, nil, - createSrvMsgReDelegate(undelAuth.MethodName(), delAddr, val2, coin100), + createSrvMsgReDelegate(undelAuth.MsgTypeURL(), delAddr, val2, coin100), false, false, &stakingtypes.StakeAuthorization{ @@ -240,7 +240,7 @@ func TestAuthzAuthorizations(t *testing.T) { []sdk.ValAddress{val1}, stakingtypes.AuthorizationType_AUTHORIZATION_TYPE_REDELEGATE, &coin100, - createSrvMsgReDelegate(undelAuth.MethodName(), delAddr, val1, coin100), + createSrvMsgReDelegate(undelAuth.MsgTypeURL(), delAddr, val1, coin100), true, false, nil, From a14a0c850de948f3e0a592b76d9c1e06d88ff170 Mon Sep 17 00:00:00 2001 From: Robert Zaremba Date: Fri, 23 Apr 2021 21:22:42 +0200 Subject: [PATCH 25/44] Apply suggestions from code review Co-authored-by: Aaron Craelius --- proto/cosmos/authz/v1beta1/query.proto | 44 -------------------------- 1 file changed, 44 deletions(-) diff --git a/proto/cosmos/authz/v1beta1/query.proto b/proto/cosmos/authz/v1beta1/query.proto index 98898405a0f5..5320116a74b0 100644 --- a/proto/cosmos/authz/v1beta1/query.proto +++ b/proto/cosmos/authz/v1beta1/query.proto @@ -32,47 +32,3 @@ message QueryGrantsResponse { // pagination defines an pagination for the response. cosmos.base.query.v1beta1.PageResponse pagination = 2; } - - -// // Query defines the gRPC querier service. -// service Query { -// // Returns any `Authorization` (or `nil`), with the expiration time, granted to the grantee by the granter for the -// // provided msg type. -// rpc Authorization(QueryAuthorizationRequest) returns (QueryAuthorizationResponse) { -// option (google.api.http).get = "/cosmos/authz/v1beta1/granters/{granter}/grantees/{grantee}/grant"; -// } - -// // Returns list of `Authorization`, granted to the grantee by the granter. -// rpc Authorizations(QueryAuthorizationsRequest) returns (QueryAuthorizationsResponse) { -// option (google.api.http).get = "/cosmos/authz/v1beta1/granters/{granter}/grantees/{grantee}/grants"; -// } -// } - -// // QueryAuthorizationRequest is the request type for the Query/Authorization RPC method. -// message QueryAuthorizationRequest { -// string granter = 1; -// string grantee = 2; -// string method_name = 3; -// } - -// // QueryAuthorizationResponse is the response type for the Query/Authorization RPC method. -// message QueryAuthorizationResponse { -// // authorization is a authorization granted for grantee by granter. -// cosmos.authz.v1beta1.AuthorizationGrant authorization = 1; -// } - -// // QueryAuthorizationsRequest is the request type for the Query/Authorizations RPC method. -// message QueryAuthorizationsRequest { -// string granter = 1; -// string grantee = 2; -// // pagination defines an pagination for the request. -// cosmos.base.query.v1beta1.PageRequest pagination = 3; -// } - -// // QueryAuthorizationsResponse is the response type for the Query/Authorizations RPC method. -// message QueryAuthorizationsResponse { -// // authorizations is a list of grants granted for grantee by granter. -// repeated cosmos.authz.v1beta1.AuthorizationGrant authorizations = 1; -// // pagination defines an pagination for the response. -// cosmos.base.query.v1beta1.PageResponse pagination = 2; -// } From 46635db7bbf1d073b649a21f37e8501c8bc57c1c Mon Sep 17 00:00:00 2001 From: Robert Zaremba Date: Tue, 27 Apr 2021 13:45:31 +0200 Subject: [PATCH 26/44] renames --- docs/core/proto-docs.md | 34 ++-- proto/cosmos/authz/v1beta1/authz.proto | 2 +- proto/cosmos/authz/v1beta1/event.proto | 5 - proto/cosmos/authz/v1beta1/tx.proto | 18 +- x/authz/keeper/keeper.go | 2 - x/authz/keeper/msg_server.go | 6 +- x/authz/simulation/operations_test.go | 6 +- x/authz/types/authz.pb.go | 2 +- x/authz/types/codec.go | 6 +- x/authz/types/event.pb.go | 130 ++----------- x/authz/types/msgs.go | 44 ++--- x/authz/types/tx.pb.go | 241 ++++++++++++------------- 12 files changed, 190 insertions(+), 306 deletions(-) diff --git a/docs/core/proto-docs.md b/docs/core/proto-docs.md index 73bd0aea802c..95a10fa5debd 100644 --- a/docs/core/proto-docs.md +++ b/docs/core/proto-docs.md @@ -57,11 +57,11 @@ - [TxResponse](#cosmos.base.abci.v1beta1.TxResponse) - [cosmos/authz/v1beta1/tx.proto](#cosmos/authz/v1beta1/tx.proto) - - [MsgExecRequest](#cosmos.authz.v1beta1.MsgExecRequest) + - [MsgExec](#cosmos.authz.v1beta1.MsgExec) - [MsgExecResponse](#cosmos.authz.v1beta1.MsgExecResponse) - - [MsgGrantRequest](#cosmos.authz.v1beta1.MsgGrantRequest) + - [MsgGrant](#cosmos.authz.v1beta1.MsgGrant) - [MsgGrantResponse](#cosmos.authz.v1beta1.MsgGrantResponse) - - [MsgRevokeRequest](#cosmos.authz.v1beta1.MsgRevokeRequest) + - [MsgRevoke](#cosmos.authz.v1beta1.MsgRevoke) - [MsgRevokeResponse](#cosmos.authz.v1beta1.MsgRevokeResponse) - [Msg](#cosmos.authz.v1beta1.Msg) @@ -896,7 +896,7 @@ the provided method on behalf of the granter's account. ### Grant -AuthorizationGrant gives permissions to execute +Grant gives permissions to execute the provide method with expiration time. @@ -934,7 +934,6 @@ EventGrant is emitted on Msg/Grant | Field | Type | Label | Description | | ----- | ---- | ----- | ----------- | -| `module` | [string](#string) | | Module which invokes the authorizaiton grant TODO: not sure if this is needed. It always has the same value | | `msg_type_url` | [string](#string) | | Msg type URL for which an autorization is granted | | `granter` | [string](#string) | | Granter account address | | `grantee` | [string](#string) | | Grantee account address | @@ -952,7 +951,6 @@ EventRevoke is emitted on Msg/Revoke | Field | Type | Label | Description | | ----- | ---- | ----- | ----------- | -| `module` | [string](#string) | | Module which invokes the authorizaiton revokation | | `msg_type_url` | [string](#string) | | Msg type URL for which an autorization is revoked | | `granter` | [string](#string) | | Granter account address | | `grantee` | [string](#string) | | Grantee account address | @@ -1284,10 +1282,10 @@ tags are stringified and the log is JSON decoded. - + -### MsgExecRequest -MsgExecRequest attempts to execute the provided messages using +### MsgExec +MsgExec attempts to execute the provided messages using authorizations granted to the grantee. Each message should have only one signer corresponding to the granter of the authorization. @@ -1317,10 +1315,10 @@ MsgExecResponse defines the Msg/MsgExecResponse response type. - + -### MsgGrantRequest -MsgGrantRequest grants the provided authorization to the grantee on the granter's +### MsgGrant +MsgGrant grants the provided authorization to the grantee on the granter's account with the provided expiration time. @@ -1346,10 +1344,10 @@ MsgGrantResponse defines the Msg/MsgGrant response type. - + -### MsgRevokeRequest -MsgRevokeRequest revokes any authorization with the provided sdk.Msg type on the +### MsgRevoke +MsgRevoke revokes any authorization with the provided sdk.Msg type on the granter's account with that has been granted to the grantee. @@ -1387,9 +1385,9 @@ Msg defines the authz Msg service. | Method Name | Request Type | Response Type | Description | HTTP Verb | Endpoint | | ----------- | ------------ | ------------- | ------------| ------- | -------- | -| `Grant` | [MsgGrantRequest](#cosmos.authz.v1beta1.MsgGrantRequest) | [MsgGrantResponse](#cosmos.authz.v1beta1.MsgGrantResponse) | Grant grants the provided authorization to the grantee on the granter's account with the provided expiration time. | | -| `Exec` | [MsgExecRequest](#cosmos.authz.v1beta1.MsgExecRequest) | [MsgExecResponse](#cosmos.authz.v1beta1.MsgExecResponse) | Exec attempts to execute the provided messages using authorizations granted to the grantee. Each message should have only one signer corresponding to the granter of the authorization. | | -| `Revoke` | [MsgRevokeRequest](#cosmos.authz.v1beta1.MsgRevokeRequest) | [MsgRevokeResponse](#cosmos.authz.v1beta1.MsgRevokeResponse) | Revoke revokes any authorization corresponding to the provided method name on the granter's account that has been granted to the grantee. | | +| `Grant` | [MsgGrant](#cosmos.authz.v1beta1.MsgGrant) | [MsgGrantResponse](#cosmos.authz.v1beta1.MsgGrantResponse) | Grant grants the provided authorization to the grantee on the granter's account with the provided expiration time. | | +| `Exec` | [MsgExec](#cosmos.authz.v1beta1.MsgExec) | [MsgExecResponse](#cosmos.authz.v1beta1.MsgExecResponse) | Exec attempts to execute the provided messages using authorizations granted to the grantee. Each message should have only one signer corresponding to the granter of the authorization. | | +| `Revoke` | [MsgRevoke](#cosmos.authz.v1beta1.MsgRevoke) | [MsgRevokeResponse](#cosmos.authz.v1beta1.MsgRevokeResponse) | Revoke revokes any authorization corresponding to the provided method name on the granter's account that has been granted to the grantee. | | diff --git a/proto/cosmos/authz/v1beta1/authz.proto b/proto/cosmos/authz/v1beta1/authz.proto index bdd06cc928cd..ce4cd64cef2f 100644 --- a/proto/cosmos/authz/v1beta1/authz.proto +++ b/proto/cosmos/authz/v1beta1/authz.proto @@ -18,7 +18,7 @@ message GenericAuthorization { string msg = 1; } -// AuthorizationGrant gives permissions to execute +// Grant gives permissions to execute // the provide method with expiration time. message Grant { google.protobuf.Any authorization = 1 [(cosmos_proto.accepts_interface) = "Authorization"]; diff --git a/proto/cosmos/authz/v1beta1/event.proto b/proto/cosmos/authz/v1beta1/event.proto index 4fd77ac0cf20..69659337cb81 100644 --- a/proto/cosmos/authz/v1beta1/event.proto +++ b/proto/cosmos/authz/v1beta1/event.proto @@ -11,9 +11,6 @@ option go_package = "github.com/cosmos/cosmos-sdk/x/authz/types"; // EventGrant is emitted on Msg/Grant message EventGrant { - // Module which invokes the authorizaiton grant - // TODO: not sure if this is needed. It always has the same value - string module = 1; // Msg type URL for which an autorization is granted string msg_type_url = 2; // Granter account address @@ -24,8 +21,6 @@ message EventGrant { // EventRevoke is emitted on Msg/Revoke message EventRevoke { - // Module which invokes the authorizaiton revokation - string module = 1; // Msg type URL for which an autorization is revoked string msg_type_url = 2; // Granter account address diff --git a/proto/cosmos/authz/v1beta1/tx.proto b/proto/cosmos/authz/v1beta1/tx.proto index c15cde0749a7..58757be3b048 100644 --- a/proto/cosmos/authz/v1beta1/tx.proto +++ b/proto/cosmos/authz/v1beta1/tx.proto @@ -14,21 +14,21 @@ option (gogoproto.goproto_getters_all) = false; service Msg { // Grant grants the provided authorization to the grantee on the granter's // account with the provided expiration time. - rpc Grant(MsgGrantRequest) returns (MsgGrantResponse); + rpc Grant(MsgGrant) returns (MsgGrantResponse); // Exec attempts to execute the provided messages using // authorizations granted to the grantee. Each message should have only // one signer corresponding to the granter of the authorization. - rpc Exec(MsgExecRequest) returns (MsgExecResponse); + rpc Exec(MsgExec) returns (MsgExecResponse); // Revoke revokes any authorization corresponding to the provided method name on the // granter's account that has been granted to the grantee. - rpc Revoke(MsgRevokeRequest) returns (MsgRevokeResponse); + rpc Revoke(MsgRevoke) returns (MsgRevokeResponse); } -// MsgGrantRequest grants the provided authorization to the grantee on the granter's +// MsgGrant grants the provided authorization to the grantee on the granter's // account with the provided expiration time. -message MsgGrantRequest { +message MsgGrant { string granter = 1; string grantee = 2; @@ -41,10 +41,10 @@ message MsgExecResponse { cosmos.base.abci.v1beta1.Result result = 1; } -// MsgExecRequest attempts to execute the provided messages using +// MsgExec attempts to execute the provided messages using // authorizations granted to the grantee. Each message should have only // one signer corresponding to the granter of the authorization. -message MsgExecRequest { +message MsgExec { string grantee = 1; repeated google.protobuf.Any msgs = 2; } @@ -52,9 +52,9 @@ message MsgExecRequest { // MsgGrantResponse defines the Msg/MsgGrant response type. message MsgGrantResponse {} -// MsgRevokeRequest revokes any authorization with the provided sdk.Msg type on the +// MsgRevoke revokes any authorization with the provided sdk.Msg type on the // granter's account with that has been granted to the grantee. -message MsgRevokeRequest { +message MsgRevoke { string granter = 1; string grantee = 2; string msg_type_url = 3; diff --git a/x/authz/keeper/keeper.go b/x/authz/keeper/keeper.go index ed9cf206b1c8..700c8d4ad650 100644 --- a/x/authz/keeper/keeper.go +++ b/x/authz/keeper/keeper.go @@ -135,7 +135,6 @@ func (k Keeper) SaveGrant(ctx sdk.Context, grantee, granter sdk.AccAddress, auth skey := grantStoreKey(grantee, granter, authorization.MsgTypeURL()) store.Set(skey, bz) return ctx.EventManager().EmitTypedEvent(&types.EventGrant{ - Module: types.ModuleName, MsgTypeUrl: authorization.MsgTypeURL(), Granter: granter.String(), Grantee: grantee.String(), @@ -153,7 +152,6 @@ func (k Keeper) DeleteGrant(ctx sdk.Context, grantee sdk.AccAddress, granter sdk } store.Delete(skey) return ctx.EventManager().EmitTypedEvent(&types.EventRevoke{ - Module: types.ModuleName, MsgTypeUrl: msgType, Granter: granter.String(), Grantee: grantee.String(), diff --git a/x/authz/keeper/msg_server.go b/x/authz/keeper/msg_server.go index b31fee07648e..23f318bc44b2 100644 --- a/x/authz/keeper/msg_server.go +++ b/x/authz/keeper/msg_server.go @@ -11,7 +11,7 @@ import ( var _ types.MsgServer = Keeper{} // GrantAuthorization implements the MsgServer.Grant method. -func (k Keeper) Grant(goCtx context.Context, msg *types.MsgGrantRequest) (*types.MsgGrantResponse, error) { +func (k Keeper) Grant(goCtx context.Context, msg *types.MsgGrant) (*types.MsgGrantResponse, error) { ctx := sdk.UnwrapSDKContext(goCtx) grantee, err := sdk.AccAddressFromBech32(msg.Grantee) if err != nil { @@ -40,7 +40,7 @@ func (k Keeper) Grant(goCtx context.Context, msg *types.MsgGrantRequest) (*types } // RevokeAuthorization implements the MsgServer.Revoke method. -func (k Keeper) Revoke(goCtx context.Context, msg *types.MsgRevokeRequest) (*types.MsgRevokeResponse, error) { +func (k Keeper) Revoke(goCtx context.Context, msg *types.MsgRevoke) (*types.MsgRevokeResponse, error) { ctx := sdk.UnwrapSDKContext(goCtx) grantee, err := sdk.AccAddressFromBech32(msg.Grantee) if err != nil { @@ -60,7 +60,7 @@ func (k Keeper) Revoke(goCtx context.Context, msg *types.MsgRevokeRequest) (*typ } // Exec implements the MsgServer.Exec method. -func (k Keeper) Exec(goCtx context.Context, msg *types.MsgExecRequest) (*types.MsgExecResponse, error) { +func (k Keeper) Exec(goCtx context.Context, msg *types.MsgExec) (*types.MsgExecResponse, error) { ctx := sdk.UnwrapSDKContext(goCtx) grantee, err := sdk.AccAddressFromBech32(msg.Grantee) if err != nil { diff --git a/x/authz/simulation/operations_test.go b/x/authz/simulation/operations_test.go index 86367ef4c5d8..2cc6a36f395d 100644 --- a/x/authz/simulation/operations_test.go +++ b/x/authz/simulation/operations_test.go @@ -110,7 +110,7 @@ func (suite *SimTestSuite) TestSimulateGrantAuthorization() { operationMsg, futureOperations, err := op(r, suite.app.BaseApp, ctx, accounts, "") suite.Require().NoError(err) - var msg types.MsgGrantRequest + var msg types.MsgGrant suite.app.AppCodec().UnmarshalJSON(operationMsg.Msg, &msg) suite.Require().True(operationMsg.OK) suite.Require().Equal(granter.Address.String(), msg.Granter) @@ -147,7 +147,7 @@ func (suite *SimTestSuite) TestSimulateRevokeAuthorization() { operationMsg, futureOperations, err := op(r, suite.app.BaseApp, suite.ctx, accounts, "") suite.Require().NoError(err) - var msg types.MsgRevokeRequest + var msg types.MsgRevoke suite.app.AppCodec().UnmarshalJSON(operationMsg.Msg, &msg) suite.Require().True(operationMsg.OK) @@ -182,7 +182,7 @@ func (suite *SimTestSuite) TestSimulateExecAuthorization() { operationMsg, futureOperations, err := op(r, suite.app.BaseApp, suite.ctx, accounts, "") suite.Require().NoError(err) - var msg types.MsgExecRequest + var msg types.MsgExec suite.app.AppCodec().UnmarshalJSON(operationMsg.Msg, &msg) diff --git a/x/authz/types/authz.pb.go b/x/authz/types/authz.pb.go index 0529619c44bf..4715197b7589 100644 --- a/x/authz/types/authz.pb.go +++ b/x/authz/types/authz.pb.go @@ -69,7 +69,7 @@ func (m *GenericAuthorization) XXX_DiscardUnknown() { var xxx_messageInfo_GenericAuthorization proto.InternalMessageInfo -// AuthorizationGrant gives permissions to execute +// Grant gives permissions to execute // the provide method with expiration time. type Grant struct { Authorization *types.Any `protobuf:"bytes,1,opt,name=authorization,proto3" json:"authorization,omitempty"` diff --git a/x/authz/types/codec.go b/x/authz/types/codec.go index c9f735446094..9bc92a7a670e 100644 --- a/x/authz/types/codec.go +++ b/x/authz/types/codec.go @@ -12,9 +12,9 @@ import ( // RegisterInterfaces registers the interfaces types with the interface registry func RegisterInterfaces(registry types.InterfaceRegistry) { registry.RegisterImplementations((*sdk.MsgRequest)(nil), - &MsgGrantRequest{}, - &MsgRevokeRequest{}, - &MsgExecRequest{}, + &MsgGrant{}, + &MsgRevoke{}, + &MsgExec{}, ) registry.RegisterInterface( diff --git a/x/authz/types/event.pb.go b/x/authz/types/event.pb.go index 5cfc19612ed7..8f1d7ad60b48 100644 --- a/x/authz/types/event.pb.go +++ b/x/authz/types/event.pb.go @@ -24,9 +24,6 @@ const _ = proto.GoGoProtoPackageIsVersion3 // please upgrade the proto package // EventGrant is emitted on Msg/Grant type EventGrant struct { - // Module which invokes the authorizaiton grant - // TODO: not sure if this is needed. It always has the same value - Module string `protobuf:"bytes,1,opt,name=module,proto3" json:"module,omitempty"` // Msg type URL for which an autorization is granted MsgTypeUrl string `protobuf:"bytes,2,opt,name=msg_type_url,json=msgTypeUrl,proto3" json:"msg_type_url,omitempty"` // Granter account address @@ -68,13 +65,6 @@ func (m *EventGrant) XXX_DiscardUnknown() { var xxx_messageInfo_EventGrant proto.InternalMessageInfo -func (m *EventGrant) GetModule() string { - if m != nil { - return m.Module - } - return "" -} - func (m *EventGrant) GetMsgTypeUrl() string { if m != nil { return m.MsgTypeUrl @@ -98,8 +88,6 @@ func (m *EventGrant) GetGrantee() string { // EventRevoke is emitted on Msg/Revoke type EventRevoke struct { - // Module which invokes the authorizaiton revokation - Module string `protobuf:"bytes,1,opt,name=module,proto3" json:"module,omitempty"` // Msg type URL for which an autorization is revoked MsgTypeUrl string `protobuf:"bytes,2,opt,name=msg_type_url,json=msgTypeUrl,proto3" json:"msg_type_url,omitempty"` // Granter account address @@ -141,13 +129,6 @@ func (m *EventRevoke) XXX_DiscardUnknown() { var xxx_messageInfo_EventRevoke proto.InternalMessageInfo -func (m *EventRevoke) GetModule() string { - if m != nil { - return m.Module - } - return "" -} - func (m *EventRevoke) GetMsgTypeUrl() string { if m != nil { return m.MsgTypeUrl @@ -177,22 +158,21 @@ func init() { func init() { proto.RegisterFile("cosmos/authz/v1beta1/event.proto", fileDescriptor_1f88cbc71a8baf1f) } var fileDescriptor_1f88cbc71a8baf1f = []byte{ - // 229 bytes of a gzipped FileDescriptorProto + // 213 bytes of a gzipped FileDescriptorProto 0x1f, 0x8b, 0x08, 0x00, 0x00, 0x00, 0x00, 0x00, 0x02, 0xff, 0xe2, 0x52, 0x48, 0xce, 0x2f, 0xce, 0xcd, 0x2f, 0xd6, 0x4f, 0x2c, 0x2d, 0xc9, 0xa8, 0xd2, 0x2f, 0x33, 0x4c, 0x4a, 0x2d, 0x49, 0x34, 0xd4, 0x4f, 0x2d, 0x4b, 0xcd, 0x2b, 0xd1, 0x2b, 0x28, 0xca, 0x2f, 0xc9, 0x17, 0x12, 0x81, 0xa8, - 0xd0, 0x03, 0xab, 0xd0, 0x83, 0xaa, 0x50, 0xaa, 0xe2, 0xe2, 0x72, 0x05, 0x29, 0x72, 0x2f, 0x4a, - 0xcc, 0x2b, 0x11, 0x12, 0xe3, 0x62, 0xcb, 0xcd, 0x4f, 0x29, 0xcd, 0x49, 0x95, 0x60, 0x54, 0x60, - 0xd4, 0xe0, 0x0c, 0x82, 0xf2, 0x84, 0x14, 0xb8, 0x78, 0x72, 0x8b, 0xd3, 0xe3, 0x4b, 0x2a, 0x0b, - 0x52, 0xe3, 0x4b, 0x8b, 0x72, 0x24, 0x98, 0xc0, 0xb2, 0x5c, 0xb9, 0xc5, 0xe9, 0x21, 0x95, 0x05, - 0xa9, 0xa1, 0x45, 0x39, 0x42, 0x12, 0x5c, 0xec, 0xe9, 0x20, 0x23, 0x52, 0x8b, 0x24, 0x98, 0xc1, - 0x92, 0x30, 0x2e, 0x42, 0x26, 0x55, 0x82, 0x05, 0x59, 0x26, 0x55, 0xa9, 0x9a, 0x8b, 0x1b, 0x6c, - 0x77, 0x50, 0x6a, 0x59, 0x7e, 0x76, 0x2a, 0x7d, 0x2d, 0x77, 0x72, 0x39, 0xf1, 0x48, 0x8e, 0xf1, - 0xc2, 0x23, 0x39, 0xc6, 0x07, 0x8f, 0xe4, 0x18, 0x27, 0x3c, 0x96, 0x63, 0xb8, 0xf0, 0x58, 0x8e, - 0xe1, 0xc6, 0x63, 0x39, 0x86, 0x28, 0xad, 0xf4, 0xcc, 0x92, 0x8c, 0xd2, 0x24, 0xbd, 0xe4, 0xfc, - 0x5c, 0x7d, 0x68, 0xa8, 0x42, 0x28, 0xdd, 0xe2, 0x94, 0x6c, 0xfd, 0x0a, 0x68, 0x10, 0x83, 0x9c, - 0x53, 0x9c, 0xc4, 0x06, 0x0e, 0x5b, 0x63, 0x40, 0x00, 0x00, 0x00, 0xff, 0xff, 0x97, 0x7a, 0x04, - 0x1c, 0x7f, 0x01, 0x00, 0x00, + 0xd0, 0x03, 0xab, 0xd0, 0x83, 0xaa, 0x50, 0x4a, 0xe2, 0xe2, 0x72, 0x05, 0x29, 0x72, 0x2f, 0x4a, + 0xcc, 0x2b, 0x11, 0x52, 0xe0, 0xe2, 0xc9, 0x2d, 0x4e, 0x8f, 0x2f, 0xa9, 0x2c, 0x48, 0x8d, 0x2f, + 0x2d, 0xca, 0x91, 0x60, 0x52, 0x60, 0xd4, 0xe0, 0x0c, 0xe2, 0xca, 0x2d, 0x4e, 0x0f, 0xa9, 0x2c, + 0x48, 0x0d, 0x2d, 0xca, 0x11, 0x92, 0xe0, 0x62, 0x4f, 0x07, 0x29, 0x4d, 0x2d, 0x92, 0x60, 0x06, + 0x4b, 0xc2, 0xb8, 0x08, 0x99, 0x54, 0x09, 0x16, 0x64, 0x99, 0x54, 0xa5, 0x64, 0x2e, 0x6e, 0xb0, + 0x1d, 0x41, 0xa9, 0x65, 0xf9, 0xd9, 0xa9, 0xb4, 0xb1, 0xc4, 0xc9, 0xe5, 0xc4, 0x23, 0x39, 0xc6, + 0x0b, 0x8f, 0xe4, 0x18, 0x1f, 0x3c, 0x92, 0x63, 0x9c, 0xf0, 0x58, 0x8e, 0xe1, 0xc2, 0x63, 0x39, + 0x86, 0x1b, 0x8f, 0xe5, 0x18, 0xa2, 0xb4, 0xd2, 0x33, 0x4b, 0x32, 0x4a, 0x93, 0xf4, 0x92, 0xf3, + 0x73, 0xf5, 0xa1, 0xa1, 0x04, 0xa1, 0x74, 0x8b, 0x53, 0xb2, 0xf5, 0x2b, 0xa0, 0x41, 0x06, 0x72, + 0x4e, 0x71, 0x12, 0x1b, 0x38, 0xac, 0x8c, 0x01, 0x01, 0x00, 0x00, 0xff, 0xff, 0xcf, 0xa7, 0xc5, + 0x7e, 0x4f, 0x01, 0x00, 0x00, } func (m *EventGrant) Marshal() (dAtA []byte, err error) { @@ -236,13 +216,6 @@ func (m *EventGrant) MarshalToSizedBuffer(dAtA []byte) (int, error) { i-- dAtA[i] = 0x12 } - if len(m.Module) > 0 { - i -= len(m.Module) - copy(dAtA[i:], m.Module) - i = encodeVarintEvent(dAtA, i, uint64(len(m.Module))) - i-- - dAtA[i] = 0xa - } return len(dAtA) - i, nil } @@ -287,13 +260,6 @@ func (m *EventRevoke) MarshalToSizedBuffer(dAtA []byte) (int, error) { i-- dAtA[i] = 0x12 } - if len(m.Module) > 0 { - i -= len(m.Module) - copy(dAtA[i:], m.Module) - i = encodeVarintEvent(dAtA, i, uint64(len(m.Module))) - i-- - dAtA[i] = 0xa - } return len(dAtA) - i, nil } @@ -314,10 +280,6 @@ func (m *EventGrant) Size() (n int) { } var l int _ = l - l = len(m.Module) - if l > 0 { - n += 1 + l + sovEvent(uint64(l)) - } l = len(m.MsgTypeUrl) if l > 0 { n += 1 + l + sovEvent(uint64(l)) @@ -339,10 +301,6 @@ func (m *EventRevoke) Size() (n int) { } var l int _ = l - l = len(m.Module) - if l > 0 { - n += 1 + l + sovEvent(uint64(l)) - } l = len(m.MsgTypeUrl) if l > 0 { n += 1 + l + sovEvent(uint64(l)) @@ -393,38 +351,6 @@ func (m *EventGrant) Unmarshal(dAtA []byte) error { return fmt.Errorf("proto: EventGrant: illegal tag %d (wire type %d)", fieldNum, wire) } switch fieldNum { - case 1: - if wireType != 2 { - return fmt.Errorf("proto: wrong wireType = %d for field Module", wireType) - } - var stringLen uint64 - for shift := uint(0); ; shift += 7 { - if shift >= 64 { - return ErrIntOverflowEvent - } - 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 ErrInvalidLengthEvent - } - postIndex := iNdEx + intStringLen - if postIndex < 0 { - return ErrInvalidLengthEvent - } - if postIndex > l { - return io.ErrUnexpectedEOF - } - m.Module = string(dAtA[iNdEx:postIndex]) - iNdEx = postIndex case 2: if wireType != 2 { return fmt.Errorf("proto: wrong wireType = %d for field MsgTypeUrl", wireType) @@ -571,38 +497,6 @@ func (m *EventRevoke) Unmarshal(dAtA []byte) error { return fmt.Errorf("proto: EventRevoke: illegal tag %d (wire type %d)", fieldNum, wire) } switch fieldNum { - case 1: - if wireType != 2 { - return fmt.Errorf("proto: wrong wireType = %d for field Module", wireType) - } - var stringLen uint64 - for shift := uint(0); ; shift += 7 { - if shift >= 64 { - return ErrIntOverflowEvent - } - 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 ErrInvalidLengthEvent - } - postIndex := iNdEx + intStringLen - if postIndex < 0 { - return ErrInvalidLengthEvent - } - if postIndex > l { - return io.ErrUnexpectedEOF - } - m.Module = string(dAtA[iNdEx:postIndex]) - iNdEx = postIndex case 2: if wireType != 2 { return fmt.Errorf("proto: wrong wireType = %d for field MsgTypeUrl", wireType) diff --git a/x/authz/types/msgs.go b/x/authz/types/msgs.go index d3bae106c1ac..a2cba5166db3 100644 --- a/x/authz/types/msgs.go +++ b/x/authz/types/msgs.go @@ -12,18 +12,18 @@ import ( ) var ( - _ sdk.MsgRequest = &MsgGrantRequest{} - _ sdk.MsgRequest = &MsgRevokeRequest{} - _ sdk.MsgRequest = &MsgExecRequest{} + _ sdk.MsgRequest = &MsgGrant{} + _ sdk.MsgRequest = &MsgRevoke{} + _ sdk.MsgRequest = &MsgExec{} - _ types.UnpackInterfacesMessage = &MsgGrantRequest{} - _ types.UnpackInterfacesMessage = &MsgExecRequest{} + _ types.UnpackInterfacesMessage = &MsgGrant{} + _ types.UnpackInterfacesMessage = &MsgExec{} ) // NewMsgGrant creates a new MsgGrant //nolint:interfacer -func NewMsgGrant(granter sdk.AccAddress, grantee sdk.AccAddress, authorization exported.Authorization, expiration time.Time) (*MsgGrantRequest, error) { - m := &MsgGrantRequest{ +func NewMsgGrant(granter sdk.AccAddress, grantee sdk.AccAddress, authorization exported.Authorization, expiration time.Time) (*MsgGrant, error) { + m := &MsgGrant{ Granter: granter.String(), Grantee: grantee.String(), Expiration: expiration, @@ -36,7 +36,7 @@ func NewMsgGrant(granter sdk.AccAddress, grantee sdk.AccAddress, authorization e } // GetSigners implements Msg -func (msg MsgGrantRequest) GetSigners() []sdk.AccAddress { +func (msg MsgGrant) GetSigners() []sdk.AccAddress { granter, err := sdk.AccAddressFromBech32(msg.Granter) if err != nil { panic(err) @@ -45,7 +45,7 @@ func (msg MsgGrantRequest) GetSigners() []sdk.AccAddress { } // ValidateBasic implements Msg -func (msg MsgGrantRequest) ValidateBasic() error { +func (msg MsgGrant) ValidateBasic() error { granter, err := sdk.AccAddressFromBech32(msg.Granter) if err != nil { return sdkerrors.Wrap(sdkerrors.ErrInvalidAddress, "invalid granter address") @@ -71,7 +71,7 @@ func (msg MsgGrantRequest) ValidateBasic() error { } // GetAuthorization returns the cache value from the MsgGrant.Authorization if present. -func (msg *MsgGrantRequest) GetAuthorization() exported.Authorization { +func (msg *MsgGrant) GetAuthorization() exported.Authorization { authorization, ok := msg.Authorization.GetCachedValue().(exported.Authorization) if !ok { return nil @@ -80,7 +80,7 @@ func (msg *MsgGrantRequest) GetAuthorization() exported.Authorization { } // SetAuthorization converts Authorization to any and adds it to MsgGrant.Authorization. -func (msg *MsgGrantRequest) SetAuthorization(authorization exported.Authorization) error { +func (msg *MsgGrant) SetAuthorization(authorization exported.Authorization) error { m, ok := authorization.(proto.Message) if !ok { return sdkerrors.Wrapf(sdkerrors.ErrPackAny, "can't proto marshal %T", m) @@ -94,7 +94,7 @@ func (msg *MsgGrantRequest) SetAuthorization(authorization exported.Authorizatio } // UnpackInterfaces implements UnpackInterfacesMessage.UnpackInterfaces -func (msg MsgExecRequest) UnpackInterfaces(unpacker types.AnyUnpacker) error { +func (msg MsgExec) UnpackInterfaces(unpacker types.AnyUnpacker) error { for _, x := range msg.Msgs { var msgExecAuthorized sdk.MsgRequest err := unpacker.UnpackAny(x, &msgExecAuthorized) @@ -107,15 +107,15 @@ func (msg MsgExecRequest) UnpackInterfaces(unpacker types.AnyUnpacker) error { } // UnpackInterfaces implements UnpackInterfacesMessage.UnpackInterfaces -func (msg MsgGrantRequest) UnpackInterfaces(unpacker types.AnyUnpacker) error { +func (msg MsgGrant) UnpackInterfaces(unpacker types.AnyUnpacker) error { var authorization exported.Authorization return unpacker.UnpackAny(msg.Authorization, &authorization) } // NewMsgRevoke creates a new MsgRevoke //nolint:interfacer -func NewMsgRevoke(granter sdk.AccAddress, grantee sdk.AccAddress, msgTypeURL string) MsgRevokeRequest { - return MsgRevokeRequest{ +func NewMsgRevoke(granter sdk.AccAddress, grantee sdk.AccAddress, msgTypeURL string) MsgRevoke { + return MsgRevoke{ Granter: granter.String(), Grantee: grantee.String(), MsgTypeUrl: msgTypeURL, @@ -123,7 +123,7 @@ func NewMsgRevoke(granter sdk.AccAddress, grantee sdk.AccAddress, msgTypeURL str } // GetSigners implements Msg -func (msg MsgRevokeRequest) GetSigners() []sdk.AccAddress { +func (msg MsgRevoke) GetSigners() []sdk.AccAddress { granter, err := sdk.AccAddressFromBech32(msg.Granter) if err != nil { panic(err) @@ -132,7 +132,7 @@ func (msg MsgRevokeRequest) GetSigners() []sdk.AccAddress { } // ValidateBasic implements MsgRequest.ValidateBasic -func (msg MsgRevokeRequest) ValidateBasic() error { +func (msg MsgRevoke) ValidateBasic() error { granter, err := sdk.AccAddressFromBech32(msg.Granter) if err != nil { return sdkerrors.Wrap(sdkerrors.ErrInvalidAddress, "invalid granter address") @@ -155,7 +155,7 @@ func (msg MsgRevokeRequest) ValidateBasic() error { // NewMsgExec creates a new MsgExecAuthorized //nolint:interfacer -func NewMsgExec(grantee sdk.AccAddress, msgs []sdk.ServiceMsg) MsgExecRequest { +func NewMsgExec(grantee sdk.AccAddress, msgs []sdk.ServiceMsg) MsgExec { msgsAny := make([]*types.Any, len(msgs)) for i, msg := range msgs { bz, err := proto.Marshal(msg.Request) @@ -171,14 +171,14 @@ func NewMsgExec(grantee sdk.AccAddress, msgs []sdk.ServiceMsg) MsgExecRequest { msgsAny[i] = anyMsg } - return MsgExecRequest{ + return MsgExec{ Grantee: grantee.String(), Msgs: msgsAny, } } // GetServiceMsgs returns the cache values from the MsgExecAuthorized.Msgs if present. -func (msg MsgExecRequest) GetServiceMsgs() ([]sdk.ServiceMsg, error) { +func (msg MsgExec) GetServiceMsgs() ([]sdk.ServiceMsg, error) { msgs := make([]sdk.ServiceMsg, len(msg.Msgs)) for i, msgAny := range msg.Msgs { msgReq, ok := msgAny.GetCachedValue().(sdk.MsgRequest) @@ -197,7 +197,7 @@ func (msg MsgExecRequest) GetServiceMsgs() ([]sdk.ServiceMsg, error) { } // GetSigners implements Msg -func (msg MsgExecRequest) GetSigners() []sdk.AccAddress { +func (msg MsgExec) GetSigners() []sdk.AccAddress { grantee, err := sdk.AccAddressFromBech32(msg.Grantee) if err != nil { panic(err) @@ -206,7 +206,7 @@ func (msg MsgExecRequest) GetSigners() []sdk.AccAddress { } // ValidateBasic implements Msg -func (msg MsgExecRequest) ValidateBasic() error { +func (msg MsgExec) ValidateBasic() error { _, err := sdk.AccAddressFromBech32(msg.Grantee) if err != nil { return sdkerrors.Wrap(sdkerrors.ErrInvalidAddress, "invalid grantee address") diff --git a/x/authz/types/tx.pb.go b/x/authz/types/tx.pb.go index f180edf24776..3f5b9bcbe7ef 100644 --- a/x/authz/types/tx.pb.go +++ b/x/authz/types/tx.pb.go @@ -35,27 +35,27 @@ var _ = time.Kitchen // proto package needs to be updated. const _ = proto.GoGoProtoPackageIsVersion3 // please upgrade the proto package -// MsgGrantRequest grants the provided authorization to the grantee on the granter's +// MsgGrant grants the provided authorization to the grantee on the granter's // account with the provided expiration time. -type MsgGrantRequest struct { +type MsgGrant struct { Granter string `protobuf:"bytes,1,opt,name=granter,proto3" json:"granter,omitempty"` Grantee string `protobuf:"bytes,2,opt,name=grantee,proto3" json:"grantee,omitempty"` Authorization *types.Any `protobuf:"bytes,3,opt,name=authorization,proto3" json:"authorization,omitempty"` Expiration time.Time `protobuf:"bytes,4,opt,name=expiration,proto3,stdtime" json:"expiration"` } -func (m *MsgGrantRequest) Reset() { *m = MsgGrantRequest{} } -func (m *MsgGrantRequest) String() string { return proto.CompactTextString(m) } -func (*MsgGrantRequest) ProtoMessage() {} -func (*MsgGrantRequest) Descriptor() ([]byte, []int) { +func (m *MsgGrant) Reset() { *m = MsgGrant{} } +func (m *MsgGrant) String() string { return proto.CompactTextString(m) } +func (*MsgGrant) ProtoMessage() {} +func (*MsgGrant) Descriptor() ([]byte, []int) { return fileDescriptor_3ceddab7d8589ad1, []int{0} } -func (m *MsgGrantRequest) XXX_Unmarshal(b []byte) error { +func (m *MsgGrant) XXX_Unmarshal(b []byte) error { return m.Unmarshal(b) } -func (m *MsgGrantRequest) XXX_Marshal(b []byte, deterministic bool) ([]byte, error) { +func (m *MsgGrant) XXX_Marshal(b []byte, deterministic bool) ([]byte, error) { if deterministic { - return xxx_messageInfo_MsgGrantRequest.Marshal(b, m, deterministic) + return xxx_messageInfo_MsgGrant.Marshal(b, m, deterministic) } else { b = b[:cap(b)] n, err := m.MarshalToSizedBuffer(b) @@ -65,17 +65,17 @@ func (m *MsgGrantRequest) XXX_Marshal(b []byte, deterministic bool) ([]byte, err return b[:n], nil } } -func (m *MsgGrantRequest) XXX_Merge(src proto.Message) { - xxx_messageInfo_MsgGrantRequest.Merge(m, src) +func (m *MsgGrant) XXX_Merge(src proto.Message) { + xxx_messageInfo_MsgGrant.Merge(m, src) } -func (m *MsgGrantRequest) XXX_Size() int { +func (m *MsgGrant) XXX_Size() int { return m.Size() } -func (m *MsgGrantRequest) XXX_DiscardUnknown() { - xxx_messageInfo_MsgGrantRequest.DiscardUnknown(m) +func (m *MsgGrant) XXX_DiscardUnknown() { + xxx_messageInfo_MsgGrant.DiscardUnknown(m) } -var xxx_messageInfo_MsgGrantRequest proto.InternalMessageInfo +var xxx_messageInfo_MsgGrant proto.InternalMessageInfo // MsgExecResponse defines the Msg/MsgExecResponse response type. type MsgExecResponse struct { @@ -115,26 +115,26 @@ func (m *MsgExecResponse) XXX_DiscardUnknown() { var xxx_messageInfo_MsgExecResponse proto.InternalMessageInfo -// MsgExecRequest attempts to execute the provided messages using +// MsgExec attempts to execute the provided messages using // authorizations granted to the grantee. Each message should have only // one signer corresponding to the granter of the authorization. -type MsgExecRequest struct { +type MsgExec struct { Grantee string `protobuf:"bytes,1,opt,name=grantee,proto3" json:"grantee,omitempty"` Msgs []*types.Any `protobuf:"bytes,2,rep,name=msgs,proto3" json:"msgs,omitempty"` } -func (m *MsgExecRequest) Reset() { *m = MsgExecRequest{} } -func (m *MsgExecRequest) String() string { return proto.CompactTextString(m) } -func (*MsgExecRequest) ProtoMessage() {} -func (*MsgExecRequest) Descriptor() ([]byte, []int) { +func (m *MsgExec) Reset() { *m = MsgExec{} } +func (m *MsgExec) String() string { return proto.CompactTextString(m) } +func (*MsgExec) ProtoMessage() {} +func (*MsgExec) Descriptor() ([]byte, []int) { return fileDescriptor_3ceddab7d8589ad1, []int{2} } -func (m *MsgExecRequest) XXX_Unmarshal(b []byte) error { +func (m *MsgExec) XXX_Unmarshal(b []byte) error { return m.Unmarshal(b) } -func (m *MsgExecRequest) XXX_Marshal(b []byte, deterministic bool) ([]byte, error) { +func (m *MsgExec) XXX_Marshal(b []byte, deterministic bool) ([]byte, error) { if deterministic { - return xxx_messageInfo_MsgExecRequest.Marshal(b, m, deterministic) + return xxx_messageInfo_MsgExec.Marshal(b, m, deterministic) } else { b = b[:cap(b)] n, err := m.MarshalToSizedBuffer(b) @@ -144,17 +144,17 @@ func (m *MsgExecRequest) XXX_Marshal(b []byte, deterministic bool) ([]byte, erro return b[:n], nil } } -func (m *MsgExecRequest) XXX_Merge(src proto.Message) { - xxx_messageInfo_MsgExecRequest.Merge(m, src) +func (m *MsgExec) XXX_Merge(src proto.Message) { + xxx_messageInfo_MsgExec.Merge(m, src) } -func (m *MsgExecRequest) XXX_Size() int { +func (m *MsgExec) XXX_Size() int { return m.Size() } -func (m *MsgExecRequest) XXX_DiscardUnknown() { - xxx_messageInfo_MsgExecRequest.DiscardUnknown(m) +func (m *MsgExec) XXX_DiscardUnknown() { + xxx_messageInfo_MsgExec.DiscardUnknown(m) } -var xxx_messageInfo_MsgExecRequest proto.InternalMessageInfo +var xxx_messageInfo_MsgExec proto.InternalMessageInfo // MsgGrantResponse defines the Msg/MsgGrant response type. type MsgGrantResponse struct { @@ -193,26 +193,26 @@ func (m *MsgGrantResponse) XXX_DiscardUnknown() { var xxx_messageInfo_MsgGrantResponse proto.InternalMessageInfo -// MsgRevokeRequest revokes any authorization with the provided sdk.Msg type on the +// MsgRevoke revokes any authorization with the provided sdk.Msg type on the // granter's account with that has been granted to the grantee. -type MsgRevokeRequest struct { +type MsgRevoke struct { Granter string `protobuf:"bytes,1,opt,name=granter,proto3" json:"granter,omitempty"` Grantee string `protobuf:"bytes,2,opt,name=grantee,proto3" json:"grantee,omitempty"` MsgTypeUrl string `protobuf:"bytes,3,opt,name=msg_type_url,json=msgTypeUrl,proto3" json:"msg_type_url,omitempty"` } -func (m *MsgRevokeRequest) Reset() { *m = MsgRevokeRequest{} } -func (m *MsgRevokeRequest) String() string { return proto.CompactTextString(m) } -func (*MsgRevokeRequest) ProtoMessage() {} -func (*MsgRevokeRequest) Descriptor() ([]byte, []int) { +func (m *MsgRevoke) Reset() { *m = MsgRevoke{} } +func (m *MsgRevoke) String() string { return proto.CompactTextString(m) } +func (*MsgRevoke) ProtoMessage() {} +func (*MsgRevoke) Descriptor() ([]byte, []int) { return fileDescriptor_3ceddab7d8589ad1, []int{4} } -func (m *MsgRevokeRequest) XXX_Unmarshal(b []byte) error { +func (m *MsgRevoke) XXX_Unmarshal(b []byte) error { return m.Unmarshal(b) } -func (m *MsgRevokeRequest) XXX_Marshal(b []byte, deterministic bool) ([]byte, error) { +func (m *MsgRevoke) XXX_Marshal(b []byte, deterministic bool) ([]byte, error) { if deterministic { - return xxx_messageInfo_MsgRevokeRequest.Marshal(b, m, deterministic) + return xxx_messageInfo_MsgRevoke.Marshal(b, m, deterministic) } else { b = b[:cap(b)] n, err := m.MarshalToSizedBuffer(b) @@ -222,17 +222,17 @@ func (m *MsgRevokeRequest) XXX_Marshal(b []byte, deterministic bool) ([]byte, er return b[:n], nil } } -func (m *MsgRevokeRequest) XXX_Merge(src proto.Message) { - xxx_messageInfo_MsgRevokeRequest.Merge(m, src) +func (m *MsgRevoke) XXX_Merge(src proto.Message) { + xxx_messageInfo_MsgRevoke.Merge(m, src) } -func (m *MsgRevokeRequest) XXX_Size() int { +func (m *MsgRevoke) XXX_Size() int { return m.Size() } -func (m *MsgRevokeRequest) XXX_DiscardUnknown() { - xxx_messageInfo_MsgRevokeRequest.DiscardUnknown(m) +func (m *MsgRevoke) XXX_DiscardUnknown() { + xxx_messageInfo_MsgRevoke.DiscardUnknown(m) } -var xxx_messageInfo_MsgRevokeRequest proto.InternalMessageInfo +var xxx_messageInfo_MsgRevoke proto.InternalMessageInfo // MsgRevokeResponse defines the Msg/MsgRevokeResponse response type. type MsgRevokeResponse struct { @@ -272,51 +272,50 @@ func (m *MsgRevokeResponse) XXX_DiscardUnknown() { var xxx_messageInfo_MsgRevokeResponse proto.InternalMessageInfo func init() { - proto.RegisterType((*MsgGrantRequest)(nil), "cosmos.authz.v1beta1.MsgGrantRequest") + proto.RegisterType((*MsgGrant)(nil), "cosmos.authz.v1beta1.MsgGrant") proto.RegisterType((*MsgExecResponse)(nil), "cosmos.authz.v1beta1.MsgExecResponse") - proto.RegisterType((*MsgExecRequest)(nil), "cosmos.authz.v1beta1.MsgExecRequest") + proto.RegisterType((*MsgExec)(nil), "cosmos.authz.v1beta1.MsgExec") proto.RegisterType((*MsgGrantResponse)(nil), "cosmos.authz.v1beta1.MsgGrantResponse") - proto.RegisterType((*MsgRevokeRequest)(nil), "cosmos.authz.v1beta1.MsgRevokeRequest") + proto.RegisterType((*MsgRevoke)(nil), "cosmos.authz.v1beta1.MsgRevoke") proto.RegisterType((*MsgRevokeResponse)(nil), "cosmos.authz.v1beta1.MsgRevokeResponse") } func init() { proto.RegisterFile("cosmos/authz/v1beta1/tx.proto", fileDescriptor_3ceddab7d8589ad1) } var fileDescriptor_3ceddab7d8589ad1 = []byte{ - // 517 bytes of a gzipped FileDescriptorProto - 0x1f, 0x8b, 0x08, 0x00, 0x00, 0x00, 0x00, 0x00, 0x02, 0xff, 0xa4, 0x94, 0xcf, 0x6e, 0xd3, 0x40, - 0x10, 0xc6, 0xe3, 0x26, 0x04, 0xba, 0xa5, 0x40, 0x97, 0x1c, 0x52, 0x4b, 0x38, 0x91, 0xa1, 0x10, - 0x21, 0x75, 0xad, 0x86, 0x0b, 0xd7, 0x46, 0x20, 0x90, 0x50, 0x2e, 0x4b, 0x40, 0x82, 0x4b, 0x64, - 0x87, 0x61, 0x63, 0x35, 0xf6, 0x1a, 0xef, 0xba, 0x4a, 0xfa, 0x0e, 0x48, 0x7d, 0x18, 0x1e, 0x22, - 0xe2, 0xd4, 0x23, 0xe2, 0xc0, 0x9f, 0xe4, 0x45, 0x90, 0x77, 0x37, 0xad, 0x13, 0x88, 0x72, 0xe0, - 0x94, 0xcc, 0xcc, 0x6f, 0x67, 0xbf, 0xf9, 0x66, 0x13, 0x74, 0x6f, 0xc0, 0x45, 0xc4, 0x85, 0xe7, - 0x67, 0x72, 0x78, 0xe6, 0x9d, 0x1e, 0x05, 0x20, 0xfd, 0x23, 0x4f, 0x8e, 0x49, 0x92, 0x72, 0xc9, - 0x71, 0x4d, 0x97, 0x89, 0x2a, 0x13, 0x53, 0xb6, 0xf7, 0x75, 0xb6, 0xaf, 0x18, 0xcf, 0x20, 0x2a, - 0xb0, 0x6b, 0x8c, 0x33, 0xae, 0xf3, 0xf9, 0x37, 0x93, 0x6d, 0x30, 0xce, 0xd9, 0x08, 0x3c, 0x15, - 0x05, 0xd9, 0x47, 0x4f, 0x86, 0x11, 0x08, 0xe9, 0x47, 0x89, 0x01, 0xf6, 0x57, 0x01, 0x3f, 0x9e, - 0x98, 0xd2, 0x7d, 0xa3, 0x30, 0xf0, 0x05, 0x78, 0x7e, 0x30, 0x08, 0x2f, 0x55, 0xe6, 0x81, 0x86, - 0xdc, 0xef, 0x16, 0xba, 0xdd, 0x15, 0xec, 0x45, 0xea, 0xc7, 0x92, 0xc2, 0xa7, 0x0c, 0x84, 0xc4, - 0x75, 0x74, 0x9d, 0xe5, 0x31, 0xa4, 0x75, 0xab, 0x69, 0xb5, 0xb6, 0xe9, 0x22, 0xbc, 0xaa, 0x40, - 0x7d, 0xab, 0x58, 0x01, 0xdc, 0x45, 0xbb, 0xf9, 0xa8, 0x3c, 0x0d, 0xcf, 0x7c, 0x19, 0xf2, 0xb8, - 0x5e, 0x6e, 0x5a, 0xad, 0x9d, 0x76, 0x8d, 0x68, 0x7d, 0x64, 0xa1, 0x8f, 0x1c, 0xc7, 0x93, 0xce, - 0xde, 0xd7, 0x2f, 0x87, 0xbb, 0xc7, 0x45, 0x9c, 0x2e, 0x9f, 0xc6, 0xcf, 0x10, 0x82, 0x71, 0x12, - 0xa6, 0xba, 0x57, 0x45, 0xf5, 0xb2, 0xff, 0xea, 0xd5, 0x5b, 0x98, 0xd1, 0xb9, 0x31, 0xfd, 0xd1, - 0x28, 0x9d, 0xff, 0x6c, 0x58, 0xb4, 0x70, 0xce, 0x7d, 0xa5, 0x66, 0x7b, 0x3e, 0x86, 0x01, 0x05, - 0x91, 0xf0, 0x58, 0x00, 0x7e, 0x8a, 0xaa, 0x29, 0x88, 0x6c, 0x24, 0xd5, 0x68, 0x3b, 0xed, 0x26, - 0x31, 0x5b, 0xc8, 0x5d, 0x22, 0xca, 0x18, 0xe3, 0x12, 0xa1, 0x8a, 0xa3, 0x86, 0x77, 0x7b, 0xe8, - 0xd6, 0x65, 0xb3, 0x15, 0x9f, 0x60, 0xd9, 0x27, 0xc0, 0x2d, 0x54, 0x89, 0x04, 0x13, 0xf5, 0xad, - 0x66, 0x79, 0x9d, 0x09, 0x54, 0x11, 0x2e, 0x46, 0x77, 0xae, 0xec, 0xd7, 0x1a, 0xdd, 0xa1, 0xca, - 0x51, 0x38, 0xe5, 0x27, 0xf0, 0x3f, 0x3b, 0x69, 0xa2, 0x9b, 0x91, 0x60, 0x7d, 0x39, 0x49, 0xa0, - 0x9f, 0xa5, 0x23, 0xb5, 0x92, 0x6d, 0x8a, 0x22, 0xc1, 0x7a, 0x93, 0x04, 0xde, 0xa4, 0x23, 0xf7, - 0x2e, 0xda, 0x2b, 0xdc, 0xa4, 0xaf, 0x6f, 0x7f, 0xde, 0x42, 0xe5, 0xae, 0x60, 0xf8, 0x2d, 0xba, - 0xa6, 0x74, 0xe1, 0x03, 0xf2, 0xaf, 0xc7, 0x4c, 0x56, 0x9e, 0x8d, 0xfd, 0x70, 0x13, 0x66, 0x56, - 0xf0, 0x1a, 0x55, 0x72, 0x17, 0xf1, 0x83, 0xb5, 0x7c, 0xc1, 0x64, 0xfb, 0x60, 0x03, 0x65, 0x9a, - 0xbe, 0x43, 0x55, 0x3d, 0x06, 0x5e, 0x2f, 0x63, 0xc9, 0x51, 0xfb, 0xd1, 0x46, 0x4e, 0xb7, 0xee, - 0xbc, 0x9c, 0xfe, 0x76, 0x4a, 0xd3, 0x99, 0x63, 0x5d, 0xcc, 0x1c, 0xeb, 0xd7, 0xcc, 0xb1, 0xce, - 0xe7, 0x4e, 0xe9, 0x62, 0xee, 0x94, 0xbe, 0xcd, 0x9d, 0xd2, 0xfb, 0xc7, 0x2c, 0x94, 0xc3, 0x2c, - 0x20, 0x03, 0x1e, 0x99, 0x1f, 0xb4, 0xf9, 0x38, 0x14, 0x1f, 0x4e, 0xbc, 0xb1, 0xf9, 0x7f, 0xc8, - 0x77, 0x20, 0x82, 0xaa, 0x7a, 0x00, 0x4f, 0xfe, 0x04, 0x00, 0x00, 0xff, 0xff, 0x2f, 0xc0, 0x87, - 0xd6, 0x3c, 0x04, 0x00, 0x00, + // 509 bytes of a gzipped FileDescriptorProto + 0x1f, 0x8b, 0x08, 0x00, 0x00, 0x00, 0x00, 0x00, 0x02, 0xff, 0x9c, 0x93, 0x4f, 0x6f, 0xd3, 0x30, + 0x18, 0xc6, 0xe3, 0xb5, 0x74, 0xeb, 0x3b, 0x26, 0x58, 0xe8, 0x21, 0x8b, 0xb4, 0x34, 0x0a, 0x02, + 0x2a, 0xa4, 0x39, 0x5a, 0xb9, 0x70, 0x5d, 0x05, 0x02, 0x09, 0x22, 0x24, 0x6b, 0x5c, 0xb8, 0x54, + 0x49, 0x31, 0x5e, 0xb4, 0x26, 0x8e, 0x62, 0x67, 0x6a, 0xf7, 0x29, 0xf6, 0x61, 0xf8, 0x10, 0x15, + 0xa7, 0x49, 0x5c, 0x38, 0xf1, 0xa7, 0xfd, 0x12, 0x1c, 0x51, 0x1c, 0xa7, 0x74, 0x40, 0x87, 0xb4, + 0x53, 0xf2, 0xfa, 0x79, 0xfc, 0xfa, 0xf1, 0xcf, 0x36, 0xec, 0x8f, 0xb8, 0x48, 0xb8, 0xf0, 0xc3, + 0x42, 0x9e, 0x9c, 0xfb, 0x67, 0x87, 0x11, 0x95, 0xe1, 0xa1, 0x2f, 0x27, 0x38, 0xcb, 0xb9, 0xe4, + 0x66, 0xa7, 0x92, 0xb1, 0x92, 0xb1, 0x96, 0xed, 0xbd, 0x6a, 0x74, 0xa8, 0x3c, 0xbe, 0xb6, 0xa8, + 0xc2, 0xee, 0x30, 0xce, 0x78, 0x35, 0x5e, 0xfe, 0xe9, 0xd1, 0x2e, 0xe3, 0x9c, 0x8d, 0xa9, 0xaf, + 0xaa, 0xa8, 0xf8, 0xe0, 0xcb, 0x38, 0xa1, 0x42, 0x86, 0x49, 0xa6, 0x0d, 0x7b, 0x7f, 0x1a, 0xc2, + 0x74, 0xaa, 0xa5, 0xfb, 0x3a, 0x61, 0x14, 0x0a, 0xea, 0x87, 0xd1, 0x28, 0x5e, 0xa6, 0x2c, 0x8b, + 0xca, 0xe4, 0x7d, 0x46, 0xb0, 0x15, 0x08, 0xf6, 0x22, 0x0f, 0x53, 0x69, 0x5a, 0xb0, 0xc9, 0xca, + 0x1f, 0x9a, 0x5b, 0xc8, 0x45, 0xbd, 0x36, 0xa9, 0xcb, 0xdf, 0x0a, 0xb5, 0x36, 0x56, 0x15, 0x6a, + 0x06, 0xb0, 0x53, 0xee, 0x91, 0xe7, 0xf1, 0x79, 0x28, 0x63, 0x9e, 0x5a, 0x0d, 0x17, 0xf5, 0xb6, + 0xfb, 0x1d, 0x5c, 0x05, 0xc3, 0x75, 0x30, 0x7c, 0x94, 0x4e, 0x07, 0xbb, 0x9f, 0x3e, 0x1e, 0xec, + 0x1c, 0xad, 0xda, 0xc9, 0xd5, 0xd9, 0xe6, 0x33, 0x00, 0x3a, 0xc9, 0xe2, 0xbc, 0xea, 0xd5, 0x54, + 0xbd, 0xec, 0xbf, 0x7a, 0x1d, 0xd7, 0x14, 0x06, 0x5b, 0xb3, 0xaf, 0x5d, 0xe3, 0xe2, 0x5b, 0x17, + 0x91, 0x95, 0x79, 0xde, 0x2b, 0xb8, 0x13, 0x08, 0xf6, 0x7c, 0x42, 0x47, 0x84, 0x8a, 0x8c, 0xa7, + 0x82, 0x9a, 0x4f, 0xa1, 0x95, 0x53, 0x51, 0x8c, 0xa5, 0xda, 0xda, 0x76, 0xdf, 0xc5, 0x1a, 0x7f, + 0x89, 0x07, 0x2b, 0x22, 0x1a, 0x0f, 0x26, 0xca, 0x47, 0xb4, 0xdf, 0x0b, 0x60, 0x53, 0x37, 0x5b, + 0xc5, 0x80, 0xae, 0x62, 0xe8, 0x41, 0x33, 0x11, 0x4c, 0x58, 0x1b, 0x6e, 0x63, 0xdd, 0xee, 0x89, + 0x72, 0x78, 0x26, 0xdc, 0xad, 0x81, 0xd7, 0xe1, 0xbc, 0x10, 0xda, 0x81, 0x60, 0x84, 0x9e, 0xf1, + 0x53, 0x7a, 0xa3, 0x53, 0x70, 0xe1, 0x76, 0x22, 0xd8, 0x50, 0x4e, 0x33, 0x3a, 0x2c, 0xf2, 0xb1, + 0x3a, 0x84, 0x36, 0x81, 0x44, 0xb0, 0xe3, 0x69, 0x46, 0xdf, 0xe6, 0x63, 0xef, 0x1e, 0xec, 0x2e, + 0x97, 0xa8, 0xd7, 0xed, 0xff, 0x44, 0xd0, 0x08, 0x04, 0x33, 0xdf, 0xc0, 0xad, 0xea, 0x06, 0x38, + 0xf8, 0x5f, 0xf7, 0x16, 0xd7, 0x81, 0xed, 0x87, 0xd7, 0xeb, 0x4b, 0xda, 0xaf, 0xa1, 0xa9, 0x80, + 0xed, 0xaf, 0xf5, 0x97, 0xb2, 0xfd, 0xe0, 0x5a, 0x79, 0xd9, 0x8d, 0x40, 0x4b, 0xb3, 0xe9, 0xae, + 0x9d, 0x50, 0x19, 0xec, 0x47, 0xff, 0x31, 0xd4, 0x3d, 0x07, 0x2f, 0x67, 0x3f, 0x1c, 0x63, 0x36, + 0x77, 0xd0, 0xe5, 0xdc, 0x41, 0xdf, 0xe7, 0x0e, 0xba, 0x58, 0x38, 0xc6, 0xe5, 0xc2, 0x31, 0xbe, + 0x2c, 0x1c, 0xe3, 0xdd, 0x63, 0x16, 0xcb, 0x93, 0x22, 0xc2, 0x23, 0x9e, 0xe8, 0x67, 0xaa, 0x3f, + 0x07, 0xe2, 0xfd, 0xa9, 0x3f, 0xd1, 0xaf, 0xbe, 0xc4, 0x2d, 0xa2, 0x96, 0x3a, 0xe4, 0x27, 0xbf, + 0x02, 0x00, 0x00, 0xff, 0xff, 0xaf, 0x57, 0x47, 0xcd, 0x12, 0x04, 0x00, 0x00, } // Reference imports to suppress errors if they are not otherwise used. @@ -333,14 +332,14 @@ const _ = grpc.SupportPackageIsVersion4 type MsgClient interface { // Grant grants the provided authorization to the grantee on the granter's // account with the provided expiration time. - Grant(ctx context.Context, in *MsgGrantRequest, opts ...grpc.CallOption) (*MsgGrantResponse, error) + Grant(ctx context.Context, in *MsgGrant, opts ...grpc.CallOption) (*MsgGrantResponse, error) // Exec attempts to execute the provided messages using // authorizations granted to the grantee. Each message should have only // one signer corresponding to the granter of the authorization. - Exec(ctx context.Context, in *MsgExecRequest, opts ...grpc.CallOption) (*MsgExecResponse, error) + Exec(ctx context.Context, in *MsgExec, opts ...grpc.CallOption) (*MsgExecResponse, error) // Revoke revokes any authorization corresponding to the provided method name on the // granter's account that has been granted to the grantee. - Revoke(ctx context.Context, in *MsgRevokeRequest, opts ...grpc.CallOption) (*MsgRevokeResponse, error) + Revoke(ctx context.Context, in *MsgRevoke, opts ...grpc.CallOption) (*MsgRevokeResponse, error) } type msgClient struct { @@ -351,7 +350,7 @@ func NewMsgClient(cc grpc1.ClientConn) MsgClient { return &msgClient{cc} } -func (c *msgClient) Grant(ctx context.Context, in *MsgGrantRequest, opts ...grpc.CallOption) (*MsgGrantResponse, error) { +func (c *msgClient) Grant(ctx context.Context, in *MsgGrant, opts ...grpc.CallOption) (*MsgGrantResponse, error) { out := new(MsgGrantResponse) err := c.cc.Invoke(ctx, "/cosmos.authz.v1beta1.Msg/Grant", in, out, opts...) if err != nil { @@ -360,7 +359,7 @@ func (c *msgClient) Grant(ctx context.Context, in *MsgGrantRequest, opts ...grpc return out, nil } -func (c *msgClient) Exec(ctx context.Context, in *MsgExecRequest, opts ...grpc.CallOption) (*MsgExecResponse, error) { +func (c *msgClient) Exec(ctx context.Context, in *MsgExec, opts ...grpc.CallOption) (*MsgExecResponse, error) { out := new(MsgExecResponse) err := c.cc.Invoke(ctx, "/cosmos.authz.v1beta1.Msg/Exec", in, out, opts...) if err != nil { @@ -369,7 +368,7 @@ func (c *msgClient) Exec(ctx context.Context, in *MsgExecRequest, opts ...grpc.C return out, nil } -func (c *msgClient) Revoke(ctx context.Context, in *MsgRevokeRequest, opts ...grpc.CallOption) (*MsgRevokeResponse, error) { +func (c *msgClient) Revoke(ctx context.Context, in *MsgRevoke, opts ...grpc.CallOption) (*MsgRevokeResponse, error) { out := new(MsgRevokeResponse) err := c.cc.Invoke(ctx, "/cosmos.authz.v1beta1.Msg/Revoke", in, out, opts...) if err != nil { @@ -382,27 +381,27 @@ func (c *msgClient) Revoke(ctx context.Context, in *MsgRevokeRequest, opts ...gr type MsgServer interface { // Grant grants the provided authorization to the grantee on the granter's // account with the provided expiration time. - Grant(context.Context, *MsgGrantRequest) (*MsgGrantResponse, error) + Grant(context.Context, *MsgGrant) (*MsgGrantResponse, error) // Exec attempts to execute the provided messages using // authorizations granted to the grantee. Each message should have only // one signer corresponding to the granter of the authorization. - Exec(context.Context, *MsgExecRequest) (*MsgExecResponse, error) + Exec(context.Context, *MsgExec) (*MsgExecResponse, error) // Revoke revokes any authorization corresponding to the provided method name on the // granter's account that has been granted to the grantee. - Revoke(context.Context, *MsgRevokeRequest) (*MsgRevokeResponse, error) + Revoke(context.Context, *MsgRevoke) (*MsgRevokeResponse, error) } // UnimplementedMsgServer can be embedded to have forward compatible implementations. type UnimplementedMsgServer struct { } -func (*UnimplementedMsgServer) Grant(ctx context.Context, req *MsgGrantRequest) (*MsgGrantResponse, error) { +func (*UnimplementedMsgServer) Grant(ctx context.Context, req *MsgGrant) (*MsgGrantResponse, error) { return nil, status.Errorf(codes.Unimplemented, "method Grant not implemented") } -func (*UnimplementedMsgServer) Exec(ctx context.Context, req *MsgExecRequest) (*MsgExecResponse, error) { +func (*UnimplementedMsgServer) Exec(ctx context.Context, req *MsgExec) (*MsgExecResponse, error) { return nil, status.Errorf(codes.Unimplemented, "method Exec not implemented") } -func (*UnimplementedMsgServer) Revoke(ctx context.Context, req *MsgRevokeRequest) (*MsgRevokeResponse, error) { +func (*UnimplementedMsgServer) Revoke(ctx context.Context, req *MsgRevoke) (*MsgRevokeResponse, error) { return nil, status.Errorf(codes.Unimplemented, "method Revoke not implemented") } @@ -411,7 +410,7 @@ func RegisterMsgServer(s grpc1.Server, srv MsgServer) { } func _Msg_Grant_Handler(srv interface{}, ctx context.Context, dec func(interface{}) error, interceptor grpc.UnaryServerInterceptor) (interface{}, error) { - in := new(MsgGrantRequest) + in := new(MsgGrant) if err := dec(in); err != nil { return nil, err } @@ -423,13 +422,13 @@ func _Msg_Grant_Handler(srv interface{}, ctx context.Context, dec func(interface FullMethod: "/cosmos.authz.v1beta1.Msg/Grant", } handler := func(ctx context.Context, req interface{}) (interface{}, error) { - return srv.(MsgServer).Grant(ctx, req.(*MsgGrantRequest)) + return srv.(MsgServer).Grant(ctx, req.(*MsgGrant)) } return interceptor(ctx, in, info, handler) } func _Msg_Exec_Handler(srv interface{}, ctx context.Context, dec func(interface{}) error, interceptor grpc.UnaryServerInterceptor) (interface{}, error) { - in := new(MsgExecRequest) + in := new(MsgExec) if err := dec(in); err != nil { return nil, err } @@ -441,13 +440,13 @@ func _Msg_Exec_Handler(srv interface{}, ctx context.Context, dec func(interface{ FullMethod: "/cosmos.authz.v1beta1.Msg/Exec", } handler := func(ctx context.Context, req interface{}) (interface{}, error) { - return srv.(MsgServer).Exec(ctx, req.(*MsgExecRequest)) + return srv.(MsgServer).Exec(ctx, req.(*MsgExec)) } return interceptor(ctx, in, info, handler) } func _Msg_Revoke_Handler(srv interface{}, ctx context.Context, dec func(interface{}) error, interceptor grpc.UnaryServerInterceptor) (interface{}, error) { - in := new(MsgRevokeRequest) + in := new(MsgRevoke) if err := dec(in); err != nil { return nil, err } @@ -459,7 +458,7 @@ func _Msg_Revoke_Handler(srv interface{}, ctx context.Context, dec func(interfac FullMethod: "/cosmos.authz.v1beta1.Msg/Revoke", } handler := func(ctx context.Context, req interface{}) (interface{}, error) { - return srv.(MsgServer).Revoke(ctx, req.(*MsgRevokeRequest)) + return srv.(MsgServer).Revoke(ctx, req.(*MsgRevoke)) } return interceptor(ctx, in, info, handler) } @@ -485,7 +484,7 @@ var _Msg_serviceDesc = grpc.ServiceDesc{ Metadata: "cosmos/authz/v1beta1/tx.proto", } -func (m *MsgGrantRequest) Marshal() (dAtA []byte, err error) { +func (m *MsgGrant) Marshal() (dAtA []byte, err error) { size := m.Size() dAtA = make([]byte, size) n, err := m.MarshalToSizedBuffer(dAtA[:size]) @@ -495,12 +494,12 @@ func (m *MsgGrantRequest) Marshal() (dAtA []byte, err error) { return dAtA[:n], nil } -func (m *MsgGrantRequest) MarshalTo(dAtA []byte) (int, error) { +func (m *MsgGrant) MarshalTo(dAtA []byte) (int, error) { size := m.Size() return m.MarshalToSizedBuffer(dAtA[:size]) } -func (m *MsgGrantRequest) MarshalToSizedBuffer(dAtA []byte) (int, error) { +func (m *MsgGrant) MarshalToSizedBuffer(dAtA []byte) (int, error) { i := len(dAtA) _ = i var l int @@ -577,7 +576,7 @@ func (m *MsgExecResponse) MarshalToSizedBuffer(dAtA []byte) (int, error) { return len(dAtA) - i, nil } -func (m *MsgExecRequest) Marshal() (dAtA []byte, err error) { +func (m *MsgExec) Marshal() (dAtA []byte, err error) { size := m.Size() dAtA = make([]byte, size) n, err := m.MarshalToSizedBuffer(dAtA[:size]) @@ -587,12 +586,12 @@ func (m *MsgExecRequest) Marshal() (dAtA []byte, err error) { return dAtA[:n], nil } -func (m *MsgExecRequest) MarshalTo(dAtA []byte) (int, error) { +func (m *MsgExec) MarshalTo(dAtA []byte) (int, error) { size := m.Size() return m.MarshalToSizedBuffer(dAtA[:size]) } -func (m *MsgExecRequest) MarshalToSizedBuffer(dAtA []byte) (int, error) { +func (m *MsgExec) MarshalToSizedBuffer(dAtA []byte) (int, error) { i := len(dAtA) _ = i var l int @@ -644,7 +643,7 @@ func (m *MsgGrantResponse) MarshalToSizedBuffer(dAtA []byte) (int, error) { return len(dAtA) - i, nil } -func (m *MsgRevokeRequest) Marshal() (dAtA []byte, err error) { +func (m *MsgRevoke) Marshal() (dAtA []byte, err error) { size := m.Size() dAtA = make([]byte, size) n, err := m.MarshalToSizedBuffer(dAtA[:size]) @@ -654,12 +653,12 @@ func (m *MsgRevokeRequest) Marshal() (dAtA []byte, err error) { return dAtA[:n], nil } -func (m *MsgRevokeRequest) MarshalTo(dAtA []byte) (int, error) { +func (m *MsgRevoke) MarshalTo(dAtA []byte) (int, error) { size := m.Size() return m.MarshalToSizedBuffer(dAtA[:size]) } -func (m *MsgRevokeRequest) MarshalToSizedBuffer(dAtA []byte) (int, error) { +func (m *MsgRevoke) MarshalToSizedBuffer(dAtA []byte) (int, error) { i := len(dAtA) _ = i var l int @@ -722,7 +721,7 @@ func encodeVarintTx(dAtA []byte, offset int, v uint64) int { dAtA[offset] = uint8(v) return base } -func (m *MsgGrantRequest) Size() (n int) { +func (m *MsgGrant) Size() (n int) { if m == nil { return 0 } @@ -758,7 +757,7 @@ func (m *MsgExecResponse) Size() (n int) { return n } -func (m *MsgExecRequest) Size() (n int) { +func (m *MsgExec) Size() (n int) { if m == nil { return 0 } @@ -786,7 +785,7 @@ func (m *MsgGrantResponse) Size() (n int) { return n } -func (m *MsgRevokeRequest) Size() (n int) { +func (m *MsgRevoke) Size() (n int) { if m == nil { return 0 } @@ -822,7 +821,7 @@ func sovTx(x uint64) (n int) { func sozTx(x uint64) (n int) { return sovTx(uint64((x << 1) ^ uint64((int64(x) >> 63)))) } -func (m *MsgGrantRequest) Unmarshal(dAtA []byte) error { +func (m *MsgGrant) Unmarshal(dAtA []byte) error { l := len(dAtA) iNdEx := 0 for iNdEx < l { @@ -845,10 +844,10 @@ func (m *MsgGrantRequest) Unmarshal(dAtA []byte) error { fieldNum := int32(wire >> 3) wireType := int(wire & 0x7) if wireType == 4 { - return fmt.Errorf("proto: MsgGrantRequest: wiretype end group for non-group") + return fmt.Errorf("proto: MsgGrant: wiretype end group for non-group") } if fieldNum <= 0 { - return fmt.Errorf("proto: MsgGrantRequest: illegal tag %d (wire type %d)", fieldNum, wire) + return fmt.Errorf("proto: MsgGrant: illegal tag %d (wire type %d)", fieldNum, wire) } switch fieldNum { case 1: @@ -1091,7 +1090,7 @@ func (m *MsgExecResponse) Unmarshal(dAtA []byte) error { } return nil } -func (m *MsgExecRequest) Unmarshal(dAtA []byte) error { +func (m *MsgExec) Unmarshal(dAtA []byte) error { l := len(dAtA) iNdEx := 0 for iNdEx < l { @@ -1114,10 +1113,10 @@ func (m *MsgExecRequest) Unmarshal(dAtA []byte) error { fieldNum := int32(wire >> 3) wireType := int(wire & 0x7) if wireType == 4 { - return fmt.Errorf("proto: MsgExecRequest: wiretype end group for non-group") + return fmt.Errorf("proto: MsgExec: wiretype end group for non-group") } if fieldNum <= 0 { - return fmt.Errorf("proto: MsgExecRequest: illegal tag %d (wire type %d)", fieldNum, wire) + return fmt.Errorf("proto: MsgExec: illegal tag %d (wire type %d)", fieldNum, wire) } switch fieldNum { case 1: @@ -1257,7 +1256,7 @@ func (m *MsgGrantResponse) Unmarshal(dAtA []byte) error { } return nil } -func (m *MsgRevokeRequest) Unmarshal(dAtA []byte) error { +func (m *MsgRevoke) Unmarshal(dAtA []byte) error { l := len(dAtA) iNdEx := 0 for iNdEx < l { @@ -1280,10 +1279,10 @@ func (m *MsgRevokeRequest) Unmarshal(dAtA []byte) error { fieldNum := int32(wire >> 3) wireType := int(wire & 0x7) if wireType == 4 { - return fmt.Errorf("proto: MsgRevokeRequest: wiretype end group for non-group") + return fmt.Errorf("proto: MsgRevoke: wiretype end group for non-group") } if fieldNum <= 0 { - return fmt.Errorf("proto: MsgRevokeRequest: illegal tag %d (wire type %d)", fieldNum, wire) + return fmt.Errorf("proto: MsgRevoke: illegal tag %d (wire type %d)", fieldNum, wire) } switch fieldNum { case 1: From f73ab9e431c459bffa6c207466494330756b437b Mon Sep 17 00:00:00 2001 From: Robert Zaremba Date: Tue, 27 Apr 2021 15:50:22 +0200 Subject: [PATCH 27/44] refactore authz/exported --- docs/core/proto-docs.md | 2 +- proto/cosmos/authz/v1beta1/tx.proto | 4 +- simapp/app.go | 8 +-- x/authz/{exported => }/authorizations.go | 8 ++- x/authz/client/cli/tx.go | 4 +- x/authz/genesis.go | 31 ---------- x/authz/{ => keeper}/genesis_test.go | 5 +- x/authz/keeper/grpc_query_test.go | 10 ++-- x/authz/keeper/keeper.go | 33 +++++++++-- x/authz/{ => module}/module.go | 2 +- x/authz/types/authorization_grant.go | 10 ++-- x/authz/types/codec.go | 4 +- x/authz/types/generic_authorization.go | 2 +- x/authz/types/genesis.go | 10 ++-- x/authz/types/msgs.go | 27 ++++----- x/authz/types/msgs_test.go | 7 +-- x/authz/types/tx.pb.go | 73 ++++++++++++------------ x/bank/types/send_authorization.go | 2 +- x/staking/types/authz.go | 14 ++--- 19 files changed, 127 insertions(+), 129 deletions(-) rename x/authz/{exported => }/authorizations.go (85%) delete mode 100644 x/authz/genesis.go rename x/authz/{ => keeper}/genesis_test.go (92%) rename x/authz/{ => module}/module.go (99%) diff --git a/docs/core/proto-docs.md b/docs/core/proto-docs.md index 95a10fa5debd..9827fb50c43a 100644 --- a/docs/core/proto-docs.md +++ b/docs/core/proto-docs.md @@ -1293,7 +1293,7 @@ one signer corresponding to the granter of the authorization. | Field | Type | Label | Description | | ----- | ---- | ----- | ----------- | | `grantee` | [string](#string) | | | -| `msgs` | [google.protobuf.Any](#google.protobuf.Any) | repeated | | +| `msgs` | [google.protobuf.Any](#google.protobuf.Any) | repeated | MsgService requests to execute. The x/authz will try to find a grant matching (msg.signers[0], grantee, MsgTypeURL(msg)) triple and validate it. | diff --git a/proto/cosmos/authz/v1beta1/tx.proto b/proto/cosmos/authz/v1beta1/tx.proto index 58757be3b048..5842daf45388 100644 --- a/proto/cosmos/authz/v1beta1/tx.proto +++ b/proto/cosmos/authz/v1beta1/tx.proto @@ -46,7 +46,9 @@ message MsgExecResponse { // one signer corresponding to the granter of the authorization. message MsgExec { string grantee = 1; - repeated google.protobuf.Any msgs = 2; + // MsgService requests to execute. The x/authz will try to find a grant matching + // (msg.signers[0], grantee, MsgTypeURL(msg)) triple and validate it. + repeated google.protobuf.Any msgs = 2 [(cosmos_proto.accepts_interface) = "sdk.Msg"];; } // MsgGrantResponse defines the Msg/MsgGrant response type. diff --git a/simapp/app.go b/simapp/app.go index 0e5281a2f6d8..da28a9f66e0b 100644 --- a/simapp/app.go +++ b/simapp/app.go @@ -82,8 +82,8 @@ import ( upgradekeeper "github.com/cosmos/cosmos-sdk/x/upgrade/keeper" upgradetypes "github.com/cosmos/cosmos-sdk/x/upgrade/types" - authz "github.com/cosmos/cosmos-sdk/x/authz" authzkeeper "github.com/cosmos/cosmos-sdk/x/authz/keeper" + authz_m "github.com/cosmos/cosmos-sdk/x/authz/module" authztypes "github.com/cosmos/cosmos-sdk/x/authz/types" // unnamed import of statik for swagger UI support @@ -116,7 +116,7 @@ var ( feegrant.AppModuleBasic{}, upgrade.AppModuleBasic{}, evidence.AppModuleBasic{}, - authz.AppModuleBasic{}, + authz_m.AppModuleBasic{}, vesting.AppModuleBasic{}, ) @@ -318,7 +318,7 @@ func NewSimApp( upgrade.NewAppModule(app.UpgradeKeeper), evidence.NewAppModule(app.EvidenceKeeper), params.NewAppModule(app.ParamsKeeper), - authz.NewAppModule(appCodec, app.AuthzKeeper, app.AccountKeeper, app.BankKeeper, app.interfaceRegistry), + authz_m.NewAppModule(appCodec, app.AuthzKeeper, app.AccountKeeper, app.BankKeeper, app.interfaceRegistry), ) // During begin block slashing happens after distr.BeginBlocker so that @@ -367,7 +367,7 @@ func NewSimApp( slashing.NewAppModule(appCodec, app.SlashingKeeper, app.AccountKeeper, app.BankKeeper, app.StakingKeeper), params.NewAppModule(app.ParamsKeeper), evidence.NewAppModule(app.EvidenceKeeper), - authz.NewAppModule(appCodec, app.AuthzKeeper, app.AccountKeeper, app.BankKeeper, app.interfaceRegistry), + authz_m.NewAppModule(appCodec, app.AuthzKeeper, app.AccountKeeper, app.BankKeeper, app.interfaceRegistry), ) app.sm.RegisterStoreDecoders() diff --git a/x/authz/exported/authorizations.go b/x/authz/authorizations.go similarity index 85% rename from x/authz/exported/authorizations.go rename to x/authz/authorizations.go index 76497a862b4a..d88376d5e64f 100644 --- a/x/authz/exported/authorizations.go +++ b/x/authz/authorizations.go @@ -1,4 +1,4 @@ -package exported +package authz import ( "github.com/gogo/protobuf/proto" @@ -6,11 +6,13 @@ import ( sdk "github.com/cosmos/cosmos-sdk/types" ) -// Authorization represents the interface of various Authorization types. +// Authorization represents the interface of various Authorization types implemented +// by other modules. type Authorization interface { proto.Message - // MsgTypeURL returns the fully-qualified Msg service method name as described in ADR 031. + // MsgTypeURL returns the fully-qualified Msg service method URL (as described in ADR 031), + // which will process and accept or reject a request. MsgTypeURL() string // Accept determines whether this grant permits the provided sdk.ServiceMsg to be performed, and if diff --git a/x/authz/client/cli/tx.go b/x/authz/client/cli/tx.go index 63dccf5d3053..ecb80b54aef0 100644 --- a/x/authz/client/cli/tx.go +++ b/x/authz/client/cli/tx.go @@ -15,7 +15,7 @@ import ( "github.com/cosmos/cosmos-sdk/types/msgservice" "github.com/cosmos/cosmos-sdk/version" authclient "github.com/cosmos/cosmos-sdk/x/auth/client" - "github.com/cosmos/cosmos-sdk/x/authz/exported" + "github.com/cosmos/cosmos-sdk/x/authz" "github.com/cosmos/cosmos-sdk/x/authz/types" bank "github.com/cosmos/cosmos-sdk/x/bank/types" staking "github.com/cosmos/cosmos-sdk/x/staking/types" @@ -79,7 +79,7 @@ Examples: return err } - var authorization exported.Authorization + var authorization authz.Authorization switch args[1] { case "send": limit, err := cmd.Flags().GetString(FlagSpendLimit) diff --git a/x/authz/genesis.go b/x/authz/genesis.go deleted file mode 100644 index 0f9081fafad1..000000000000 --- a/x/authz/genesis.go +++ /dev/null @@ -1,31 +0,0 @@ -package authz - -import ( - sdk "github.com/cosmos/cosmos-sdk/types" - "github.com/cosmos/cosmos-sdk/x/authz/exported" - "github.com/cosmos/cosmos-sdk/x/authz/keeper" - "github.com/cosmos/cosmos-sdk/x/authz/types" -) - -// InitGenesis new authz genesis -func InitGenesis(ctx sdk.Context, keeper keeper.Keeper, data *types.GenesisState) { - for _, entry := range data.Authorization { - grantee, err := sdk.AccAddressFromBech32(entry.Grantee) - if err != nil { - panic(err) - } - granter, err := sdk.AccAddressFromBech32(entry.Granter) - if err != nil { - panic(err) - } - authorization, ok := entry.Authorization.GetCachedValue().(exported.Authorization) - if !ok { - panic("expected authorization") - } - - err = keeper.SaveGrant(ctx, grantee, granter, authorization, entry.Expiration) - if err != nil { - panic(err) - } - } -} diff --git a/x/authz/genesis_test.go b/x/authz/keeper/genesis_test.go similarity index 92% rename from x/authz/genesis_test.go rename to x/authz/keeper/genesis_test.go index d5992a350a5c..0af0c842d457 100644 --- a/x/authz/genesis_test.go +++ b/x/authz/keeper/genesis_test.go @@ -1,4 +1,4 @@ -package authz_test +package keeper_test import ( "testing" @@ -10,7 +10,6 @@ import ( "github.com/cosmos/cosmos-sdk/crypto/keys/secp256k1" "github.com/cosmos/cosmos-sdk/simapp" sdk "github.com/cosmos/cosmos-sdk/types" - authz "github.com/cosmos/cosmos-sdk/x/authz" "github.com/cosmos/cosmos-sdk/x/authz/keeper" bank "github.com/cosmos/cosmos-sdk/x/bank/types" ) @@ -49,7 +48,7 @@ func (suite *GenesisTestSuite) TestImportExportGenesis() { // Clear keeper suite.keeper.DeleteGrant(suite.ctx, granteeAddr, granterAddr, grant.MsgTypeURL()) - authz.InitGenesis(suite.ctx, suite.keeper, genesis) + suite.keeper.InitGenesis(suite.ctx, genesis) newGenesis := suite.keeper.ExportGenesis(suite.ctx) suite.Require().Equal(genesis, newGenesis) } diff --git a/x/authz/keeper/grpc_query_test.go b/x/authz/keeper/grpc_query_test.go index 16708ff5a112..cdd2ba68fe10 100644 --- a/x/authz/keeper/grpc_query_test.go +++ b/x/authz/keeper/grpc_query_test.go @@ -6,7 +6,7 @@ import ( "time" sdk "github.com/cosmos/cosmos-sdk/types" - "github.com/cosmos/cosmos-sdk/x/authz/exported" + "github.com/cosmos/cosmos-sdk/x/authz" "github.com/cosmos/cosmos-sdk/x/authz/types" banktypes "github.com/cosmos/cosmos-sdk/x/bank/types" "github.com/stretchr/testify/require" @@ -16,7 +16,7 @@ func (suite *TestSuite) TestGRPCQueryAuthorization() { app, ctx, queryClient, addrs := suite.app, suite.ctx, suite.queryClient, suite.addrs var ( req *types.QueryGrantsRequest - expAuthorization exported.Authorization + expAuthorization authz.Authorization ) testCases := []struct { msg string @@ -70,7 +70,7 @@ func (suite *TestSuite) TestGRPCQueryAuthorization() { }, "", func(require *require.Assertions, res *types.QueryGrantsResponse) { - var auth exported.Authorization + var auth authz.Authorization require.Equal(1, len(res.Grants)) err := suite.app.InterfaceRegistry().UnpackAny(res.Grants[0].Authorization, &auth) require.NoError(err) @@ -99,7 +99,7 @@ func (suite *TestSuite) TestGRPCQueryAuthorizations() { app, ctx, queryClient, addrs := suite.app, suite.ctx, suite.queryClient, suite.addrs var ( req *types.QueryGrantsRequest - expAuthorization exported.Authorization + expAuthorization authz.Authorization ) testCases := []struct { msg string @@ -140,7 +140,7 @@ func (suite *TestSuite) TestGRPCQueryAuthorizations() { }, true, func(res *types.QueryGrantsResponse) { - var auth exported.Authorization + var auth authz.Authorization suite.Require().Equal(1, len(res.Grants)) err := suite.app.InterfaceRegistry().UnpackAny(res.Grants[0].Authorization, &auth) suite.Require().NoError(err) diff --git a/x/authz/keeper/keeper.go b/x/authz/keeper/keeper.go index 700c8d4ad650..97dea9162d4b 100644 --- a/x/authz/keeper/keeper.go +++ b/x/authz/keeper/keeper.go @@ -13,7 +13,7 @@ import ( codectypes "github.com/cosmos/cosmos-sdk/codec/types" sdk "github.com/cosmos/cosmos-sdk/types" sdkerrors "github.com/cosmos/cosmos-sdk/types/errors" - "github.com/cosmos/cosmos-sdk/x/authz/exported" + "github.com/cosmos/cosmos-sdk/x/authz" "github.com/cosmos/cosmos-sdk/x/authz/types" ) @@ -48,7 +48,7 @@ func (k Keeper) getGrant(ctx sdk.Context, skey []byte) (grant types.Grant, found return grant, true } -func (k Keeper) update(ctx sdk.Context, grantee sdk.AccAddress, granter sdk.AccAddress, updated exported.Authorization) error { +func (k Keeper) update(ctx sdk.Context, grantee sdk.AccAddress, granter sdk.AccAddress, updated authz.Authorization) error { skey := grantStoreKey(grantee, granter, updated.MsgTypeURL()) grant, found := k.getGrant(ctx, skey) if !found { @@ -122,7 +122,7 @@ func (k Keeper) DispatchActions(ctx sdk.Context, grantee sdk.AccAddress, service // SaveGrant method grants the provided authorization to the grantee on the granter's account // with the provided expiration time. If there is an existing authorization grant for the // same `sdk.Msg` type, this grant overwrites that. -func (k Keeper) SaveGrant(ctx sdk.Context, grantee, granter sdk.AccAddress, authorization exported.Authorization, expiration time.Time) error { +func (k Keeper) SaveGrant(ctx sdk.Context, grantee, granter sdk.AccAddress, authorization authz.Authorization, expiration time.Time) error { store := ctx.KVStore(k.storeKey) grant, err := types.NewGrant(authorization, expiration) @@ -159,7 +159,7 @@ func (k Keeper) DeleteGrant(ctx sdk.Context, grantee sdk.AccAddress, granter sdk } // GetAuthorizations Returns list of `Authorizations` granted to the grantee by the granter. -func (k Keeper) GetAuthorizations(ctx sdk.Context, grantee sdk.AccAddress, granter sdk.AccAddress) (authorizations []exported.Authorization) { +func (k Keeper) GetAuthorizations(ctx sdk.Context, grantee sdk.AccAddress, granter sdk.AccAddress) (authorizations []authz.Authorization) { store := ctx.KVStore(k.storeKey) key := grantStoreKey(grantee, granter, "") iter := sdk.KVStorePrefixIterator(store, key) @@ -175,7 +175,7 @@ func (k Keeper) GetAuthorizations(ctx sdk.Context, grantee sdk.AccAddress, grant // GetCleanAuthorization returns an `Authorization` and it's expiration time for // (grantee, granter, message name) grant. If there is no grant `nil` is returned. // If the grant is expired, the grant is revoked, removed from the storage, and `nil` is returned. -func (k Keeper) GetCleanAuthorization(ctx sdk.Context, grantee sdk.AccAddress, granter sdk.AccAddress, msgType string) (cap exported.Authorization, expiration time.Time) { +func (k Keeper) GetCleanAuthorization(ctx sdk.Context, grantee sdk.AccAddress, granter sdk.AccAddress, msgType string) (cap authz.Authorization, expiration time.Time) { grant, found := k.getGrant(ctx, grantStoreKey(grantee, granter, msgType)) if !found { return nil, time.Time{} @@ -222,3 +222,26 @@ func (k Keeper) ExportGenesis(ctx sdk.Context) *types.GenesisState { return types.NewGenesisState(entries) } + +// InitGenesis new authz genesis +func (k Keeper) InitGenesis(ctx sdk.Context, data *types.GenesisState) { + for _, entry := range data.Authorization { + grantee, err := sdk.AccAddressFromBech32(entry.Grantee) + if err != nil { + panic(err) + } + granter, err := sdk.AccAddressFromBech32(entry.Granter) + if err != nil { + panic(err) + } + a, ok := entry.Authorization.GetCachedValue().(authz.Authorization) + if !ok { + panic("expected authorization") + } + + err = k.SaveGrant(ctx, grantee, granter, a, entry.Expiration) + if err != nil { + panic(err) + } + } +} diff --git a/x/authz/module.go b/x/authz/module/module.go similarity index 99% rename from x/authz/module.go rename to x/authz/module/module.go index 7eea3f56a1b2..479109bd8796 100644 --- a/x/authz/module.go +++ b/x/authz/module/module.go @@ -141,7 +141,7 @@ func (am AppModule) LegacyQuerierHandler(legacyQuerierCdc *codec.LegacyAmino) sd func (am AppModule) InitGenesis(ctx sdk.Context, cdc codec.JSONMarshaler, data json.RawMessage) []abci.ValidatorUpdate { var genesisState types.GenesisState cdc.MustUnmarshalJSON(data, &genesisState) - InitGenesis(ctx, am.keeper, &genesisState) + am.keeper.InitGenesis(ctx, &genesisState) return []abci.ValidatorUpdate{} } diff --git a/x/authz/types/authorization_grant.go b/x/authz/types/authorization_grant.go index 77d0c2a74838..6ab727fc2372 100644 --- a/x/authz/types/authorization_grant.go +++ b/x/authz/types/authorization_grant.go @@ -7,11 +7,11 @@ import ( "github.com/cosmos/cosmos-sdk/codec/types" sdkerrors "github.com/cosmos/cosmos-sdk/types/errors" - "github.com/cosmos/cosmos-sdk/x/authz/exported" + "github.com/cosmos/cosmos-sdk/x/authz" ) // NewGrant returns new AuthrizationGrant -func NewGrant(authorization exported.Authorization, expiration time.Time) (Grant, error) { +func NewGrant(authorization authz.Authorization, expiration time.Time) (Grant, error) { auth := Grant{ Expiration: expiration, } @@ -36,13 +36,13 @@ var ( // UnpackInterfaces implements UnpackInterfacesMessage.UnpackInterfaces func (auth Grant) UnpackInterfaces(unpacker types.AnyUnpacker) error { - var authorization exported.Authorization + var authorization authz.Authorization return unpacker.UnpackAny(auth.Authorization, &authorization) } // GetAuthorization returns the cached value from the Grant.Authorization if present. -func (auth Grant) GetAuthorization() exported.Authorization { - authorization, ok := auth.Authorization.GetCachedValue().(exported.Authorization) +func (auth Grant) GetAuthorization() authz.Authorization { + authorization, ok := auth.Authorization.GetCachedValue().(authz.Authorization) if !ok { return nil } diff --git a/x/authz/types/codec.go b/x/authz/types/codec.go index 9bc92a7a670e..af42b67c230d 100644 --- a/x/authz/types/codec.go +++ b/x/authz/types/codec.go @@ -4,7 +4,7 @@ import ( types "github.com/cosmos/cosmos-sdk/codec/types" sdk "github.com/cosmos/cosmos-sdk/types" "github.com/cosmos/cosmos-sdk/types/msgservice" - "github.com/cosmos/cosmos-sdk/x/authz/exported" + "github.com/cosmos/cosmos-sdk/x/authz" bank "github.com/cosmos/cosmos-sdk/x/bank/types" staking "github.com/cosmos/cosmos-sdk/x/staking/types" ) @@ -19,7 +19,7 @@ func RegisterInterfaces(registry types.InterfaceRegistry) { registry.RegisterInterface( "cosmos.authz.v1beta1.Authorization", - (*exported.Authorization)(nil), + (*authz.Authorization)(nil), &bank.SendAuthorization{}, &GenericAuthorization{}, &staking.StakeAuthorization{}, diff --git a/x/authz/types/generic_authorization.go b/x/authz/types/generic_authorization.go index 769a353de800..df7991d2b395 100644 --- a/x/authz/types/generic_authorization.go +++ b/x/authz/types/generic_authorization.go @@ -4,7 +4,7 @@ import ( sdk "github.com/cosmos/cosmos-sdk/types" sdkerrors "github.com/cosmos/cosmos-sdk/types/errors" "github.com/cosmos/cosmos-sdk/types/msgservice" - authz "github.com/cosmos/cosmos-sdk/x/authz/exported" + "github.com/cosmos/cosmos-sdk/x/authz" ) var ( diff --git a/x/authz/types/genesis.go b/x/authz/types/genesis.go index 8d2a356f5e75..79a68248c73f 100644 --- a/x/authz/types/genesis.go +++ b/x/authz/types/genesis.go @@ -2,7 +2,7 @@ package types import ( "github.com/cosmos/cosmos-sdk/codec/types" - "github.com/cosmos/cosmos-sdk/x/authz/exported" + "github.com/cosmos/cosmos-sdk/x/authz" ) // NewGenesisState creates new GenesisState object @@ -26,8 +26,8 @@ var _ types.UnpackInterfacesMessage = GenesisState{} // UnpackInterfaces implements UnpackInterfacesMessage.UnpackInterfaces func (data GenesisState) UnpackInterfaces(unpacker types.AnyUnpacker) error { - for _, authorization := range data.Authorization { - err := authorization.UnpackInterfaces(unpacker) + for _, a := range data.Authorization { + err := a.UnpackInterfaces(unpacker) if err != nil { return err } @@ -37,6 +37,6 @@ func (data GenesisState) UnpackInterfaces(unpacker types.AnyUnpacker) error { // UnpackInterfaces implements UnpackInterfacesMessage.UnpackInterfaces func (msg GrantAuthorization) UnpackInterfaces(unpacker types.AnyUnpacker) error { - var authorization exported.Authorization - return unpacker.UnpackAny(msg.Authorization, &authorization) + var a authz.Authorization + return unpacker.UnpackAny(msg.Authorization, &a) } diff --git a/x/authz/types/msgs.go b/x/authz/types/msgs.go index a2cba5166db3..664579a95f49 100644 --- a/x/authz/types/msgs.go +++ b/x/authz/types/msgs.go @@ -8,7 +8,7 @@ import ( "github.com/cosmos/cosmos-sdk/codec/types" sdk "github.com/cosmos/cosmos-sdk/types" sdkerrors "github.com/cosmos/cosmos-sdk/types/errors" - "github.com/cosmos/cosmos-sdk/x/authz/exported" + "github.com/cosmos/cosmos-sdk/x/authz" ) var ( @@ -22,13 +22,13 @@ var ( // NewMsgGrant creates a new MsgGrant //nolint:interfacer -func NewMsgGrant(granter sdk.AccAddress, grantee sdk.AccAddress, authorization exported.Authorization, expiration time.Time) (*MsgGrant, error) { +func NewMsgGrant(granter sdk.AccAddress, grantee sdk.AccAddress, a authz.Authorization, expiration time.Time) (*MsgGrant, error) { m := &MsgGrant{ Granter: granter.String(), Grantee: grantee.String(), Expiration: expiration, } - err := m.SetAuthorization(authorization) + err := m.SetAuthorization(a) if err != nil { return nil, err } @@ -63,25 +63,26 @@ func (msg MsgGrant) ValidateBasic() error { return sdkerrors.Wrap(ErrInvalidExpirationTime, "Time can't be in the past") } - authorization, ok := msg.Authorization.GetCachedValue().(exported.Authorization) + av := msg.Authorization.GetCachedValue() + a, ok := av.(authz.Authorization) if !ok { - return sdkerrors.Wrapf(sdkerrors.ErrInvalidType, "expected %T, got %T", (exported.Authorization)(nil), msg.Authorization.GetCachedValue()) + return sdkerrors.Wrapf(sdkerrors.ErrInvalidType, "expected %T, got %T", (authz.Authorization)(nil), av) } - return authorization.ValidateBasic() + return a.ValidateBasic() } // GetAuthorization returns the cache value from the MsgGrant.Authorization if present. -func (msg *MsgGrant) GetAuthorization() exported.Authorization { - authorization, ok := msg.Authorization.GetCachedValue().(exported.Authorization) +func (msg *MsgGrant) GetAuthorization() authz.Authorization { + a, ok := msg.Authorization.GetCachedValue().(authz.Authorization) if !ok { return nil } - return authorization + return a } // SetAuthorization converts Authorization to any and adds it to MsgGrant.Authorization. -func (msg *MsgGrant) SetAuthorization(authorization exported.Authorization) error { - m, ok := authorization.(proto.Message) +func (msg *MsgGrant) SetAuthorization(a authz.Authorization) error { + m, ok := a.(proto.Message) if !ok { return sdkerrors.Wrapf(sdkerrors.ErrPackAny, "can't proto marshal %T", m) } @@ -108,8 +109,8 @@ func (msg MsgExec) UnpackInterfaces(unpacker types.AnyUnpacker) error { // UnpackInterfaces implements UnpackInterfacesMessage.UnpackInterfaces func (msg MsgGrant) UnpackInterfaces(unpacker types.AnyUnpacker) error { - var authorization exported.Authorization - return unpacker.UnpackAny(msg.Authorization, &authorization) + var a authz.Authorization + return unpacker.UnpackAny(msg.Authorization, &a) } // NewMsgRevoke creates a new MsgRevoke diff --git a/x/authz/types/msgs_test.go b/x/authz/types/msgs_test.go index 0ec5372a9fbd..2784933faf6b 100644 --- a/x/authz/types/msgs_test.go +++ b/x/authz/types/msgs_test.go @@ -6,11 +6,10 @@ import ( "github.com/stretchr/testify/require" - banktypes "github.com/cosmos/cosmos-sdk/x/bank/types" - sdk "github.com/cosmos/cosmos-sdk/types" - "github.com/cosmos/cosmos-sdk/x/authz/exported" + "github.com/cosmos/cosmos-sdk/x/authz" "github.com/cosmos/cosmos-sdk/x/authz/types" + banktypes "github.com/cosmos/cosmos-sdk/x/bank/types" ) var ( @@ -74,7 +73,7 @@ func TestMsgGrantAuthorization(t *testing.T) { tests := []struct { title string granter, grantee sdk.AccAddress - authorization exported.Authorization + authorization authz.Authorization expiration time.Time expectErr bool expectPass bool diff --git a/x/authz/types/tx.pb.go b/x/authz/types/tx.pb.go index 3f5b9bcbe7ef..02e8b2ae9d8c 100644 --- a/x/authz/types/tx.pb.go +++ b/x/authz/types/tx.pb.go @@ -119,8 +119,10 @@ var xxx_messageInfo_MsgExecResponse proto.InternalMessageInfo // authorizations granted to the grantee. Each message should have only // one signer corresponding to the granter of the authorization. type MsgExec struct { - Grantee string `protobuf:"bytes,1,opt,name=grantee,proto3" json:"grantee,omitempty"` - Msgs []*types.Any `protobuf:"bytes,2,rep,name=msgs,proto3" json:"msgs,omitempty"` + Grantee string `protobuf:"bytes,1,opt,name=grantee,proto3" json:"grantee,omitempty"` + // MsgService requests to execute. The x/authz will try to find a grant matching + // (msg.signers[0], grantee, MsgTypeURL(msg)) triple and validate it. + Msgs []*types.Any `protobuf:"bytes,2,rep,name=msgs,proto3" json:"msgs,omitempty"` } func (m *MsgExec) Reset() { *m = MsgExec{} } @@ -283,39 +285,40 @@ func init() { func init() { proto.RegisterFile("cosmos/authz/v1beta1/tx.proto", fileDescriptor_3ceddab7d8589ad1) } var fileDescriptor_3ceddab7d8589ad1 = []byte{ - // 509 bytes of a gzipped FileDescriptorProto - 0x1f, 0x8b, 0x08, 0x00, 0x00, 0x00, 0x00, 0x00, 0x02, 0xff, 0x9c, 0x93, 0x4f, 0x6f, 0xd3, 0x30, - 0x18, 0xc6, 0xe3, 0xb5, 0x74, 0xeb, 0x3b, 0x26, 0x58, 0xe8, 0x21, 0x8b, 0xb4, 0x34, 0x0a, 0x02, - 0x2a, 0xa4, 0x39, 0x5a, 0xb9, 0x70, 0x5d, 0x05, 0x02, 0x09, 0x22, 0x24, 0x6b, 0x5c, 0xb8, 0x54, - 0x49, 0x31, 0x5e, 0xb4, 0x26, 0x8e, 0x62, 0x67, 0x6a, 0xf7, 0x29, 0xf6, 0x61, 0xf8, 0x10, 0x15, - 0xa7, 0x49, 0x5c, 0x38, 0xf1, 0xa7, 0xfd, 0x12, 0x1c, 0x51, 0x1c, 0xa7, 0x74, 0x40, 0x87, 0xb4, - 0x53, 0xf2, 0xfa, 0x79, 0xfc, 0xfa, 0xf1, 0xcf, 0x36, 0xec, 0x8f, 0xb8, 0x48, 0xb8, 0xf0, 0xc3, - 0x42, 0x9e, 0x9c, 0xfb, 0x67, 0x87, 0x11, 0x95, 0xe1, 0xa1, 0x2f, 0x27, 0x38, 0xcb, 0xb9, 0xe4, - 0x66, 0xa7, 0x92, 0xb1, 0x92, 0xb1, 0x96, 0xed, 0xbd, 0x6a, 0x74, 0xa8, 0x3c, 0xbe, 0xb6, 0xa8, - 0xc2, 0xee, 0x30, 0xce, 0x78, 0x35, 0x5e, 0xfe, 0xe9, 0xd1, 0x2e, 0xe3, 0x9c, 0x8d, 0xa9, 0xaf, - 0xaa, 0xa8, 0xf8, 0xe0, 0xcb, 0x38, 0xa1, 0x42, 0x86, 0x49, 0xa6, 0x0d, 0x7b, 0x7f, 0x1a, 0xc2, - 0x74, 0xaa, 0xa5, 0xfb, 0x3a, 0x61, 0x14, 0x0a, 0xea, 0x87, 0xd1, 0x28, 0x5e, 0xa6, 0x2c, 0x8b, - 0xca, 0xe4, 0x7d, 0x46, 0xb0, 0x15, 0x08, 0xf6, 0x22, 0x0f, 0x53, 0x69, 0x5a, 0xb0, 0xc9, 0xca, - 0x1f, 0x9a, 0x5b, 0xc8, 0x45, 0xbd, 0x36, 0xa9, 0xcb, 0xdf, 0x0a, 0xb5, 0x36, 0x56, 0x15, 0x6a, - 0x06, 0xb0, 0x53, 0xee, 0x91, 0xe7, 0xf1, 0x79, 0x28, 0x63, 0x9e, 0x5a, 0x0d, 0x17, 0xf5, 0xb6, - 0xfb, 0x1d, 0x5c, 0x05, 0xc3, 0x75, 0x30, 0x7c, 0x94, 0x4e, 0x07, 0xbb, 0x9f, 0x3e, 0x1e, 0xec, - 0x1c, 0xad, 0xda, 0xc9, 0xd5, 0xd9, 0xe6, 0x33, 0x00, 0x3a, 0xc9, 0xe2, 0xbc, 0xea, 0xd5, 0x54, - 0xbd, 0xec, 0xbf, 0x7a, 0x1d, 0xd7, 0x14, 0x06, 0x5b, 0xb3, 0xaf, 0x5d, 0xe3, 0xe2, 0x5b, 0x17, - 0x91, 0x95, 0x79, 0xde, 0x2b, 0xb8, 0x13, 0x08, 0xf6, 0x7c, 0x42, 0x47, 0x84, 0x8a, 0x8c, 0xa7, - 0x82, 0x9a, 0x4f, 0xa1, 0x95, 0x53, 0x51, 0x8c, 0xa5, 0xda, 0xda, 0x76, 0xdf, 0xc5, 0x1a, 0x7f, - 0x89, 0x07, 0x2b, 0x22, 0x1a, 0x0f, 0x26, 0xca, 0x47, 0xb4, 0xdf, 0x0b, 0x60, 0x53, 0x37, 0x5b, - 0xc5, 0x80, 0xae, 0x62, 0xe8, 0x41, 0x33, 0x11, 0x4c, 0x58, 0x1b, 0x6e, 0x63, 0xdd, 0xee, 0x89, - 0x72, 0x78, 0x26, 0xdc, 0xad, 0x81, 0xd7, 0xe1, 0xbc, 0x10, 0xda, 0x81, 0x60, 0x84, 0x9e, 0xf1, - 0x53, 0x7a, 0xa3, 0x53, 0x70, 0xe1, 0x76, 0x22, 0xd8, 0x50, 0x4e, 0x33, 0x3a, 0x2c, 0xf2, 0xb1, - 0x3a, 0x84, 0x36, 0x81, 0x44, 0xb0, 0xe3, 0x69, 0x46, 0xdf, 0xe6, 0x63, 0xef, 0x1e, 0xec, 0x2e, - 0x97, 0xa8, 0xd7, 0xed, 0xff, 0x44, 0xd0, 0x08, 0x04, 0x33, 0xdf, 0xc0, 0xad, 0xea, 0x06, 0x38, - 0xf8, 0x5f, 0xf7, 0x16, 0xd7, 0x81, 0xed, 0x87, 0xd7, 0xeb, 0x4b, 0xda, 0xaf, 0xa1, 0xa9, 0x80, - 0xed, 0xaf, 0xf5, 0x97, 0xb2, 0xfd, 0xe0, 0x5a, 0x79, 0xd9, 0x8d, 0x40, 0x4b, 0xb3, 0xe9, 0xae, - 0x9d, 0x50, 0x19, 0xec, 0x47, 0xff, 0x31, 0xd4, 0x3d, 0x07, 0x2f, 0x67, 0x3f, 0x1c, 0x63, 0x36, - 0x77, 0xd0, 0xe5, 0xdc, 0x41, 0xdf, 0xe7, 0x0e, 0xba, 0x58, 0x38, 0xc6, 0xe5, 0xc2, 0x31, 0xbe, - 0x2c, 0x1c, 0xe3, 0xdd, 0x63, 0x16, 0xcb, 0x93, 0x22, 0xc2, 0x23, 0x9e, 0xe8, 0x67, 0xaa, 0x3f, - 0x07, 0xe2, 0xfd, 0xa9, 0x3f, 0xd1, 0xaf, 0xbe, 0xc4, 0x2d, 0xa2, 0x96, 0x3a, 0xe4, 0x27, 0xbf, - 0x02, 0x00, 0x00, 0xff, 0xff, 0xaf, 0x57, 0x47, 0xcd, 0x12, 0x04, 0x00, 0x00, + // 520 bytes of a gzipped FileDescriptorProto + 0x1f, 0x8b, 0x08, 0x00, 0x00, 0x00, 0x00, 0x00, 0x02, 0xff, 0x9c, 0x94, 0x4f, 0x6f, 0xd3, 0x30, + 0x18, 0xc6, 0xe3, 0xad, 0xb4, 0xeb, 0x5b, 0x26, 0x58, 0xe8, 0x21, 0x8b, 0xb4, 0x34, 0x0a, 0x02, + 0x26, 0xa4, 0x3a, 0x5a, 0x11, 0x12, 0xd7, 0x55, 0x20, 0x90, 0x20, 0x42, 0x8a, 0xc6, 0x65, 0x97, + 0x2a, 0xe9, 0x8c, 0x17, 0xb5, 0x89, 0xa3, 0xd8, 0x99, 0xda, 0x7d, 0x8a, 0x7d, 0x98, 0x7d, 0x88, + 0x6a, 0xa7, 0x49, 0x5c, 0x38, 0xf1, 0xa7, 0xfd, 0x12, 0x1c, 0x51, 0x1c, 0xa7, 0x74, 0x40, 0x87, + 0xc4, 0xa9, 0x7e, 0xfd, 0xfc, 0xfc, 0xfa, 0xf1, 0x63, 0x37, 0xb0, 0x37, 0x64, 0x3c, 0x66, 0xdc, + 0x0d, 0x72, 0x71, 0x7a, 0xee, 0x9e, 0x1d, 0x84, 0x44, 0x04, 0x07, 0xae, 0x98, 0xe0, 0x34, 0x63, + 0x82, 0xe9, 0xed, 0x52, 0xc6, 0x52, 0xc6, 0x4a, 0x36, 0x77, 0xcb, 0xd9, 0x81, 0x64, 0x5c, 0x85, + 0xc8, 0xc2, 0x6c, 0x53, 0x46, 0x59, 0x39, 0x5f, 0x8c, 0xd4, 0x6c, 0x87, 0x32, 0x46, 0xc7, 0xc4, + 0x95, 0x55, 0x98, 0x7f, 0x74, 0x45, 0x14, 0x13, 0x2e, 0x82, 0x38, 0x55, 0xc0, 0xee, 0xef, 0x40, + 0x90, 0x4c, 0x95, 0xf4, 0x50, 0x39, 0x0c, 0x03, 0x4e, 0xdc, 0x20, 0x1c, 0x46, 0x4b, 0x97, 0x45, + 0x51, 0x42, 0xce, 0x27, 0x04, 0x5b, 0x1e, 0xa7, 0xaf, 0xb3, 0x20, 0x11, 0xba, 0x01, 0x0d, 0x5a, + 0x0c, 0x48, 0x66, 0x20, 0x1b, 0xed, 0x37, 0xfd, 0xaa, 0xfc, 0xa5, 0x10, 0x63, 0x63, 0x55, 0x21, + 0xba, 0x07, 0xdb, 0xc5, 0x19, 0x59, 0x16, 0x9d, 0x07, 0x22, 0x62, 0x89, 0xb1, 0x69, 0xa3, 0xfd, + 0x56, 0xaf, 0x8d, 0x4b, 0x63, 0xb8, 0x32, 0x86, 0x0f, 0x93, 0x69, 0x7f, 0xe7, 0xea, 0xb2, 0xbb, + 0x7d, 0xb8, 0x8a, 0xfb, 0x37, 0x57, 0xeb, 0x2f, 0x01, 0xc8, 0x24, 0x8d, 0xb2, 0xb2, 0x57, 0x4d, + 0xf6, 0x32, 0xff, 0xe8, 0x75, 0x54, 0xa5, 0xd0, 0xdf, 0x9a, 0x7d, 0xe9, 0x68, 0x17, 0x5f, 0x3b, + 0xc8, 0x5f, 0x59, 0xe7, 0xbc, 0x85, 0x7b, 0x1e, 0xa7, 0xaf, 0x26, 0x64, 0xe8, 0x13, 0x9e, 0xb2, + 0x84, 0x13, 0xfd, 0x05, 0xd4, 0x33, 0xc2, 0xf3, 0xb1, 0x90, 0x47, 0x6b, 0xf5, 0x6c, 0xac, 0xe2, + 0x2f, 0xe2, 0xc1, 0x32, 0x11, 0x15, 0x0f, 0xf6, 0x25, 0xe7, 0x2b, 0xde, 0x39, 0x86, 0x86, 0x6a, + 0xb6, 0x1a, 0x03, 0xba, 0x19, 0xc3, 0x73, 0xa8, 0xc5, 0x9c, 0x72, 0x63, 0xc3, 0xde, 0x5c, 0x7b, + 0xfa, 0xd6, 0xd5, 0x65, 0xb7, 0xc1, 0x4f, 0x46, 0xd8, 0xe3, 0xd4, 0x97, 0xb8, 0xa3, 0xc3, 0xfd, + 0x2a, 0xfd, 0xca, 0xa9, 0x13, 0x40, 0xb3, 0x00, 0xc8, 0x19, 0x1b, 0x91, 0xff, 0xba, 0x12, 0x1b, + 0xee, 0xc6, 0x9c, 0x0e, 0xc4, 0x34, 0x25, 0x83, 0x3c, 0x1b, 0xcb, 0x1b, 0x69, 0xfa, 0x10, 0x73, + 0x7a, 0x34, 0x4d, 0xc9, 0x87, 0x6c, 0xec, 0x3c, 0x80, 0x9d, 0xe5, 0x16, 0xd5, 0xbe, 0xbd, 0x1f, + 0x08, 0x36, 0x3d, 0x4e, 0xf5, 0xf7, 0x70, 0xa7, 0x7c, 0x0e, 0x16, 0xfe, 0xdb, 0x23, 0xc6, 0x95, + 0x61, 0xf3, 0xf1, 0xed, 0xfa, 0x32, 0xfa, 0x77, 0x50, 0x93, 0xe9, 0xed, 0xad, 0xe5, 0x0b, 0xd9, + 0x7c, 0x74, 0xab, 0xbc, 0xec, 0xe6, 0x43, 0x5d, 0x65, 0xd3, 0x59, 0xbb, 0xa0, 0x04, 0xcc, 0x27, + 0xff, 0x00, 0xaa, 0x9e, 0xfd, 0x37, 0xb3, 0xef, 0x96, 0x36, 0x9b, 0x5b, 0xe8, 0x7a, 0x6e, 0xa1, + 0x6f, 0x73, 0x0b, 0x5d, 0x2c, 0x2c, 0xed, 0x7a, 0x61, 0x69, 0x9f, 0x17, 0x96, 0x76, 0xfc, 0x94, + 0x46, 0xe2, 0x34, 0x0f, 0xf1, 0x90, 0xc5, 0xea, 0x3f, 0xab, 0x7e, 0xba, 0xfc, 0x64, 0xe4, 0x4e, + 0xd4, 0x27, 0xa0, 0x88, 0x9b, 0x87, 0x75, 0x79, 0xe3, 0xcf, 0x7e, 0x06, 0x00, 0x00, 0xff, 0xff, + 0x14, 0x49, 0xd2, 0xe5, 0x1f, 0x04, 0x00, 0x00, } // Reference imports to suppress errors if they are not otherwise used. diff --git a/x/bank/types/send_authorization.go b/x/bank/types/send_authorization.go index bba77b126a72..e25cb9c09f03 100644 --- a/x/bank/types/send_authorization.go +++ b/x/bank/types/send_authorization.go @@ -3,7 +3,7 @@ package types import ( sdk "github.com/cosmos/cosmos-sdk/types" sdkerrors "github.com/cosmos/cosmos-sdk/types/errors" - authz "github.com/cosmos/cosmos-sdk/x/authz/exported" + "github.com/cosmos/cosmos-sdk/x/authz" ) var ( diff --git a/x/staking/types/authz.go b/x/staking/types/authz.go index 459d8860bcd2..3026256d7603 100644 --- a/x/staking/types/authz.go +++ b/x/staking/types/authz.go @@ -3,7 +3,7 @@ package types import ( sdk "github.com/cosmos/cosmos-sdk/types" sdkerrors "github.com/cosmos/cosmos-sdk/types/errors" - authz "github.com/cosmos/cosmos-sdk/x/authz/exported" + "github.com/cosmos/cosmos-sdk/x/authz" ) // TODO: Revisit this once we have propoer gas fee framework. @@ -25,19 +25,19 @@ func NewStakeAuthorization(allowed []sdk.ValAddress, denied []sdk.ValAddress, au return nil, err } - authorization := StakeAuthorization{} + a := StakeAuthorization{} if allowedValidators != nil { - authorization.Validators = &StakeAuthorization_AllowList{AllowList: &StakeAuthorization_Validators{Address: allowedValidators}} + a.Validators = &StakeAuthorization_AllowList{AllowList: &StakeAuthorization_Validators{Address: allowedValidators}} } else { - authorization.Validators = &StakeAuthorization_DenyList{DenyList: &StakeAuthorization_Validators{Address: deniedValidators}} + a.Validators = &StakeAuthorization_DenyList{DenyList: &StakeAuthorization_Validators{Address: deniedValidators}} } if amount != nil { - authorization.MaxTokens = amount + a.MaxTokens = amount } - authorization.AuthorizationType = authzType + a.AuthorizationType = authzType - return &authorization, nil + return &a, nil } // MsgTypeURL implements Authorization.MsgTypeURL. From 90329fc36d00ab4f3d14ee36fa736b802b70663b Mon Sep 17 00:00:00 2001 From: Robert Zaremba Date: Wed, 28 Apr 2021 09:26:44 +0200 Subject: [PATCH 28/44] lint fix --- x/authz/keeper/grpc_query.go | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/x/authz/keeper/grpc_query.go b/x/authz/keeper/grpc_query.go index adb2dbf2586b..d4682b894ef0 100644 --- a/x/authz/keeper/grpc_query.go +++ b/x/authz/keeper/grpc_query.go @@ -49,7 +49,7 @@ func (k Keeper) Grants(c context.Context, req *types.QueryGrantsRequest) (*types return nil, status.Errorf(codes.Internal, err.Error()) } return &types.QueryGrantsResponse{ - Grants: []*types.Grant{&types.Grant{ + Grants: []*types.Grant{{ Authorization: authorizationAny, Expiration: expiration, }}, From 2465221687ceac6d99a97cb4d2226e261e6b91b1 Mon Sep 17 00:00:00 2001 From: Robert Zaremba Date: Wed, 28 Apr 2021 13:32:03 +0200 Subject: [PATCH 29/44] authz/types refactore --- proto/cosmos/authz/v1beta1/authz.proto | 2 +- proto/cosmos/authz/v1beta1/event.proto | 8 +-- proto/cosmos/authz/v1beta1/genesis.proto | 2 +- proto/cosmos/authz/v1beta1/query.proto | 2 +- proto/cosmos/authz/v1beta1/tx.proto | 2 +- simapp/app.go | 8 +-- simapp/app_test.go | 6 +- simapp/genesis.go | 2 +- simapp/sim_test.go | 4 +- x/authz/{types => }/authorization_grant.go | 19 +++-- x/authz/{types => }/authz.pb.go | 13 ++-- x/authz/client/cli/query.go | 12 ++-- x/authz/client/cli/tx.go | 42 +++++------ x/authz/client/rest/grpc_query_test.go | 22 +++--- x/authz/client/testutil/query.go | 5 +- x/authz/{types => codec}/codec.go | 10 +-- x/authz/{types => }/errors.go | 2 +- x/authz/{types => }/event.pb.go | 14 ++-- x/authz/{types => }/expected_keepers.go | 6 +- x/authz/{types => }/generic_authorization.go | 9 ++- .../{types => }/generic_authorization_test.go | 8 +-- x/authz/{types => }/genesis.go | 13 ++-- x/authz/{types => }/genesis.pb.go | 46 ++++++------ x/authz/keeper/grpc_query.go | 18 ++--- x/authz/keeper/grpc_query_test.go | 37 +++++----- x/authz/keeper/keeper.go | 31 ++++---- x/authz/keeper/keeper_test.go | 21 +++--- x/authz/keeper/keys.go | 4 +- x/authz/keeper/msg_server.go | 16 ++--- x/authz/{types => }/keys.go | 2 +- x/authz/module/module.go | 39 +++++----- x/authz/{types => }/msgs.go | 33 +++++---- x/authz/{types => }/msgs_test.go | 9 ++- x/authz/proto_desc.go | 8 +++ x/authz/{types => }/query.pb.go | 53 +++++++------- x/authz/{types => }/query.pb.gw.go | 4 +- x/authz/simulation/decoder.go | 6 +- x/authz/simulation/decoder_test.go | 6 +- x/authz/simulation/genesis.go | 19 +++-- x/authz/simulation/genesis_test.go | 6 +- x/authz/simulation/operations.go | 72 +++++++++---------- x/authz/simulation/operations_test.go | 14 ++-- x/authz/{types => }/tx.pb.go | 70 +++++++++--------- 43 files changed, 356 insertions(+), 369 deletions(-) rename x/authz/{types => }/authorization_grant.go (58%) rename x/authz/{types => }/authz.pb.go (97%) rename x/authz/{types => codec}/codec.go (80%) rename x/authz/{types => }/errors.go (94%) rename x/authz/{types => }/event.pb.go (98%) rename x/authz/{types => }/expected_keepers.go (70%) rename x/authz/{types => }/generic_authorization.go (81%) rename x/authz/{types => }/generic_authorization_test.go (72%) rename x/authz/{types => }/genesis.go (69%) rename x/authz/{types => }/genesis.pb.go (88%) rename x/authz/{types => }/keys.go (97%) rename x/authz/{types => }/msgs.go (86%) rename x/authz/{types => }/msgs_test.go (93%) create mode 100644 x/authz/proto_desc.go rename x/authz/{types => }/query.pb.go (89%) rename x/authz/{types => }/query.pb.gw.go (99%) rename x/authz/{types => }/tx.pb.go (92%) diff --git a/proto/cosmos/authz/v1beta1/authz.proto b/proto/cosmos/authz/v1beta1/authz.proto index ce4cd64cef2f..38d49f154699 100644 --- a/proto/cosmos/authz/v1beta1/authz.proto +++ b/proto/cosmos/authz/v1beta1/authz.proto @@ -6,7 +6,7 @@ import "google/protobuf/timestamp.proto"; import "gogoproto/gogo.proto"; import "google/protobuf/any.proto"; -option go_package = "github.com/cosmos/cosmos-sdk/x/authz/types"; +option go_package = "github.com/cosmos/cosmos-sdk/x/authz"; option (gogoproto.goproto_getters_all) = false; // GenericAuthorization gives the grantee unrestricted permissions to execute diff --git a/proto/cosmos/authz/v1beta1/event.proto b/proto/cosmos/authz/v1beta1/event.proto index 69659337cb81..c77cea3e6a81 100644 --- a/proto/cosmos/authz/v1beta1/event.proto +++ b/proto/cosmos/authz/v1beta1/event.proto @@ -1,13 +1,7 @@ syntax = "proto3"; package cosmos.authz.v1beta1; -// import "cosmos_proto/cosmos.proto"; -// import "google/protobuf/timestamp.proto"; -// import "gogoproto/gogo.proto"; -// import "google/protobuf/any.proto"; - -option go_package = "github.com/cosmos/cosmos-sdk/x/authz/types"; - +option go_package = "github.com/cosmos/cosmos-sdk/x/authz"; // EventGrant is emitted on Msg/Grant message EventGrant { diff --git a/proto/cosmos/authz/v1beta1/genesis.proto b/proto/cosmos/authz/v1beta1/genesis.proto index e593c43f219c..411fd276fb24 100644 --- a/proto/cosmos/authz/v1beta1/genesis.proto +++ b/proto/cosmos/authz/v1beta1/genesis.proto @@ -6,7 +6,7 @@ import "google/protobuf/any.proto"; import "gogoproto/gogo.proto"; import "cosmos_proto/cosmos.proto"; -option go_package = "github.com/cosmos/cosmos-sdk/x/authz/types"; +option go_package = "github.com/cosmos/cosmos-sdk/x/authz"; // GenesisState defines the authz module's genesis state. message GenesisState { diff --git a/proto/cosmos/authz/v1beta1/query.proto b/proto/cosmos/authz/v1beta1/query.proto index 5320116a74b0..6434790050e4 100644 --- a/proto/cosmos/authz/v1beta1/query.proto +++ b/proto/cosmos/authz/v1beta1/query.proto @@ -5,7 +5,7 @@ import "google/api/annotations.proto"; import "cosmos/base/query/v1beta1/pagination.proto"; import "cosmos/authz/v1beta1/authz.proto"; -option go_package = "github.com/cosmos/cosmos-sdk/x/authz/types"; +option go_package = "github.com/cosmos/cosmos-sdk/x/authz"; // Query defines the gRPC querier service. service Query { diff --git a/proto/cosmos/authz/v1beta1/tx.proto b/proto/cosmos/authz/v1beta1/tx.proto index 5842daf45388..47e6ca630fd7 100644 --- a/proto/cosmos/authz/v1beta1/tx.proto +++ b/proto/cosmos/authz/v1beta1/tx.proto @@ -7,7 +7,7 @@ import "google/protobuf/timestamp.proto"; import "google/protobuf/any.proto"; import "cosmos/base/abci/v1beta1/abci.proto"; -option go_package = "github.com/cosmos/cosmos-sdk/x/authz/types"; +option go_package = "github.com/cosmos/cosmos-sdk/x/authz"; option (gogoproto.goproto_getters_all) = false; // Msg defines the authz Msg service. diff --git a/simapp/app.go b/simapp/app.go index da28a9f66e0b..19f0b9bae5fd 100644 --- a/simapp/app.go +++ b/simapp/app.go @@ -82,9 +82,9 @@ import ( upgradekeeper "github.com/cosmos/cosmos-sdk/x/upgrade/keeper" upgradetypes "github.com/cosmos/cosmos-sdk/x/upgrade/types" + "github.com/cosmos/cosmos-sdk/x/authz" authzkeeper "github.com/cosmos/cosmos-sdk/x/authz/keeper" authz_m "github.com/cosmos/cosmos-sdk/x/authz/module" - authztypes "github.com/cosmos/cosmos-sdk/x/authz/types" // unnamed import of statik for swagger UI support _ "github.com/cosmos/cosmos-sdk/client/docs/statik" @@ -208,7 +208,7 @@ func NewSimApp( minttypes.StoreKey, distrtypes.StoreKey, slashingtypes.StoreKey, govtypes.StoreKey, paramstypes.StoreKey, upgradetypes.StoreKey, feegranttypes.StoreKey, evidencetypes.StoreKey, capabilitytypes.StoreKey, - authztypes.StoreKey, + authz.StoreKey, ) tkeys := sdk.NewTransientStoreKeys(paramstypes.TStoreKey) memKeys := sdk.NewMemoryStoreKeys(capabilitytypes.MemStoreKey) @@ -265,7 +265,7 @@ func NewSimApp( stakingtypes.NewMultiStakingHooks(app.DistrKeeper.Hooks(), app.SlashingKeeper.Hooks()), ) - app.AuthzKeeper = authzkeeper.NewKeeper(keys[authztypes.StoreKey], appCodec, app.BaseApp.MsgServiceRouter()) + app.AuthzKeeper = authzkeeper.NewKeeper(keys[authz.StoreKey], appCodec, app.BaseApp.MsgServiceRouter()) // register the proposal types govRouter := govtypes.NewRouter() @@ -339,7 +339,7 @@ func NewSimApp( app.mm.SetOrderInitGenesis( capabilitytypes.ModuleName, authtypes.ModuleName, banktypes.ModuleName, distrtypes.ModuleName, stakingtypes.ModuleName, slashingtypes.ModuleName, govtypes.ModuleName, minttypes.ModuleName, crisistypes.ModuleName, - genutiltypes.ModuleName, evidencetypes.ModuleName, authztypes.ModuleName, + genutiltypes.ModuleName, evidencetypes.ModuleName, authz.ModuleName, feegranttypes.ModuleName, ) diff --git a/simapp/app_test.go b/simapp/app_test.go index bfab92c05477..7d4d144a72e9 100644 --- a/simapp/app_test.go +++ b/simapp/app_test.go @@ -18,7 +18,7 @@ import ( "github.com/cosmos/cosmos-sdk/types/module" "github.com/cosmos/cosmos-sdk/x/auth" "github.com/cosmos/cosmos-sdk/x/auth/vesting" - "github.com/cosmos/cosmos-sdk/x/authz" + authz_m "github.com/cosmos/cosmos-sdk/x/authz/module" "github.com/cosmos/cosmos-sdk/x/bank" banktypes "github.com/cosmos/cosmos-sdk/x/bank/types" "github.com/cosmos/cosmos-sdk/x/capability" @@ -168,7 +168,7 @@ func TestRunMigrations(t *testing.T) { module.VersionMap{ "bank": 1, "auth": auth.AppModule{}.ConsensusVersion(), - "authz": authz.AppModule{}.ConsensusVersion(), + "authz": authz_m.AppModule{}.ConsensusVersion(), "staking": staking.AppModule{}.ConsensusVersion(), "mint": mint.AppModule{}.ConsensusVersion(), "distribution": distribution.AppModule{}.ConsensusVersion(), @@ -219,7 +219,7 @@ func TestInitGenesisOnMigration(t *testing.T) { module.VersionMap{ "bank": bank.AppModule{}.ConsensusVersion(), "auth": auth.AppModule{}.ConsensusVersion(), - "authz": authz.AppModule{}.ConsensusVersion(), + "authz": authz_m.AppModule{}.ConsensusVersion(), "staking": staking.AppModule{}.ConsensusVersion(), "mint": mint.AppModule{}.ConsensusVersion(), "distribution": distribution.AppModule{}.ConsensusVersion(), diff --git a/simapp/genesis.go b/simapp/genesis.go index dbb4e01c7690..500a2c2f723d 100644 --- a/simapp/genesis.go +++ b/simapp/genesis.go @@ -6,7 +6,7 @@ import ( "github.com/cosmos/cosmos-sdk/codec" ) -// The genesis state of the blockchain is represented here as a map of raw json +// GenesisState of the blockchain is represented here as a map of raw json // messages key'd by a identifier string. // The identifier is used to determine which module genesis information belongs // to so it may be appropriately routed during init chain. diff --git a/simapp/sim_test.go b/simapp/sim_test.go index 130bee23c0d2..70236018aa60 100644 --- a/simapp/sim_test.go +++ b/simapp/sim_test.go @@ -19,7 +19,7 @@ import ( sdk "github.com/cosmos/cosmos-sdk/types" simtypes "github.com/cosmos/cosmos-sdk/types/simulation" authtypes "github.com/cosmos/cosmos-sdk/x/auth/types" - authztypes "github.com/cosmos/cosmos-sdk/x/authz/types" + "github.com/cosmos/cosmos-sdk/x/authz" banktypes "github.com/cosmos/cosmos-sdk/x/bank/types" capabilitytypes "github.com/cosmos/cosmos-sdk/x/capability/types" distrtypes "github.com/cosmos/cosmos-sdk/x/distribution/types" @@ -174,7 +174,7 @@ func TestAppImportExport(t *testing.T) { {app.keys[govtypes.StoreKey], newApp.keys[govtypes.StoreKey], [][]byte{}}, {app.keys[evidencetypes.StoreKey], newApp.keys[evidencetypes.StoreKey], [][]byte{}}, {app.keys[capabilitytypes.StoreKey], newApp.keys[capabilitytypes.StoreKey], [][]byte{}}, - {app.keys[authztypes.StoreKey], newApp.keys[authztypes.StoreKey], [][]byte{}}, + {app.keys[authz.StoreKey], newApp.keys[authz.StoreKey], [][]byte{}}, } for _, skp := range storeKeysPrefixes { diff --git a/x/authz/types/authorization_grant.go b/x/authz/authorization_grant.go similarity index 58% rename from x/authz/types/authorization_grant.go rename to x/authz/authorization_grant.go index 6ab727fc2372..8a5995c5d0d0 100644 --- a/x/authz/types/authorization_grant.go +++ b/x/authz/authorization_grant.go @@ -1,17 +1,16 @@ -package types +package authz import ( "time" proto "github.com/gogo/protobuf/proto" - "github.com/cosmos/cosmos-sdk/codec/types" + cdctypes "github.com/cosmos/cosmos-sdk/codec/types" sdkerrors "github.com/cosmos/cosmos-sdk/types/errors" - "github.com/cosmos/cosmos-sdk/x/authz" ) // NewGrant returns new AuthrizationGrant -func NewGrant(authorization authz.Authorization, expiration time.Time) (Grant, error) { +func NewGrant(authorization Authorization, expiration time.Time) (Grant, error) { auth := Grant{ Expiration: expiration, } @@ -20,7 +19,7 @@ func NewGrant(authorization authz.Authorization, expiration time.Time) (Grant, e return Grant{}, sdkerrors.Wrapf(sdkerrors.ErrPackAny, "cannot proto marshal %T", authorization) } - any, err := types.NewAnyWithValue(msg) + any, err := cdctypes.NewAnyWithValue(msg) if err != nil { return Grant{}, err } @@ -31,18 +30,18 @@ func NewGrant(authorization authz.Authorization, expiration time.Time) (Grant, e } var ( - _ types.UnpackInterfacesMessage = &Grant{} + _ cdctypes.UnpackInterfacesMessage = &Grant{} ) // UnpackInterfaces implements UnpackInterfacesMessage.UnpackInterfaces -func (auth Grant) UnpackInterfaces(unpacker types.AnyUnpacker) error { - var authorization authz.Authorization +func (auth Grant) UnpackInterfaces(unpacker cdctypes.AnyUnpacker) error { + var authorization Authorization return unpacker.UnpackAny(auth.Authorization, &authorization) } // GetAuthorization returns the cached value from the Grant.Authorization if present. -func (auth Grant) GetAuthorization() authz.Authorization { - authorization, ok := auth.Authorization.GetCachedValue().(authz.Authorization) +func (auth Grant) GetAuthorization() Authorization { + authorization, ok := auth.Authorization.GetCachedValue().(Authorization) if !ok { return nil } diff --git a/x/authz/types/authz.pb.go b/x/authz/authz.pb.go similarity index 97% rename from x/authz/types/authz.pb.go rename to x/authz/authz.pb.go index 4715197b7589..34fe197e01db 100644 --- a/x/authz/types/authz.pb.go +++ b/x/authz/authz.pb.go @@ -1,7 +1,7 @@ // Code generated by protoc-gen-gogo. DO NOT EDIT. // source: cosmos/authz/v1beta1/authz.proto -package types +package authz import ( fmt "fmt" @@ -117,7 +117,7 @@ func init() { func init() { proto.RegisterFile("cosmos/authz/v1beta1/authz.proto", fileDescriptor_544dc2e84b61c637) } var fileDescriptor_544dc2e84b61c637 = []byte{ - // 308 bytes of a gzipped FileDescriptorProto + // 303 bytes of a gzipped FileDescriptorProto 0x1f, 0x8b, 0x08, 0x00, 0x00, 0x00, 0x00, 0x00, 0x02, 0xff, 0xe2, 0x52, 0x48, 0xce, 0x2f, 0xce, 0xcd, 0x2f, 0xd6, 0x4f, 0x2c, 0x2d, 0xc9, 0xa8, 0xd2, 0x2f, 0x33, 0x4c, 0x4a, 0x2d, 0x49, 0x34, 0x84, 0xf0, 0xf4, 0x0a, 0x8a, 0xf2, 0x4b, 0xf2, 0x85, 0x44, 0x20, 0x2a, 0xf4, 0x20, 0x62, 0x50, @@ -132,12 +132,11 @@ var fileDescriptor_544dc2e84b61c637 = []byte{ 0x41, 0x6c, 0xd6, 0x83, 0xd9, 0xac, 0xe7, 0x98, 0x57, 0xe9, 0x24, 0x78, 0x0a, 0xdd, 0xa4, 0x20, 0x54, 0xdd, 0x42, 0x2e, 0x5c, 0x5c, 0xa9, 0x15, 0x05, 0x99, 0x45, 0x10, 0xb3, 0x98, 0xc0, 0x66, 0x49, 0x61, 0x98, 0x15, 0x02, 0xf3, 0xbc, 0x13, 0xc7, 0x89, 0x7b, 0xf2, 0x0c, 0x13, 0xee, 0xcb, - 0x33, 0x06, 0x21, 0xe9, 0x73, 0xf2, 0x38, 0xf1, 0x50, 0x8e, 0xe1, 0xc4, 0x23, 0x39, 0xc6, 0x0b, + 0x33, 0x06, 0x21, 0xe9, 0x73, 0x72, 0x3a, 0xf1, 0x50, 0x8e, 0xe1, 0xc4, 0x23, 0x39, 0xc6, 0x0b, 0x8f, 0xe4, 0x18, 0x1f, 0x3c, 0x92, 0x63, 0x9c, 0xf0, 0x58, 0x8e, 0xe1, 0xc2, 0x63, 0x39, 0x86, - 0x1b, 0x8f, 0xe5, 0x18, 0xa2, 0xb4, 0xd2, 0x33, 0x4b, 0x32, 0x4a, 0x93, 0xf4, 0x92, 0xf3, 0x73, - 0xa1, 0x81, 0x0c, 0xa5, 0x74, 0x8b, 0x53, 0xb2, 0xf5, 0x2b, 0xa0, 0xd1, 0x56, 0x52, 0x59, 0x90, - 0x5a, 0x9c, 0xc4, 0x06, 0xb6, 0xd3, 0x18, 0x10, 0x00, 0x00, 0xff, 0xff, 0x08, 0xb2, 0x09, 0x58, - 0xd3, 0x01, 0x00, 0x00, + 0x1b, 0x8f, 0xe5, 0x18, 0xa2, 0x54, 0xd2, 0x33, 0x4b, 0x32, 0x4a, 0x93, 0xf4, 0x92, 0xf3, 0x73, + 0xa1, 0x81, 0x0c, 0xa5, 0x74, 0x8b, 0x53, 0xb2, 0xf5, 0x2b, 0x20, 0x11, 0x95, 0xc4, 0x06, 0xb6, + 0xcd, 0x18, 0x10, 0x00, 0x00, 0xff, 0xff, 0x6e, 0xbe, 0xf1, 0x5a, 0xcd, 0x01, 0x00, 0x00, } func (m *GenericAuthorization) Marshal() (dAtA []byte, err error) { diff --git a/x/authz/client/cli/query.go b/x/authz/client/cli/query.go index f1a5869650e0..afd144686161 100644 --- a/x/authz/client/cli/query.go +++ b/x/authz/client/cli/query.go @@ -10,14 +10,14 @@ import ( "github.com/cosmos/cosmos-sdk/client/flags" sdk "github.com/cosmos/cosmos-sdk/types" "github.com/cosmos/cosmos-sdk/version" - "github.com/cosmos/cosmos-sdk/x/authz/types" + "github.com/cosmos/cosmos-sdk/x/authz" bank "github.com/cosmos/cosmos-sdk/x/bank/types" ) // GetQueryCmd returns the cli query commands for this module func GetQueryCmd() *cobra.Command { authorizationQueryCmd := &cobra.Command{ - Use: types.ModuleName, + Use: authz.ModuleName, Short: "Querying commands for the authz module", Long: "", DisableFlagParsing: true, @@ -45,15 +45,15 @@ Examples: $ %s query %s grants cosmos1skj.. cosmos1skjwj.. $ %s query %s grants cosmos1skjw.. cosmos1skjwj.. %s `, - version.AppName, types.ModuleName, - version.AppName, types.ModuleName, bank.SendAuthorization{}.MsgTypeURL()), + version.AppName, authz.ModuleName, + version.AppName, authz.ModuleName, bank.SendAuthorization{}.MsgTypeURL()), ), RunE: func(cmd *cobra.Command, args []string) error { clientCtx, err := client.GetClientQueryContext(cmd) if err != nil { return err } - queryClient := types.NewQueryClient(clientCtx) + queryClient := authz.NewQueryClient(clientCtx) granter, err := sdk.AccAddressFromBech32(args[0]) if err != nil { @@ -74,7 +74,7 @@ $ %s query %s grants cosmos1skjw.. cosmos1skjwj.. %s res, err := queryClient.Grants( cmd.Context(), - &types.QueryGrantsRequest{ + &authz.QueryGrantsRequest{ Granter: granter.String(), Grantee: grantee.String(), MsgTypeUrl: msgAuthorized, diff --git a/x/authz/client/cli/tx.go b/x/authz/client/cli/tx.go index ecb80b54aef0..b1324546a619 100644 --- a/x/authz/client/cli/tx.go +++ b/x/authz/client/cli/tx.go @@ -16,24 +16,26 @@ import ( "github.com/cosmos/cosmos-sdk/version" authclient "github.com/cosmos/cosmos-sdk/x/auth/client" "github.com/cosmos/cosmos-sdk/x/authz" - "github.com/cosmos/cosmos-sdk/x/authz/types" bank "github.com/cosmos/cosmos-sdk/x/bank/types" staking "github.com/cosmos/cosmos-sdk/x/staking/types" ) -const FlagSpendLimit = "spend-limit" -const FlagMsgType = "msg-type" -const FlagExpiration = "expiration" -const FlagAllowedValidators = "allowed-validators" -const FlagDenyValidators = "deny-validators" -const delegate = "delegate" -const redelegate = "redelegate" -const unbond = "unbond" +// Flag names and values +const ( + FlagSpendLimit = "spend-limit" + FlagMsgType = "msg-type" + FlagExpiration = "expiration" + FlagAllowedValidators = "allowed-validators" + FlagDenyValidators = "deny-validators" + delegate = "delegate" + redelegate = "redelegate" + unbond = "unbond" +) // GetTxCmd returns the transaction commands for this module func GetTxCmd() *cobra.Command { AuthorizationTxCmd := &cobra.Command{ - Use: types.ModuleName, + Use: authz.ModuleName, Short: "Authorization transactions subcommands", Long: "Authorize and revoke access to execute transactions on behalf of your address", DisableFlagParsing: true, @@ -60,7 +62,7 @@ func NewCmdGrantAuthorization() *cobra.Command { Examples: $ %s tx %s grant cosmos1skjw.. send %s --spend-limit=1000stake --from=cosmos1skl.. $ %s tx %s grant cosmos1skjw.. generic --msg-type=/cosmos.gov.v1beta1.Msg/Vote --from=cosmos1sk.. - `, version.AppName, types.ModuleName, bank.SendAuthorization{}.MsgTypeURL(), version.AppName, types.ModuleName), + `, version.AppName, authz.ModuleName, bank.SendAuthorization{}.MsgTypeURL(), version.AppName, authz.ModuleName), ), Args: cobra.ExactArgs(2), RunE: func(cmd *cobra.Command, args []string) error { @@ -103,7 +105,7 @@ Examples: return err } - authorization = types.NewGenericAuthorization(msgType) + authorization = authz.NewGenericAuthorization(msgType) case delegate, unbond, redelegate: limit, err := cmd.Flags().GetString(FlagSpendLimit) if err != nil { @@ -159,13 +161,13 @@ Examples: return fmt.Errorf("invalid authorization type, %s", args[1]) } - msg, err := types.NewMsgGrant(clientCtx.GetFromAddress(), grantee, authorization, time.Unix(exp, 0)) + msg, err := authz.NewMsgGrant(clientCtx.GetFromAddress(), grantee, authorization, time.Unix(exp, 0)) if err != nil { return err } svcMsgClientConn := &msgservice.ServiceMsgClientConn{} - msgClient := types.NewMsgClient(svcMsgClientConn) + msgClient := authz.NewMsgClient(svcMsgClientConn) _, err = msgClient.Grant(cmd.Context(), msg) if err != nil { return err @@ -191,7 +193,7 @@ func NewCmdRevokeAuthorization() *cobra.Command { fmt.Sprintf(`revoke authorization from a granter to a grantee: Example: $ %s tx %s revoke cosmos1skj.. %s --from=cosmos1skj.. - `, version.AppName, types.ModuleName, bank.SendAuthorization{}.MsgTypeURL()), + `, version.AppName, authz.ModuleName, bank.SendAuthorization{}.MsgTypeURL()), ), Args: cobra.ExactArgs(2), RunE: func(cmd *cobra.Command, args []string) error { @@ -207,10 +209,10 @@ Example: granter := clientCtx.GetFromAddress() msgAuthorized := args[1] - msg := types.NewMsgRevoke(granter, grantee, msgAuthorized) + msg := authz.NewMsgRevoke(granter, grantee, msgAuthorized) svcMsgClientConn := &msgservice.ServiceMsgClientConn{} - msgClient := types.NewMsgClient(svcMsgClientConn) + msgClient := authz.NewMsgClient(svcMsgClientConn) _, err = msgClient.Revoke(cmd.Context(), &msg) if err != nil { return err @@ -232,7 +234,7 @@ func NewCmdExecAuthorization() *cobra.Command { Example: $ %s tx %s exec tx.json --from grantee $ %s tx bank send --from --chain-id --generate-only > tx.json && %s tx %s exec tx.json --from grantee - `, version.AppName, types.ModuleName, version.AppName, version.AppName, types.ModuleName), + `, version.AppName, authz.ModuleName, version.AppName, version.AppName, authz.ModuleName), ), Args: cobra.ExactArgs(1), RunE: func(cmd *cobra.Command, args []string) error { @@ -261,9 +263,9 @@ Example: serviceMsgs[i] = srvMsg } - msg := types.NewMsgExec(grantee, serviceMsgs) + msg := authz.NewMsgExec(grantee, serviceMsgs) svcMsgClientConn := &msgservice.ServiceMsgClientConn{} - msgClient := types.NewMsgClient(svcMsgClientConn) + msgClient := authz.NewMsgClient(svcMsgClientConn) _, err = msgClient.Exec(cmd.Context(), &msg) if err != nil { return err diff --git a/x/authz/client/rest/grpc_query_test.go b/x/authz/client/rest/grpc_query_test.go index 676af3915b01..c2d95c119d08 100644 --- a/x/authz/client/rest/grpc_query_test.go +++ b/x/authz/client/rest/grpc_query_test.go @@ -15,9 +15,9 @@ import ( "github.com/cosmos/cosmos-sdk/testutil/network" sdk "github.com/cosmos/cosmos-sdk/types" "github.com/cosmos/cosmos-sdk/types/rest" + "github.com/cosmos/cosmos-sdk/x/authz" "github.com/cosmos/cosmos-sdk/x/authz/client/cli" authztestutil "github.com/cosmos/cosmos-sdk/x/authz/client/testutil" - types "github.com/cosmos/cosmos-sdk/x/authz/types" banktestutil "github.com/cosmos/cosmos-sdk/x/bank/client/testutil" banktypes "github.com/cosmos/cosmos-sdk/x/bank/types" ) @@ -134,7 +134,7 @@ func (s *IntegrationTestSuite) TestQueryAuthorizationGRPC() { if tc.expectErr { s.Require().Contains(string(resp), tc.errorMsg) } else { - var authorization types.QueryAuthorizationResponse + var authorization authz.QueryAuthorizationResponse err := val.ClientCtx.JSONMarshaler.UnmarshalJSON(resp, &authorization) s.Require().NoError(err) authorization.Authorization.UnpackInterfaces(val.ClientCtx.InterfaceRegistry) @@ -154,7 +154,7 @@ func (s *IntegrationTestSuite) TestQueryAuthorizationsGRPC() { expectErr bool errMsg string preRun func() - postRun func(*types.QueryAuthorizationsResponse) + postRun func(*authz.QueryAuthorizationsResponse) }{ { "fail invalid granter address", @@ -162,7 +162,7 @@ func (s *IntegrationTestSuite) TestQueryAuthorizationsGRPC() { true, "decoding bech32 failed: invalid index of 1: invalid request", func() {}, - func(_ *types.QueryAuthorizationsResponse) {}, + func(_ *authz.QueryAuthorizationsResponse) {}, }, { "fail invalid grantee address", @@ -170,7 +170,7 @@ func (s *IntegrationTestSuite) TestQueryAuthorizationsGRPC() { true, "decoding bech32 failed: invalid index of 1: invalid request", func() {}, - func(_ *types.QueryAuthorizationsResponse) {}, + func(_ *authz.QueryAuthorizationsResponse) {}, }, { "fail empty grantee address", @@ -178,7 +178,7 @@ func (s *IntegrationTestSuite) TestQueryAuthorizationsGRPC() { true, "Not Implemented", func() {}, - func(_ *types.QueryAuthorizationsResponse) {}, + func(_ *authz.QueryAuthorizationsResponse) {}, }, { "valid query: expect single grant", @@ -187,7 +187,7 @@ func (s *IntegrationTestSuite) TestQueryAuthorizationsGRPC() { "", func() { }, - func(authorizations *types.QueryAuthorizationsResponse) { + func(authorizations *authz.QueryAuthorizationsResponse) { s.Require().Equal(len(authorizations.Authorizations), 1) }, }, @@ -209,7 +209,7 @@ func (s *IntegrationTestSuite) TestQueryAuthorizationsGRPC() { }) s.Require().NoError(err) }, - func(authorizations *types.QueryAuthorizationsResponse) { + func(authorizations *authz.QueryAuthorizationsResponse) { s.Require().Equal(len(authorizations.Authorizations), 2) }, }, @@ -219,7 +219,7 @@ func (s *IntegrationTestSuite) TestQueryAuthorizationsGRPC() { false, "", func() {}, - func(authorizations *types.QueryAuthorizationsResponse) { + func(authorizations *authz.QueryAuthorizationsResponse) { s.Require().Equal(len(authorizations.Authorizations), 1) }, }, @@ -229,7 +229,7 @@ func (s *IntegrationTestSuite) TestQueryAuthorizationsGRPC() { false, "", func() {}, - func(authorizations *types.QueryAuthorizationsResponse) { + func(authorizations *authz.QueryAuthorizationsResponse) { s.Require().Equal(len(authorizations.Authorizations), 2) }, }, @@ -242,7 +242,7 @@ func (s *IntegrationTestSuite) TestQueryAuthorizationsGRPC() { if tc.expectErr { s.Require().Contains(string(resp), tc.errMsg) } else { - var authorizations types.QueryAuthorizationsResponse + var authorizations authz.QueryAuthorizationsResponse err := val.ClientCtx.JSONMarshaler.UnmarshalJSON(resp, &authorizations) s.Require().NoError(err) tc.postRun(&authorizations) diff --git a/x/authz/client/testutil/query.go b/x/authz/client/testutil/query.go index 42bce081d885..f57f619f9f87 100644 --- a/x/authz/client/testutil/query.go +++ b/x/authz/client/testutil/query.go @@ -10,9 +10,8 @@ import ( "github.com/cosmos/cosmos-sdk/client/flags" clitestutil "github.com/cosmos/cosmos-sdk/testutil/cli" sdk "github.com/cosmos/cosmos-sdk/types" + "github.com/cosmos/cosmos-sdk/x/authz" "github.com/cosmos/cosmos-sdk/x/authz/client/cli" - - "github.com/cosmos/cosmos-sdk/x/authz/types" ) func (s *IntegrationTestSuite) TestQueryAuthorizations() { @@ -85,7 +84,7 @@ func (s *IntegrationTestSuite) TestQueryAuthorizations() { s.Require().Contains(string(resp.Bytes()), tc.expErrMsg) } else { s.Require().NoError(err) - var grants types.QueryGrantsResponse + var grants authz.QueryGrantsResponse err = val.ClientCtx.JSONMarshaler.UnmarshalJSON(resp.Bytes(), &grants) s.Require().NoError(err) } diff --git a/x/authz/types/codec.go b/x/authz/codec/codec.go similarity index 80% rename from x/authz/types/codec.go rename to x/authz/codec/codec.go index af42b67c230d..ec243f6c45b2 100644 --- a/x/authz/types/codec.go +++ b/x/authz/codec/codec.go @@ -12,18 +12,18 @@ import ( // RegisterInterfaces registers the interfaces types with the interface registry func RegisterInterfaces(registry types.InterfaceRegistry) { registry.RegisterImplementations((*sdk.MsgRequest)(nil), - &MsgGrant{}, - &MsgRevoke{}, - &MsgExec{}, + &authz.MsgGrant{}, + &authz.MsgRevoke{}, + &authz.MsgExec{}, ) registry.RegisterInterface( "cosmos.authz.v1beta1.Authorization", (*authz.Authorization)(nil), &bank.SendAuthorization{}, - &GenericAuthorization{}, + &authz.GenericAuthorization{}, &staking.StakeAuthorization{}, ) - msgservice.RegisterMsgServiceDesc(registry, &_Msg_serviceDesc) + msgservice.RegisterMsgServiceDesc(registry, authz.MsgServiceDesc()) } diff --git a/x/authz/types/errors.go b/x/authz/errors.go similarity index 94% rename from x/authz/types/errors.go rename to x/authz/errors.go index dc4357b1f9a2..02251c8d6f7e 100644 --- a/x/authz/types/errors.go +++ b/x/authz/errors.go @@ -1,4 +1,4 @@ -package types +package authz import ( sdkerrors "github.com/cosmos/cosmos-sdk/types/errors" diff --git a/x/authz/types/event.pb.go b/x/authz/event.pb.go similarity index 98% rename from x/authz/types/event.pb.go rename to x/authz/event.pb.go index 8f1d7ad60b48..4737782814c8 100644 --- a/x/authz/types/event.pb.go +++ b/x/authz/event.pb.go @@ -1,7 +1,7 @@ // Code generated by protoc-gen-gogo. DO NOT EDIT. // source: cosmos/authz/v1beta1/event.proto -package types +package authz import ( fmt "fmt" @@ -158,7 +158,7 @@ func init() { func init() { proto.RegisterFile("cosmos/authz/v1beta1/event.proto", fileDescriptor_1f88cbc71a8baf1f) } var fileDescriptor_1f88cbc71a8baf1f = []byte{ - // 213 bytes of a gzipped FileDescriptorProto + // 210 bytes of a gzipped FileDescriptorProto 0x1f, 0x8b, 0x08, 0x00, 0x00, 0x00, 0x00, 0x00, 0x02, 0xff, 0xe2, 0x52, 0x48, 0xce, 0x2f, 0xce, 0xcd, 0x2f, 0xd6, 0x4f, 0x2c, 0x2d, 0xc9, 0xa8, 0xd2, 0x2f, 0x33, 0x4c, 0x4a, 0x2d, 0x49, 0x34, 0xd4, 0x4f, 0x2d, 0x4b, 0xcd, 0x2b, 0xd1, 0x2b, 0x28, 0xca, 0x2f, 0xc9, 0x17, 0x12, 0x81, 0xa8, @@ -167,12 +167,12 @@ var fileDescriptor_1f88cbc71a8baf1f = []byte{ 0x2d, 0xca, 0x91, 0x60, 0x52, 0x60, 0xd4, 0xe0, 0x0c, 0xe2, 0xca, 0x2d, 0x4e, 0x0f, 0xa9, 0x2c, 0x48, 0x0d, 0x2d, 0xca, 0x11, 0x92, 0xe0, 0x62, 0x4f, 0x07, 0x29, 0x4d, 0x2d, 0x92, 0x60, 0x06, 0x4b, 0xc2, 0xb8, 0x08, 0x99, 0x54, 0x09, 0x16, 0x64, 0x99, 0x54, 0xa5, 0x64, 0x2e, 0x6e, 0xb0, - 0x1d, 0x41, 0xa9, 0x65, 0xf9, 0xd9, 0xa9, 0xb4, 0xb1, 0xc4, 0xc9, 0xe5, 0xc4, 0x23, 0x39, 0xc6, + 0x1d, 0x41, 0xa9, 0x65, 0xf9, 0xd9, 0xa9, 0xb4, 0xb1, 0xc4, 0xc9, 0xee, 0xc4, 0x23, 0x39, 0xc6, 0x0b, 0x8f, 0xe4, 0x18, 0x1f, 0x3c, 0x92, 0x63, 0x9c, 0xf0, 0x58, 0x8e, 0xe1, 0xc2, 0x63, 0x39, - 0x86, 0x1b, 0x8f, 0xe5, 0x18, 0xa2, 0xb4, 0xd2, 0x33, 0x4b, 0x32, 0x4a, 0x93, 0xf4, 0x92, 0xf3, - 0x73, 0xf5, 0xa1, 0xa1, 0x04, 0xa1, 0x74, 0x8b, 0x53, 0xb2, 0xf5, 0x2b, 0xa0, 0x41, 0x06, 0x72, - 0x4e, 0x71, 0x12, 0x1b, 0x38, 0xac, 0x8c, 0x01, 0x01, 0x00, 0x00, 0xff, 0xff, 0xcf, 0xa7, 0xc5, - 0x7e, 0x4f, 0x01, 0x00, 0x00, + 0x86, 0x1b, 0x8f, 0xe5, 0x18, 0xa2, 0x54, 0xd2, 0x33, 0x4b, 0x32, 0x4a, 0x93, 0xf4, 0x92, 0xf3, + 0x73, 0xf5, 0xa1, 0xa1, 0x04, 0xa1, 0x74, 0x8b, 0x53, 0xb2, 0xf5, 0x2b, 0x20, 0x41, 0x96, 0xc4, + 0x06, 0x0e, 0x25, 0x63, 0x40, 0x00, 0x00, 0x00, 0xff, 0xff, 0x98, 0xf0, 0x6c, 0x35, 0x49, 0x01, + 0x00, 0x00, } func (m *EventGrant) Marshal() (dAtA []byte, err error) { diff --git a/x/authz/types/expected_keepers.go b/x/authz/expected_keepers.go similarity index 70% rename from x/authz/types/expected_keepers.go rename to x/authz/expected_keepers.go index ef7869dd2c7d..bd1f792ef1c3 100644 --- a/x/authz/types/expected_keepers.go +++ b/x/authz/expected_keepers.go @@ -1,13 +1,13 @@ -package types +package authz import ( sdk "github.com/cosmos/cosmos-sdk/types" - "github.com/cosmos/cosmos-sdk/x/auth/types" + authtypes "github.com/cosmos/cosmos-sdk/x/auth/types" ) // AccountKeeper defines the expected account keeper (noalias) type AccountKeeper interface { - GetAccount(ctx sdk.Context, addr sdk.AccAddress) types.AccountI + GetAccount(ctx sdk.Context, addr sdk.AccAddress) authtypes.AccountI } // BankKeeper defines the expected interface needed to retrieve account balances. diff --git a/x/authz/types/generic_authorization.go b/x/authz/generic_authorization.go similarity index 81% rename from x/authz/types/generic_authorization.go rename to x/authz/generic_authorization.go index df7991d2b395..ba843c56b26f 100644 --- a/x/authz/types/generic_authorization.go +++ b/x/authz/generic_authorization.go @@ -1,14 +1,13 @@ -package types +package authz import ( sdk "github.com/cosmos/cosmos-sdk/types" sdkerrors "github.com/cosmos/cosmos-sdk/types/errors" "github.com/cosmos/cosmos-sdk/types/msgservice" - "github.com/cosmos/cosmos-sdk/x/authz" ) var ( - _ authz.Authorization = &GenericAuthorization{} + _ Authorization = &GenericAuthorization{} ) // NewGenericAuthorization creates a new GenericAuthorization object. @@ -24,8 +23,8 @@ func (a GenericAuthorization) MsgTypeURL() string { } // Accept implements Authorization.Accept. -func (a GenericAuthorization) Accept(ctx sdk.Context, msg sdk.ServiceMsg) (authz.AcceptResponse, error) { - return authz.AcceptResponse{Accept: true}, nil +func (a GenericAuthorization) Accept(ctx sdk.Context, msg sdk.ServiceMsg) (AcceptResponse, error) { + return AcceptResponse{Accept: true}, nil } // ValidateBasic implements Authorization.ValidateBasic. diff --git a/x/authz/types/generic_authorization_test.go b/x/authz/generic_authorization_test.go similarity index 72% rename from x/authz/types/generic_authorization_test.go rename to x/authz/generic_authorization_test.go index f13c927bc007..65b035197d28 100644 --- a/x/authz/types/generic_authorization_test.go +++ b/x/authz/generic_authorization_test.go @@ -1,21 +1,21 @@ -package types_test +package authz_test import ( "testing" "github.com/stretchr/testify/require" - "github.com/cosmos/cosmos-sdk/x/authz/types" + "github.com/cosmos/cosmos-sdk/x/authz" banktypes "github.com/cosmos/cosmos-sdk/x/bank/types" ) func TestGenericAuthorization(t *testing.T) { t.Log("verify ValidateBasic returns error for non-service msg") - authorization := types.NewGenericAuthorization(banktypes.TypeMsgSend) + authorization := authz.NewGenericAuthorization(banktypes.TypeMsgSend) require.Error(t, authorization.ValidateBasic()) t.Log("verify ValidateBasic returns nil for service msg") - authorization = types.NewGenericAuthorization(banktypes.SendAuthorization{}.MsgTypeURL()) + authorization = authz.NewGenericAuthorization(banktypes.SendAuthorization{}.MsgTypeURL()) require.NoError(t, authorization.ValidateBasic()) require.Equal(t, banktypes.SendAuthorization{}.MsgTypeURL(), authorization.Msg) } diff --git a/x/authz/types/genesis.go b/x/authz/genesis.go similarity index 69% rename from x/authz/types/genesis.go rename to x/authz/genesis.go index 79a68248c73f..d14bbbb18a8c 100644 --- a/x/authz/types/genesis.go +++ b/x/authz/genesis.go @@ -1,8 +1,7 @@ -package types +package authz import ( - "github.com/cosmos/cosmos-sdk/codec/types" - "github.com/cosmos/cosmos-sdk/x/authz" + cdctypes "github.com/cosmos/cosmos-sdk/codec/types" ) // NewGenesisState creates new GenesisState object @@ -22,10 +21,10 @@ func DefaultGenesisState() *GenesisState { return &GenesisState{} } -var _ types.UnpackInterfacesMessage = GenesisState{} +var _ cdctypes.UnpackInterfacesMessage = GenesisState{} // UnpackInterfaces implements UnpackInterfacesMessage.UnpackInterfaces -func (data GenesisState) UnpackInterfaces(unpacker types.AnyUnpacker) error { +func (data GenesisState) UnpackInterfaces(unpacker cdctypes.AnyUnpacker) error { for _, a := range data.Authorization { err := a.UnpackInterfaces(unpacker) if err != nil { @@ -36,7 +35,7 @@ func (data GenesisState) UnpackInterfaces(unpacker types.AnyUnpacker) error { } // UnpackInterfaces implements UnpackInterfacesMessage.UnpackInterfaces -func (msg GrantAuthorization) UnpackInterfaces(unpacker types.AnyUnpacker) error { - var a authz.Authorization +func (msg GrantAuthorization) UnpackInterfaces(unpacker cdctypes.AnyUnpacker) error { + var a Authorization return unpacker.UnpackAny(msg.Authorization, &a) } diff --git a/x/authz/types/genesis.pb.go b/x/authz/genesis.pb.go similarity index 88% rename from x/authz/types/genesis.pb.go rename to x/authz/genesis.pb.go index eec163fc12ac..eb6b63d4c72b 100644 --- a/x/authz/types/genesis.pb.go +++ b/x/authz/genesis.pb.go @@ -1,7 +1,7 @@ // Code generated by protoc-gen-gogo. DO NOT EDIT. // source: cosmos/authz/v1beta1/genesis.proto -package types +package authz import ( fmt "fmt" @@ -153,29 +153,29 @@ func init() { } var fileDescriptor_4c2fbb971da7c892 = []byte{ - // 340 bytes of a gzipped FileDescriptorProto + // 337 bytes of a gzipped FileDescriptorProto 0x1f, 0x8b, 0x08, 0x00, 0x00, 0x00, 0x00, 0x00, 0x02, 0xff, 0x6c, 0x52, 0xbb, 0x6e, 0xc2, 0x30, - 0x14, 0x8d, 0x0b, 0xea, 0xc3, 0x94, 0xa1, 0x11, 0x43, 0xca, 0x10, 0x10, 0x53, 0x54, 0x09, 0x5b, - 0xd0, 0x2f, 0x20, 0x42, 0x62, 0xea, 0x42, 0x99, 0xba, 0x54, 0x0e, 0xb8, 0x26, 0x6a, 0x13, 0x47, - 0xb1, 0xa9, 0x80, 0xaf, 0xe0, 0x63, 0xfa, 0x11, 0xa8, 0x13, 0x63, 0x97, 0x3e, 0x04, 0x3f, 0x52, - 0xc5, 0x76, 0x54, 0x08, 0x9d, 0x72, 0x6f, 0xce, 0xb9, 0xe7, 0x1c, 0x5f, 0x1b, 0xb6, 0xc6, 0x5c, - 0x44, 0x5c, 0x60, 0x32, 0x93, 0xd3, 0x25, 0x7e, 0xed, 0x04, 0x54, 0x92, 0x0e, 0x66, 0x34, 0xa6, - 0x22, 0x14, 0x28, 0x49, 0xb9, 0xe4, 0x76, 0x4d, 0x73, 0x90, 0xe2, 0x20, 0xc3, 0xa9, 0x37, 0x18, - 0xe7, 0xec, 0x85, 0x62, 0xc5, 0x09, 0x66, 0x4f, 0x58, 0x86, 0x11, 0x15, 0x92, 0x44, 0x89, 0x1e, - 0xab, 0x5f, 0x17, 0x09, 0x24, 0x5e, 0x18, 0xa8, 0xc6, 0x38, 0xe3, 0xaa, 0xc4, 0x59, 0x95, 0x0f, - 0x68, 0x9f, 0x47, 0x0d, 0x18, 0x53, 0xd5, 0xb4, 0x26, 0xf0, 0x72, 0xa0, 0x33, 0xdd, 0x4b, 0x22, - 0xa9, 0x3d, 0x82, 0xd5, 0x2c, 0x0d, 0x4f, 0xc3, 0x25, 0x91, 0x21, 0x8f, 0x1d, 0xd0, 0x2c, 0x79, - 0x95, 0xae, 0x87, 0xfe, 0x8b, 0x8a, 0x06, 0x29, 0x89, 0x65, 0x6f, 0x9f, 0xef, 0x97, 0xd7, 0x5f, - 0x0d, 0x6b, 0x78, 0x28, 0xd2, 0xfa, 0x04, 0xd0, 0x3e, 0xe6, 0xda, 0x0e, 0x3c, 0x63, 0xd9, 0x5f, - 0x9a, 0x3a, 0xa0, 0x09, 0xbc, 0x8b, 0x61, 0xde, 0xfe, 0x21, 0xd4, 0x39, 0xd9, 0x47, 0xa8, 0x7d, - 0x57, 0x0c, 0x58, 0x6a, 0x02, 0xaf, 0xd2, 0xad, 0x21, 0xbd, 0x14, 0x94, 0x2f, 0x05, 0xf5, 0xe2, - 0x85, 0x7f, 0xf5, 0xfe, 0xd6, 0xae, 0x1e, 0x78, 0x16, 0x92, 0xd9, 0x7d, 0x08, 0xe9, 0x3c, 0x09, - 0x53, 0xad, 0x55, 0x56, 0x5a, 0xf5, 0x23, 0xad, 0x51, 0x7e, 0x03, 0xfe, 0x79, 0x76, 0xbc, 0xd5, - 0x77, 0x03, 0x0c, 0xf7, 0xe6, 0xfc, 0xfe, 0x7a, 0xeb, 0x82, 0xcd, 0xd6, 0x05, 0x3f, 0x5b, 0x17, - 0xac, 0x76, 0xae, 0xb5, 0xd9, 0xb9, 0xd6, 0xc7, 0xce, 0xb5, 0x1e, 0x6e, 0x58, 0x28, 0xa7, 0xb3, - 0x00, 0x8d, 0x79, 0x64, 0x16, 0x6f, 0x3e, 0x6d, 0x31, 0x79, 0xc6, 0x73, 0xf3, 0x3c, 0xe4, 0x22, - 0xa1, 0x22, 0x38, 0x55, 0x7e, 0xb7, 0xbf, 0x01, 0x00, 0x00, 0xff, 0xff, 0x94, 0xbe, 0x5b, 0xfa, - 0x3b, 0x02, 0x00, 0x00, + 0x14, 0x8d, 0x0b, 0xea, 0xc3, 0x94, 0xa1, 0x11, 0x43, 0xca, 0x60, 0x10, 0xea, 0x90, 0x05, 0x5b, + 0xd0, 0xbd, 0x12, 0x51, 0x25, 0xa6, 0x2e, 0x94, 0xa9, 0x4b, 0xe5, 0x80, 0x6b, 0xac, 0x36, 0x31, + 0x8a, 0x4d, 0x05, 0x7c, 0x05, 0x1f, 0xd3, 0x8f, 0x40, 0x9d, 0x18, 0xbb, 0xf4, 0x21, 0xf8, 0x91, + 0x2a, 0x76, 0xa2, 0xf2, 0xe8, 0x94, 0x7b, 0x73, 0xce, 0x3d, 0xe7, 0xf8, 0xda, 0xb0, 0x31, 0x90, + 0x2a, 0x92, 0x8a, 0xd0, 0x89, 0x1e, 0xcd, 0xc9, 0x6b, 0x2b, 0x64, 0x9a, 0xb6, 0x08, 0x67, 0x31, + 0x53, 0x42, 0xe1, 0x71, 0x22, 0xb5, 0x74, 0x2b, 0x96, 0x83, 0x0d, 0x07, 0x67, 0x9c, 0x6a, 0x8d, + 0x4b, 0xc9, 0x5f, 0x18, 0x31, 0x9c, 0x70, 0xf2, 0x44, 0xb4, 0x88, 0x98, 0xd2, 0x34, 0x1a, 0xdb, + 0xb1, 0xea, 0xe5, 0x3e, 0x81, 0xc6, 0xb3, 0x0c, 0xaa, 0x70, 0xc9, 0xa5, 0x29, 0x49, 0x5a, 0xe5, + 0x03, 0xd6, 0xe7, 0xd1, 0x02, 0x99, 0xa9, 0x69, 0x1a, 0x43, 0x78, 0xde, 0xb5, 0x99, 0xee, 0x35, + 0xd5, 0xcc, 0xed, 0xc3, 0x72, 0x9a, 0x46, 0x26, 0x62, 0x4e, 0xb5, 0x90, 0xb1, 0x07, 0xea, 0x05, + 0xbf, 0xd4, 0xf6, 0xf1, 0x7f, 0x51, 0x71, 0x37, 0xa1, 0xb1, 0xee, 0x6c, 0xf3, 0x83, 0xe2, 0xf2, + 0xab, 0xe6, 0xf4, 0x76, 0x45, 0x1a, 0x9f, 0x00, 0xba, 0x87, 0x5c, 0xd7, 0x83, 0x27, 0x3c, 0xfd, + 0xcb, 0x12, 0x0f, 0xd4, 0x81, 0x7f, 0xd6, 0xcb, 0xdb, 0x3f, 0x84, 0x79, 0x47, 0xdb, 0x08, 0x73, + 0xef, 0xf6, 0x03, 0x16, 0xea, 0xc0, 0x2f, 0xb5, 0x2b, 0xd8, 0x2e, 0x05, 0xe7, 0x4b, 0xc1, 0x9d, + 0x78, 0x16, 0x5c, 0xbc, 0xbf, 0x35, 0xcb, 0x3b, 0x9e, 0x7b, 0xc9, 0xdc, 0x5b, 0x08, 0xd9, 0x74, + 0x2c, 0x12, 0xab, 0x55, 0x34, 0x5a, 0xd5, 0x03, 0xad, 0x7e, 0x7e, 0x03, 0xc1, 0x69, 0x7a, 0xbc, + 0xc5, 0x77, 0x0d, 0xf4, 0xb6, 0xe6, 0x82, 0x9b, 0xe5, 0x1a, 0x81, 0xd5, 0x1a, 0x81, 0x9f, 0x35, + 0x02, 0x8b, 0x0d, 0x72, 0x56, 0x1b, 0xe4, 0x7c, 0x6c, 0x90, 0xf3, 0x70, 0xc5, 0x85, 0x1e, 0x4d, + 0x42, 0x3c, 0x90, 0x51, 0xb6, 0xf8, 0xec, 0xd3, 0x54, 0xc3, 0x67, 0x32, 0xb5, 0xcf, 0x23, 0x3c, + 0x36, 0x4e, 0xd7, 0xbf, 0x01, 0x00, 0x00, 0xff, 0xff, 0x7c, 0xdb, 0x6c, 0xcb, 0x35, 0x02, 0x00, + 0x00, } func (m *GenesisState) Marshal() (dAtA []byte, err error) { diff --git a/x/authz/keeper/grpc_query.go b/x/authz/keeper/grpc_query.go index d4682b894ef0..4bf6d975f4bc 100644 --- a/x/authz/keeper/grpc_query.go +++ b/x/authz/keeper/grpc_query.go @@ -13,13 +13,13 @@ import ( "github.com/cosmos/cosmos-sdk/store/prefix" sdk "github.com/cosmos/cosmos-sdk/types" "github.com/cosmos/cosmos-sdk/types/query" - "github.com/cosmos/cosmos-sdk/x/authz/types" + "github.com/cosmos/cosmos-sdk/x/authz" ) -var _ types.QueryServer = Keeper{} +var _ authz.QueryServer = Keeper{} // Authorizations implements the Query/Grants gRPC method. -func (k Keeper) Grants(c context.Context, req *types.QueryGrantsRequest) (*types.QueryGrantsResponse, error) { +func (k Keeper) Grants(c context.Context, req *authz.QueryGrantsRequest) (*authz.QueryGrantsResponse, error) { if req == nil { return nil, status.Errorf(codes.InvalidArgument, "empty request") } @@ -48,15 +48,15 @@ func (k Keeper) Grants(c context.Context, req *types.QueryGrantsRequest) (*types if err != nil { return nil, status.Errorf(codes.Internal, err.Error()) } - return &types.QueryGrantsResponse{ - Grants: []*types.Grant{{ + return &authz.QueryGrantsResponse{ + Grants: []*authz.Grant{{ Authorization: authorizationAny, Expiration: expiration, }}, }, nil } - var authorizations []*types.Grant + var authorizations []*authz.Grant pageRes, err := query.FilteredPaginate(authStore, req.Pagination, func(key []byte, value []byte, accumulate bool) (bool, error) { auth, err := unmarshalAuthorization(k.cdc, value) if err != nil { @@ -73,7 +73,7 @@ func (k Keeper) Grants(c context.Context, req *types.QueryGrantsRequest) (*types if err != nil { return false, status.Errorf(codes.Internal, err.Error()) } - authorizations = append(authorizations, &types.Grant{ + authorizations = append(authorizations, &authz.Grant{ Authorization: authorizationAny, Expiration: auth.Expiration, }) @@ -84,14 +84,14 @@ func (k Keeper) Grants(c context.Context, req *types.QueryGrantsRequest) (*types return nil, err } - return &types.QueryGrantsResponse{ + return &authz.QueryGrantsResponse{ Grants: authorizations, Pagination: pageRes, }, nil } // unmarshal an authorization from a store value -func unmarshalAuthorization(cdc codec.BinaryMarshaler, value []byte) (v types.Grant, err error) { +func unmarshalAuthorization(cdc codec.BinaryMarshaler, value []byte) (v authz.Grant, err error) { err = cdc.UnmarshalBinaryBare(value, &v) return v, err } diff --git a/x/authz/keeper/grpc_query_test.go b/x/authz/keeper/grpc_query_test.go index cdd2ba68fe10..80ddf4dc136e 100644 --- a/x/authz/keeper/grpc_query_test.go +++ b/x/authz/keeper/grpc_query_test.go @@ -7,7 +7,6 @@ import ( sdk "github.com/cosmos/cosmos-sdk/types" "github.com/cosmos/cosmos-sdk/x/authz" - "github.com/cosmos/cosmos-sdk/x/authz/types" banktypes "github.com/cosmos/cosmos-sdk/x/bank/types" "github.com/stretchr/testify/require" ) @@ -15,44 +14,44 @@ import ( func (suite *TestSuite) TestGRPCQueryAuthorization() { app, ctx, queryClient, addrs := suite.app, suite.ctx, suite.queryClient, suite.addrs var ( - req *types.QueryGrantsRequest + req *authz.QueryGrantsRequest expAuthorization authz.Authorization ) testCases := []struct { msg string malleate func(require *require.Assertions) expError string - postTest func(require *require.Assertions, res *types.QueryGrantsResponse) + postTest func(require *require.Assertions, res *authz.QueryGrantsResponse) }{ { "fail invalid granter addr", func(require *require.Assertions) { - req = &types.QueryGrantsRequest{} + req = &authz.QueryGrantsRequest{} }, "empty address string is not allowed", - func(require *require.Assertions, res *types.QueryGrantsResponse) {}, + func(require *require.Assertions, res *authz.QueryGrantsResponse) {}, }, { "fail invalid grantee addr", func(require *require.Assertions) { - req = &types.QueryGrantsRequest{ + req = &authz.QueryGrantsRequest{ Granter: addrs[0].String(), } }, "empty address string is not allowed", - func(require *require.Assertions, res *types.QueryGrantsResponse) {}, + func(require *require.Assertions, res *authz.QueryGrantsResponse) {}, }, { "fail invalid msg-type", func(require *require.Assertions) { - req = &types.QueryGrantsRequest{ + req = &authz.QueryGrantsRequest{ Granter: addrs[0].String(), Grantee: addrs[1].String(), MsgTypeUrl: "unknown", } }, "no authorization found for unknown type", - func(require *require.Assertions, res *types.QueryGrantsResponse) {}, + func(require *require.Assertions, res *authz.QueryGrantsResponse) {}, }, { "Success", @@ -62,14 +61,14 @@ func (suite *TestSuite) TestGRPCQueryAuthorization() { expAuthorization = &banktypes.SendAuthorization{SpendLimit: newCoins} err := app.AuthzKeeper.SaveGrant(ctx, addrs[0], addrs[1], expAuthorization, now.Add(time.Hour)) require.NoError(err) - req = &types.QueryGrantsRequest{ + req = &authz.QueryGrantsRequest{ Granter: addrs[1].String(), Grantee: addrs[0].String(), MsgTypeUrl: expAuthorization.MsgTypeURL(), } }, "", - func(require *require.Assertions, res *types.QueryGrantsResponse) { + func(require *require.Assertions, res *authz.QueryGrantsResponse) { var auth authz.Authorization require.Equal(1, len(res.Grants)) err := suite.app.InterfaceRegistry().UnpackAny(res.Grants[0].Authorization, &auth) @@ -98,32 +97,32 @@ func (suite *TestSuite) TestGRPCQueryAuthorization() { func (suite *TestSuite) TestGRPCQueryAuthorizations() { app, ctx, queryClient, addrs := suite.app, suite.ctx, suite.queryClient, suite.addrs var ( - req *types.QueryGrantsRequest + req *authz.QueryGrantsRequest expAuthorization authz.Authorization ) testCases := []struct { msg string malleate func() expPass bool - postTest func(res *types.QueryGrantsResponse) + postTest func(res *authz.QueryGrantsResponse) }{ { "fail invalid granter addr", func() { - req = &types.QueryGrantsRequest{} + req = &authz.QueryGrantsRequest{} }, false, - func(res *types.QueryGrantsResponse) {}, + func(res *authz.QueryGrantsResponse) {}, }, { "fail invalid grantee addr", func() { - req = &types.QueryGrantsRequest{ + req = &authz.QueryGrantsRequest{ Granter: addrs[0].String(), } }, false, - func(res *types.QueryGrantsResponse) {}, + func(res *authz.QueryGrantsResponse) {}, }, { "Success", @@ -133,13 +132,13 @@ func (suite *TestSuite) TestGRPCQueryAuthorizations() { expAuthorization = &banktypes.SendAuthorization{SpendLimit: newCoins} err := app.AuthzKeeper.SaveGrant(ctx, addrs[0], addrs[1], expAuthorization, now.Add(time.Hour)) suite.Require().NoError(err) - req = &types.QueryGrantsRequest{ + req = &authz.QueryGrantsRequest{ Granter: addrs[1].String(), Grantee: addrs[0].String(), } }, true, - func(res *types.QueryGrantsResponse) { + func(res *authz.QueryGrantsResponse) { var auth authz.Authorization suite.Require().Equal(1, len(res.Grants)) err := suite.app.InterfaceRegistry().UnpackAny(res.Grants[0].Authorization, &auth) diff --git a/x/authz/keeper/keeper.go b/x/authz/keeper/keeper.go index 97dea9162d4b..0bcdf2f7fc5c 100644 --- a/x/authz/keeper/keeper.go +++ b/x/authz/keeper/keeper.go @@ -14,7 +14,6 @@ import ( sdk "github.com/cosmos/cosmos-sdk/types" sdkerrors "github.com/cosmos/cosmos-sdk/types/errors" "github.com/cosmos/cosmos-sdk/x/authz" - "github.com/cosmos/cosmos-sdk/x/authz/types" ) type Keeper struct { @@ -34,11 +33,11 @@ func NewKeeper(storeKey sdk.StoreKey, cdc codec.BinaryMarshaler, router *baseapp // Logger returns a module-specific logger. func (k Keeper) Logger(ctx sdk.Context) log.Logger { - return ctx.Logger().With("module", fmt.Sprintf("x/%s", types.ModuleName)) + return ctx.Logger().With("module", fmt.Sprintf("x/%s", authz.ModuleName)) } // getGrant returns grant stored at skey. -func (k Keeper) getGrant(ctx sdk.Context, skey []byte) (grant types.Grant, found bool) { +func (k Keeper) getGrant(ctx sdk.Context, skey []byte) (grant authz.Grant, found bool) { store := ctx.KVStore(k.storeKey) bz := store.Get(skey) if bz == nil { @@ -125,7 +124,7 @@ func (k Keeper) DispatchActions(ctx sdk.Context, grantee sdk.AccAddress, service func (k Keeper) SaveGrant(ctx sdk.Context, grantee, granter sdk.AccAddress, authorization authz.Authorization, expiration time.Time) error { store := ctx.KVStore(k.storeKey) - grant, err := types.NewGrant(authorization, expiration) + grant, err := authz.NewGrant(authorization, expiration) if err != nil { return err } @@ -134,7 +133,7 @@ func (k Keeper) SaveGrant(ctx sdk.Context, grantee, granter sdk.AccAddress, auth bz := k.cdc.MustMarshalBinaryBare(&grant) skey := grantStoreKey(grantee, granter, authorization.MsgTypeURL()) store.Set(skey, bz) - return ctx.EventManager().EmitTypedEvent(&types.EventGrant{ + return ctx.EventManager().EmitTypedEvent(&authz.EventGrant{ MsgTypeUrl: authorization.MsgTypeURL(), Granter: granter.String(), Grantee: grantee.String(), @@ -151,7 +150,7 @@ func (k Keeper) DeleteGrant(ctx sdk.Context, grantee sdk.AccAddress, granter sdk return sdkerrors.ErrNotFound.Wrap("authorization not found") } store.Delete(skey) - return ctx.EventManager().EmitTypedEvent(&types.EventRevoke{ + return ctx.EventManager().EmitTypedEvent(&authz.EventRevoke{ MsgTypeUrl: msgType, Granter: granter.String(), Grantee: grantee.String(), @@ -164,7 +163,7 @@ func (k Keeper) GetAuthorizations(ctx sdk.Context, grantee sdk.AccAddress, grant key := grantStoreKey(grantee, granter, "") iter := sdk.KVStorePrefixIterator(store, key) defer iter.Close() - var authorization types.Grant + var authorization authz.Grant for ; iter.Valid(); iter.Next() { k.cdc.MustUnmarshalBinaryBare(iter.Value(), &authorization) authorizations = append(authorizations, authorization.GetAuthorization()) @@ -192,12 +191,12 @@ func (k Keeper) GetCleanAuthorization(ctx sdk.Context, grantee sdk.AccAddress, g // This function should be used with caution because it can involve significant IO operations. // It should not be used in query or msg services without charging additional gas. func (k Keeper) IterateGrants(ctx sdk.Context, - handler func(granterAddr sdk.AccAddress, granteeAddr sdk.AccAddress, grant types.Grant) bool) { + handler func(granterAddr sdk.AccAddress, granteeAddr sdk.AccAddress, grant authz.Grant) bool) { store := ctx.KVStore(k.storeKey) - iter := sdk.KVStorePrefixIterator(store, types.GrantKey) + iter := sdk.KVStorePrefixIterator(store, authz.GrantKey) defer iter.Close() for ; iter.Valid(); iter.Next() { - var grant types.Grant + var grant authz.Grant granterAddr, granteeAddr := addressesFromGrantStoreKey(iter.Key()) k.cdc.MustUnmarshalBinaryBare(iter.Value(), &grant) if handler(granterAddr, granteeAddr, grant) { @@ -207,11 +206,11 @@ func (k Keeper) IterateGrants(ctx sdk.Context, } // ExportGenesis returns a GenesisState for a given context. -func (k Keeper) ExportGenesis(ctx sdk.Context) *types.GenesisState { - var entries []types.GrantAuthorization - k.IterateGrants(ctx, func(granter, grantee sdk.AccAddress, grant types.Grant) bool { +func (k Keeper) ExportGenesis(ctx sdk.Context) *authz.GenesisState { + var entries []authz.GrantAuthorization + k.IterateGrants(ctx, func(granter, grantee sdk.AccAddress, grant authz.Grant) bool { exp := grant.Expiration - entries = append(entries, types.GrantAuthorization{ + entries = append(entries, authz.GrantAuthorization{ Granter: granter.String(), Grantee: grantee.String(), Expiration: exp, @@ -220,11 +219,11 @@ func (k Keeper) ExportGenesis(ctx sdk.Context) *types.GenesisState { return false }) - return types.NewGenesisState(entries) + return authz.NewGenesisState(entries) } // InitGenesis new authz genesis -func (k Keeper) InitGenesis(ctx sdk.Context, data *types.GenesisState) { +func (k Keeper) InitGenesis(ctx sdk.Context, data *authz.GenesisState) { for _, entry := range data.Authorization { grantee, err := sdk.AccAddressFromBech32(entry.Grantee) if err != nil { diff --git a/x/authz/keeper/keeper_test.go b/x/authz/keeper/keeper_test.go index 85bf91e19447..703a17268f1b 100644 --- a/x/authz/keeper/keeper_test.go +++ b/x/authz/keeper/keeper_test.go @@ -5,17 +5,14 @@ import ( "time" proto "github.com/gogo/protobuf/proto" - - "github.com/cosmos/cosmos-sdk/baseapp" - + "github.com/stretchr/testify/suite" tmproto "github.com/tendermint/tendermint/proto/tendermint/types" tmtime "github.com/tendermint/tendermint/types/time" - "github.com/stretchr/testify/suite" - + "github.com/cosmos/cosmos-sdk/baseapp" "github.com/cosmos/cosmos-sdk/simapp" sdk "github.com/cosmos/cosmos-sdk/types" - "github.com/cosmos/cosmos-sdk/x/authz/types" + "github.com/cosmos/cosmos-sdk/x/authz" banktypes "github.com/cosmos/cosmos-sdk/x/bank/types" ) @@ -27,7 +24,7 @@ type TestSuite struct { app *simapp.SimApp ctx sdk.Context addrs []sdk.AccAddress - queryClient types.QueryClient + queryClient authz.QueryClient } func (s *TestSuite) SetupTest() { @@ -36,8 +33,8 @@ func (s *TestSuite) SetupTest() { now := tmtime.Now() ctx = ctx.WithBlockHeader(tmproto.Header{Time: now}) queryHelper := baseapp.NewQueryServerTestHelper(ctx, app.InterfaceRegistry()) - types.RegisterQueryServer(queryHelper, app.AuthzKeeper) - queryClient := types.NewQueryClient(queryHelper) + authz.RegisterQueryServer(queryHelper, app.AuthzKeeper) + queryClient := authz.NewQueryClient(queryHelper) s.queryClient = queryClient s.app = app @@ -120,7 +117,7 @@ func (s *TestSuite) TestKeeperIter() { authorization, _ = app.AuthzKeeper.GetCleanAuthorization(ctx, granteeAddr, granterAddr, "abcd") s.Require().Nil(authorization) - app.AuthzKeeper.IterateGrants(ctx, func(granter, grantee sdk.AccAddress, grant types.Grant) bool { + app.AuthzKeeper.IterateGrants(ctx, func(granter, grantee sdk.AccAddress, grant authz.Grant) bool { s.Require().Equal(granter, granterAddr) s.Require().Equal(grantee, granteeAddr) return true @@ -141,7 +138,7 @@ func (s *TestSuite) TestKeeperFees() { smallCoin := sdk.NewCoins(sdk.NewInt64Coin("steak", 20)) someCoin := sdk.NewCoins(sdk.NewInt64Coin("steak", 123)) - msgs := types.NewMsgExec(granteeAddr, []sdk.ServiceMsg{ + msgs := authz.NewMsgExec(granteeAddr, []sdk.ServiceMsg{ { MethodName: bankSendAuthMsgType, Request: &banktypes.MsgSend{ @@ -184,7 +181,7 @@ func (s *TestSuite) TestKeeperFees() { s.T().Log("verify dispatch fails with overlimit") // grant authorization - msgs = types.NewMsgExec(granteeAddr, []sdk.ServiceMsg{ + msgs = authz.NewMsgExec(granteeAddr, []sdk.ServiceMsg{ { MethodName: bankSendAuthMsgType, Request: &banktypes.MsgSend{ diff --git a/x/authz/keeper/keys.go b/x/authz/keeper/keys.go index 9c44c0f03292..d4e79708e091 100644 --- a/x/authz/keeper/keys.go +++ b/x/authz/keeper/keys.go @@ -3,13 +3,13 @@ package keeper import ( sdk "github.com/cosmos/cosmos-sdk/types" "github.com/cosmos/cosmos-sdk/types/address" - "github.com/cosmos/cosmos-sdk/x/authz/types" + "github.com/cosmos/cosmos-sdk/x/authz" ) // grantStoreKey - return authorization store key func grantStoreKey(grantee sdk.AccAddress, granter sdk.AccAddress, msgType string) []byte { return append(append(append( - types.GrantKey, + authz.GrantKey, address.MustLengthPrefix(granter)...), address.MustLengthPrefix(grantee)...), []byte(msgType)..., diff --git a/x/authz/keeper/msg_server.go b/x/authz/keeper/msg_server.go index 23f318bc44b2..b60bbe49e8a9 100644 --- a/x/authz/keeper/msg_server.go +++ b/x/authz/keeper/msg_server.go @@ -5,13 +5,13 @@ import ( sdk "github.com/cosmos/cosmos-sdk/types" sdkerrors "github.com/cosmos/cosmos-sdk/types/errors" - "github.com/cosmos/cosmos-sdk/x/authz/types" + "github.com/cosmos/cosmos-sdk/x/authz" ) -var _ types.MsgServer = Keeper{} +var _ authz.MsgServer = Keeper{} // GrantAuthorization implements the MsgServer.Grant method. -func (k Keeper) Grant(goCtx context.Context, msg *types.MsgGrant) (*types.MsgGrantResponse, error) { +func (k Keeper) Grant(goCtx context.Context, msg *authz.MsgGrant) (*authz.MsgGrantResponse, error) { ctx := sdk.UnwrapSDKContext(goCtx) grantee, err := sdk.AccAddressFromBech32(msg.Grantee) if err != nil { @@ -36,11 +36,11 @@ func (k Keeper) Grant(goCtx context.Context, msg *types.MsgGrant) (*types.MsgGra return nil, err } - return &types.MsgGrantResponse{}, nil + return &authz.MsgGrantResponse{}, nil } // RevokeAuthorization implements the MsgServer.Revoke method. -func (k Keeper) Revoke(goCtx context.Context, msg *types.MsgRevoke) (*types.MsgRevokeResponse, error) { +func (k Keeper) Revoke(goCtx context.Context, msg *authz.MsgRevoke) (*authz.MsgRevokeResponse, error) { ctx := sdk.UnwrapSDKContext(goCtx) grantee, err := sdk.AccAddressFromBech32(msg.Grantee) if err != nil { @@ -56,11 +56,11 @@ func (k Keeper) Revoke(goCtx context.Context, msg *types.MsgRevoke) (*types.MsgR return nil, err } - return &types.MsgRevokeResponse{}, nil + return &authz.MsgRevokeResponse{}, nil } // Exec implements the MsgServer.Exec method. -func (k Keeper) Exec(goCtx context.Context, msg *types.MsgExec) (*types.MsgExecResponse, error) { +func (k Keeper) Exec(goCtx context.Context, msg *authz.MsgExec) (*authz.MsgExecResponse, error) { ctx := sdk.UnwrapSDKContext(goCtx) grantee, err := sdk.AccAddressFromBech32(msg.Grantee) if err != nil { @@ -74,5 +74,5 @@ func (k Keeper) Exec(goCtx context.Context, msg *types.MsgExec) (*types.MsgExecR if err != nil { return nil, err } - return &types.MsgExecResponse{Result: result}, nil + return &authz.MsgExecResponse{Result: result}, nil } diff --git a/x/authz/types/keys.go b/x/authz/keys.go similarity index 97% rename from x/authz/types/keys.go rename to x/authz/keys.go index be75dc045cdc..c609c6d3b083 100644 --- a/x/authz/types/keys.go +++ b/x/authz/keys.go @@ -1,4 +1,4 @@ -package types +package authz const ( // ModuleName is the module name constant used in many places diff --git a/x/authz/module/module.go b/x/authz/module/module.go index 479109bd8796..c4da61840641 100644 --- a/x/authz/module/module.go +++ b/x/authz/module/module.go @@ -16,12 +16,11 @@ import ( sdk "github.com/cosmos/cosmos-sdk/types" sdkerrors "github.com/cosmos/cosmos-sdk/types/errors" "github.com/cosmos/cosmos-sdk/types/module" - "github.com/cosmos/cosmos-sdk/x/authz/keeper" - "github.com/cosmos/cosmos-sdk/x/authz/types" - simtypes "github.com/cosmos/cosmos-sdk/types/simulation" - + "github.com/cosmos/cosmos-sdk/x/authz" "github.com/cosmos/cosmos-sdk/x/authz/client/cli" + authzcdc "github.com/cosmos/cosmos-sdk/x/authz/codec" + "github.com/cosmos/cosmos-sdk/x/authz/keeper" "github.com/cosmos/cosmos-sdk/x/authz/simulation" ) @@ -38,14 +37,14 @@ type AppModuleBasic struct { // Name returns the authz module's name. func (AppModuleBasic) Name() string { - return types.ModuleName + return authz.ModuleName } // RegisterServices registers a gRPC query service to respond to the // module-specific gRPC queries. func (am AppModule) RegisterServices(cfg module.Configurator) { - types.RegisterQueryServer(cfg.QueryServer(), am.keeper) - types.RegisterMsgServer(cfg.MsgServer(), am.keeper) + authz.RegisterQueryServer(cfg.QueryServer(), am.keeper) + authz.RegisterMsgServer(cfg.MsgServer(), am.keeper) } // RegisterLegacyAminoCodec registers the authz module's types for the given codec. @@ -53,23 +52,23 @@ func (AppModuleBasic) RegisterLegacyAminoCodec(cdc *codec.LegacyAmino) {} // RegisterInterfaces registers the authz module's interface types func (AppModuleBasic) RegisterInterfaces(registry cdctypes.InterfaceRegistry) { - types.RegisterInterfaces(registry) + authzcdc.RegisterInterfaces(registry) } // DefaultGenesis returns default genesis state as raw bytes for the authz // module. func (AppModuleBasic) DefaultGenesis(cdc codec.JSONMarshaler) json.RawMessage { - return cdc.MustMarshalJSON(types.DefaultGenesisState()) + return cdc.MustMarshalJSON(authz.DefaultGenesisState()) } // ValidateGenesis performs genesis state validation for the authz module. func (AppModuleBasic) ValidateGenesis(cdc codec.JSONMarshaler, config sdkclient.TxEncodingConfig, bz json.RawMessage) error { - var data types.GenesisState + var data authz.GenesisState if err := cdc.UnmarshalJSON(bz, &data); err != nil { - return sdkerrors.Wrapf(err, "failed to unmarshal %s genesis state", types.ModuleName) + return sdkerrors.Wrapf(err, "failed to unmarshal %s genesis state", authz.ModuleName) } - return types.ValidateGenesis(data) + return authz.ValidateGenesis(data) } // RegisterRESTRoutes registers the REST routes for the authz module. @@ -78,7 +77,7 @@ func (AppModuleBasic) RegisterRESTRoutes(clientCtx sdkclient.Context, r *mux.Rou // RegisterGRPCGatewayRoutes registers the gRPC Gateway routes for the authz module. func (a AppModuleBasic) RegisterGRPCGatewayRoutes(clientCtx sdkclient.Context, mux *runtime.ServeMux) { - types.RegisterQueryHandlerClient(context.Background(), mux, types.NewQueryClient(clientCtx)) + authz.RegisterQueryHandlerClient(context.Background(), mux, authz.NewQueryClient(clientCtx)) } // GetQueryCmd returns the cli query commands for the authz module @@ -95,13 +94,13 @@ func (AppModuleBasic) GetTxCmd() *cobra.Command { type AppModule struct { AppModuleBasic keeper keeper.Keeper - accountKeeper types.AccountKeeper - bankKeeper types.BankKeeper + accountKeeper authz.AccountKeeper + bankKeeper authz.BankKeeper registry cdctypes.InterfaceRegistry } // NewAppModule creates a new AppModule object -func NewAppModule(cdc codec.Marshaler, keeper keeper.Keeper, ak types.AccountKeeper, bk types.BankKeeper, registry cdctypes.InterfaceRegistry) AppModule { +func NewAppModule(cdc codec.Marshaler, keeper keeper.Keeper, ak authz.AccountKeeper, bk authz.BankKeeper, registry cdctypes.InterfaceRegistry) AppModule { return AppModule{ AppModuleBasic: AppModuleBasic{cdc: cdc}, keeper: keeper, @@ -113,7 +112,7 @@ func NewAppModule(cdc codec.Marshaler, keeper keeper.Keeper, ak types.AccountKee // Name returns the authz module's name. func (AppModule) Name() string { - return types.ModuleName + return authz.ModuleName } // RegisterInvariants does nothing, there are no invariants to enforce @@ -121,7 +120,7 @@ func (AppModule) RegisterInvariants(_ sdk.InvariantRegistry) {} // Route returns the message routing key for the staking module. func (am AppModule) Route() sdk.Route { - return sdk.NewRoute(types.RouterKey, nil) + return sdk.NewRoute(authz.RouterKey, nil) } func (am AppModule) NewHandler() sdk.Handler { @@ -139,7 +138,7 @@ func (am AppModule) LegacyQuerierHandler(legacyQuerierCdc *codec.LegacyAmino) sd // InitGenesis performs genesis initialization for the authz module. It returns // no validator updates. func (am AppModule) InitGenesis(ctx sdk.Context, cdc codec.JSONMarshaler, data json.RawMessage) []abci.ValidatorUpdate { - var genesisState types.GenesisState + var genesisState authz.GenesisState cdc.MustUnmarshalJSON(data, &genesisState) am.keeper.InitGenesis(ctx, &genesisState) return []abci.ValidatorUpdate{} @@ -184,7 +183,7 @@ func (AppModule) RandomizedParams(r *rand.Rand) []simtypes.ParamChange { // RegisterStoreDecoder registers a decoder for authz module's types func (am AppModule) RegisterStoreDecoder(sdr sdk.StoreDecoderRegistry) { - sdr[types.StoreKey] = simulation.NewDecodeStore(am.cdc) + sdr[authz.StoreKey] = simulation.NewDecodeStore(am.cdc) } // WeightedOperations returns the all the gov module operations with their respective weights. diff --git a/x/authz/types/msgs.go b/x/authz/msgs.go similarity index 86% rename from x/authz/types/msgs.go rename to x/authz/msgs.go index 664579a95f49..8a47ab05d7f7 100644 --- a/x/authz/types/msgs.go +++ b/x/authz/msgs.go @@ -1,14 +1,13 @@ -package types +package authz import ( "time" "github.com/gogo/protobuf/proto" - "github.com/cosmos/cosmos-sdk/codec/types" + cdctypes "github.com/cosmos/cosmos-sdk/codec/types" sdk "github.com/cosmos/cosmos-sdk/types" sdkerrors "github.com/cosmos/cosmos-sdk/types/errors" - "github.com/cosmos/cosmos-sdk/x/authz" ) var ( @@ -16,13 +15,13 @@ var ( _ sdk.MsgRequest = &MsgRevoke{} _ sdk.MsgRequest = &MsgExec{} - _ types.UnpackInterfacesMessage = &MsgGrant{} - _ types.UnpackInterfacesMessage = &MsgExec{} + _ cdctypes.UnpackInterfacesMessage = &MsgGrant{} + _ cdctypes.UnpackInterfacesMessage = &MsgExec{} ) // NewMsgGrant creates a new MsgGrant //nolint:interfacer -func NewMsgGrant(granter sdk.AccAddress, grantee sdk.AccAddress, a authz.Authorization, expiration time.Time) (*MsgGrant, error) { +func NewMsgGrant(granter sdk.AccAddress, grantee sdk.AccAddress, a Authorization, expiration time.Time) (*MsgGrant, error) { m := &MsgGrant{ Granter: granter.String(), Grantee: grantee.String(), @@ -64,16 +63,16 @@ func (msg MsgGrant) ValidateBasic() error { } av := msg.Authorization.GetCachedValue() - a, ok := av.(authz.Authorization) + a, ok := av.(Authorization) if !ok { - return sdkerrors.Wrapf(sdkerrors.ErrInvalidType, "expected %T, got %T", (authz.Authorization)(nil), av) + return sdkerrors.Wrapf(sdkerrors.ErrInvalidType, "expected %T, got %T", (Authorization)(nil), av) } return a.ValidateBasic() } // GetAuthorization returns the cache value from the MsgGrant.Authorization if present. -func (msg *MsgGrant) GetAuthorization() authz.Authorization { - a, ok := msg.Authorization.GetCachedValue().(authz.Authorization) +func (msg *MsgGrant) GetAuthorization() Authorization { + a, ok := msg.Authorization.GetCachedValue().(Authorization) if !ok { return nil } @@ -81,12 +80,12 @@ func (msg *MsgGrant) GetAuthorization() authz.Authorization { } // SetAuthorization converts Authorization to any and adds it to MsgGrant.Authorization. -func (msg *MsgGrant) SetAuthorization(a authz.Authorization) error { +func (msg *MsgGrant) SetAuthorization(a Authorization) error { m, ok := a.(proto.Message) if !ok { return sdkerrors.Wrapf(sdkerrors.ErrPackAny, "can't proto marshal %T", m) } - any, err := types.NewAnyWithValue(m) + any, err := cdctypes.NewAnyWithValue(m) if err != nil { return err } @@ -95,7 +94,7 @@ func (msg *MsgGrant) SetAuthorization(a authz.Authorization) error { } // UnpackInterfaces implements UnpackInterfacesMessage.UnpackInterfaces -func (msg MsgExec) UnpackInterfaces(unpacker types.AnyUnpacker) error { +func (msg MsgExec) UnpackInterfaces(unpacker cdctypes.AnyUnpacker) error { for _, x := range msg.Msgs { var msgExecAuthorized sdk.MsgRequest err := unpacker.UnpackAny(x, &msgExecAuthorized) @@ -108,8 +107,8 @@ func (msg MsgExec) UnpackInterfaces(unpacker types.AnyUnpacker) error { } // UnpackInterfaces implements UnpackInterfacesMessage.UnpackInterfaces -func (msg MsgGrant) UnpackInterfaces(unpacker types.AnyUnpacker) error { - var a authz.Authorization +func (msg MsgGrant) UnpackInterfaces(unpacker cdctypes.AnyUnpacker) error { + var a Authorization return unpacker.UnpackAny(msg.Authorization, &a) } @@ -157,14 +156,14 @@ func (msg MsgRevoke) ValidateBasic() error { // NewMsgExec creates a new MsgExecAuthorized //nolint:interfacer func NewMsgExec(grantee sdk.AccAddress, msgs []sdk.ServiceMsg) MsgExec { - msgsAny := make([]*types.Any, len(msgs)) + msgsAny := make([]*cdctypes.Any, len(msgs)) for i, msg := range msgs { bz, err := proto.Marshal(msg.Request) if err != nil { panic(err) } - anyMsg := &types.Any{ + anyMsg := &cdctypes.Any{ TypeUrl: msg.MethodName, Value: bz, } diff --git a/x/authz/types/msgs_test.go b/x/authz/msgs_test.go similarity index 93% rename from x/authz/types/msgs_test.go rename to x/authz/msgs_test.go index 2784933faf6b..1eba1e6f6556 100644 --- a/x/authz/types/msgs_test.go +++ b/x/authz/msgs_test.go @@ -1,4 +1,4 @@ -package types_test +package authz_test import ( "testing" @@ -8,7 +8,6 @@ import ( sdk "github.com/cosmos/cosmos-sdk/types" "github.com/cosmos/cosmos-sdk/x/authz" - "github.com/cosmos/cosmos-sdk/x/authz/types" banktypes "github.com/cosmos/cosmos-sdk/x/bank/types" ) @@ -39,7 +38,7 @@ func TestMsgExecAuthorized(t *testing.T) { }, true}, } for i, tc := range tests { - msg := types.NewMsgExec(tc.grantee, tc.msgs) + msg := authz.NewMsgExec(tc.grantee, tc.msgs) if tc.expectPass { require.NoError(t, msg.ValidateBasic(), "test: %v", i) } else { @@ -60,7 +59,7 @@ func TestMsgRevokeAuthorization(t *testing.T) { {"valid test case", granter, grantee, "hello", true}, } for i, tc := range tests { - msg := types.NewMsgRevoke(tc.granter, tc.grantee, tc.msgType) + msg := authz.NewMsgRevoke(tc.granter, tc.grantee, tc.msgType) if tc.expectPass { require.NoError(t, msg.ValidateBasic(), "test: %v", i) } else { @@ -86,7 +85,7 @@ func TestMsgGrantAuthorization(t *testing.T) { {"past time", granter, grantee, &banktypes.SendAuthorization{SpendLimit: coinsPos}, time.Now().AddDate(0, 0, -1), false, false}, } for i, tc := range tests { - msg, err := types.NewMsgGrant( + msg, err := authz.NewMsgGrant( tc.granter, tc.grantee, tc.authorization, tc.expiration, ) if !tc.expectErr { diff --git a/x/authz/proto_desc.go b/x/authz/proto_desc.go new file mode 100644 index 000000000000..cc5e62e7a3d6 --- /dev/null +++ b/x/authz/proto_desc.go @@ -0,0 +1,8 @@ +package authz + +import grpc "google.golang.org/grpc" + +// MsgServiceDesc return ServiceDesc for Msg server +func MsgServiceDesc() *grpc.ServiceDesc { + return &_Msg_serviceDesc +} diff --git a/x/authz/types/query.pb.go b/x/authz/query.pb.go similarity index 89% rename from x/authz/types/query.pb.go rename to x/authz/query.pb.go index ed8ecc394046..ced860c00127 100644 --- a/x/authz/types/query.pb.go +++ b/x/authz/query.pb.go @@ -1,7 +1,7 @@ // Code generated by protoc-gen-gogo. DO NOT EDIT. // source: cosmos/authz/v1beta1/query.proto -package types +package authz import ( context "context" @@ -163,32 +163,31 @@ func init() { func init() { proto.RegisterFile("cosmos/authz/v1beta1/query.proto", fileDescriptor_376d714ffdeb1545) } var fileDescriptor_376d714ffdeb1545 = []byte{ - // 385 bytes of a gzipped FileDescriptorProto - 0x1f, 0x8b, 0x08, 0x00, 0x00, 0x00, 0x00, 0x00, 0x02, 0xff, 0x8c, 0x92, 0xc1, 0x4a, 0xeb, 0x40, - 0x14, 0x86, 0x3b, 0xed, 0xbd, 0xbd, 0xdc, 0xe9, 0x5d, 0xcd, 0x75, 0x11, 0x6a, 0x09, 0xa1, 0x88, - 0xc6, 0x82, 0x13, 0xda, 0xbe, 0x81, 0x88, 0xdd, 0x6a, 0xd0, 0x8d, 0x9b, 0x32, 0xa9, 0xc3, 0x34, - 0xd8, 0x64, 0xd2, 0xcc, 0x44, 0xac, 0x4b, 0x5d, 0x0b, 0x42, 0xdf, 0xc4, 0xa7, 0x70, 0x59, 0x70, - 0xe3, 0x52, 0x5a, 0x1f, 0x44, 0x32, 0x33, 0xb5, 0x2d, 0x06, 0x74, 0x15, 0x92, 0xf3, 0x9d, 0xff, - 0x7c, 0x73, 0x26, 0xd0, 0x19, 0x70, 0x11, 0x71, 0xe1, 0x91, 0x4c, 0x0e, 0x6f, 0xbd, 0xeb, 0x76, - 0x40, 0x25, 0x69, 0x7b, 0xe3, 0x8c, 0xa6, 0x13, 0x9c, 0xa4, 0x5c, 0x72, 0xb4, 0xa5, 0x09, 0xac, - 0x08, 0x6c, 0x88, 0x7a, 0x83, 0x71, 0xce, 0x46, 0xd4, 0x23, 0x49, 0xe8, 0x91, 0x38, 0xe6, 0x92, - 0xc8, 0x90, 0xc7, 0x42, 0xf7, 0xd4, 0x5b, 0x26, 0x35, 0x20, 0x82, 0xea, 0xb0, 0xcf, 0xe8, 0x84, - 0xb0, 0x30, 0x56, 0xb0, 0x61, 0x8b, 0x0d, 0xf4, 0x34, 0x45, 0x34, 0x9f, 0x00, 0x44, 0xa7, 0x79, - 0x48, 0x2f, 0x25, 0xb1, 0x14, 0x3e, 0x1d, 0x67, 0x54, 0x48, 0x64, 0xc1, 0x3f, 0x2c, 0xff, 0x40, - 0x53, 0x0b, 0x38, 0xc0, 0xfd, 0xeb, 0x2f, 0x5f, 0x57, 0x15, 0x6a, 0x95, 0xd7, 0x2b, 0x14, 0x39, - 0xf0, 0x5f, 0x24, 0x58, 0x5f, 0x4e, 0x12, 0xda, 0xcf, 0xd2, 0x91, 0x55, 0x51, 0x65, 0x18, 0x09, - 0x76, 0x36, 0x49, 0xe8, 0x79, 0x3a, 0x42, 0xc7, 0x10, 0xae, 0x14, 0xad, 0x5f, 0x0e, 0x70, 0x6b, - 0x9d, 0x5d, 0x6c, 0x76, 0x90, 0x9f, 0x07, 0xeb, 0xe5, 0x18, 0x51, 0x7c, 0x42, 0x18, 0x35, 0x46, - 0xfe, 0x5a, 0x67, 0x73, 0x0a, 0xe0, 0xff, 0x0d, 0x69, 0x91, 0xf0, 0x58, 0x50, 0xd4, 0x85, 0x55, - 0x25, 0x23, 0x2c, 0xe0, 0x54, 0xdc, 0x5a, 0x67, 0x1b, 0x17, 0xed, 0x17, 0xab, 0x2e, 0xdf, 0xa0, - 0xa8, 0xb7, 0x21, 0x55, 0x56, 0x52, 0x7b, 0xdf, 0x4a, 0xe9, 0x89, 0xeb, 0x56, 0x9d, 0x07, 0x00, - 0x7f, 0x2b, 0x2b, 0x74, 0x0f, 0x60, 0x55, 0xab, 0x21, 0xb7, 0x58, 0xe1, 0xeb, 0xca, 0xeb, 0xfb, - 0x3f, 0x20, 0xf5, 0xd4, 0xe6, 0xce, 0xdd, 0xcb, 0xfb, 0xb4, 0x6c, 0xa3, 0x86, 0x57, 0x78, 0xbf, - 0xfa, 0x60, 0x87, 0x47, 0xcf, 0x73, 0x1b, 0xcc, 0xe6, 0x36, 0x78, 0x9b, 0xdb, 0xe0, 0x71, 0x61, - 0x97, 0x66, 0x0b, 0xbb, 0xf4, 0xba, 0xb0, 0x4b, 0x17, 0x2d, 0x16, 0xca, 0x61, 0x16, 0xe0, 0x01, - 0x8f, 0x96, 0x09, 0xfa, 0x71, 0x20, 0x2e, 0xaf, 0xbc, 0x1b, 0x13, 0x97, 0x5f, 0xa4, 0x08, 0xaa, - 0xea, 0x3f, 0xe9, 0x7e, 0x04, 0x00, 0x00, 0xff, 0xff, 0x99, 0xb7, 0x9e, 0x9d, 0xcd, 0x02, 0x00, - 0x00, + // 381 bytes of a gzipped FileDescriptorProto + 0x1f, 0x8b, 0x08, 0x00, 0x00, 0x00, 0x00, 0x00, 0x02, 0xff, 0x8c, 0x92, 0x41, 0x4f, 0xf2, 0x30, + 0x18, 0xc7, 0x29, 0xbc, 0x2f, 0xc6, 0xe2, 0xa9, 0x7a, 0x58, 0x90, 0x2c, 0x0b, 0x21, 0x3a, 0x4d, + 0xec, 0x02, 0xdc, 0x3d, 0x78, 0x90, 0xab, 0x2e, 0x7a, 0xf1, 0x42, 0x3a, 0x6c, 0xca, 0x22, 0x5b, + 0xc7, 0xda, 0x19, 0xf1, 0xa8, 0x67, 0x13, 0x13, 0xbe, 0x89, 0x9f, 0xc2, 0x23, 0x89, 0x17, 0x8f, + 0x06, 0xfc, 0x20, 0x86, 0xb6, 0x08, 0xc4, 0x25, 0x7a, 0x5a, 0xb6, 0xe7, 0xf7, 0xfc, 0x9f, 0x5f, + 0x9f, 0x15, 0x3a, 0x3d, 0x2e, 0x22, 0x2e, 0x3c, 0x92, 0xc9, 0xfe, 0xbd, 0x77, 0xdb, 0x0c, 0xa8, + 0x24, 0x4d, 0x6f, 0x98, 0xd1, 0x74, 0x84, 0x93, 0x94, 0x4b, 0x8e, 0x76, 0x34, 0x81, 0x15, 0x81, + 0x0d, 0x51, 0xad, 0x31, 0xce, 0xd9, 0x80, 0x7a, 0x24, 0x09, 0x3d, 0x12, 0xc7, 0x5c, 0x12, 0x19, + 0xf2, 0x58, 0xe8, 0x9e, 0xea, 0xa1, 0x49, 0x0d, 0x88, 0xa0, 0x3a, 0xec, 0x3b, 0x3a, 0x21, 0x2c, + 0x8c, 0x15, 0x6c, 0xd8, 0x7c, 0x03, 0x3d, 0x4d, 0x11, 0xf5, 0x17, 0x00, 0xd1, 0xf9, 0x3c, 0xa4, + 0x93, 0x92, 0x58, 0x0a, 0x9f, 0x0e, 0x33, 0x2a, 0x24, 0xb2, 0xe0, 0x06, 0x9b, 0x7f, 0xa0, 0xa9, + 0x05, 0x1c, 0xe0, 0x6e, 0xfa, 0x8b, 0xd7, 0x65, 0x85, 0x5a, 0xc5, 0xd5, 0x0a, 0x45, 0x0e, 0xdc, + 0x8a, 0x04, 0xeb, 0xca, 0x51, 0x42, 0xbb, 0x59, 0x3a, 0xb0, 0x4a, 0xaa, 0x0c, 0x23, 0xc1, 0x2e, + 0x46, 0x09, 0xbd, 0x4c, 0x07, 0xe8, 0x14, 0xc2, 0xa5, 0xa2, 0xf5, 0xcf, 0x01, 0x6e, 0xa5, 0xb5, + 0x87, 0xcd, 0x0e, 0xe6, 0xe7, 0xc1, 0x7a, 0x39, 0x46, 0x14, 0x9f, 0x11, 0x46, 0x8d, 0x91, 0xbf, + 0xd2, 0x59, 0x1f, 0x03, 0xb8, 0xbd, 0x26, 0x2d, 0x12, 0x1e, 0x0b, 0x8a, 0xda, 0xb0, 0xac, 0x64, + 0x84, 0x05, 0x9c, 0x92, 0x5b, 0x69, 0xed, 0xe2, 0xbc, 0xfd, 0x62, 0xd5, 0xe5, 0x1b, 0x14, 0x75, + 0xd6, 0xa4, 0x8a, 0x4a, 0x6a, 0xff, 0x57, 0x29, 0x3d, 0x71, 0xd5, 0xaa, 0xf5, 0x04, 0xe0, 0x7f, + 0x65, 0x85, 0x1e, 0x01, 0x2c, 0x6b, 0x35, 0xe4, 0xe6, 0x2b, 0xfc, 0x5c, 0x79, 0xf5, 0xe0, 0x0f, + 0xa4, 0x9e, 0x5a, 0x6f, 0x3c, 0xbc, 0x7d, 0x8e, 0x8b, 0x36, 0xaa, 0x79, 0xb9, 0xff, 0x57, 0x1f, + 0xec, 0xe4, 0xf8, 0x75, 0x6a, 0x83, 0xc9, 0xd4, 0x06, 0x1f, 0x53, 0x1b, 0x3c, 0xcf, 0xec, 0xc2, + 0x64, 0x66, 0x17, 0xde, 0x67, 0x76, 0xe1, 0xaa, 0xc1, 0x42, 0xd9, 0xcf, 0x02, 0xdc, 0xe3, 0xd1, + 0x22, 0x41, 0x3f, 0x8e, 0xc4, 0xf5, 0x8d, 0x77, 0xa7, 0xe3, 0x82, 0xb2, 0xba, 0x21, 0xed, 0xaf, + 0x00, 0x00, 0x00, 0xff, 0xff, 0xf2, 0x52, 0x9e, 0x65, 0xc7, 0x02, 0x00, 0x00, } // Reference imports to suppress errors if they are not otherwise used. diff --git a/x/authz/types/query.pb.gw.go b/x/authz/query.pb.gw.go similarity index 99% rename from x/authz/types/query.pb.gw.go rename to x/authz/query.pb.gw.go index 3fb00f6ca59c..3278cb6baa3c 100644 --- a/x/authz/types/query.pb.gw.go +++ b/x/authz/query.pb.gw.go @@ -2,11 +2,11 @@ // source: cosmos/authz/v1beta1/query.proto /* -Package types is a reverse proxy. +Package authz is a reverse proxy. It translates gRPC into RESTful JSON APIs. */ -package types +package authz import ( "context" diff --git a/x/authz/simulation/decoder.go b/x/authz/simulation/decoder.go index c1e4c407b607..05c836581752 100644 --- a/x/authz/simulation/decoder.go +++ b/x/authz/simulation/decoder.go @@ -6,7 +6,7 @@ import ( "github.com/cosmos/cosmos-sdk/codec" "github.com/cosmos/cosmos-sdk/types/kv" - "github.com/cosmos/cosmos-sdk/x/authz/types" + "github.com/cosmos/cosmos-sdk/x/authz" ) // NewDecodeStore returns a decoder function closure that umarshals the KVPair's @@ -14,8 +14,8 @@ import ( func NewDecodeStore(cdc codec.Marshaler) func(kvA, kvB kv.Pair) string { return func(kvA, kvB kv.Pair) string { switch { - case bytes.Equal(kvA.Key[:1], types.GrantKey): - var grantA, grantB types.Grant + case bytes.Equal(kvA.Key[:1], authz.GrantKey): + var grantA, grantB authz.Grant cdc.MustUnmarshalBinaryBare(kvA.Value, &grantA) cdc.MustUnmarshalBinaryBare(kvB.Value, &grantB) return fmt.Sprintf("%v\n%v", grantA, grantB) diff --git a/x/authz/simulation/decoder_test.go b/x/authz/simulation/decoder_test.go index f7d664b9a823..4eec1407229b 100644 --- a/x/authz/simulation/decoder_test.go +++ b/x/authz/simulation/decoder_test.go @@ -10,8 +10,8 @@ import ( "github.com/cosmos/cosmos-sdk/simapp" sdk "github.com/cosmos/cosmos-sdk/types" "github.com/cosmos/cosmos-sdk/types/kv" + "github.com/cosmos/cosmos-sdk/x/authz" "github.com/cosmos/cosmos-sdk/x/authz/simulation" - "github.com/cosmos/cosmos-sdk/x/authz/types" banktypes "github.com/cosmos/cosmos-sdk/x/bank/types" ) @@ -19,12 +19,12 @@ func TestDecodeStore(t *testing.T) { cdc := simapp.MakeTestEncodingConfig().Marshaler dec := simulation.NewDecodeStore(cdc) - grant, _ := types.NewGrant(banktypes.NewSendAuthorization(sdk.NewCoins(sdk.NewInt64Coin("foo", 123))), time.Now().UTC()) + grant, _ := authz.NewGrant(banktypes.NewSendAuthorization(sdk.NewCoins(sdk.NewInt64Coin("foo", 123))), time.Now().UTC()) grantBz, err := cdc.MarshalBinaryBare(&grant) require.NoError(t, err) kvPairs := kv.Pairs{ Pairs: []kv.Pair{ - {Key: []byte(types.GrantKey), Value: grantBz}, + {Key: []byte(authz.GrantKey), Value: grantBz}, {Key: []byte{0x99}, Value: []byte{0x99}}, }, } diff --git a/x/authz/simulation/genesis.go b/x/authz/simulation/genesis.go index ea674e24ea62..33c8b9a68672 100644 --- a/x/authz/simulation/genesis.go +++ b/x/authz/simulation/genesis.go @@ -7,32 +7,29 @@ import ( "github.com/cosmos/cosmos-sdk/types/module" simtypes "github.com/cosmos/cosmos-sdk/types/simulation" - "github.com/cosmos/cosmos-sdk/x/authz/types" + "github.com/cosmos/cosmos-sdk/x/authz" ) -// Simulation parameter constant. -const authz = "authz" - // GenAuthorizationGrant returns an empty slice of authorization grants. -func GenAuthorizationGrant(_ *rand.Rand, _ []simtypes.Account) []types.GrantAuthorization { - return []types.GrantAuthorization{} +func GenAuthorizationGrant(_ *rand.Rand, _ []simtypes.Account) []authz.GrantAuthorization { + return []authz.GrantAuthorization{} } // RandomizedGenState generates a random GenesisState for authz. func RandomizedGenState(simState *module.SimulationState) { - var grants []types.GrantAuthorization + var grants []authz.GrantAuthorization simState.AppParams.GetOrGenerate( - simState.Cdc, authz, &grants, simState.Rand, + simState.Cdc, "authz", &grants, simState.Rand, func(r *rand.Rand) { grants = GenAuthorizationGrant(r, simState.Accounts) }, ) - authzGrantsGenesis := types.NewGenesisState(grants) + authzGrantsGenesis := authz.NewGenesisState(grants) bz, err := json.MarshalIndent(&authzGrantsGenesis, "", " ") if err != nil { panic(err) } - fmt.Printf("Selected randomly generated %s parameters:\n%s\n", types.ModuleName, bz) - simState.GenState[types.ModuleName] = simState.Cdc.MustMarshalJSON(authzGrantsGenesis) + fmt.Printf("Selected randomly generated %s parameters:\n%s\n", authz.ModuleName, bz) + simState.GenState[authz.ModuleName] = simState.Cdc.MustMarshalJSON(authzGrantsGenesis) } diff --git a/x/authz/simulation/genesis_test.go b/x/authz/simulation/genesis_test.go index 4672d195ec0a..4e015afb0d1e 100644 --- a/x/authz/simulation/genesis_test.go +++ b/x/authz/simulation/genesis_test.go @@ -11,8 +11,8 @@ import ( codectypes "github.com/cosmos/cosmos-sdk/codec/types" "github.com/cosmos/cosmos-sdk/types/module" simtypes "github.com/cosmos/cosmos-sdk/types/simulation" + "github.com/cosmos/cosmos-sdk/x/authz" "github.com/cosmos/cosmos-sdk/x/authz/simulation" - "github.com/cosmos/cosmos-sdk/x/authz/types" ) func TestRandomizedGenState(t *testing.T) { @@ -33,8 +33,8 @@ func TestRandomizedGenState(t *testing.T) { } simulation.RandomizedGenState(&simState) - var authzGenesis types.GenesisState - simState.Cdc.MustUnmarshalJSON(simState.GenState[types.ModuleName], &authzGenesis) + var authzGenesis authz.GenesisState + simState.Cdc.MustUnmarshalJSON(simState.GenState[authz.ModuleName], &authzGenesis) require.Len(t, authzGenesis.Authorization, 0) } diff --git a/x/authz/simulation/operations.go b/x/authz/simulation/operations.go index 10e9b094260a..c429d3e5d801 100644 --- a/x/authz/simulation/operations.go +++ b/x/authz/simulation/operations.go @@ -13,8 +13,8 @@ import ( sdk "github.com/cosmos/cosmos-sdk/types" "github.com/cosmos/cosmos-sdk/types/msgservice" simtypes "github.com/cosmos/cosmos-sdk/types/simulation" + "github.com/cosmos/cosmos-sdk/x/authz" "github.com/cosmos/cosmos-sdk/x/authz/keeper" - "github.com/cosmos/cosmos-sdk/x/authz/types" banktype "github.com/cosmos/cosmos-sdk/x/bank/types" "github.com/cosmos/cosmos-sdk/x/simulation" ) @@ -35,7 +35,7 @@ const ( // WeightedOperations returns all the operations from the module with their respective weights func WeightedOperations( - appParams simtypes.AppParams, cdc codec.JSONMarshaler, ak types.AccountKeeper, bk types.BankKeeper, k keeper.Keeper, appCdc cdctypes.AnyUnpacker, protoCdc *codec.ProtoCodec) simulation.WeightedOperations { + appParams simtypes.AppParams, cdc codec.JSONMarshaler, ak authz.AccountKeeper, bk authz.BankKeeper, k keeper.Keeper, appCdc cdctypes.AnyUnpacker, protoCdc *codec.ProtoCodec) simulation.WeightedOperations { var ( weightMsgGrantAuthorization int @@ -79,7 +79,7 @@ func WeightedOperations( // SimulateMsgGrantAuthorization generates a MsgGrantAuthorization with random values. // nolint: funlen -func SimulateMsgGrantAuthorization(ak types.AccountKeeper, bk types.BankKeeper, k keeper.Keeper, +func SimulateMsgGrantAuthorization(ak authz.AccountKeeper, bk authz.BankKeeper, _ keeper.Keeper, protoCdc *codec.ProtoCodec) simtypes.Operation { return func( r *rand.Rand, app *baseapp.BaseApp, ctx sdk.Context, accs []simtypes.Account, chainID string, @@ -92,26 +92,26 @@ func SimulateMsgGrantAuthorization(ak types.AccountKeeper, bk types.BankKeeper, spendableCoins := bk.SpendableCoins(ctx, account.GetAddress()) fees, err := simtypes.RandomFees(r, ctx, spendableCoins) if err != nil { - return simtypes.NoOpMsg(types.ModuleName, TypeMsgGrantAuthorization, err.Error()), nil, err + return simtypes.NoOpMsg(authz.ModuleName, TypeMsgGrantAuthorization, err.Error()), nil, err } blockTime := ctx.BlockTime() spendLimit := spendableCoins.Sub(fees) if spendLimit == nil { - return simtypes.NoOpMsg(types.ModuleName, TypeMsgGrantAuthorization, "spend limit is nil"), nil, nil + return simtypes.NoOpMsg(authz.ModuleName, TypeMsgGrantAuthorization, "spend limit is nil"), nil, nil } - msg, err := types.NewMsgGrant(granter.Address, grantee.Address, + msg, err := authz.NewMsgGrant(granter.Address, grantee.Address, banktype.NewSendAuthorization(spendLimit), blockTime.AddDate(1, 0, 0)) if err != nil { - return simtypes.NoOpMsg(types.ModuleName, TypeMsgGrantAuthorization, err.Error()), nil, err + return simtypes.NoOpMsg(authz.ModuleName, TypeMsgGrantAuthorization, err.Error()), nil, err } txGen := simappparams.MakeTestEncodingConfig().TxConfig svcMsgClientConn := &msgservice.ServiceMsgClientConn{} - authzMsgClient := types.NewMsgClient(svcMsgClientConn) + authzMsgClient := authz.NewMsgClient(svcMsgClientConn) _, err = authzMsgClient.Grant(context.Background(), msg) if err != nil { - return simtypes.NoOpMsg(types.ModuleName, TypeMsgGrantAuthorization, err.Error()), nil, err + return simtypes.NoOpMsg(authz.ModuleName, TypeMsgGrantAuthorization, err.Error()), nil, err } tx, err := helpers.GenTx( txGen, @@ -125,12 +125,12 @@ func SimulateMsgGrantAuthorization(ak types.AccountKeeper, bk types.BankKeeper, ) if err != nil { - return simtypes.NoOpMsg(types.ModuleName, TypeMsgGrantAuthorization, "unable to generate mock tx"), nil, err + return simtypes.NoOpMsg(authz.ModuleName, TypeMsgGrantAuthorization, "unable to generate mock tx"), nil, err } _, _, err = app.Deliver(txGen.TxEncoder(), tx) if err != nil { - return simtypes.NoOpMsg(types.ModuleName, svcMsgClientConn.GetMsgs()[0].Type(), "unable to deliver tx"), nil, err + return simtypes.NoOpMsg(authz.ModuleName, svcMsgClientConn.GetMsgs()[0].Type(), "unable to deliver tx"), nil, err } return simtypes.NewOperationMsg(svcMsgClientConn.GetMsgs()[0], true, "", protoCdc), nil, err } @@ -138,15 +138,15 @@ func SimulateMsgGrantAuthorization(ak types.AccountKeeper, bk types.BankKeeper, // SimulateMsgRevokeAuthorization generates a MsgRevokeAuthorization with random values. // nolint: funlen -func SimulateMsgRevokeAuthorization(ak types.AccountKeeper, bk types.BankKeeper, k keeper.Keeper, protoCdc *codec.ProtoCodec) simtypes.Operation { +func SimulateMsgRevokeAuthorization(ak authz.AccountKeeper, bk authz.BankKeeper, k keeper.Keeper, protoCdc *codec.ProtoCodec) simtypes.Operation { return func( r *rand.Rand, app *baseapp.BaseApp, ctx sdk.Context, accs []simtypes.Account, chainID string, ) (simtypes.OperationMsg, []simtypes.FutureOperation, error) { hasGrant := false - var targetGrant types.Grant + var targetGrant authz.Grant var granterAddr sdk.AccAddress var granteeAddr sdk.AccAddress - k.IterateGrants(ctx, func(granter, grantee sdk.AccAddress, grant types.Grant) bool { + k.IterateGrants(ctx, func(granter, grantee sdk.AccAddress, grant authz.Grant) bool { targetGrant = grant granterAddr = granter granteeAddr = grantee @@ -155,29 +155,29 @@ func SimulateMsgRevokeAuthorization(ak types.AccountKeeper, bk types.BankKeeper, }) if !hasGrant { - return simtypes.NoOpMsg(types.ModuleName, TypeMsgRevokeAuthorization, "no grants"), nil, nil + return simtypes.NoOpMsg(authz.ModuleName, TypeMsgRevokeAuthorization, "no grants"), nil, nil } granter, ok := simtypes.FindAccount(accs, granterAddr) if !ok { - return simtypes.NoOpMsg(types.ModuleName, TypeMsgRevokeAuthorization, "Account not found"), nil, nil + return simtypes.NoOpMsg(authz.ModuleName, TypeMsgRevokeAuthorization, "Account not found"), nil, nil } account := ak.GetAccount(ctx, granter.Address) spendableCoins := bk.SpendableCoins(ctx, account.GetAddress()) fees, err := simtypes.RandomFees(r, ctx, spendableCoins) if err != nil { - return simtypes.NoOpMsg(types.ModuleName, TypeMsgRevokeAuthorization, "fee error"), nil, err + return simtypes.NoOpMsg(authz.ModuleName, TypeMsgRevokeAuthorization, "fee error"), nil, err } auth := targetGrant.GetAuthorization() - msg := types.NewMsgRevoke(granterAddr, granteeAddr, auth.MsgTypeURL()) + msg := authz.NewMsgRevoke(granterAddr, granteeAddr, auth.MsgTypeURL()) txGen := simappparams.MakeTestEncodingConfig().TxConfig svcMsgClientConn := &msgservice.ServiceMsgClientConn{} - authzMsgClient := types.NewMsgClient(svcMsgClientConn) + authzMsgClient := authz.NewMsgClient(svcMsgClientConn) _, err = authzMsgClient.Revoke(context.Background(), &msg) if err != nil { - return simtypes.NoOpMsg(types.ModuleName, TypeMsgRevokeAuthorization, err.Error()), nil, err + return simtypes.NoOpMsg(authz.ModuleName, TypeMsgRevokeAuthorization, err.Error()), nil, err } tx, err := helpers.GenTx( txGen, @@ -191,7 +191,7 @@ func SimulateMsgRevokeAuthorization(ak types.AccountKeeper, bk types.BankKeeper, ) if err != nil { - return simtypes.NoOpMsg(types.ModuleName, TypeMsgRevokeAuthorization, err.Error()), nil, err + return simtypes.NoOpMsg(authz.ModuleName, TypeMsgRevokeAuthorization, err.Error()), nil, err } _, _, err = app.Deliver(txGen.TxEncoder(), tx) @@ -201,16 +201,16 @@ func SimulateMsgRevokeAuthorization(ak types.AccountKeeper, bk types.BankKeeper, // SimulateMsgExecuteAuthorized generates a MsgExecuteAuthorized with random values. // nolint: funlen -func SimulateMsgExecuteAuthorized(ak types.AccountKeeper, bk types.BankKeeper, k keeper.Keeper, cdc cdctypes.AnyUnpacker, protoCdc *codec.ProtoCodec) simtypes.Operation { +func SimulateMsgExecuteAuthorized(ak authz.AccountKeeper, bk authz.BankKeeper, k keeper.Keeper, cdc cdctypes.AnyUnpacker, protoCdc *codec.ProtoCodec) simtypes.Operation { return func( r *rand.Rand, app *baseapp.BaseApp, ctx sdk.Context, accs []simtypes.Account, chainID string, ) (simtypes.OperationMsg, []simtypes.FutureOperation, error) { hasGrant := false - var targetGrant types.Grant + var targetGrant authz.Grant var granterAddr sdk.AccAddress var granteeAddr sdk.AccAddress - k.IterateGrants(ctx, func(granter, grantee sdk.AccAddress, grant types.Grant) bool { + k.IterateGrants(ctx, func(granter, grantee sdk.AccAddress, grant authz.Grant) bool { targetGrant = grant granterAddr = granter granteeAddr = grantee @@ -219,7 +219,7 @@ func SimulateMsgExecuteAuthorized(ak types.AccountKeeper, bk types.BankKeeper, k }) if !hasGrant { - return simtypes.NoOpMsg(types.ModuleName, TypeMsgExecDelegated, "Not found"), nil, nil + return simtypes.NoOpMsg(authz.ModuleName, TypeMsgExecDelegated, "Not found"), nil, nil } grantee, _ := simtypes.FindAccount(accs, granteeAddr) @@ -228,17 +228,17 @@ func SimulateMsgExecuteAuthorized(ak types.AccountKeeper, bk types.BankKeeper, k granterspendableCoins := bk.SpendableCoins(ctx, granterAccount.GetAddress()) if granterspendableCoins.Empty() { - return simtypes.NoOpMsg(types.ModuleName, TypeMsgExecDelegated, "no coins"), nil, nil + return simtypes.NoOpMsg(authz.ModuleName, TypeMsgExecDelegated, "no coins"), nil, nil } if targetGrant.Expiration.Before(ctx.BlockHeader().Time) { - return simtypes.NoOpMsg(types.ModuleName, TypeMsgExecDelegated, "grant expired"), nil, nil + return simtypes.NoOpMsg(authz.ModuleName, TypeMsgExecDelegated, "grant expired"), nil, nil } granteespendableCoins := bk.SpendableCoins(ctx, granteeAccount.GetAddress()) fees, err := simtypes.RandomFees(r, ctx, granteespendableCoins) if err != nil { - return simtypes.NoOpMsg(types.ModuleName, TypeMsgExecDelegated, "fee error"), nil, err + return simtypes.NoOpMsg(authz.ModuleName, TypeMsgExecDelegated, "fee error"), nil, err } sendCoins := sdk.NewCoins(sdk.NewCoin("foo", sdk.NewInt(10))) @@ -251,19 +251,19 @@ func SimulateMsgExecuteAuthorized(ak types.AccountKeeper, bk types.BankKeeper, k ), } - msg := types.NewMsgExec(grantee.Address, []sdk.ServiceMsg{execMsg}) + msg := authz.NewMsgExec(grantee.Address, []sdk.ServiceMsg{execMsg}) sendGrant := targetGrant.Authorization.GetCachedValue().(*banktype.SendAuthorization) _, err = sendGrant.Accept(ctx, execMsg) if err != nil { - return simtypes.NoOpMsg(types.ModuleName, TypeMsgExecDelegated, err.Error()), nil, nil + return simtypes.NoOpMsg(authz.ModuleName, TypeMsgExecDelegated, err.Error()), nil, nil } txGen := simappparams.MakeTestEncodingConfig().TxConfig svcMsgClientConn := &msgservice.ServiceMsgClientConn{} - authzMsgClient := types.NewMsgClient(svcMsgClientConn) + authzMsgClient := authz.NewMsgClient(svcMsgClientConn) _, err = authzMsgClient.Exec(context.Background(), &msg) if err != nil { - return simtypes.NoOpMsg(types.ModuleName, TypeMsgExecDelegated, err.Error()), nil, err + return simtypes.NoOpMsg(authz.ModuleName, TypeMsgExecDelegated, err.Error()), nil, err } tx, err := helpers.GenTx( txGen, @@ -277,18 +277,18 @@ func SimulateMsgExecuteAuthorized(ak types.AccountKeeper, bk types.BankKeeper, k ) if err != nil { - return simtypes.NoOpMsg(types.ModuleName, TypeMsgExecDelegated, err.Error()), nil, err + return simtypes.NoOpMsg(authz.ModuleName, TypeMsgExecDelegated, err.Error()), nil, err } _, _, err = app.Deliver(txGen.TxEncoder(), tx) if err != nil { if strings.Contains(err.Error(), "insufficient fee") { - return simtypes.NoOpMsg(types.ModuleName, TypeMsgExecDelegated, "insufficient fee"), nil, nil + return simtypes.NoOpMsg(authz.ModuleName, TypeMsgExecDelegated, "insufficient fee"), nil, nil } - return simtypes.NoOpMsg(types.ModuleName, TypeMsgExecDelegated, err.Error()), nil, err + return simtypes.NoOpMsg(authz.ModuleName, TypeMsgExecDelegated, err.Error()), nil, err } msg.UnpackInterfaces(cdc) if err != nil { - return simtypes.NoOpMsg(types.ModuleName, TypeMsgExecDelegated, "unmarshal error"), nil, err + return simtypes.NoOpMsg(authz.ModuleName, TypeMsgExecDelegated, "unmarshal error"), nil, err } return simtypes.NewOperationMsg(svcMsgClientConn.GetMsgs()[0], true, "success", protoCdc), nil, nil } diff --git a/x/authz/simulation/operations_test.go b/x/authz/simulation/operations_test.go index 2cc6a36f395d..d93a8d896c8e 100644 --- a/x/authz/simulation/operations_test.go +++ b/x/authz/simulation/operations_test.go @@ -15,8 +15,8 @@ import ( simappparams "github.com/cosmos/cosmos-sdk/simapp/params" sdk "github.com/cosmos/cosmos-sdk/types" simtypes "github.com/cosmos/cosmos-sdk/types/simulation" + "github.com/cosmos/cosmos-sdk/x/authz" "github.com/cosmos/cosmos-sdk/x/authz/simulation" - "github.com/cosmos/cosmos-sdk/x/authz/types" banktypes "github.com/cosmos/cosmos-sdk/x/bank/types" ) @@ -54,9 +54,9 @@ func (suite *SimTestSuite) TestWeightedOperations() { opMsgRoute string opMsgName string }{ - {simappparams.DefaultWeightMsgDelegate, types.ModuleName, simulation.TypeMsgGrantAuthorization}, - {simappparams.DefaultWeightMsgUndelegate, types.ModuleName, simulation.TypeMsgRevokeAuthorization}, - {simappparams.DefaultWeightMsgSend, types.ModuleName, simulation.TypeMsgExecDelegated}, + {simappparams.DefaultWeightMsgDelegate, authz.ModuleName, simulation.TypeMsgGrantAuthorization}, + {simappparams.DefaultWeightMsgUndelegate, authz.ModuleName, simulation.TypeMsgRevokeAuthorization}, + {simappparams.DefaultWeightMsgSend, authz.ModuleName, simulation.TypeMsgExecDelegated}, } for i, w := range weightesOps { @@ -110,7 +110,7 @@ func (suite *SimTestSuite) TestSimulateGrantAuthorization() { operationMsg, futureOperations, err := op(r, suite.app.BaseApp, ctx, accounts, "") suite.Require().NoError(err) - var msg types.MsgGrant + var msg authz.MsgGrant suite.app.AppCodec().UnmarshalJSON(operationMsg.Msg, &msg) suite.Require().True(operationMsg.OK) suite.Require().Equal(granter.Address.String(), msg.Granter) @@ -147,7 +147,7 @@ func (suite *SimTestSuite) TestSimulateRevokeAuthorization() { operationMsg, futureOperations, err := op(r, suite.app.BaseApp, suite.ctx, accounts, "") suite.Require().NoError(err) - var msg types.MsgRevoke + var msg authz.MsgRevoke suite.app.AppCodec().UnmarshalJSON(operationMsg.Msg, &msg) suite.Require().True(operationMsg.OK) @@ -182,7 +182,7 @@ func (suite *SimTestSuite) TestSimulateExecAuthorization() { operationMsg, futureOperations, err := op(r, suite.app.BaseApp, suite.ctx, accounts, "") suite.Require().NoError(err) - var msg types.MsgExec + var msg authz.MsgExec suite.app.AppCodec().UnmarshalJSON(operationMsg.Msg, &msg) diff --git a/x/authz/types/tx.pb.go b/x/authz/tx.pb.go similarity index 92% rename from x/authz/types/tx.pb.go rename to x/authz/tx.pb.go index 02e8b2ae9d8c..a73136071b41 100644 --- a/x/authz/types/tx.pb.go +++ b/x/authz/tx.pb.go @@ -1,7 +1,7 @@ // Code generated by protoc-gen-gogo. DO NOT EDIT. // source: cosmos/authz/v1beta1/tx.proto -package types +package authz import ( context "context" @@ -285,40 +285,40 @@ func init() { func init() { proto.RegisterFile("cosmos/authz/v1beta1/tx.proto", fileDescriptor_3ceddab7d8589ad1) } var fileDescriptor_3ceddab7d8589ad1 = []byte{ - // 520 bytes of a gzipped FileDescriptorProto - 0x1f, 0x8b, 0x08, 0x00, 0x00, 0x00, 0x00, 0x00, 0x02, 0xff, 0x9c, 0x94, 0x4f, 0x6f, 0xd3, 0x30, - 0x18, 0xc6, 0xe3, 0xad, 0xb4, 0xeb, 0x5b, 0x26, 0x58, 0xe8, 0x21, 0x8b, 0xb4, 0x34, 0x0a, 0x02, - 0x26, 0xa4, 0x3a, 0x5a, 0x11, 0x12, 0xd7, 0x55, 0x20, 0x90, 0x20, 0x42, 0x8a, 0xc6, 0x65, 0x97, - 0x2a, 0xe9, 0x8c, 0x17, 0xb5, 0x89, 0xa3, 0xd8, 0x99, 0xda, 0x7d, 0x8a, 0x7d, 0x98, 0x7d, 0x88, - 0x6a, 0xa7, 0x49, 0x5c, 0x38, 0xf1, 0xa7, 0xfd, 0x12, 0x1c, 0x51, 0x1c, 0xa7, 0x74, 0x40, 0x87, - 0xc4, 0xa9, 0x7e, 0xfd, 0xfc, 0xfc, 0xfa, 0xf1, 0x63, 0x37, 0xb0, 0x37, 0x64, 0x3c, 0x66, 0xdc, - 0x0d, 0x72, 0x71, 0x7a, 0xee, 0x9e, 0x1d, 0x84, 0x44, 0x04, 0x07, 0xae, 0x98, 0xe0, 0x34, 0x63, - 0x82, 0xe9, 0xed, 0x52, 0xc6, 0x52, 0xc6, 0x4a, 0x36, 0x77, 0xcb, 0xd9, 0x81, 0x64, 0x5c, 0x85, - 0xc8, 0xc2, 0x6c, 0x53, 0x46, 0x59, 0x39, 0x5f, 0x8c, 0xd4, 0x6c, 0x87, 0x32, 0x46, 0xc7, 0xc4, - 0x95, 0x55, 0x98, 0x7f, 0x74, 0x45, 0x14, 0x13, 0x2e, 0x82, 0x38, 0x55, 0xc0, 0xee, 0xef, 0x40, - 0x90, 0x4c, 0x95, 0xf4, 0x50, 0x39, 0x0c, 0x03, 0x4e, 0xdc, 0x20, 0x1c, 0x46, 0x4b, 0x97, 0x45, - 0x51, 0x42, 0xce, 0x27, 0x04, 0x5b, 0x1e, 0xa7, 0xaf, 0xb3, 0x20, 0x11, 0xba, 0x01, 0x0d, 0x5a, - 0x0c, 0x48, 0x66, 0x20, 0x1b, 0xed, 0x37, 0xfd, 0xaa, 0xfc, 0xa5, 0x10, 0x63, 0x63, 0x55, 0x21, - 0xba, 0x07, 0xdb, 0xc5, 0x19, 0x59, 0x16, 0x9d, 0x07, 0x22, 0x62, 0x89, 0xb1, 0x69, 0xa3, 0xfd, - 0x56, 0xaf, 0x8d, 0x4b, 0x63, 0xb8, 0x32, 0x86, 0x0f, 0x93, 0x69, 0x7f, 0xe7, 0xea, 0xb2, 0xbb, - 0x7d, 0xb8, 0x8a, 0xfb, 0x37, 0x57, 0xeb, 0x2f, 0x01, 0xc8, 0x24, 0x8d, 0xb2, 0xb2, 0x57, 0x4d, - 0xf6, 0x32, 0xff, 0xe8, 0x75, 0x54, 0xa5, 0xd0, 0xdf, 0x9a, 0x7d, 0xe9, 0x68, 0x17, 0x5f, 0x3b, - 0xc8, 0x5f, 0x59, 0xe7, 0xbc, 0x85, 0x7b, 0x1e, 0xa7, 0xaf, 0x26, 0x64, 0xe8, 0x13, 0x9e, 0xb2, - 0x84, 0x13, 0xfd, 0x05, 0xd4, 0x33, 0xc2, 0xf3, 0xb1, 0x90, 0x47, 0x6b, 0xf5, 0x6c, 0xac, 0xe2, - 0x2f, 0xe2, 0xc1, 0x32, 0x11, 0x15, 0x0f, 0xf6, 0x25, 0xe7, 0x2b, 0xde, 0x39, 0x86, 0x86, 0x6a, - 0xb6, 0x1a, 0x03, 0xba, 0x19, 0xc3, 0x73, 0xa8, 0xc5, 0x9c, 0x72, 0x63, 0xc3, 0xde, 0x5c, 0x7b, - 0xfa, 0xd6, 0xd5, 0x65, 0xb7, 0xc1, 0x4f, 0x46, 0xd8, 0xe3, 0xd4, 0x97, 0xb8, 0xa3, 0xc3, 0xfd, - 0x2a, 0xfd, 0xca, 0xa9, 0x13, 0x40, 0xb3, 0x00, 0xc8, 0x19, 0x1b, 0x91, 0xff, 0xba, 0x12, 0x1b, - 0xee, 0xc6, 0x9c, 0x0e, 0xc4, 0x34, 0x25, 0x83, 0x3c, 0x1b, 0xcb, 0x1b, 0x69, 0xfa, 0x10, 0x73, - 0x7a, 0x34, 0x4d, 0xc9, 0x87, 0x6c, 0xec, 0x3c, 0x80, 0x9d, 0xe5, 0x16, 0xd5, 0xbe, 0xbd, 0x1f, - 0x08, 0x36, 0x3d, 0x4e, 0xf5, 0xf7, 0x70, 0xa7, 0x7c, 0x0e, 0x16, 0xfe, 0xdb, 0x23, 0xc6, 0x95, - 0x61, 0xf3, 0xf1, 0xed, 0xfa, 0x32, 0xfa, 0x77, 0x50, 0x93, 0xe9, 0xed, 0xad, 0xe5, 0x0b, 0xd9, - 0x7c, 0x74, 0xab, 0xbc, 0xec, 0xe6, 0x43, 0x5d, 0x65, 0xd3, 0x59, 0xbb, 0xa0, 0x04, 0xcc, 0x27, - 0xff, 0x00, 0xaa, 0x9e, 0xfd, 0x37, 0xb3, 0xef, 0x96, 0x36, 0x9b, 0x5b, 0xe8, 0x7a, 0x6e, 0xa1, - 0x6f, 0x73, 0x0b, 0x5d, 0x2c, 0x2c, 0xed, 0x7a, 0x61, 0x69, 0x9f, 0x17, 0x96, 0x76, 0xfc, 0x94, - 0x46, 0xe2, 0x34, 0x0f, 0xf1, 0x90, 0xc5, 0xea, 0x3f, 0xab, 0x7e, 0xba, 0xfc, 0x64, 0xe4, 0x4e, - 0xd4, 0x27, 0xa0, 0x88, 0x9b, 0x87, 0x75, 0x79, 0xe3, 0xcf, 0x7e, 0x06, 0x00, 0x00, 0xff, 0xff, - 0x14, 0x49, 0xd2, 0xe5, 0x1f, 0x04, 0x00, 0x00, + // 518 bytes of a gzipped FileDescriptorProto + 0x1f, 0x8b, 0x08, 0x00, 0x00, 0x00, 0x00, 0x00, 0x02, 0xff, 0x9c, 0x94, 0x4f, 0x6f, 0xd3, 0x3e, + 0x18, 0xc7, 0xe3, 0xb5, 0xbf, 0x76, 0x7d, 0xfa, 0x9b, 0x60, 0xa1, 0x87, 0x2c, 0xd2, 0xd2, 0x28, + 0xfc, 0xdb, 0xa5, 0x8e, 0x56, 0x84, 0xc4, 0x75, 0x15, 0x88, 0x03, 0x44, 0x48, 0xd1, 0xb8, 0xec, + 0x52, 0x25, 0x9d, 0xf1, 0xa2, 0x36, 0x71, 0x14, 0x3b, 0x53, 0xbb, 0x57, 0xb1, 0x17, 0xb3, 0x17, + 0x51, 0xed, 0x34, 0x89, 0x0b, 0x27, 0xfe, 0xb4, 0x6f, 0x82, 0x23, 0x8a, 0xe3, 0x94, 0x0e, 0xe8, + 0x90, 0x38, 0xd5, 0x8f, 0xbf, 0x1f, 0x3f, 0xfe, 0xfa, 0x6b, 0x37, 0xb0, 0x3f, 0x62, 0x3c, 0x66, + 0xdc, 0x0d, 0x72, 0x71, 0x76, 0xe1, 0x9e, 0x1f, 0x86, 0x44, 0x04, 0x87, 0xae, 0x98, 0xe2, 0x34, + 0x63, 0x82, 0xe9, 0x9d, 0x52, 0xc6, 0x52, 0xc6, 0x4a, 0x36, 0xf7, 0xca, 0xd9, 0xa1, 0x64, 0x5c, + 0x85, 0xc8, 0xc2, 0xec, 0x50, 0x46, 0x59, 0x39, 0x5f, 0x8c, 0xd4, 0x6c, 0x97, 0x32, 0x46, 0x27, + 0xc4, 0x95, 0x55, 0x98, 0x7f, 0x70, 0x45, 0x14, 0x13, 0x2e, 0x82, 0x38, 0x55, 0xc0, 0xde, 0xaf, + 0x40, 0x90, 0xcc, 0x94, 0xf4, 0x50, 0x39, 0x0c, 0x03, 0x4e, 0xdc, 0x20, 0x1c, 0x45, 0x2b, 0x97, + 0x45, 0x51, 0x42, 0xce, 0x47, 0x04, 0xdb, 0x1e, 0xa7, 0xaf, 0xb3, 0x20, 0x11, 0xba, 0x01, 0x4d, + 0x5a, 0x0c, 0x48, 0x66, 0x20, 0x1b, 0x1d, 0xb4, 0xfc, 0xaa, 0xfc, 0xa9, 0x10, 0x63, 0x6b, 0x5d, + 0x21, 0xba, 0x07, 0x3b, 0xc5, 0x19, 0x59, 0x16, 0x5d, 0x04, 0x22, 0x62, 0x89, 0x51, 0xb3, 0xd1, + 0x41, 0xbb, 0xdf, 0xc1, 0xa5, 0x31, 0x5c, 0x19, 0xc3, 0x47, 0xc9, 0x6c, 0xb0, 0x7b, 0x7d, 0xd5, + 0xdb, 0x39, 0x5a, 0xc7, 0xfd, 0xdb, 0xab, 0xf5, 0x97, 0x00, 0x64, 0x9a, 0x46, 0x59, 0xd9, 0xab, + 0x2e, 0x7b, 0x99, 0xbf, 0xf5, 0x3a, 0xae, 0x52, 0x18, 0x6c, 0xcf, 0x3f, 0x77, 0xb5, 0xcb, 0x2f, + 0x5d, 0xe4, 0xaf, 0xad, 0x73, 0xde, 0xc0, 0x3d, 0x8f, 0xd3, 0x57, 0x53, 0x32, 0xf2, 0x09, 0x4f, + 0x59, 0xc2, 0x89, 0xfe, 0x02, 0x1a, 0x19, 0xe1, 0xf9, 0x44, 0xc8, 0xa3, 0xb5, 0xfb, 0x36, 0x56, + 0xf1, 0x17, 0xf1, 0x60, 0x99, 0x88, 0x8a, 0x07, 0xfb, 0x92, 0xf3, 0x15, 0xef, 0x9c, 0x40, 0x53, + 0x35, 0x5b, 0x8f, 0x01, 0xdd, 0x8e, 0xe1, 0x39, 0xd4, 0x63, 0x4e, 0xb9, 0xb1, 0x65, 0xd7, 0x36, + 0x9e, 0xbe, 0x7d, 0x7d, 0xd5, 0x6b, 0xf2, 0xd3, 0x31, 0xf6, 0x38, 0xf5, 0x25, 0xee, 0xe8, 0x70, + 0xbf, 0x4a, 0xbf, 0x72, 0xea, 0x04, 0xd0, 0x2a, 0x00, 0x72, 0xce, 0xc6, 0xe4, 0x9f, 0xae, 0xc4, + 0x86, 0xff, 0x63, 0x4e, 0x87, 0x62, 0x96, 0x92, 0x61, 0x9e, 0x4d, 0xe4, 0x8d, 0xb4, 0x7c, 0x88, + 0x39, 0x3d, 0x9e, 0xa5, 0xe4, 0x7d, 0x36, 0x71, 0x1e, 0xc0, 0xee, 0x6a, 0x8b, 0x6a, 0xdf, 0xfe, + 0x77, 0x04, 0x35, 0x8f, 0x53, 0xfd, 0x1d, 0xfc, 0x57, 0x3e, 0x07, 0x0b, 0xff, 0xe9, 0x11, 0xe3, + 0xca, 0xb0, 0xf9, 0xe4, 0x6e, 0x7d, 0x15, 0xfd, 0x5b, 0xa8, 0xcb, 0xf4, 0xf6, 0x37, 0xf2, 0x85, + 0x6c, 0x3e, 0xbe, 0x53, 0x5e, 0x75, 0xf3, 0xa1, 0xa1, 0xb2, 0xe9, 0x6e, 0x5c, 0x50, 0x02, 0xe6, + 0xd3, 0xbf, 0x00, 0x55, 0xcf, 0xc1, 0x60, 0xfe, 0xcd, 0xd2, 0xe6, 0x0b, 0x0b, 0xdd, 0x2c, 0x2c, + 0xf4, 0x75, 0x61, 0xa1, 0xcb, 0xa5, 0xa5, 0xdd, 0x2c, 0x2d, 0xed, 0xd3, 0xd2, 0xd2, 0x4e, 0x1e, + 0xd1, 0x48, 0x9c, 0xe5, 0x21, 0x1e, 0xb1, 0x58, 0xfd, 0x67, 0xd5, 0x4f, 0x8f, 0x9f, 0x8e, 0xdd, + 0x69, 0xf9, 0x09, 0x08, 0x1b, 0xf2, 0xae, 0x9f, 0xfd, 0x08, 0x00, 0x00, 0xff, 0xff, 0x82, 0x87, + 0x39, 0xef, 0x19, 0x04, 0x00, 0x00, } // Reference imports to suppress errors if they are not otherwise used. From 79a69d3cae8544e33263904dec28cfdd8a0bdd30 Mon Sep 17 00:00:00 2001 From: Robert Zaremba Date: Wed, 28 Apr 2021 13:58:34 +0200 Subject: [PATCH 30/44] comment update --- x/staking/types/authz.go | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/x/staking/types/authz.go b/x/staking/types/authz.go index 3026256d7603..9b4c816b0d0d 100644 --- a/x/staking/types/authz.go +++ b/x/staking/types/authz.go @@ -10,14 +10,15 @@ import ( // Tracking issues https://github.com/cosmos/cosmos-sdk/issues/9054, https://github.com/cosmos/cosmos-sdk/discussions/9072 const gasCostPerIteration = uint64(10) +// Normalized Msg type URLs var ( - _ authz.Authorization = &StakeAuthorization{} - TypeDelegate = "/cosmos.staking.v1beta1.Msg/Delegate" TypeUndelegate = "/cosmos.staking.v1beta1.Msg/Undelegate" TypeBeginRedelegate = "/cosmos.staking.v1beta1.Msg/BeginRedelegate" ) +var _ authz.Authorization = &StakeAuthorization{} + // NewStakeAuthorization creates a new StakeAuthorization object. func NewStakeAuthorization(allowed []sdk.ValAddress, denied []sdk.ValAddress, authzType AuthorizationType, amount *sdk.Coin) (*StakeAuthorization, error) { allowedValidators, deniedValidators, err := validateAndBech32fy(allowed, denied) @@ -61,7 +62,6 @@ func (a StakeAuthorization) ValidateBasic() error { } // Accept implements Authorization.Accept. -// func (authorization StakeAuthorization) Accept(ctx sdk.Context, msg sdk.ServiceMsg) (updated authz.Authorization, delete bool, err error) { func (a StakeAuthorization) Accept(ctx sdk.Context, msg sdk.ServiceMsg) (authz.AcceptResponse, error) { var validatorAddress string var amount sdk.Coin From 8320e4e47ffd820459a15c27cca3d98ff6be6422 Mon Sep 17 00:00:00 2001 From: Robert Zaremba Date: Sat, 1 May 2021 15:59:41 +0200 Subject: [PATCH 31/44] conflict updates --- x/authz/authorizations.go | 2 +- x/authz/client/cli/tx.go | 4 ++-- x/authz/client/rest/grpc_query_test.go | 8 ++++---- x/authz/codec/codec.go | 4 ---- x/authz/generic_authorization.go | 7 +------ x/authz/keeper/keeper.go | 2 +- x/authz/keeper/keeper_test.go | 2 +- x/authz/keeper/msg_server.go | 2 +- x/authz/module/module.go | 2 +- x/authz/msgs.go | 8 ++++---- x/authz/simulation/operations.go | 6 +++--- x/bank/types/codec.go | 5 +++++ x/bank/types/send_authorization.go | 6 +++--- x/staking/types/codec.go | 5 +++++ 14 files changed, 32 insertions(+), 31 deletions(-) diff --git a/x/authz/authorizations.go b/x/authz/authorizations.go index d88376d5e64f..337b71086733 100644 --- a/x/authz/authorizations.go +++ b/x/authz/authorizations.go @@ -17,7 +17,7 @@ type Authorization interface { // Accept determines whether this grant permits the provided sdk.ServiceMsg to be performed, and if // so provides an upgraded authorization instance. - Accept(ctx sdk.Context, msg sdk.ServiceMsg) (AcceptResponse, error) + Accept(ctx sdk.Context, msg sdk.Msg) (AcceptResponse, error) // ValidateBasic does a simple validation check that // doesn't require access to any other information. diff --git a/x/authz/client/cli/tx.go b/x/authz/client/cli/tx.go index c0ccb796bb7d..70752f35f13c 100644 --- a/x/authz/client/cli/tx.go +++ b/x/authz/client/cli/tx.go @@ -62,7 +62,7 @@ func NewCmdGrantAuthorization() *cobra.Command { Examples: $ %s tx %s grant cosmos1skjw.. send %s --spend-limit=1000stake --from=cosmos1skl.. $ %s tx %s grant cosmos1skjw.. generic --msg-type=/cosmos.gov.v1beta1.MsgVote --from=cosmos1sk.. - `, version.AppName, types.ModuleName, bank.SendAuthorization{}.MsgTypeURL(), version.AppName, types.ModuleName), + `, version.AppName, authz.ModuleName, bank.SendAuthorization{}.MsgTypeURL(), version.AppName, authz.ModuleName), ), Args: cobra.ExactArgs(2), RunE: func(cmd *cobra.Command, args []string) error { @@ -253,7 +253,7 @@ Example: if err != nil { return err } - msg := types.NewMsgExecAuthorized(grantee, theTx.GetMsgs()) + msg := authz.NewMsgExec(grantee, theTx.GetMsgs()) svcMsgClientConn := &msgservice.ServiceMsgClientConn{} msgClient := authz.NewMsgClient(svcMsgClientConn) _, err = msgClient.Exec(cmd.Context(), &msg) diff --git a/x/authz/client/rest/grpc_query_test.go b/x/authz/client/rest/grpc_query_test.go index a8a5bf157c98..fd41dc39415b 100644 --- a/x/authz/client/rest/grpc_query_test.go +++ b/x/authz/client/rest/grpc_query_test.go @@ -190,7 +190,7 @@ func (s *IntegrationTestSuite) TestQueryAuthorizationsGRPC() { "", func() {}, func(authorizations *authz.QueryAuthorizationsResponse) { - s.Require().Len(authorizations.Authorizations), 1) + s.Require().Len(authorizations.Authorizations, 1) }, }, { @@ -212,7 +212,7 @@ func (s *IntegrationTestSuite) TestQueryAuthorizationsGRPC() { s.Require().NoError(err) }, func(authorizations *authz.QueryAuthorizationsResponse) { - s.Require().Equal(len(authorizations.Authorizations), 2) + s.Require().Len(authorizations.Authorizations, 2) }, }, { @@ -222,7 +222,7 @@ func (s *IntegrationTestSuite) TestQueryAuthorizationsGRPC() { "", func() {}, func(authorizations *authz.QueryAuthorizationsResponse) { - s.Require().Equal(len(authorizations.Authorizations), 1) + s.Require().Len(authorizations.Authorizations, 1) }, }, { @@ -232,7 +232,7 @@ func (s *IntegrationTestSuite) TestQueryAuthorizationsGRPC() { "", func() {}, func(authorizations *authz.QueryAuthorizationsResponse) { - s.Require().Equal(len(authorizations.Authorizations), 2) + s.Require().Len(authorizations.Authorizations, 2) }, }, } diff --git a/x/authz/codec/codec.go b/x/authz/codec/codec.go index 9f3ccd9556e4..69ee22fbee6e 100644 --- a/x/authz/codec/codec.go +++ b/x/authz/codec/codec.go @@ -5,8 +5,6 @@ import ( sdk "github.com/cosmos/cosmos-sdk/types" "github.com/cosmos/cosmos-sdk/types/msgservice" "github.com/cosmos/cosmos-sdk/x/authz" - bank "github.com/cosmos/cosmos-sdk/x/bank/types" - staking "github.com/cosmos/cosmos-sdk/x/staking/types" ) // RegisterInterfaces registers the interfaces types with the interface registry @@ -20,9 +18,7 @@ func RegisterInterfaces(registry types.InterfaceRegistry) { registry.RegisterInterface( "cosmos.authz.v1beta1.Authorization", (*authz.Authorization)(nil), - &bank.SendAuthorization{}, &authz.GenericAuthorization{}, - &staking.StakeAuthorization{}, ) msgservice.RegisterMsgServiceDesc(registry, authz.MsgServiceDesc()) diff --git a/x/authz/generic_authorization.go b/x/authz/generic_authorization.go index ba843c56b26f..692636660b2e 100644 --- a/x/authz/generic_authorization.go +++ b/x/authz/generic_authorization.go @@ -2,8 +2,6 @@ package authz import ( sdk "github.com/cosmos/cosmos-sdk/types" - sdkerrors "github.com/cosmos/cosmos-sdk/types/errors" - "github.com/cosmos/cosmos-sdk/types/msgservice" ) var ( @@ -23,14 +21,11 @@ func (a GenericAuthorization) MsgTypeURL() string { } // Accept implements Authorization.Accept. -func (a GenericAuthorization) Accept(ctx sdk.Context, msg sdk.ServiceMsg) (AcceptResponse, error) { +func (a GenericAuthorization) Accept(ctx sdk.Context, msg sdk.Msg) (AcceptResponse, error) { return AcceptResponse{Accept: true}, nil } // ValidateBasic implements Authorization.ValidateBasic. func (a GenericAuthorization) ValidateBasic() error { - if !msgservice.IsServiceMsg(a.Msg) { - return sdkerrors.Wrapf(sdkerrors.ErrInvalidType, " %s is not a valid service msg", a.Msg) - } return nil } diff --git a/x/authz/keeper/keeper.go b/x/authz/keeper/keeper.go index 51e7a12d4f89..38ff5d9f263e 100644 --- a/x/authz/keeper/keeper.go +++ b/x/authz/keeper/keeper.go @@ -129,7 +129,7 @@ func (k Keeper) SaveGrant(ctx sdk.Context, grantee, granter sdk.AccAddress, auth return err } - bz := k.cdc.MustMarshalBinaryBare(&grant) + bz := k.cdc.MustMarshal(&grant) skey := grantStoreKey(grantee, granter, authorization.MsgTypeURL()) store.Set(skey, bz) return ctx.EventManager().EmitTypedEvent(&authz.EventGrant{ diff --git a/x/authz/keeper/keeper_test.go b/x/authz/keeper/keeper_test.go index c22317d6cab4..ec60e9571275 100644 --- a/x/authz/keeper/keeper_test.go +++ b/x/authz/keeper/keeper_test.go @@ -136,7 +136,7 @@ func (s *TestSuite) TestKeeperFees() { smallCoin := sdk.NewCoins(sdk.NewInt64Coin("steak", 20)) someCoin := sdk.NewCoins(sdk.NewInt64Coin("steak", 123)) - msgs := types.NewMsgExec(granteeAddr, []sdk.Msg{ + msgs := authz.NewMsgExec(granteeAddr, []sdk.Msg{ &banktypes.MsgSend{ Amount: sdk.NewCoins(sdk.NewInt64Coin("steak", 2)), FromAddress: granterAddr.String(), diff --git a/x/authz/keeper/msg_server.go b/x/authz/keeper/msg_server.go index 06c7c6866bc0..96f0c5cc1aa9 100644 --- a/x/authz/keeper/msg_server.go +++ b/x/authz/keeper/msg_server.go @@ -28,7 +28,7 @@ func (k Keeper) Grant(goCtx context.Context, msg *authz.MsgGrant) (*authz.MsgGra } t := authorization.MsgTypeURL() if k.router.HandlerbyTypeURL(t) == nil { - return nil, sdkerrors.Wrapf(sdkerrors.ErrInvalidType, "%s doesn't exist.", t + return nil, sdkerrors.Wrapf(sdkerrors.ErrInvalidType, "%s doesn't exist.", t) } err = k.SaveGrant(ctx, grantee, granter, authorization, msg.Expiration) diff --git a/x/authz/module/module.go b/x/authz/module/module.go index 1f010c486e6e..7b0c7f2f84f1 100644 --- a/x/authz/module/module.go +++ b/x/authz/module/module.go @@ -147,7 +147,7 @@ func (am AppModule) InitGenesis(ctx sdk.Context, cdc codec.JSONCodec, data json. // ExportGenesis returns the exported genesis state as raw bytes for the authz // module. func (am AppModule) ExportGenesis(ctx sdk.Context, cdc codec.JSONCodec) json.RawMessage { - gs := am.keeper.ExportGenesis(ctx, am.keeper) + gs := am.keeper.ExportGenesis(ctx) return cdc.MustMarshalJSON(gs) } diff --git a/x/authz/msgs.go b/x/authz/msgs.go index f45c3c4e8bf2..a5dbe5afb9c8 100644 --- a/x/authz/msgs.go +++ b/x/authz/msgs.go @@ -12,9 +12,9 @@ import ( ) var ( - _ sdk.Msg = &MsgGrantRequest{} - _ sdk.Msg = &MsgRevokeRequest{} - _ sdk.Msg = &MsgExecRequest{} + _ sdk.Msg = &MsgGrant{} + _ sdk.Msg = &MsgRevoke{} + _ sdk.Msg = &MsgExec{} _ cdctypes.UnpackInterfacesMessage = &MsgGrant{} _ cdctypes.UnpackInterfacesMessage = &MsgExec{} @@ -156,7 +156,7 @@ func (msg MsgRevoke) ValidateBasic() error { // NewMsgExec creates a new MsgExecAuthorized //nolint:interfacer -func NewMsgExec(grantee sdk.AccAddress, msgs []sdk.Msg) MsgExecRequest { +func NewMsgExec(grantee sdk.AccAddress, msgs []sdk.Msg) MsgExec { msgsAny := make([]*types.Any, len(msgs)) for i, msg := range msgs { any, err := types.NewAnyWithValue(msg) diff --git a/x/authz/simulation/operations.go b/x/authz/simulation/operations.go index 70aec72eb25b..af521abefc8f 100644 --- a/x/authz/simulation/operations.go +++ b/x/authz/simulation/operations.go @@ -23,9 +23,9 @@ import ( var ( // TODO Remove `Request` suffix // https://github.com/cosmos/cosmos-sdk/issues/9114 - TypeMsgGrantAuthorization = sdk.MsgTypeURL(&authz.MsgGrantRequest{}) - TypeMsgRevokeAuthorization = sdk.MsgTypeURL(&authz.MsgRevokeRequest{}) - TypeMsgExecDelegated = sdk.MsgTypeURL(&authz.MsgExecRequest{}) + TypeMsgGrantAuthorization = sdk.MsgTypeURL(&authz.MsgGrant{}) + TypeMsgRevokeAuthorization = sdk.MsgTypeURL(&authz.MsgRevoke{}) + TypeMsgExecDelegated = sdk.MsgTypeURL(&authz.MsgExec{}) ) // Simulation operation weights constants diff --git a/x/bank/types/codec.go b/x/bank/types/codec.go index 62a59fe0d34f..07859ceab603 100644 --- a/x/bank/types/codec.go +++ b/x/bank/types/codec.go @@ -6,6 +6,7 @@ import ( cryptocodec "github.com/cosmos/cosmos-sdk/crypto/codec" sdk "github.com/cosmos/cosmos-sdk/types" "github.com/cosmos/cosmos-sdk/types/msgservice" + "github.com/cosmos/cosmos-sdk/x/authz" ) // RegisterLegacyAminoCodec registers the necessary x/bank interfaces and concrete types @@ -20,6 +21,10 @@ func RegisterInterfaces(registry types.InterfaceRegistry) { &MsgSend{}, &MsgMultiSend{}, ) + registry.RegisterImplementations( + (*authz.Authorization)(nil), + &SendAuthorization{}, + ) msgservice.RegisterMsgServiceDesc(registry, &_Msg_serviceDesc) } diff --git a/x/bank/types/send_authorization.go b/x/bank/types/send_authorization.go index 498d24ce72c6..510c9647a90f 100644 --- a/x/bank/types/send_authorization.go +++ b/x/bank/types/send_authorization.go @@ -18,17 +18,17 @@ func NewSendAuthorization(spendLimit sdk.Coins) *SendAuthorization { } // MethodName implements Authorization.MsgTypeURL. -func (authorization SendAuthorization) MsgTypeURL() string { +func (a SendAuthorization) MsgTypeURL() string { return sdk.MsgTypeURL(&MsgSend{}) } // Accept implements Authorization.Accept. func (a SendAuthorization) Accept(ctx sdk.Context, msg sdk.Msg) (authz.AcceptResponse, error) { - msgR, ok := msg.Request.(*MsgSend) + mSend, ok := msg.(*MsgSend) if !ok { return authz.AcceptResponse{}, sdkerrors.ErrInvalidType.Wrap("type mismatch") } - limitLeft, isNegative := a.SpendLimit.SafeSub(msgR.Amount) + limitLeft, isNegative := a.SpendLimit.SafeSub(mSend.Amount) if isNegative { return authz.AcceptResponse{}, sdkerrors.ErrInsufficientFunds.Wrapf("requested amount is more than spend limit") } diff --git a/x/staking/types/codec.go b/x/staking/types/codec.go index 714554a33ca8..485549077bd0 100644 --- a/x/staking/types/codec.go +++ b/x/staking/types/codec.go @@ -6,6 +6,7 @@ import ( cryptocodec "github.com/cosmos/cosmos-sdk/crypto/codec" sdk "github.com/cosmos/cosmos-sdk/types" "github.com/cosmos/cosmos-sdk/types/msgservice" + "github.com/cosmos/cosmos-sdk/x/authz" ) // RegisterLegacyAminoCodec registers the necessary x/staking interfaces and concrete types @@ -27,6 +28,10 @@ func RegisterInterfaces(registry types.InterfaceRegistry) { &MsgUndelegate{}, &MsgBeginRedelegate{}, ) + registry.RegisterImplementations( + (*authz.Authorization)(nil), + &StakeAuthorization{}, + ) msgservice.RegisterMsgServiceDesc(registry, &_Msg_serviceDesc) } From b589571eac6de590f220da12f66595d6781c786c Mon Sep 17 00:00:00 2001 From: Robert Zaremba Date: Tue, 4 May 2021 09:58:38 +0200 Subject: [PATCH 32/44] Apply suggestions from code review Co-authored-by: Amaury <1293565+amaurym@users.noreply.github.com> --- proto/cosmos/authz/v1beta1/query.proto | 2 +- x/authz/generic_authorization.go | 4 ++-- x/authz/keeper/keys.go | 2 +- x/authz/spec/01_concepts.md | 4 ++-- x/authz/spec/02_state.md | 2 +- x/authz/spec/04_events.md | 2 +- 6 files changed, 8 insertions(+), 8 deletions(-) diff --git a/proto/cosmos/authz/v1beta1/query.proto b/proto/cosmos/authz/v1beta1/query.proto index 6434790050e4..3b66e03107df 100644 --- a/proto/cosmos/authz/v1beta1/query.proto +++ b/proto/cosmos/authz/v1beta1/query.proto @@ -19,7 +19,7 @@ service Query { message QueryGrantsRequest { string granter = 1; string grantee = 2; - // Optional, msg_type_url, when set, will query only grants matching give msg type. + // Optional, msg_type_url, when set, will query only grants matching given msg type. string msg_type_url = 3; // pagination defines an pagination for the request. cosmos.base.query.v1beta1.PageRequest pagination = 4; diff --git a/x/authz/generic_authorization.go b/x/authz/generic_authorization.go index 692636660b2e..d6249b137a28 100644 --- a/x/authz/generic_authorization.go +++ b/x/authz/generic_authorization.go @@ -9,9 +9,9 @@ var ( ) // NewGenericAuthorization creates a new GenericAuthorization object. -func NewGenericAuthorization(methodName string) *GenericAuthorization { +func NewGenericAuthorization(msgTypeURL string) *GenericAuthorization { return &GenericAuthorization{ - Msg: methodName, + Msg: msgTypeURL, } } diff --git a/x/authz/keeper/keys.go b/x/authz/keeper/keys.go index d4e79708e091..24fe703b3c71 100644 --- a/x/authz/keeper/keys.go +++ b/x/authz/keeper/keys.go @@ -18,7 +18,7 @@ func grantStoreKey(grantee sdk.AccAddress, granter sdk.AccAddress, msgType strin // addressesFromGrantStoreKey - split granter & grantee address from the authorization key func addressesFromGrantStoreKey(key []byte) (granterAddr, granteeAddr sdk.AccAddress) { - // key if of format: + // key is of format: // 0x01 granterAddrLen := key[1] // remove prefix key granterAddr = sdk.AccAddress(key[2 : 2+granterAddrLen]) diff --git a/x/authz/spec/01_concepts.md b/x/authz/spec/01_concepts.md index 7a2c3b33a149..6b55c8328487 100644 --- a/x/authz/spec/01_concepts.md +++ b/x/authz/spec/01_concepts.md @@ -23,7 +23,7 @@ Cosmos-SDK `x/authz` module comes with following authorization types ### SendAuthorization -`SendAuthorization` implements `Authorization` interface for the `cosmos.bank.v1beta1.Msg/Send` Msg, that takes a `SpendLimit` and updates it down to zero. +`SendAuthorization` implements `Authorization` interface for the `cosmos.bank.v1beta1.MsgSend` Msg, that takes a `SpendLimit` and updates it down to zero. +++ https://github.com/cosmos/cosmos-sdk/blob/c95de9c4177442dee4c69d96917efc955b5d19d9/proto/cosmos/authz/v1beta1/authz.proto#L12-L19 @@ -40,7 +40,7 @@ Cosmos-SDK `x/authz` module comes with following authorization types +++ https://github.com/cosmos/cosmos-sdk/blob/c95de9c4177442dee4c69d96917efc955b5d19d9/x/authz/types/generic_authorization.go#L20-L28 -- `method_name` stores Msg type URL. +- `msg` stores Msg type URL. ## Gas diff --git a/x/authz/spec/02_state.md b/x/authz/spec/02_state.md index ea2b6cac2e64..9648b623ef39 100644 --- a/x/authz/spec/02_state.md +++ b/x/authz/spec/02_state.md @@ -6,7 +6,7 @@ order: 2 ## AuthorizationGrant -Grants are identified by combining granter address (the address bytes of the granter), grantee address (the address bytes of the grantee) and Msg type (its URL). Hence we only allow one grant for the (granter, grantee, msg type) triple. +Grants are identified by combining granter address (the address bytes of the granter), grantee address (the address bytes of the grantee) and Msg type (its TypeURL). Hence we only allow one grant for the (granter, grantee, msg type) triple. - AuthorizationGrant: `0x01 | granter_address_len (1 byte) | granter_address_bytes | grantee_address_len (1 byte) | grantee_address_bytes | msgType_bytes-> ProtocolBuffer(AuthorizationGrant)` diff --git a/x/authz/spec/04_events.md b/x/authz/spec/04_events.md index 1094105a79c8..18b71db3c490 100644 --- a/x/authz/spec/04_events.md +++ b/x/authz/spec/04_events.md @@ -4,4 +4,4 @@ order: 4 # Events -The authz module emits proto eevents defined in [](../../../docs/core/proto-docs.md#cosmos/authz/v1beta1/event.proto) +The authz module emits proto events defined in [the Protobuf reference](../../../docs/core/proto-docs.md#cosmos/authz/v1beta1/event.proto). From a813d4079e89753894efa7910c72b3339ebcd46b Mon Sep 17 00:00:00 2001 From: Robert Zaremba Date: Tue, 4 May 2021 13:51:32 +0200 Subject: [PATCH 33/44] authz: move storage keys to keeper --- simapp/app.go | 11 +++++------ x/authz/keeper/keeper.go | 2 +- x/authz/keeper/keys.go | 30 ++++++++++++++++++++++++------ x/authz/keeper/keys_test.go | 9 +++++++-- x/authz/keys.go | 13 ------------- x/authz/module/module.go | 2 +- x/authz/simulation/decoder.go | 3 ++- x/authz/simulation/operations.go | 2 -- 8 files changed, 40 insertions(+), 32 deletions(-) diff --git a/simapp/app.go b/simapp/app.go index ff9027717227..95692e701e3f 100644 --- a/simapp/app.go +++ b/simapp/app.go @@ -45,6 +45,9 @@ import ( capabilitykeeper "github.com/cosmos/cosmos-sdk/x/capability/keeper" capabilitytypes "github.com/cosmos/cosmos-sdk/x/capability/types" + "github.com/cosmos/cosmos-sdk/x/authz" + authzkeeper "github.com/cosmos/cosmos-sdk/x/authz/keeper" + authz_m "github.com/cosmos/cosmos-sdk/x/authz/module" "github.com/cosmos/cosmos-sdk/x/crisis" crisiskeeper "github.com/cosmos/cosmos-sdk/x/crisis/keeper" crisistypes "github.com/cosmos/cosmos-sdk/x/crisis/types" @@ -82,10 +85,6 @@ import ( upgradekeeper "github.com/cosmos/cosmos-sdk/x/upgrade/keeper" upgradetypes "github.com/cosmos/cosmos-sdk/x/upgrade/types" - "github.com/cosmos/cosmos-sdk/x/authz" - authzkeeper "github.com/cosmos/cosmos-sdk/x/authz/keeper" - authz_m "github.com/cosmos/cosmos-sdk/x/authz/module" - // unnamed import of statik for swagger UI support _ "github.com/cosmos/cosmos-sdk/client/docs/statik" ) @@ -208,7 +207,7 @@ func NewSimApp( minttypes.StoreKey, distrtypes.StoreKey, slashingtypes.StoreKey, govtypes.StoreKey, paramstypes.StoreKey, upgradetypes.StoreKey, feegranttypes.StoreKey, evidencetypes.StoreKey, capabilitytypes.StoreKey, - authz.StoreKey, + authzkeeper.StoreKey, ) tkeys := sdk.NewTransientStoreKeys(paramstypes.TStoreKey) memKeys := sdk.NewMemoryStoreKeys(capabilitytypes.MemStoreKey) @@ -265,7 +264,7 @@ func NewSimApp( stakingtypes.NewMultiStakingHooks(app.DistrKeeper.Hooks(), app.SlashingKeeper.Hooks()), ) - app.AuthzKeeper = authzkeeper.NewKeeper(keys[authz.StoreKey], appCodec, app.BaseApp.MsgServiceRouter()) + app.AuthzKeeper = authzkeeper.NewKeeper(keys[authzkeeper.StoreKey], appCodec, app.BaseApp.MsgServiceRouter()) // register the proposal types govRouter := govtypes.NewRouter() diff --git a/x/authz/keeper/keeper.go b/x/authz/keeper/keeper.go index 38ff5d9f263e..10d516040029 100644 --- a/x/authz/keeper/keeper.go +++ b/x/authz/keeper/keeper.go @@ -192,7 +192,7 @@ func (k Keeper) GetCleanAuthorization(ctx sdk.Context, grantee sdk.AccAddress, g func (k Keeper) IterateGrants(ctx sdk.Context, handler func(granterAddr sdk.AccAddress, granteeAddr sdk.AccAddress, grant authz.Grant) bool) { store := ctx.KVStore(k.storeKey) - iter := sdk.KVStorePrefixIterator(store, authz.GrantKey) + iter := sdk.KVStorePrefixIterator(store, GrantKey) defer iter.Close() for ; iter.Valid(); iter.Next() { var grant authz.Grant diff --git a/x/authz/keeper/keys.go b/x/authz/keeper/keys.go index 24fe703b3c71..3bdd02138efb 100644 --- a/x/authz/keeper/keys.go +++ b/x/authz/keeper/keys.go @@ -1,19 +1,37 @@ package keeper import ( + "github.com/cosmos/cosmos-sdk/internal/conv" sdk "github.com/cosmos/cosmos-sdk/types" "github.com/cosmos/cosmos-sdk/types/address" "github.com/cosmos/cosmos-sdk/x/authz" ) +// Keys for store prefixes +var ( + GrantKey = []byte{0x01} // prefix for each key +) + +// StoreKey is the store key string for authz +const StoreKey = authz.ModuleName + // grantStoreKey - return authorization store key +// Items are stored with the following key: values +// +// - 0x01: Grant func grantStoreKey(grantee sdk.AccAddress, granter sdk.AccAddress, msgType string) []byte { - return append(append(append( - authz.GrantKey, - address.MustLengthPrefix(granter)...), - address.MustLengthPrefix(grantee)...), - []byte(msgType)..., - ) + m := conv.UnsafeStrToBytes(msgType) + granter = address.MustLengthPrefix(granter) + grantee = address.MustLengthPrefix(grantee) + + l := 1 + len(grantee) + len(granter) + len(m) + var key = make([]byte, l) + copy(key, GrantKey) + copy(key[1:], granter) + copy(key[1+len(granter):], grantee) + copy(key[l-len(m):], m) + // fmt.Println(">>>> len", l, key) + return key } // addressesFromGrantStoreKey - split granter & grantee address from the authorization key diff --git a/x/authz/keeper/keys_test.go b/x/authz/keeper/keys_test.go index f643474565c6..4af555eef410 100644 --- a/x/authz/keeper/keys_test.go +++ b/x/authz/keeper/keys_test.go @@ -7,6 +7,7 @@ import ( "github.com/cosmos/cosmos-sdk/crypto/keys/ed25519" sdk "github.com/cosmos/cosmos-sdk/types" + "github.com/cosmos/cosmos-sdk/types/address" bank "github.com/cosmos/cosmos-sdk/x/bank/types" ) @@ -15,7 +16,11 @@ var grantee = sdk.AccAddress(ed25519.GenPrivKey().PubKey().Address()) var msgType = bank.SendAuthorization{}.MsgTypeURL() func TestGrantkey(t *testing.T) { + require := require.New(t) + key := grantStoreKey(grantee, granter, msgType) + require.Len(key, len(GrantKey)+len(address.MustLengthPrefix(grantee))+len(address.MustLengthPrefix(granter))+len([]byte(msgType))) + granter1, grantee1 := addressesFromGrantStoreKey(grantStoreKey(grantee, granter, msgType)) - require.Equal(t, granter, granter1) - require.Equal(t, grantee, grantee1) + require.Equal(granter, granter1) + require.Equal(grantee, grantee1) } diff --git a/x/authz/keys.go b/x/authz/keys.go index c609c6d3b083..f0ecb467aebf 100644 --- a/x/authz/keys.go +++ b/x/authz/keys.go @@ -4,22 +4,9 @@ const ( // ModuleName is the module name constant used in many places ModuleName = "authz" - // StoreKey is the store key string for authz - StoreKey = ModuleName - // RouterKey is the message route for authz RouterKey = ModuleName // QuerierRoute is the querier route for authz QuerierRoute = ModuleName ) - -// Keys for authz store -// Items are stored with the following key: values -// -// - 0x01: Grant - -var ( - // Keys for store prefixes - GrantKey = []byte{0x01} // prefix for each key -) diff --git a/x/authz/module/module.go b/x/authz/module/module.go index 7b0c7f2f84f1..e2622db6f75d 100644 --- a/x/authz/module/module.go +++ b/x/authz/module/module.go @@ -183,7 +183,7 @@ func (AppModule) RandomizedParams(r *rand.Rand) []simtypes.ParamChange { // RegisterStoreDecoder registers a decoder for authz module's types func (am AppModule) RegisterStoreDecoder(sdr sdk.StoreDecoderRegistry) { - sdr[authz.StoreKey] = simulation.NewDecodeStore(am.cdc) + sdr[keeper.StoreKey] = simulation.NewDecodeStore(am.cdc) } // WeightedOperations returns the all the gov module operations with their respective weights. diff --git a/x/authz/simulation/decoder.go b/x/authz/simulation/decoder.go index f720713e5151..908a90abf554 100644 --- a/x/authz/simulation/decoder.go +++ b/x/authz/simulation/decoder.go @@ -7,6 +7,7 @@ import ( "github.com/cosmos/cosmos-sdk/codec" "github.com/cosmos/cosmos-sdk/types/kv" "github.com/cosmos/cosmos-sdk/x/authz" + "github.com/cosmos/cosmos-sdk/x/authz/keeper" ) // NewDecodeStore returns a decoder function closure that umarshals the KVPair's @@ -14,7 +15,7 @@ import ( func NewDecodeStore(cdc codec.Codec) func(kvA, kvB kv.Pair) string { return func(kvA, kvB kv.Pair) string { switch { - case bytes.Equal(kvA.Key[:1], authz.GrantKey): + case bytes.Equal(kvA.Key[:1], keeper.GrantKey): var grantA, grantB authz.Grant cdc.MustUnmarshal(kvA.Value, &grantA) cdc.MustUnmarshal(kvB.Value, &grantB) diff --git a/x/authz/simulation/operations.go b/x/authz/simulation/operations.go index af521abefc8f..b6018167e985 100644 --- a/x/authz/simulation/operations.go +++ b/x/authz/simulation/operations.go @@ -21,8 +21,6 @@ import ( // authz message types var ( - // TODO Remove `Request` suffix - // https://github.com/cosmos/cosmos-sdk/issues/9114 TypeMsgGrantAuthorization = sdk.MsgTypeURL(&authz.MsgGrant{}) TypeMsgRevokeAuthorization = sdk.MsgTypeURL(&authz.MsgRevoke{}) TypeMsgExecDelegated = sdk.MsgTypeURL(&authz.MsgExec{}) From b5209b65960ec73d794c5698d4f1c473767e3ce4 Mon Sep 17 00:00:00 2001 From: Robert Zaremba Date: Tue, 4 May 2021 13:57:36 +0200 Subject: [PATCH 34/44] review updates --- x/authz/spec/01_concepts.md | 2 -- x/staking/types/authz.go | 2 -- 2 files changed, 4 deletions(-) diff --git a/x/authz/spec/01_concepts.md b/x/authz/spec/01_concepts.md index 6b55c8328487..48ef52d20b1c 100644 --- a/x/authz/spec/01_concepts.md +++ b/x/authz/spec/01_concepts.md @@ -11,8 +11,6 @@ on behalf of one account to other accounts. The design is defined in the [ADR 03 Grant is an allowance to execute an Msg by grantee address on behalf of the granter. Authorization is an interface which must be implemented by a concrete authorization logic to validate and execute grants. They are extensible and can be defined for any Msg service method even outside of the module where the Msg method is defined. See the `SendAuthorization` example below for more details. -Authorizations use the new `Msg` type from [ADR 031](../../../architecture/adr-031-msg-service.md). - +++ https://github.com/cosmos/cosmos-sdk/blob/c95de9c4177442dee4c69d96917efc955b5d19d9/x/authz/types/authorizations.go#L15-L24 diff --git a/x/staking/types/authz.go b/x/staking/types/authz.go index e0ea168c203a..f1c2a717069a 100644 --- a/x/staking/types/authz.go +++ b/x/staking/types/authz.go @@ -15,8 +15,6 @@ var ( _ authz.Authorization = &StakeAuthorization{} ) -var _ authz.Authorization = &StakeAuthorization{} - // NewStakeAuthorization creates a new StakeAuthorization object. func NewStakeAuthorization(allowed []sdk.ValAddress, denied []sdk.ValAddress, authzType AuthorizationType, amount *sdk.Coin) (*StakeAuthorization, error) { allowedValidators, deniedValidators, err := validateAndBech32fy(allowed, denied) From ead0ee8f2b973964c264d640cfe55ea08e1960c6 Mon Sep 17 00:00:00 2001 From: Robert Zaremba Date: Tue, 4 May 2021 21:58:13 +0200 Subject: [PATCH 35/44] docs update --- docs/core/proto-docs.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/docs/core/proto-docs.md b/docs/core/proto-docs.md index 9827fb50c43a..f6d37ac93a6f 100644 --- a/docs/core/proto-docs.md +++ b/docs/core/proto-docs.md @@ -1035,7 +1035,7 @@ QueryGrantsRequest is the request type for the Query/Grants RPC method. | ----- | ---- | ----- | ----------- | | `granter` | [string](#string) | | | | `grantee` | [string](#string) | | | -| `msg_type_url` | [string](#string) | | Optional, msg_type_url, when set, will query only grants matching give msg type. | +| `msg_type_url` | [string](#string) | | Optional, msg_type_url, when set, will query only grants matching given msg type. | | `pagination` | [cosmos.base.query.v1beta1.PageRequest](#cosmos.base.query.v1beta1.PageRequest) | | pagination defines an pagination for the request. | From a4bd3d9cbed92e535f1cd2e32823c66471bb7ff8 Mon Sep 17 00:00:00 2001 From: Robert Zaremba Date: Thu, 6 May 2021 00:01:52 +0200 Subject: [PATCH 36/44] Update x/authz/client/cli/query.go Co-authored-by: Aaron Craelius --- x/authz/client/cli/query.go | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/x/authz/client/cli/query.go b/x/authz/client/cli/query.go index afd144686161..fc82ace03334 100644 --- a/x/authz/client/cli/query.go +++ b/x/authz/client/cli/query.go @@ -35,7 +35,7 @@ func GetQueryCmd() *cobra.Command { // GetCmdQueryGrants implements the query authorization command. func GetCmdQueryGrants() *cobra.Command { cmd := &cobra.Command{ - Use: "authorization [granter-addr] [grantee-addr] [msg-type-url]?", + Use: "authorizations [granter-addr] [grantee-addr] [msg-type-url]?", Args: cobra.RangeArgs(2, 3), Short: "query grants for a granter-grantee pair and optionally a msg-type-url", Long: strings.TrimSpace( From 6050e1e6e14dd549641d61e29b51384efb7a885e Mon Sep 17 00:00:00 2001 From: Robert Zaremba Date: Thu, 6 May 2021 00:08:05 +0200 Subject: [PATCH 37/44] move codec to the root package --- x/authz/{codec => }/codec.go | 17 ++++++++--------- x/authz/module/module.go | 3 +-- x/authz/simulation/decoder_test.go | 3 ++- 3 files changed, 11 insertions(+), 12 deletions(-) rename x/authz/{codec => }/codec.go (57%) diff --git a/x/authz/codec/codec.go b/x/authz/codec.go similarity index 57% rename from x/authz/codec/codec.go rename to x/authz/codec.go index 69ee22fbee6e..e9a490cea379 100644 --- a/x/authz/codec/codec.go +++ b/x/authz/codec.go @@ -1,25 +1,24 @@ -package types +package authz import ( types "github.com/cosmos/cosmos-sdk/codec/types" sdk "github.com/cosmos/cosmos-sdk/types" "github.com/cosmos/cosmos-sdk/types/msgservice" - "github.com/cosmos/cosmos-sdk/x/authz" ) // RegisterInterfaces registers the interfaces types with the interface registry func RegisterInterfaces(registry types.InterfaceRegistry) { registry.RegisterImplementations((*sdk.Msg)(nil), - &authz.MsgGrant{}, - &authz.MsgRevoke{}, - &authz.MsgExec{}, + &MsgGrant{}, + &MsgRevoke{}, + &MsgExec{}, ) registry.RegisterInterface( - "cosmos.authz.v1beta1.Authorization", - (*authz.Authorization)(nil), - &authz.GenericAuthorization{}, + "cosmos.v1beta1.Authorization", + (*Authorization)(nil), + &GenericAuthorization{}, ) - msgservice.RegisterMsgServiceDesc(registry, authz.MsgServiceDesc()) + msgservice.RegisterMsgServiceDesc(registry, MsgServiceDesc()) } diff --git a/x/authz/module/module.go b/x/authz/module/module.go index e2622db6f75d..e3235a723f15 100644 --- a/x/authz/module/module.go +++ b/x/authz/module/module.go @@ -19,7 +19,6 @@ import ( simtypes "github.com/cosmos/cosmos-sdk/types/simulation" "github.com/cosmos/cosmos-sdk/x/authz" "github.com/cosmos/cosmos-sdk/x/authz/client/cli" - authzcdc "github.com/cosmos/cosmos-sdk/x/authz/codec" "github.com/cosmos/cosmos-sdk/x/authz/keeper" "github.com/cosmos/cosmos-sdk/x/authz/simulation" ) @@ -52,7 +51,7 @@ func (AppModuleBasic) RegisterLegacyAminoCodec(cdc *codec.LegacyAmino) {} // RegisterInterfaces registers the authz module's interface types func (AppModuleBasic) RegisterInterfaces(registry cdctypes.InterfaceRegistry) { - authzcdc.RegisterInterfaces(registry) + authz.RegisterInterfaces(registry) } // DefaultGenesis returns default genesis state as raw bytes for the authz diff --git a/x/authz/simulation/decoder_test.go b/x/authz/simulation/decoder_test.go index 8fc07dc52312..fc0b1a45f72a 100644 --- a/x/authz/simulation/decoder_test.go +++ b/x/authz/simulation/decoder_test.go @@ -11,6 +11,7 @@ import ( sdk "github.com/cosmos/cosmos-sdk/types" "github.com/cosmos/cosmos-sdk/types/kv" "github.com/cosmos/cosmos-sdk/x/authz" + "github.com/cosmos/cosmos-sdk/x/authz/keeper" "github.com/cosmos/cosmos-sdk/x/authz/simulation" banktypes "github.com/cosmos/cosmos-sdk/x/bank/types" ) @@ -24,7 +25,7 @@ func TestDecodeStore(t *testing.T) { require.NoError(t, err) kvPairs := kv.Pairs{ Pairs: []kv.Pair{ - {Key: []byte(authz.GrantKey), Value: grantBz}, + {Key: []byte(keeper.GrantKey), Value: grantBz}, {Key: []byte{0x99}, Value: []byte{0x99}}, }, } From b7403e84340ecad199345cc854cd1acd965c1306 Mon Sep 17 00:00:00 2001 From: Robert Zaremba Date: Thu, 6 May 2021 00:27:21 +0200 Subject: [PATCH 38/44] authz CMD info update --- x/authz/client/cli/query.go | 2 +- x/authz/client/cli/tx.go | 2 +- x/authz/client/rest/grpc_query_test.go | 54 +++++++++++++------------ x/authz/client/testutil/query.go | 4 +- x/authz/client/testutil/test_helpers.go | 2 +- x/authz/client/testutil/tx.go | 22 +++++----- 6 files changed, 44 insertions(+), 42 deletions(-) diff --git a/x/authz/client/cli/query.go b/x/authz/client/cli/query.go index fc82ace03334..c8772b2aaa46 100644 --- a/x/authz/client/cli/query.go +++ b/x/authz/client/cli/query.go @@ -35,7 +35,7 @@ func GetQueryCmd() *cobra.Command { // GetCmdQueryGrants implements the query authorization command. func GetCmdQueryGrants() *cobra.Command { cmd := &cobra.Command{ - Use: "authorizations [granter-addr] [grantee-addr] [msg-type-url]?", + Use: "grants [granter-addr] [grantee-addr] [msg-type-url]?", Args: cobra.RangeArgs(2, 3), Short: "query grants for a granter-grantee pair and optionally a msg-type-url", Long: strings.TrimSpace( diff --git a/x/authz/client/cli/tx.go b/x/authz/client/cli/tx.go index 70752f35f13c..f59bc6e4b20b 100644 --- a/x/authz/client/cli/tx.go +++ b/x/authz/client/cli/tx.go @@ -57,7 +57,7 @@ func NewCmdGrantAuthorization() *cobra.Command { Use: "grant --from ", Short: "Grant authorization to an address", Long: strings.TrimSpace( - fmt.Sprintf(`Grant authorization to an address to execute a transaction on your behalf: + fmt.Sprintf(`grant authorization to an address to execute a transaction on your behalf: Examples: $ %s tx %s grant cosmos1skjw.. send %s --spend-limit=1000stake --from=cosmos1skl.. diff --git a/x/authz/client/rest/grpc_query_test.go b/x/authz/client/rest/grpc_query_test.go index 23bab2e85828..655f8a13cd1c 100644 --- a/x/authz/client/rest/grpc_query_test.go +++ b/x/authz/client/rest/grpc_query_test.go @@ -1,4 +1,4 @@ -// +build norace +// x+build norace package rest_test @@ -30,7 +30,7 @@ type IntegrationTestSuite struct { grantee sdk.AccAddress } -var typeMsgSend = banktypes.SendAuthorization{}.MethodName() +var typeMsgSend = banktypes.SendAuthorization{}.MsgTypeURL() var typeMsgVote = sdk.MsgTypeURL(&govtypes.MsgVote{}) func (s *IntegrationTestSuite) SetupSuite() { @@ -61,7 +61,7 @@ func (s *IntegrationTestSuite) SetupSuite() { s.Require().Contains(out.String(), `"code":0`) // grant authorization - out, err = authztestutil.ExecGrantAuthorization(val, []string{ + out, err = authztestutil.ExecGrant(val, []string{ newAddr.String(), "send", fmt.Sprintf("--%s=100steak", cli.FlagSpendLimit), @@ -84,7 +84,7 @@ func (s *IntegrationTestSuite) TearDownSuite() { s.network.Cleanup() } -func (s *IntegrationTestSuite) TestQueryAuthorizationGRPC() { +func (s *IntegrationTestSuite) TestQueryGrantGRPC() { val := s.network.Validators[0] baseURL := val.APIAddress testCases := []struct { @@ -134,21 +134,23 @@ func (s *IntegrationTestSuite) TestQueryAuthorizationGRPC() { tc := tc s.Run(tc.name, func() { resp, _ := rest.GetRequest(tc.url) + require := s.Require() if tc.expectErr { - s.Require().Contains(string(resp), tc.errorMsg) + require.Contains(string(resp), tc.errorMsg) } else { - var authorization authz.QueryAuthorizationResponse - err := val.ClientCtx.JSONCodec.UnmarshalJSON(resp, &authorization) - s.Require().NoError(err) - authorization.Authorization.UnpackInterfaces(val.ClientCtx.InterfaceRegistry) - auth := authorization.Authorization.GetAuthorizationGrant() - s.Require().Equal(auth.MethodName(), banktypes.SendAuthorization{}.MethodName()) + var g authz.QueryGrantsResponse + err := val.ClientCtx.JSONCodec.UnmarshalJSON(resp, &g) + require.NoError(err) + require.Len(g, 1) + g.Grants[0].UnpackInterfaces(val.ClientCtx.InterfaceRegistry) + auth := g.Grants[0].GetAuthorization() + require.Equal(auth.MsgTypeURL(), banktypes.SendAuthorization{}.MsgTypeURL()) } }) } } -func (s *IntegrationTestSuite) TestQueryAuthorizationsGRPC() { +func (s *IntegrationTestSuite) TestQueryGrantsGRPC() { val := s.network.Validators[0] baseURL := val.APIAddress testCases := []struct { @@ -157,7 +159,7 @@ func (s *IntegrationTestSuite) TestQueryAuthorizationsGRPC() { expectErr bool errMsg string preRun func() - postRun func(*authz.QueryAuthorizationsResponse) + postRun func(*authz.QueryGrantsResponse) }{ { "fail invalid granter address", @@ -165,7 +167,7 @@ func (s *IntegrationTestSuite) TestQueryAuthorizationsGRPC() { true, "decoding bech32 failed: invalid index of 1: invalid request", func() {}, - func(_ *authz.QueryAuthorizationsResponse) {}, + func(_ *authz.QueryGrantsResponse) {}, }, { "fail invalid grantee address", @@ -173,7 +175,7 @@ func (s *IntegrationTestSuite) TestQueryAuthorizationsGRPC() { true, "decoding bech32 failed: invalid index of 1: invalid request", func() {}, - func(_ *authz.QueryAuthorizationsResponse) {}, + func(_ *authz.QueryGrantsResponse) {}, }, { "fail empty grantee address", @@ -181,7 +183,7 @@ func (s *IntegrationTestSuite) TestQueryAuthorizationsGRPC() { true, "Not Implemented", func() {}, - func(_ *authz.QueryAuthorizationsResponse) {}, + func(_ *authz.QueryGrantsResponse) {}, }, { "valid query: expect single grant", @@ -189,8 +191,8 @@ func (s *IntegrationTestSuite) TestQueryAuthorizationsGRPC() { false, "", func() {}, - func(authorizations *authz.QueryAuthorizationsResponse) { - s.Require().Len(authorizations.Authorizations, 1) + func(g *authz.QueryGrantsResponse) { + s.Require().Len(g.Grants, 1) }, }, { @@ -199,7 +201,7 @@ func (s *IntegrationTestSuite) TestQueryAuthorizationsGRPC() { false, "", func() { - _, err := authztestutil.ExecGrantAuthorization(val, []string{ + _, err := authztestutil.ExecGrant(val, []string{ s.grantee.String(), "generic", fmt.Sprintf("--%s=%s", flags.FlagFrom, val.Address.String()), @@ -211,8 +213,8 @@ func (s *IntegrationTestSuite) TestQueryAuthorizationsGRPC() { }) s.Require().NoError(err) }, - func(authorizations *authz.QueryAuthorizationsResponse) { - s.Require().Len(authorizations.Authorizations, 2) + func(g *authz.QueryGrantsResponse) { + s.Require().Len(g.Grants, 2) }, }, { @@ -221,8 +223,8 @@ func (s *IntegrationTestSuite) TestQueryAuthorizationsGRPC() { false, "", func() {}, - func(authorizations *authz.QueryAuthorizationsResponse) { - s.Require().Len(authorizations.Authorizations, 1) + func(g *authz.QueryGrantsResponse) { + s.Require().Len(g.Grants, 1) }, }, { @@ -231,8 +233,8 @@ func (s *IntegrationTestSuite) TestQueryAuthorizationsGRPC() { false, "", func() {}, - func(authorizations *authz.QueryAuthorizationsResponse) { - s.Require().Len(authorizations.Authorizations, 2) + func(g *authz.QueryGrantsResponse) { + s.Require().Len(g.Grants, 2) }, }, } @@ -244,7 +246,7 @@ func (s *IntegrationTestSuite) TestQueryAuthorizationsGRPC() { if tc.expectErr { s.Require().Contains(string(resp), tc.errMsg) } else { - var authorizations authz.QueryAuthorizationsResponse + var authorizations authz.QueryGrantsResponse err := val.ClientCtx.JSONCodec.UnmarshalJSON(resp, &authorizations) s.Require().NoError(err) tc.postRun(&authorizations) diff --git a/x/authz/client/testutil/query.go b/x/authz/client/testutil/query.go index fae220b3915b..acdd7b7abf77 100644 --- a/x/authz/client/testutil/query.go +++ b/x/authz/client/testutil/query.go @@ -20,7 +20,7 @@ func (s *IntegrationTestSuite) TestQueryAuthorizations() { grantee := s.grantee twoHours := time.Now().Add(time.Minute * time.Duration(120)).Unix() - _, err := ExecGrantAuthorization( + _, err := ExecGrant( val, []string{ grantee.String(), @@ -98,7 +98,7 @@ func (s *IntegrationTestSuite) TestQueryAuthorization() { grantee := s.grantee twoHours := time.Now().Add(time.Minute * time.Duration(120)).Unix() - _, err := ExecGrantAuthorization( + _, err := ExecGrant( val, []string{ grantee.String(), diff --git a/x/authz/client/testutil/test_helpers.go b/x/authz/client/testutil/test_helpers.go index e1b728389902..1a1cd4830fc1 100644 --- a/x/authz/client/testutil/test_helpers.go +++ b/x/authz/client/testutil/test_helpers.go @@ -7,7 +7,7 @@ import ( "github.com/cosmos/cosmos-sdk/x/authz/client/cli" ) -func ExecGrantAuthorization(val *network.Validator, args []string) (testutil.BufferWriter, error) { +func ExecGrant(val *network.Validator, args []string) (testutil.BufferWriter, error) { cmd := cli.NewCmdGrantAuthorization() clientCtx := val.ClientCtx return clitestutil.ExecTestCLICmd(clientCtx, cmd, args) diff --git a/x/authz/client/testutil/tx.go b/x/authz/client/testutil/tx.go index 573f936213b3..91f1275f4a15 100644 --- a/x/authz/client/testutil/tx.go +++ b/x/authz/client/testutil/tx.go @@ -264,7 +264,7 @@ func (s *IntegrationTestSuite) TestCLITxGrantAuthorization() { tc := tc s.Run(tc.name, func() { clientCtx := val.ClientCtx - out, err := ExecGrantAuthorization( + out, err := ExecGrant( val, tc.args, ) @@ -293,7 +293,7 @@ func (s *IntegrationTestSuite) TestCmdRevokeAuthorizations() { twoHours := time.Now().Add(time.Minute * time.Duration(120)).Unix() // send-authorization - _, err := ExecGrantAuthorization( + _, err := ExecGrant( val, []string{ grantee.String(), @@ -309,7 +309,7 @@ func (s *IntegrationTestSuite) TestCmdRevokeAuthorizations() { s.Require().NoError(err) // generic-authorization - _, err = ExecGrantAuthorization( + _, err = ExecGrant( val, []string{ grantee.String(), @@ -407,7 +407,7 @@ func (s *IntegrationTestSuite) TestExecAuthorizationWithExpiration() { grantee := s.grantee tenSeconds := time.Now().Add(time.Second * time.Duration(10)).Unix() - _, err := ExecGrantAuthorization( + _, err := ExecGrant( val, []string{ grantee.String(), @@ -447,7 +447,7 @@ func (s *IntegrationTestSuite) TestNewExecGenericAuthorized() { grantee := s.grantee twoHours := time.Now().Add(time.Minute * time.Duration(120)).Unix() - _, err := ExecGrantAuthorization( + _, err := ExecGrant( val, []string{ grantee.String(), @@ -536,7 +536,7 @@ func (s *IntegrationTestSuite) TestNewExecGrantAuthorized() { grantee := s.grantee twoHours := time.Now().Add(time.Minute * time.Duration(120)).Unix() - _, err := ExecGrantAuthorization( + _, err := ExecGrant( val, []string{ grantee.String(), @@ -621,7 +621,7 @@ func (s *IntegrationTestSuite) TestExecDelegateAuthorization() { grantee := s.grantee twoHours := time.Now().Add(time.Minute * time.Duration(120)).Unix() - _, err := ExecGrantAuthorization( + _, err := ExecGrant( val, []string{ grantee.String(), @@ -713,7 +713,7 @@ func (s *IntegrationTestSuite) TestExecDelegateAuthorization() { } // test delegate no spend-limit - _, err = ExecGrantAuthorization( + _, err = ExecGrant( val, []string{ grantee.String(), @@ -790,7 +790,7 @@ func (s *IntegrationTestSuite) TestExecDelegateAuthorization() { } // test delegating to denied validator - _, err = ExecGrantAuthorization( + _, err = ExecGrant( val, []string{ grantee.String(), @@ -825,7 +825,7 @@ func (s *IntegrationTestSuite) TestExecUndelegateAuthorization() { twoHours := time.Now().Add(time.Minute * time.Duration(120)).Unix() // granting undelegate msg authorization - _, err := ExecGrantAuthorization( + _, err := ExecGrant( val, []string{ grantee.String(), @@ -931,7 +931,7 @@ func (s *IntegrationTestSuite) TestExecUndelegateAuthorization() { } // grant undelegate authorization without limit - _, err = ExecGrantAuthorization( + _, err = ExecGrant( val, []string{ grantee.String(), From 52bc0b1b9fa53cbf3d6e439b54836b66df3e4167 Mon Sep 17 00:00:00 2001 From: Robert Zaremba Date: Thu, 6 May 2021 00:37:22 +0200 Subject: [PATCH 39/44] comment update --- docs/core/proto-docs.md | 2 +- proto/cosmos/authz/v1beta1/tx.proto | 2 +- x/authz/query.pb.go | 2 +- x/authz/tx.pb.go | 2 +- 4 files changed, 4 insertions(+), 4 deletions(-) diff --git a/docs/core/proto-docs.md b/docs/core/proto-docs.md index f460c31eabd7..ab45bab0bebd 100644 --- a/docs/core/proto-docs.md +++ b/docs/core/proto-docs.md @@ -1291,7 +1291,7 @@ one signer corresponding to the granter of the authorization. | Field | Type | Label | Description | | ----- | ---- | ----- | ----------- | | `grantee` | [string](#string) | | | -| `msgs` | [google.protobuf.Any](#google.protobuf.Any) | repeated | MsgService requests to execute. The x/authz will try to find a grant matching (msg.signers[0], grantee, MsgTypeURL(msg)) triple and validate it. | +| `msgs` | [google.protobuf.Any](#google.protobuf.Any) | repeated | Msg requests to execute. The x/authz will try to find a grant matching (msg.signers[0], grantee, MsgTypeURL(msg)) triple and validate it. | diff --git a/proto/cosmos/authz/v1beta1/tx.proto b/proto/cosmos/authz/v1beta1/tx.proto index 47e6ca630fd7..45c1eacc1847 100644 --- a/proto/cosmos/authz/v1beta1/tx.proto +++ b/proto/cosmos/authz/v1beta1/tx.proto @@ -46,7 +46,7 @@ message MsgExecResponse { // one signer corresponding to the granter of the authorization. message MsgExec { string grantee = 1; - // MsgService requests to execute. The x/authz will try to find a grant matching + // Msg requests to execute. The x/authz will try to find a grant matching // (msg.signers[0], grantee, MsgTypeURL(msg)) triple and validate it. repeated google.protobuf.Any msgs = 2 [(cosmos_proto.accepts_interface) = "sdk.Msg"];; } diff --git a/x/authz/query.pb.go b/x/authz/query.pb.go index ced860c00127..3e332ef64453 100644 --- a/x/authz/query.pb.go +++ b/x/authz/query.pb.go @@ -33,7 +33,7 @@ const _ = proto.GoGoProtoPackageIsVersion3 // please upgrade the proto package type QueryGrantsRequest struct { Granter string `protobuf:"bytes,1,opt,name=granter,proto3" json:"granter,omitempty"` Grantee string `protobuf:"bytes,2,opt,name=grantee,proto3" json:"grantee,omitempty"` - // Optional, msg_type_url, when set, will query only grants matching give msg type. + // Optional, msg_type_url, when set, will query only grants matching given msg type. MsgTypeUrl string `protobuf:"bytes,3,opt,name=msg_type_url,json=msgTypeUrl,proto3" json:"msg_type_url,omitempty"` // pagination defines an pagination for the request. Pagination *query.PageRequest `protobuf:"bytes,4,opt,name=pagination,proto3" json:"pagination,omitempty"` diff --git a/x/authz/tx.pb.go b/x/authz/tx.pb.go index a73136071b41..ec7d7a386352 100644 --- a/x/authz/tx.pb.go +++ b/x/authz/tx.pb.go @@ -120,7 +120,7 @@ var xxx_messageInfo_MsgExecResponse proto.InternalMessageInfo // one signer corresponding to the granter of the authorization. type MsgExec struct { Grantee string `protobuf:"bytes,1,opt,name=grantee,proto3" json:"grantee,omitempty"` - // MsgService requests to execute. The x/authz will try to find a grant matching + // Msg requests to execute. The x/authz will try to find a grant matching // (msg.signers[0], grantee, MsgTypeURL(msg)) triple and validate it. Msgs []*types.Any `protobuf:"bytes,2,rep,name=msgs,proto3" json:"msgs,omitempty"` } From 059982c56700b8ed735a61f0239c0570e2d2de67 Mon Sep 17 00:00:00 2001 From: Robert Zaremba Date: Thu, 6 May 2021 00:45:48 +0200 Subject: [PATCH 40/44] update imports and build flags --- x/authz/client/rest/grpc_query_test.go | 2 +- x/authz/msgs.go | 5 ++--- 2 files changed, 3 insertions(+), 4 deletions(-) diff --git a/x/authz/client/rest/grpc_query_test.go b/x/authz/client/rest/grpc_query_test.go index 655f8a13cd1c..1121afe39aa2 100644 --- a/x/authz/client/rest/grpc_query_test.go +++ b/x/authz/client/rest/grpc_query_test.go @@ -1,4 +1,4 @@ -// x+build norace +// +build norace package rest_test diff --git a/x/authz/msgs.go b/x/authz/msgs.go index a5dbe5afb9c8..a747d2c7a5a8 100644 --- a/x/authz/msgs.go +++ b/x/authz/msgs.go @@ -6,7 +6,6 @@ import ( "github.com/gogo/protobuf/proto" cdctypes "github.com/cosmos/cosmos-sdk/codec/types" - types "github.com/cosmos/cosmos-sdk/codec/types" sdk "github.com/cosmos/cosmos-sdk/types" sdkerrors "github.com/cosmos/cosmos-sdk/types/errors" ) @@ -157,9 +156,9 @@ func (msg MsgRevoke) ValidateBasic() error { // NewMsgExec creates a new MsgExecAuthorized //nolint:interfacer func NewMsgExec(grantee sdk.AccAddress, msgs []sdk.Msg) MsgExec { - msgsAny := make([]*types.Any, len(msgs)) + msgsAny := make([]*cdctypes.Any, len(msgs)) for i, msg := range msgs { - any, err := types.NewAnyWithValue(msg) + any, err := cdctypes.NewAnyWithValue(msg) if err != nil { panic(err) } From 42183891ecafdfb543e73a26eaa4d5f481e3df30 Mon Sep 17 00:00:00 2001 From: Robert Zaremba Date: Thu, 6 May 2021 01:15:36 +0200 Subject: [PATCH 41/44] fix functional tests --- x/authz/client/rest/grpc_query_test.go | 54 +++++++------------------- x/authz/client/testutil/cli_test.go | 4 +- 2 files changed, 17 insertions(+), 41 deletions(-) diff --git a/x/authz/client/rest/grpc_query_test.go b/x/authz/client/rest/grpc_query_test.go index 1121afe39aa2..00106b430252 100644 --- a/x/authz/client/rest/grpc_query_test.go +++ b/x/authz/client/rest/grpc_query_test.go @@ -86,7 +86,7 @@ func (s *IntegrationTestSuite) TearDownSuite() { func (s *IntegrationTestSuite) TestQueryGrantGRPC() { val := s.network.Validators[0] - baseURL := val.APIAddress + grantsURL := val.APIAddress + "/cosmos/authz/v1beta1/grants?granter=%s&grantee=%s&msg_type_url=%s" testCases := []struct { name string url string @@ -95,37 +95,37 @@ func (s *IntegrationTestSuite) TestQueryGrantGRPC() { }{ { "fail invalid granter address", - fmt.Sprintf("%s/cosmos/authz/v1beta1/granters/%s/grantees/%s/grant?method_name=%s", baseURL, "invalid_granter", s.grantee.String(), typeMsgSend), + fmt.Sprintf(grantsURL, "invalid_granter", s.grantee.String(), typeMsgSend), true, "decoding bech32 failed: invalid index of 1: invalid request", }, { "fail invalid grantee address", - fmt.Sprintf("%s/cosmos/authz/v1beta1/granters/%s/grantees/%s/grant?method_name=%s", baseURL, val.Address.String(), "invalid_grantee", typeMsgSend), + fmt.Sprintf(grantsURL, val.Address.String(), "invalid_grantee", typeMsgSend), true, "decoding bech32 failed: invalid index of 1: invalid request", }, { "fail with empty granter", - fmt.Sprintf("%s/cosmos/authz/v1beta1/granters/%s/grantees/%s/grant?method_name=%s", baseURL, "", s.grantee.String(), typeMsgSend), + fmt.Sprintf(grantsURL, "", s.grantee.String(), typeMsgSend), true, - "Not Implemented", + "empty address string is not allowed: invalid request", }, { "fail with empty grantee", - fmt.Sprintf("%s/cosmos/authz/v1beta1/granters/%s/grantees/%s/grant?method_name=%s", baseURL, val.Address.String(), "", typeMsgSend), + fmt.Sprintf(grantsURL, val.Address.String(), "", typeMsgSend), true, - "Not Implemented", + "empty address string is not allowed: invalid request", }, { "fail invalid msg-type", - fmt.Sprintf("%s/cosmos/authz/v1beta1/granters/%s/grantees/%s/grant?method_name=%s", baseURL, val.Address.String(), s.grantee.String(), "invalidMsg"), + fmt.Sprintf(grantsURL, val.Address.String(), s.grantee.String(), "invalidMsg"), true, "rpc error: code = NotFound desc = no authorization found for invalidMsg type: key not found", }, { "valid query", - fmt.Sprintf("%s/cosmos/authz/v1beta1/granters/%s/grantees/%s/grant?method_name=%s", baseURL, val.Address.String(), s.grantee.String(), typeMsgSend), + fmt.Sprintf(grantsURL, val.Address.String(), s.grantee.String(), typeMsgSend), false, "", }, @@ -141,7 +141,7 @@ func (s *IntegrationTestSuite) TestQueryGrantGRPC() { var g authz.QueryGrantsResponse err := val.ClientCtx.JSONCodec.UnmarshalJSON(resp, &g) require.NoError(err) - require.Len(g, 1) + require.Len(g.Grants, 1) g.Grants[0].UnpackInterfaces(val.ClientCtx.InterfaceRegistry) auth := g.Grants[0].GetAuthorization() require.Equal(auth.MsgTypeURL(), banktypes.SendAuthorization{}.MsgTypeURL()) @@ -152,7 +152,7 @@ func (s *IntegrationTestSuite) TestQueryGrantGRPC() { func (s *IntegrationTestSuite) TestQueryGrantsGRPC() { val := s.network.Validators[0] - baseURL := val.APIAddress + grantsURL := val.APIAddress + "/cosmos/authz/v1beta1/grants?granter=%s&grantee=%s" testCases := []struct { name string url string @@ -161,33 +161,9 @@ func (s *IntegrationTestSuite) TestQueryGrantsGRPC() { preRun func() postRun func(*authz.QueryGrantsResponse) }{ - { - "fail invalid granter address", - fmt.Sprintf("%s/cosmos/authz/v1beta1/granters/%s/grantees/%s/grants", baseURL, "invalid_granter", s.grantee.String()), - true, - "decoding bech32 failed: invalid index of 1: invalid request", - func() {}, - func(_ *authz.QueryGrantsResponse) {}, - }, - { - "fail invalid grantee address", - fmt.Sprintf("%s/cosmos/authz/v1beta1/granters/%s/grantees/%s/grants", baseURL, val.Address.String(), "invalid_grantee"), - true, - "decoding bech32 failed: invalid index of 1: invalid request", - func() {}, - func(_ *authz.QueryGrantsResponse) {}, - }, - { - "fail empty grantee address", - fmt.Sprintf("%s/cosmos/authz/v1beta1/granters/%s/grantees/%s/grants", baseURL, "", "invalid_grantee"), - true, - "Not Implemented", - func() {}, - func(_ *authz.QueryGrantsResponse) {}, - }, { "valid query: expect single grant", - fmt.Sprintf("%s/cosmos/authz/v1beta1/granters/%s/grantees/%s/grants", baseURL, val.Address.String(), s.grantee.String()), + fmt.Sprintf(grantsURL, val.Address.String(), s.grantee.String()), false, "", func() {}, @@ -197,7 +173,7 @@ func (s *IntegrationTestSuite) TestQueryGrantsGRPC() { }, { "valid query: expect two grants", - fmt.Sprintf("%s/cosmos/authz/v1beta1/granters/%s/grantees/%s/grants", baseURL, val.Address.String(), s.grantee.String()), + fmt.Sprintf(grantsURL, val.Address.String(), s.grantee.String()), false, "", func() { @@ -219,7 +195,7 @@ func (s *IntegrationTestSuite) TestQueryGrantsGRPC() { }, { "valid query: expect single grant with pagination", - fmt.Sprintf("%s/cosmos/authz/v1beta1/granters/%s/grantees/%s/grants?pagination.limit=1", baseURL, val.Address.String(), s.grantee.String()), + fmt.Sprintf(grantsURL+"&pagination.limit=1", val.Address.String(), s.grantee.String()), false, "", func() {}, @@ -229,7 +205,7 @@ func (s *IntegrationTestSuite) TestQueryGrantsGRPC() { }, { "valid query: expect two grants with pagination", - fmt.Sprintf("%s/cosmos/authz/v1beta1/granters/%s/grantees/%s/grants?pagination.limit=2", baseURL, val.Address.String(), s.grantee.String()), + fmt.Sprintf(grantsURL+"&pagination.limit=2", val.Address.String(), s.grantee.String()), false, "", func() {}, diff --git a/x/authz/client/testutil/cli_test.go b/x/authz/client/testutil/cli_test.go index dd36a6af2d3e..3c083e694726 100644 --- a/x/authz/client/testutil/cli_test.go +++ b/x/authz/client/testutil/cli_test.go @@ -5,9 +5,9 @@ package testutil import ( "testing" - "github.com/cosmos/cosmos-sdk/testutil/network" - "github.com/stretchr/testify/suite" + + "github.com/cosmos/cosmos-sdk/testutil/network" ) func TestIntegrationTestSuite(t *testing.T) { From 2e8caf5aabac2bf05352a056819a2564c86829da Mon Sep 17 00:00:00 2001 From: Robert Zaremba Date: Thu, 6 May 2021 12:22:51 +0200 Subject: [PATCH 42/44] update proto comment --- docs/core/proto-docs.md | 2 +- proto/cosmos/authz/v1beta1/tx.proto | 7 +-- x/authz/tx.pb.go | 73 +++++++++++++++-------------- 3 files changed, 42 insertions(+), 40 deletions(-) diff --git a/docs/core/proto-docs.md b/docs/core/proto-docs.md index ab45bab0bebd..ed603e9e452d 100644 --- a/docs/core/proto-docs.md +++ b/docs/core/proto-docs.md @@ -1291,7 +1291,7 @@ one signer corresponding to the granter of the authorization. | Field | Type | Label | Description | | ----- | ---- | ----- | ----------- | | `grantee` | [string](#string) | | | -| `msgs` | [google.protobuf.Any](#google.protobuf.Any) | repeated | Msg requests to execute. The x/authz will try to find a grant matching (msg.signers[0], grantee, MsgTypeURL(msg)) triple and validate it. | +| `msgs` | [google.protobuf.Any](#google.protobuf.Any) | repeated | Authorization Msg requests to execute. Each msg must implement Authorization interface The x/authz will try to find a grant matching (msg.signers[0], grantee, MsgTypeURL(msg)) triple and validate it. | diff --git a/proto/cosmos/authz/v1beta1/tx.proto b/proto/cosmos/authz/v1beta1/tx.proto index 45c1eacc1847..7932881da419 100644 --- a/proto/cosmos/authz/v1beta1/tx.proto +++ b/proto/cosmos/authz/v1beta1/tx.proto @@ -46,9 +46,10 @@ message MsgExecResponse { // one signer corresponding to the granter of the authorization. message MsgExec { string grantee = 1; - // Msg requests to execute. The x/authz will try to find a grant matching - // (msg.signers[0], grantee, MsgTypeURL(msg)) triple and validate it. - repeated google.protobuf.Any msgs = 2 [(cosmos_proto.accepts_interface) = "sdk.Msg"];; + // Authorization Msg requests to execute. Each msg must implement Authorization interface + // The x/authz will try to find a grant matching (msg.signers[0], grantee, MsgTypeURL(msg)) + // triple and validate it. + repeated google.protobuf.Any msgs = 2 [(cosmos_proto.accepts_interface) = "sdk.Msg, authz.Authorization"];; } // MsgGrantResponse defines the Msg/MsgGrant response type. diff --git a/x/authz/tx.pb.go b/x/authz/tx.pb.go index ec7d7a386352..7042d701737d 100644 --- a/x/authz/tx.pb.go +++ b/x/authz/tx.pb.go @@ -120,8 +120,9 @@ var xxx_messageInfo_MsgExecResponse proto.InternalMessageInfo // one signer corresponding to the granter of the authorization. type MsgExec struct { Grantee string `protobuf:"bytes,1,opt,name=grantee,proto3" json:"grantee,omitempty"` - // Msg requests to execute. The x/authz will try to find a grant matching - // (msg.signers[0], grantee, MsgTypeURL(msg)) triple and validate it. + // Authorization Msg requests to execute. Each msg must implement Authorization interface + // The x/authz will try to find a grant matching (msg.signers[0], grantee, MsgTypeURL(msg)) + // triple and validate it. Msgs []*types.Any `protobuf:"bytes,2,rep,name=msgs,proto3" json:"msgs,omitempty"` } @@ -285,40 +286,40 @@ func init() { func init() { proto.RegisterFile("cosmos/authz/v1beta1/tx.proto", fileDescriptor_3ceddab7d8589ad1) } var fileDescriptor_3ceddab7d8589ad1 = []byte{ - // 518 bytes of a gzipped FileDescriptorProto - 0x1f, 0x8b, 0x08, 0x00, 0x00, 0x00, 0x00, 0x00, 0x02, 0xff, 0x9c, 0x94, 0x4f, 0x6f, 0xd3, 0x3e, - 0x18, 0xc7, 0xe3, 0xb5, 0xbf, 0x76, 0x7d, 0xfa, 0x9b, 0x60, 0xa1, 0x87, 0x2c, 0xd2, 0xd2, 0x28, - 0xfc, 0xdb, 0xa5, 0x8e, 0x56, 0x84, 0xc4, 0x75, 0x15, 0x88, 0x03, 0x44, 0x48, 0xd1, 0xb8, 0xec, - 0x52, 0x25, 0x9d, 0xf1, 0xa2, 0x36, 0x71, 0x14, 0x3b, 0x53, 0xbb, 0x57, 0xb1, 0x17, 0xb3, 0x17, - 0x51, 0xed, 0x34, 0x89, 0x0b, 0x27, 0xfe, 0xb4, 0x6f, 0x82, 0x23, 0x8a, 0xe3, 0x94, 0x0e, 0xe8, - 0x90, 0x38, 0xd5, 0x8f, 0xbf, 0x1f, 0x3f, 0xfe, 0xfa, 0x6b, 0x37, 0xb0, 0x3f, 0x62, 0x3c, 0x66, - 0xdc, 0x0d, 0x72, 0x71, 0x76, 0xe1, 0x9e, 0x1f, 0x86, 0x44, 0x04, 0x87, 0xae, 0x98, 0xe2, 0x34, - 0x63, 0x82, 0xe9, 0x9d, 0x52, 0xc6, 0x52, 0xc6, 0x4a, 0x36, 0xf7, 0xca, 0xd9, 0xa1, 0x64, 0x5c, - 0x85, 0xc8, 0xc2, 0xec, 0x50, 0x46, 0x59, 0x39, 0x5f, 0x8c, 0xd4, 0x6c, 0x97, 0x32, 0x46, 0x27, - 0xc4, 0x95, 0x55, 0x98, 0x7f, 0x70, 0x45, 0x14, 0x13, 0x2e, 0x82, 0x38, 0x55, 0xc0, 0xde, 0xaf, - 0x40, 0x90, 0xcc, 0x94, 0xf4, 0x50, 0x39, 0x0c, 0x03, 0x4e, 0xdc, 0x20, 0x1c, 0x45, 0x2b, 0x97, - 0x45, 0x51, 0x42, 0xce, 0x47, 0x04, 0xdb, 0x1e, 0xa7, 0xaf, 0xb3, 0x20, 0x11, 0xba, 0x01, 0x4d, - 0x5a, 0x0c, 0x48, 0x66, 0x20, 0x1b, 0x1d, 0xb4, 0xfc, 0xaa, 0xfc, 0xa9, 0x10, 0x63, 0x6b, 0x5d, - 0x21, 0xba, 0x07, 0x3b, 0xc5, 0x19, 0x59, 0x16, 0x5d, 0x04, 0x22, 0x62, 0x89, 0x51, 0xb3, 0xd1, - 0x41, 0xbb, 0xdf, 0xc1, 0xa5, 0x31, 0x5c, 0x19, 0xc3, 0x47, 0xc9, 0x6c, 0xb0, 0x7b, 0x7d, 0xd5, - 0xdb, 0x39, 0x5a, 0xc7, 0xfd, 0xdb, 0xab, 0xf5, 0x97, 0x00, 0x64, 0x9a, 0x46, 0x59, 0xd9, 0xab, - 0x2e, 0x7b, 0x99, 0xbf, 0xf5, 0x3a, 0xae, 0x52, 0x18, 0x6c, 0xcf, 0x3f, 0x77, 0xb5, 0xcb, 0x2f, - 0x5d, 0xe4, 0xaf, 0xad, 0x73, 0xde, 0xc0, 0x3d, 0x8f, 0xd3, 0x57, 0x53, 0x32, 0xf2, 0x09, 0x4f, - 0x59, 0xc2, 0x89, 0xfe, 0x02, 0x1a, 0x19, 0xe1, 0xf9, 0x44, 0xc8, 0xa3, 0xb5, 0xfb, 0x36, 0x56, - 0xf1, 0x17, 0xf1, 0x60, 0x99, 0x88, 0x8a, 0x07, 0xfb, 0x92, 0xf3, 0x15, 0xef, 0x9c, 0x40, 0x53, - 0x35, 0x5b, 0x8f, 0x01, 0xdd, 0x8e, 0xe1, 0x39, 0xd4, 0x63, 0x4e, 0xb9, 0xb1, 0x65, 0xd7, 0x36, - 0x9e, 0xbe, 0x7d, 0x7d, 0xd5, 0x6b, 0xf2, 0xd3, 0x31, 0xf6, 0x38, 0xf5, 0x25, 0xee, 0xe8, 0x70, - 0xbf, 0x4a, 0xbf, 0x72, 0xea, 0x04, 0xd0, 0x2a, 0x00, 0x72, 0xce, 0xc6, 0xe4, 0x9f, 0xae, 0xc4, - 0x86, 0xff, 0x63, 0x4e, 0x87, 0x62, 0x96, 0x92, 0x61, 0x9e, 0x4d, 0xe4, 0x8d, 0xb4, 0x7c, 0x88, - 0x39, 0x3d, 0x9e, 0xa5, 0xe4, 0x7d, 0x36, 0x71, 0x1e, 0xc0, 0xee, 0x6a, 0x8b, 0x6a, 0xdf, 0xfe, - 0x77, 0x04, 0x35, 0x8f, 0x53, 0xfd, 0x1d, 0xfc, 0x57, 0x3e, 0x07, 0x0b, 0xff, 0xe9, 0x11, 0xe3, - 0xca, 0xb0, 0xf9, 0xe4, 0x6e, 0x7d, 0x15, 0xfd, 0x5b, 0xa8, 0xcb, 0xf4, 0xf6, 0x37, 0xf2, 0x85, - 0x6c, 0x3e, 0xbe, 0x53, 0x5e, 0x75, 0xf3, 0xa1, 0xa1, 0xb2, 0xe9, 0x6e, 0x5c, 0x50, 0x02, 0xe6, - 0xd3, 0xbf, 0x00, 0x55, 0xcf, 0xc1, 0x60, 0xfe, 0xcd, 0xd2, 0xe6, 0x0b, 0x0b, 0xdd, 0x2c, 0x2c, - 0xf4, 0x75, 0x61, 0xa1, 0xcb, 0xa5, 0xa5, 0xdd, 0x2c, 0x2d, 0xed, 0xd3, 0xd2, 0xd2, 0x4e, 0x1e, - 0xd1, 0x48, 0x9c, 0xe5, 0x21, 0x1e, 0xb1, 0x58, 0xfd, 0x67, 0xd5, 0x4f, 0x8f, 0x9f, 0x8e, 0xdd, - 0x69, 0xf9, 0x09, 0x08, 0x1b, 0xf2, 0xae, 0x9f, 0xfd, 0x08, 0x00, 0x00, 0xff, 0xff, 0x82, 0x87, - 0x39, 0xef, 0x19, 0x04, 0x00, 0x00, + // 523 bytes of a gzipped FileDescriptorProto + 0x1f, 0x8b, 0x08, 0x00, 0x00, 0x00, 0x00, 0x00, 0x02, 0xff, 0x9c, 0x54, 0x4d, 0x6f, 0xd3, 0x30, + 0x18, 0xae, 0xd7, 0xd2, 0xad, 0xef, 0x98, 0x60, 0xa1, 0x87, 0x2e, 0x62, 0x69, 0x14, 0xbe, 0x76, + 0xa0, 0x8e, 0x56, 0x2e, 0x5c, 0x57, 0x81, 0x90, 0x80, 0x08, 0x29, 0x1a, 0x17, 0x2e, 0x55, 0xd2, + 0x19, 0x2f, 0x6a, 0x13, 0x47, 0xb1, 0x33, 0xb5, 0xfb, 0x15, 0xfb, 0x31, 0xfb, 0x11, 0xd5, 0x4e, + 0x93, 0xb8, 0x70, 0xe2, 0xa3, 0xfd, 0x13, 0x1c, 0x51, 0x6c, 0xa7, 0xb4, 0x40, 0x87, 0xc4, 0xa9, + 0x7e, 0xfd, 0x3c, 0x7e, 0xfc, 0xf8, 0x79, 0xdf, 0x06, 0xf6, 0x07, 0x8c, 0xc7, 0x8c, 0xbb, 0x41, + 0x2e, 0x4e, 0xcf, 0xdd, 0xb3, 0xc3, 0x90, 0x88, 0xe0, 0xd0, 0x15, 0x63, 0x9c, 0x66, 0x4c, 0x30, + 0xa3, 0xa9, 0x60, 0x2c, 0x61, 0xac, 0x61, 0x73, 0x4f, 0xed, 0xf6, 0x25, 0xc7, 0xd5, 0x14, 0x59, + 0x98, 0x4d, 0xca, 0x28, 0x53, 0xfb, 0xc5, 0x4a, 0xef, 0xb6, 0x29, 0x63, 0x74, 0x44, 0x5c, 0x59, + 0x85, 0xf9, 0x47, 0x57, 0x44, 0x31, 0xe1, 0x22, 0x88, 0x53, 0x4d, 0xd8, 0xfb, 0x9d, 0x10, 0x24, + 0x13, 0x0d, 0x3d, 0xd0, 0x0e, 0xc3, 0x80, 0x13, 0x37, 0x08, 0x07, 0xd1, 0xc2, 0x65, 0x51, 0x28, + 0x92, 0xf3, 0x09, 0xc1, 0x96, 0xc7, 0xe9, 0xab, 0x2c, 0x48, 0x84, 0xd1, 0x82, 0x4d, 0x5a, 0x2c, + 0x48, 0xd6, 0x42, 0x36, 0x3a, 0x68, 0xf8, 0x65, 0xf9, 0x0b, 0x21, 0xad, 0x8d, 0x65, 0x84, 0x18, + 0x1e, 0xec, 0x14, 0x6f, 0x64, 0x59, 0x74, 0x1e, 0x88, 0x88, 0x25, 0xad, 0xaa, 0x8d, 0x0e, 0xb6, + 0xbb, 0x4d, 0xac, 0x8c, 0xe1, 0xd2, 0x18, 0x3e, 0x4a, 0x26, 0xbd, 0xdd, 0xab, 0xcb, 0xce, 0xce, + 0xd1, 0x32, 0xdd, 0x5f, 0x3d, 0x6d, 0xbc, 0x00, 0x20, 0xe3, 0x34, 0xca, 0x94, 0x56, 0x4d, 0x6a, + 0x99, 0x7f, 0x68, 0x1d, 0x97, 0x29, 0xf4, 0xb6, 0xa6, 0x5f, 0xda, 0x95, 0x8b, 0xaf, 0x6d, 0xe4, + 0x2f, 0x9d, 0x73, 0xde, 0xc0, 0x1d, 0x8f, 0xd3, 0x97, 0x63, 0x32, 0xf0, 0x09, 0x4f, 0x59, 0xc2, + 0x89, 0xf1, 0x1c, 0xea, 0x19, 0xe1, 0xf9, 0x48, 0xc8, 0xa7, 0x6d, 0x77, 0x6d, 0xac, 0xe3, 0x2f, + 0xe2, 0xc1, 0x32, 0x11, 0x1d, 0x0f, 0xf6, 0x25, 0xcf, 0xd7, 0x7c, 0x87, 0xc1, 0xa6, 0x16, 0x5b, + 0x8e, 0x01, 0xad, 0xc6, 0xf0, 0x1a, 0x6a, 0x31, 0xa7, 0xbc, 0xb5, 0x61, 0x57, 0xd7, 0xbe, 0xde, + 0xbe, 0xba, 0xec, 0xdc, 0xe7, 0x27, 0x43, 0xec, 0x71, 0xfa, 0xd4, 0x56, 0x93, 0xb1, 0x1a, 0x86, + 0xd4, 0x70, 0x0c, 0xb8, 0x5b, 0xb6, 0xa4, 0xb4, 0xef, 0x04, 0xd0, 0xf0, 0x38, 0xf5, 0xc9, 0x19, + 0x1b, 0x92, 0xff, 0xea, 0x93, 0x0d, 0xb7, 0x63, 0x4e, 0xfb, 0x62, 0x92, 0x92, 0x7e, 0x9e, 0x8d, + 0x64, 0x9b, 0x1a, 0x3e, 0xc4, 0x9c, 0x1e, 0x4f, 0x52, 0xf2, 0x3e, 0x1b, 0x39, 0xf7, 0x60, 0x77, + 0x71, 0x45, 0x79, 0x6f, 0xf7, 0x07, 0x82, 0xaa, 0xc7, 0xa9, 0xf1, 0x0e, 0x6e, 0xa9, 0x19, 0xb1, + 0xf0, 0xdf, 0x26, 0x1b, 0x97, 0x86, 0xcd, 0xc7, 0x37, 0xe3, 0x8b, 0x7e, 0xbc, 0x85, 0x9a, 0x8c, + 0x74, 0x7f, 0x2d, 0xbf, 0x80, 0xcd, 0x47, 0x37, 0xc2, 0x0b, 0x35, 0x1f, 0xea, 0x3a, 0x9b, 0xf6, + 0xda, 0x03, 0x8a, 0x60, 0x3e, 0xf9, 0x07, 0xa1, 0xd4, 0xec, 0xf5, 0xa6, 0xdf, 0xad, 0xca, 0x74, + 0x66, 0xa1, 0xeb, 0x99, 0x85, 0xbe, 0xcd, 0x2c, 0x74, 0x31, 0xb7, 0x2a, 0xd7, 0x73, 0xab, 0xf2, + 0x79, 0x6e, 0x55, 0x3e, 0x3c, 0xa4, 0x91, 0x38, 0xcd, 0x43, 0x3c, 0x60, 0xb1, 0xfe, 0x23, 0xeb, + 0x9f, 0x0e, 0x3f, 0x19, 0xba, 0x63, 0xf5, 0x5d, 0x08, 0xeb, 0x72, 0x00, 0x9e, 0xfd, 0x0c, 0x00, + 0x00, 0xff, 0xff, 0x5b, 0x69, 0x39, 0xef, 0x2e, 0x04, 0x00, 0x00, } // Reference imports to suppress errors if they are not otherwise used. From 94b6c9ffca00a1d25ffb3f96ecf6008f441d82ad Mon Sep 17 00:00:00 2001 From: Robert Zaremba Date: Thu, 6 May 2021 19:14:37 +0200 Subject: [PATCH 43/44] fix tests --- simapp/sim_test.go | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/simapp/sim_test.go b/simapp/sim_test.go index 70236018aa60..89ab4cfa5052 100644 --- a/simapp/sim_test.go +++ b/simapp/sim_test.go @@ -160,7 +160,7 @@ func TestAppImportExport(t *testing.T) { fmt.Printf("comparing stores...\n") storeKeysPrefixes := []StoreKeysPrefixes{ - {app.keys[authtypes.StoreKey], newApp.keys[authtypes.StoreKey], [][]byte{}}, + {app.keys[authz.StoreKey], newApp.keys[authtypes.StoreKey], [][]byte{}}, {app.keys[stakingtypes.StoreKey], newApp.keys[stakingtypes.StoreKey], [][]byte{ stakingtypes.UnbondingQueueKey, stakingtypes.RedelegationQueueKey, stakingtypes.ValidatorQueueKey, From 47324d471d673c2df9fc8136628db3955705304d Mon Sep 17 00:00:00 2001 From: Robert Zaremba Date: Thu, 6 May 2021 19:48:46 +0200 Subject: [PATCH 44/44] fix test --- simapp/sim_test.go | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/simapp/sim_test.go b/simapp/sim_test.go index 89ab4cfa5052..bab40cfbf6cd 100644 --- a/simapp/sim_test.go +++ b/simapp/sim_test.go @@ -19,7 +19,7 @@ import ( sdk "github.com/cosmos/cosmos-sdk/types" simtypes "github.com/cosmos/cosmos-sdk/types/simulation" authtypes "github.com/cosmos/cosmos-sdk/x/auth/types" - "github.com/cosmos/cosmos-sdk/x/authz" + authzkeeper "github.com/cosmos/cosmos-sdk/x/authz/keeper" banktypes "github.com/cosmos/cosmos-sdk/x/bank/types" capabilitytypes "github.com/cosmos/cosmos-sdk/x/capability/types" distrtypes "github.com/cosmos/cosmos-sdk/x/distribution/types" @@ -160,7 +160,7 @@ func TestAppImportExport(t *testing.T) { fmt.Printf("comparing stores...\n") storeKeysPrefixes := []StoreKeysPrefixes{ - {app.keys[authz.StoreKey], newApp.keys[authtypes.StoreKey], [][]byte{}}, + {app.keys[authtypes.StoreKey], newApp.keys[authtypes.StoreKey], [][]byte{}}, {app.keys[stakingtypes.StoreKey], newApp.keys[stakingtypes.StoreKey], [][]byte{ stakingtypes.UnbondingQueueKey, stakingtypes.RedelegationQueueKey, stakingtypes.ValidatorQueueKey, @@ -174,7 +174,7 @@ func TestAppImportExport(t *testing.T) { {app.keys[govtypes.StoreKey], newApp.keys[govtypes.StoreKey], [][]byte{}}, {app.keys[evidencetypes.StoreKey], newApp.keys[evidencetypes.StoreKey], [][]byte{}}, {app.keys[capabilitytypes.StoreKey], newApp.keys[capabilitytypes.StoreKey], [][]byte{}}, - {app.keys[authz.StoreKey], newApp.keys[authz.StoreKey], [][]byte{}}, + {app.keys[authzkeeper.StoreKey], newApp.keys[authzkeeper.StoreKey], [][]byte{}}, } for _, skp := range storeKeysPrefixes {