This repository was archived by the owner on Jan 20, 2026. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 81
Add gov proposal handler for acl #33
Merged
Merged
Changes from all commits
Commits
Show all changes
4 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,49 @@ | ||
| syntax = "proto3"; | ||
| package cosmos.accesscontrol.v1beta1; | ||
|
|
||
| import "gogoproto/gogo.proto"; | ||
| import "cosmos/accesscontrol/constants.proto"; | ||
| import "cosmos/accesscontrol/accesscontrol.proto"; | ||
|
|
||
| option go_package = "github.com/cosmos/cosmos-sdk/x/accesscontrol/types"; | ||
|
|
||
| message MsgUpdateResourceDependencyMappingProposal { | ||
| option (gogoproto.equal) = false; | ||
| option (gogoproto.goproto_stringer) = false; | ||
| option (gogoproto.stringer) = false; | ||
| option (gogoproto.goproto_getters) = false; | ||
|
|
||
| string title = 1 [ | ||
| (gogoproto.moretags) = "yaml:\"title\"", | ||
| (gogoproto.jsontag) = "title" | ||
| ]; | ||
| string description = 2 [ | ||
| (gogoproto.moretags) = "yaml:\"description\"", | ||
| (gogoproto.jsontag) = "description" | ||
| ]; | ||
| repeated cosmos.accesscontrol.v1beta1.MessageDependencyMapping message_dependency_mapping = 3 [ | ||
| (gogoproto.nullable) = false, | ||
| (gogoproto.moretags) = "yaml:\"message_dependency_mapping\"" | ||
| ]; | ||
| } | ||
|
|
||
| message MsgUpdateResourceDependencyMappingProposalJsonFile { | ||
| string title = 1 [ | ||
| (gogoproto.moretags) = "yaml:\"title\"", | ||
| (gogoproto.jsontag) = "title" | ||
| ]; | ||
| string description = 2 [ | ||
| (gogoproto.moretags) = "yaml:\"description\"", | ||
| (gogoproto.jsontag) = "description" | ||
| ]; | ||
| string deposit = 3 [ | ||
| (gogoproto.moretags) = "yaml:\"deposit\"", | ||
| (gogoproto.jsontag) = "deposit" | ||
| ]; | ||
| repeated cosmos.accesscontrol.v1beta1.MessageDependencyMapping message_dependency_mapping = 4 [ | ||
| (gogoproto.nullable) = false, | ||
| (gogoproto.moretags) = "yaml:\"message_dependency_mapping\"" | ||
| ]; | ||
| } | ||
|
|
||
| message MsgUpdateResourceDependencyMappingProposalResponse {} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,77 @@ | ||
| package cli | ||
|
|
||
| import ( | ||
| "fmt" | ||
|
|
||
| "github.com/cosmos/cosmos-sdk/x/accesscontrol/client/utils" | ||
| "github.com/cosmos/cosmos-sdk/x/accesscontrol/types" | ||
|
|
||
| "github.com/cosmos/cosmos-sdk/client" | ||
| "github.com/cosmos/cosmos-sdk/client/flags" | ||
| "github.com/cosmos/cosmos-sdk/client/tx" | ||
| sdk "github.com/cosmos/cosmos-sdk/types" | ||
| govtypes "github.com/cosmos/cosmos-sdk/x/gov/types" | ||
|
|
||
| "github.com/spf13/cobra" | ||
| ) | ||
|
|
||
| func GetTxCmd() *cobra.Command { | ||
| cmd := &cobra.Command{ | ||
| Use: types.ModuleName, | ||
| Short: fmt.Sprintf("%s transactions subcommands", types.ModuleName), | ||
| DisableFlagParsing: true, | ||
| SuggestionsMinimumDistance: 2, | ||
| RunE: client.ValidateCmd, | ||
| } | ||
|
|
||
| updateResourceDependencyMappingProposalCmd := MsgUpdateResourceDependencyMappingProposalCmd() | ||
| flags.AddTxFlagsToCmd(updateResourceDependencyMappingProposalCmd) | ||
|
|
||
| cmd.AddCommand( | ||
| updateResourceDependencyMappingProposalCmd, | ||
| ) | ||
|
|
||
| return cmd | ||
| } | ||
|
|
||
| func MsgUpdateResourceDependencyMappingProposalCmd() *cobra.Command { | ||
| cmd := &cobra.Command{ | ||
| Use: "update-resource-dependency-mapping [proposal-file]", | ||
| Args: cobra.ExactArgs(1), | ||
| Short: "Submit an UpdateResourceDependencyMapping proposal", | ||
| RunE: func(cmd *cobra.Command, args []string) error { | ||
| clientCtx, err := client.GetClientTxContext(cmd) | ||
| if err != nil { | ||
| return err | ||
| } | ||
|
|
||
| proposal, err := utils.ParseMsgUpdateResourceDependencyMappingProposalFile(clientCtx.Codec, args[0]) | ||
| if err != nil { | ||
| return err | ||
| } | ||
|
|
||
| from := clientCtx.GetFromAddress() | ||
|
|
||
| content := types.MsgUpdateResourceDependencyMappingProposal{ | ||
| Title: proposal.Title, | ||
| Description: proposal.Description, | ||
| MessageDependencyMapping: proposal.MessageDependencyMapping, | ||
| } | ||
|
|
||
| deposit, err := sdk.ParseCoinsNormalized(proposal.Deposit) | ||
| if err != nil { | ||
| return err | ||
| } | ||
|
|
||
| msg, err := govtypes.NewMsgSubmitProposal(&content, deposit, from) | ||
| if err != nil { | ||
|
|
||
| return err | ||
| } | ||
|
|
||
| return tx.GenerateOrBroadcastTxCLI(clientCtx, cmd.Flags(), msg) | ||
| }, | ||
| } | ||
|
|
||
| return cmd | ||
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,9 @@ | ||
| package client | ||
|
|
||
| import ( | ||
| "github.com/cosmos/cosmos-sdk/x/accesscontrol/client/cli" | ||
| "github.com/cosmos/cosmos-sdk/x/accesscontrol/client/rest" | ||
| govclient "github.com/cosmos/cosmos-sdk/x/gov/client" | ||
| ) | ||
|
|
||
| var ProposalHandler = govclient.NewProposalHandler(cli.MsgUpdateResourceDependencyMappingProposalCmd, rest.ProposalRESTHandler) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,66 @@ | ||
| package rest | ||
|
|
||
| import ( | ||
| "net/http" | ||
|
|
||
| "github.com/cosmos/cosmos-sdk/client/tx" | ||
|
|
||
| govrest "github.com/cosmos/cosmos-sdk/x/gov/client/rest" | ||
|
|
||
| "github.com/cosmos/cosmos-sdk/client" | ||
| sdk "github.com/cosmos/cosmos-sdk/types" | ||
| "github.com/cosmos/cosmos-sdk/types/accesscontrol" | ||
| "github.com/cosmos/cosmos-sdk/types/rest" | ||
| "github.com/cosmos/cosmos-sdk/x/accesscontrol/types" | ||
| govtypes "github.com/cosmos/cosmos-sdk/x/gov/types" | ||
| ) | ||
|
|
||
| // PlanRequest defines a proposal for a new upgrade plan. | ||
| type UpdateResourceDependencyMappingRequest struct { | ||
| BaseReq rest.BaseReq `json:"base_req" yaml:"base_req"` | ||
| Title string `json:"title" yaml:"title"` | ||
| Description string `json:"description" yaml:"description"` | ||
| Deposit sdk.Coins `json:"deposit" yaml:"deposit"` | ||
| MessageDependencyMapping []accesscontrol.MessageDependencyMapping `json:"message_dependency_mapping" yaml:"message_dependency_mapping"` | ||
|
|
||
| } | ||
|
|
||
| func ProposalRESTHandler(clientCtx client.Context) govrest.ProposalRESTHandler { | ||
| return govrest.ProposalRESTHandler{ | ||
| SubRoute: "update_resource_dependency_mapping", | ||
| Handler: newPostPlanHandler(clientCtx), | ||
| } | ||
| } | ||
|
|
||
| func newPostPlanHandler(clientCtx client.Context) http.HandlerFunc { | ||
| return func(w http.ResponseWriter, r *http.Request) { | ||
| var req UpdateResourceDependencyMappingRequest | ||
|
|
||
| if !rest.ReadRESTReq(w, r, clientCtx.LegacyAmino, &req) { | ||
| return | ||
| } | ||
|
|
||
| req.BaseReq = req.BaseReq.Sanitize() | ||
| if !req.BaseReq.ValidateBasic(w) { | ||
| return | ||
| } | ||
|
|
||
| fromAddr, err := sdk.AccAddressFromBech32(req.BaseReq.From) | ||
| if rest.CheckBadRequestError(w, err) { | ||
| return | ||
| } | ||
|
|
||
| content := types.NewMsgUpdateResourceDependencyMappingProposal( | ||
| req.Title, req.Description, req.MessageDependencyMapping, | ||
| ) | ||
| msg, err := govtypes.NewMsgSubmitProposal(content, req.Deposit, fromAddr) | ||
| if rest.CheckBadRequestError(w, err) { | ||
| return | ||
| } | ||
| if rest.CheckBadRequestError(w, msg.ValidateBasic()) { | ||
| return | ||
| } | ||
|
|
||
| tx.WriteGeneratedTxResponse(clientCtx, w, req.BaseReq, msg) | ||
| } | ||
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,21 @@ | ||
| package utils | ||
|
|
||
| import ( | ||
| "io/ioutil" | ||
|
|
||
| "github.com/cosmos/cosmos-sdk/codec" | ||
| "github.com/cosmos/cosmos-sdk/x/accesscontrol/types" | ||
| ) | ||
|
|
||
| func ParseMsgUpdateResourceDependencyMappingProposalFile(cdc codec.JSONCodec, proposalFile string) (types.MsgUpdateResourceDependencyMappingProposalJsonFile, error) { | ||
| proposal := types.MsgUpdateResourceDependencyMappingProposalJsonFile{} | ||
|
|
||
| contents, err := ioutil.ReadFile(proposalFile) | ||
| if err != nil { | ||
| return proposal, err | ||
| } | ||
|
|
||
| cdc.MustUnmarshalJSON(contents, &proposal) | ||
|
|
||
| return proposal, nil | ||
| } |
22 changes: 22 additions & 0 deletions
22
x/accesscontrol/examples/update-access-dep-mapping-proposal.json
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,22 @@ | ||
| { | ||
| "title": "Updating Resource Dependency Mapping", | ||
| "description": "Updating mapping for message key 'testing'", | ||
| "deposit": "10sei", | ||
| "message_dependency_mapping": [ | ||
| { | ||
| "message_key": "testing", | ||
| "access_ops": [ | ||
| { | ||
| "access_type": "UNKNOWN", | ||
| "resource_type": "ANY", | ||
| "identifier_template": "*" | ||
| }, | ||
| { | ||
| "access_type": "COMMIT", | ||
| "resource_type": "ANY", | ||
| "identifier_template": "*" | ||
| } | ||
| ] | ||
| } | ||
| ] | ||
| } | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,28 @@ | ||
| package accesscontrol | ||
|
|
||
| import ( | ||
| sdk "github.com/cosmos/cosmos-sdk/types" | ||
| sdkerrors "github.com/cosmos/cosmos-sdk/types/errors" | ||
| govtypes "github.com/cosmos/cosmos-sdk/x/gov/types" | ||
|
|
||
| "github.com/cosmos/cosmos-sdk/x/accesscontrol/keeper" | ||
| "github.com/cosmos/cosmos-sdk/x/accesscontrol/types" | ||
| ) | ||
|
|
||
| func HandleMsgUpdateResourceDependencyMappingProposal(ctx sdk.Context, k *keeper.Keeper, p *types.MsgUpdateResourceDependencyMappingProposal) error { | ||
| for _, resourceDepMapping := range p.MessageDependencyMapping { | ||
| k.SetResourceDependencyMapping(ctx, resourceDepMapping) | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. do we do any checks over
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Mainly just the proto serialization checks -- all the fields that are not free form are ENUMs so the proto serialization should also cover those cases |
||
| } | ||
| return nil | ||
| } | ||
|
|
||
| func NewProposalHandler(k keeper.Keeper) govtypes.Handler { | ||
| return func(ctx sdk.Context, content govtypes.Content) error { | ||
| switch c := content.(type) { | ||
| case *types.MsgUpdateResourceDependencyMappingProposal: | ||
| return HandleMsgUpdateResourceDependencyMappingProposal(ctx, &k, c) | ||
| default: | ||
| return sdkerrors.Wrapf(sdkerrors.ErrUnknownRequest, "unrecognized accesscontrol proposal content type: %T", c) | ||
| } | ||
| } | ||
| } | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
nice