* wip * wip * wip * wip on refactoring adr 031 type URLs * Fix msg_service_router * Fix gov client queries * Fix some modules tests * Remove all instances of "*.Msg/*" * Uncomment code * Remove commented code * // simulation.NewWeightedOperation( * Fix CopyTx * Fix more tests * Fix x/gov test * proto.MessageName->sdk.MsgName * Fix authz tests * Use MsgRoute in feegrant and staking/authz * Fix more tests * Fix sims? * Add norace tag * Add CL * rebuild rosetta api test data * Update ADR * Rename MsgRoute -> MsgTypeURL * Fix codec registration * Remove sdk.GetLegacySignBytes * Update types/tx_msg.go * Update x/authz/simulation/operations.go * Move LegacyMsg to legacytx * Update CHANGELOG.md Co-authored-by: Aaron Craelius <aaron@regen.network> * Remove NewAnyWithCustomTypeURL * Keep support for ServiceMsgs * Fix TxBody UnpackInterfaces * Fix test * Address review * Remove support for ServiceMsg typeURLs * Fix lint * Update changelog * Fix tests * Use sdk.MsgTypeURL everywhere * Fix tests * Fix rosetta, run make rosetta-data * Fix rosetta thanks to froydi * Address reviews * Fix test * Remove stray log * Update CL Co-authored-by: Aaron Craelius <aaronc@users.noreply.github.com> Co-authored-by: Alessio Treglia <alessio@tendermint.com> Co-authored-by: Aaron Craelius <aaron@regen.network>
76 lines
2.2 KiB
Go
76 lines
2.2 KiB
Go
package keeper
|
|
|
|
import (
|
|
"context"
|
|
|
|
sdk "github.com/cosmos/cosmos-sdk/types"
|
|
sdkerrors "github.com/cosmos/cosmos-sdk/types/errors"
|
|
"github.com/cosmos/cosmos-sdk/x/authz/types"
|
|
)
|
|
|
|
var _ types.MsgServer = Keeper{}
|
|
|
|
// GrantAuthorization implements the MsgServer.GrantAuthorization method.
|
|
func (k Keeper) GrantAuthorization(goCtx context.Context, msg *types.MsgGrantAuthorizationRequest) (*types.MsgGrantAuthorizationResponse, error) {
|
|
ctx := sdk.UnwrapSDKContext(goCtx)
|
|
grantee, err := sdk.AccAddressFromBech32(msg.Grantee)
|
|
if err != nil {
|
|
return nil, err
|
|
}
|
|
granter, err := sdk.AccAddressFromBech32(msg.Granter)
|
|
if err != nil {
|
|
return nil, err
|
|
}
|
|
|
|
authorization := msg.GetGrantAuthorization()
|
|
// If the granted service Msg doesn't exist, we throw an error.
|
|
if k.router.HandlerbyTypeURL(authorization.MethodName()) == nil {
|
|
return nil, sdkerrors.Wrapf(sdkerrors.ErrInvalidType, "%s doesn't exist.", authorization.MethodName())
|
|
}
|
|
|
|
err = k.Grant(ctx, grantee, granter, authorization, msg.Expiration)
|
|
if err != nil {
|
|
return nil, err
|
|
}
|
|
|
|
return &types.MsgGrantAuthorizationResponse{}, nil
|
|
}
|
|
|
|
// RevokeAuthorization implements the MsgServer.RevokeAuthorization method.
|
|
func (k Keeper) RevokeAuthorization(goCtx context.Context, msg *types.MsgRevokeAuthorizationRequest) (*types.MsgRevokeAuthorizationResponse, error) {
|
|
ctx := sdk.UnwrapSDKContext(goCtx)
|
|
grantee, err := sdk.AccAddressFromBech32(msg.Grantee)
|
|
if err != nil {
|
|
return nil, err
|
|
}
|
|
granter, err := sdk.AccAddressFromBech32(msg.Granter)
|
|
if err != nil {
|
|
return nil, err
|
|
}
|
|
|
|
err = k.Revoke(ctx, grantee, granter, msg.MethodName)
|
|
if err != nil {
|
|
return nil, err
|
|
}
|
|
|
|
return &types.MsgRevokeAuthorizationResponse{}, nil
|
|
}
|
|
|
|
// ExecAuthorized implements the MsgServer.ExecAuthorized method.
|
|
func (k Keeper) ExecAuthorized(goCtx context.Context, msg *types.MsgExecAuthorizedRequest) (*types.MsgExecAuthorizedResponse, error) {
|
|
ctx := sdk.UnwrapSDKContext(goCtx)
|
|
grantee, err := sdk.AccAddressFromBech32(msg.Grantee)
|
|
if err != nil {
|
|
return nil, err
|
|
}
|
|
msgs, err := msg.GetMessages()
|
|
if err != nil {
|
|
return nil, err
|
|
}
|
|
result, err := k.DispatchActions(ctx, grantee, msgs)
|
|
if err != nil {
|
|
return nil, err
|
|
}
|
|
return &types.MsgExecAuthorizedResponse{Result: result}, nil
|
|
}
|