-
Notifications
You must be signed in to change notification settings - Fork 829
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Add gov prop handler for updating current minter #729
Merged
Merged
Changes from all commits
Commits
Show all changes
2 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 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 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,19 @@ | ||
syntax = "proto3"; | ||
package seiprotocol.seichain.mint; | ||
|
||
import "gogoproto/gogo.proto"; | ||
import "mint/v1beta1/mint.proto"; | ||
|
||
option go_package = "github.com/sei-protocol/sei-chain/x/mint/types"; | ||
|
||
// AddAssetMetadataProposal is a gov Content type for adding a new asset | ||
// to the dex module's asset list. | ||
message UpdateMinterProposal { | ||
option (gogoproto.equal) = false; | ||
option (gogoproto.goproto_getters) = false; | ||
option (gogoproto.goproto_stringer) = false; | ||
|
||
string title = 1 [ (gogoproto.moretags) = "yaml:\"title\"" ]; | ||
string description = 2 [ (gogoproto.moretags) = "yaml:\"description\"" ]; | ||
mint.Minter minter = 3 [ (gogoproto.moretags) = "yaml:\"minter\"" ]; | ||
} |
This file contains 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,97 @@ | ||
package cli | ||
|
||
import ( | ||
"fmt" | ||
"os" | ||
|
||
sdk "github.com/cosmos/cosmos-sdk/types" | ||
govcli "github.com/cosmos/cosmos-sdk/x/gov/client/cli" | ||
govtypes "github.com/cosmos/cosmos-sdk/x/gov/types" | ||
"github.com/spf13/cobra" | ||
|
||
"github.com/cosmos/cosmos-sdk/client" | ||
"github.com/cosmos/cosmos-sdk/client/flags" | ||
"github.com/cosmos/cosmos-sdk/client/tx" | ||
govclient "github.com/cosmos/cosmos-sdk/x/gov/client" | ||
mintrest "github.com/sei-protocol/sei-chain/x/mint/client/rest" | ||
"github.com/sei-protocol/sei-chain/x/mint/types" | ||
) | ||
|
||
var UpdateMinterHandler = govclient.NewProposalHandler(MsgUpdateMinterProposalCmd, mintrest.UpdateResourceDependencyProposalRESTHandler) | ||
|
||
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, | ||
} | ||
|
||
updateMinterProposalCmd := MsgUpdateMinterProposalCmd() | ||
flags.AddTxFlagsToCmd(updateMinterProposalCmd) | ||
|
||
cmd.AddCommand(updateMinterProposalCmd) | ||
return cmd | ||
} | ||
|
||
func MsgUpdateMinterProposalCmd() *cobra.Command { | ||
cmd := &cobra.Command{ | ||
Use: "update-minter [proposal-file]", | ||
Args: cobra.ExactArgs(1), | ||
Short: "Submit an UpdateMinter proposal", | ||
Long: "Submit a proposal to update the current minter. \n" + | ||
"E.g. $ seid tx gov submit-proposal update-minter [proposal-file]\n" + | ||
"The proposal file should contain the following:\n" + | ||
"{\n" + | ||
"\t title: [title],\n" + | ||
"\t description: [description],\n" + | ||
"\t minter: [new minter object] \n" + | ||
"}", | ||
RunE: func(cmd *cobra.Command, args []string) error { | ||
clientCtx, err := client.GetClientTxContext(cmd) | ||
if err != nil { | ||
return err | ||
} | ||
|
||
proposal := types.UpdateMinterProposal{} | ||
|
||
contents, err := os.ReadFile(args[0]) | ||
if err != nil { | ||
return err | ||
} | ||
|
||
clientCtx.Codec.MustUnmarshalJSON(contents, &proposal) | ||
|
||
from := clientCtx.GetFromAddress() | ||
|
||
content := types.UpdateMinterProposal{ | ||
Title: proposal.Title, | ||
Description: proposal.Description, | ||
Minter: proposal.Minter, | ||
} | ||
|
||
depositInput, err := cmd.Flags().GetString(govcli.FlagDeposit) | ||
if err != nil { | ||
return err | ||
} | ||
|
||
deposit, err := sdk.ParseCoinsNormalized(depositInput) | ||
if err != nil { | ||
return err | ||
} | ||
|
||
msg, err := govtypes.NewMsgSubmitProposal(&content, deposit, from) | ||
if err != nil { | ||
|
||
return err | ||
} | ||
|
||
return tx.GenerateOrBroadcastTxCLI(clientCtx, cmd.Flags(), msg) | ||
}, | ||
} | ||
|
||
cmd.Flags().String(govcli.FlagDeposit, "", "The proposal deposit") | ||
|
||
return cmd | ||
} |
This file contains 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 |
---|---|---|
@@ -1,14 +1,71 @@ | ||
package rest | ||
|
||
import ( | ||
"net/http" | ||
|
||
sdk "github.com/cosmos/cosmos-sdk/types" | ||
govrest "github.com/cosmos/cosmos-sdk/x/gov/client/rest" | ||
govtypes "github.com/cosmos/cosmos-sdk/x/gov/types" | ||
"github.com/gorilla/mux" | ||
"github.com/sei-protocol/sei-chain/x/mint/types" | ||
|
||
"github.com/cosmos/cosmos-sdk/client" | ||
"github.com/cosmos/cosmos-sdk/client/rest" | ||
clientrest "github.com/cosmos/cosmos-sdk/client/rest" | ||
"github.com/cosmos/cosmos-sdk/client/tx" | ||
typesrest "github.com/cosmos/cosmos-sdk/types/rest" | ||
) | ||
|
||
// RegisterRoutes registers minting module REST handlers on the provided router. | ||
func RegisterRoutes(clientCtx client.Context, rtr *mux.Router) { | ||
r := rest.WithHTTPDeprecationHeaders(rtr) | ||
r := clientrest.WithHTTPDeprecationHeaders(rtr) | ||
registerQueryRoutes(clientCtx, r) | ||
} | ||
|
||
// PlanRequest defines a proposal for a new upgrade plan. | ||
type UpdateMinterRequest struct { | ||
BaseReq typesrest.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"` | ||
Minter types.Minter `json:"minter" yaml:"minter"` | ||
} | ||
|
||
func UpdateResourceDependencyProposalRESTHandler(clientCtx client.Context) govrest.ProposalRESTHandler { | ||
return govrest.ProposalRESTHandler{ | ||
SubRoute: "update_minter", | ||
Handler: newUpdateMinterPostHandler(clientCtx), | ||
} | ||
} | ||
|
||
func newUpdateMinterPostHandler(clientCtx client.Context) http.HandlerFunc { | ||
return func(w http.ResponseWriter, r *http.Request) { | ||
var req UpdateMinterRequest | ||
|
||
if !typesrest.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 typesrest.CheckBadRequestError(w, err) { | ||
return | ||
} | ||
|
||
content := types.NewUpdateMinterProposalHandler( | ||
req.Title, req.Description, req.Minter, | ||
) | ||
msg, err := govtypes.NewMsgSubmitProposal(content, req.Deposit, fromAddr) | ||
if typesrest.CheckBadRequestError(w, err) { | ||
return | ||
} | ||
if typesrest.CheckBadRequestError(w, msg.ValidateBasic()) { | ||
return | ||
} | ||
|
||
tx.WriteGeneratedTxResponse(clientCtx, w, req.BaseReq, msg) | ||
} | ||
} |
This file contains 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,16 @@ | ||
package mint | ||
|
||
import ( | ||
sdk "github.com/cosmos/cosmos-sdk/types" | ||
"github.com/sei-protocol/sei-chain/x/mint/keeper" | ||
"github.com/sei-protocol/sei-chain/x/mint/types" | ||
) | ||
|
||
func HandleUpdateMinterProposal(ctx sdk.Context, k *keeper.Keeper, p *types.UpdateMinterProposal) error { | ||
err := types.ValidateMinter(*p.Minter) | ||
if err != nil { | ||
return err | ||
} | ||
k.SetMinter(ctx, *p.Minter) | ||
return nil | ||
} |
This file contains 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 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 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.
Is this documented any where else for how to make a proposal?
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.
I'll add it as apart of the x/mint module readme