Skip to content

Commit 72f8923

Browse files
feat: add draft-proposal for x/group (backport #13353) (#13359)
* feat: add `draft-proposal` for x/group (#13353) * feat: add `draft-proposal` for x/group * add changelog * extract useful function * add `GetMsgFromTypeURL` tests (cherry picked from commit 7eb259f) # Conflicts: # CHANGELOG.md # types/tx_msg.go # x/gov/client/cli/prompt.go * fix conflicts * fix whitespace * backport #13350 * renaming as main * updates Co-authored-by: Julien Robert <julien@rbrt.fr>
1 parent 9454b97 commit 72f8923

File tree

10 files changed

+433
-69
lines changed

10 files changed

+433
-69
lines changed

CHANGELOG.md

Lines changed: 92 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -43,7 +43,8 @@ Ref: https://keepachangelog.com/en/1.0.0/
4343

4444
### Features
4545

46-
* (cli) [#13304](https://github.com/cosmos/cosmos-sdk/pull/13304) Add `tx gov draft-proposal` command for generating proposal JSONs.
46+
* (cli) [#13353](https://github.com/cosmos/cosmos-sdk/pull/13353) Add `tx group draft-proposal` command for generating group proposal JSONs (skeleton).
47+
* (cli) [#13304](https://github.com/cosmos/cosmos-sdk/pull/13304) Add `tx gov draft-proposal` command for generating proposal JSONs (skeleton).
4748
* (x/authz) [#13047](https://github.com/cosmos/cosmos-sdk/pull/13047) Add a GetAuthorization function to the keeper.
4849
* (cli) [#12742](https://github.com/cosmos/cosmos-sdk/pull/12742) Add the `prune` CLI cmd to manually prune app store history versions based on the pruning options.
4950

@@ -389,8 +390,96 @@ Ref: https://keepachangelog.com/en/1.0.0/
389390

390391
### Deprecated
391392

392-
* (x/upgrade) [\#9906](https://github.com/cosmos/cosmos-sdk/pull/9906) Deprecate `UpgradeConsensusState` gRPC query since this functionality is only used for IBC, which now has its own [IBC replacement](https://github.com/cosmos/ibc-go/blob/2c880a22e9f9cc75f62b527ca94aa75ce1106001/proto/ibc/core/client/v1/query.proto#L54)
393-
* (types) [\#10948](https://github.com/cosmos/cosmos-sdk/issues/10948) Deprecate the types.DBBackend variable and types.NewLevelDB function. They are replaced by a new entry in `app.toml`: `app-db-backend` and `tendermint/tm-db`s `NewDB` function. If `app-db-backend` is defined, then it is used. Otherwise, if `types.DBBackend` is defined, it is used (until removed: [\#11241](https://github.com/cosmos/cosmos-sdk/issues/11241)). Otherwise, Tendermint config's `db-backend` is used.
393+
* (x/upgrade) [#9906](https://github.com/cosmos/cosmos-sdk/pull/9906) Deprecate `UpgradeConsensusState` gRPC query since this functionality is only used for IBC, which now has its own [IBC replacement](https://github.com/cosmos/ibc-go/blob/2c880a22e9f9cc75f62b527ca94aa75ce1106001/proto/ibc/core/client/v1/query.proto#L54)
394+
* (types) [#10948](https://github.com/cosmos/cosmos-sdk/issues/10948) Deprecate the types.DBBackend variable and types.NewLevelDB function. They are replaced by a new entry in `app.toml`: `app-db-backend` and `tendermint/tm-db`s `NewDB` function. If `app-db-backend` is defined, then it is used. Otherwise, if `types.DBBackend` is defined, it is used (until removed: [#11241](https://github.com/cosmos/cosmos-sdk/issues/11241)). Otherwise, Tendermint config's `db-backend` is used.
395+
396+
## v0.45.8 - 2022-08-25
397+
398+
### Improvements
399+
400+
* [#12981](https://github.com/cosmos/cosmos-sdk/pull/12981) Return proper error when parsing telemetry configuration.
401+
* [#12885](https://github.com/cosmos/cosmos-sdk/pull/12885) Amortize cost of processing cache KV store.
402+
* [#12970](https://github.com/cosmos/cosmos-sdk/pull/12970) Bump Tendermint to `v0.34.21` and IAVL to `v0.19.1`.
403+
* [#12693](https://github.com/cosmos/cosmos-sdk/pull/12693) Make sure the order of each node is consistent when emitting proto events.
404+
405+
### Bug Fixes
406+
407+
* [#13046](https://github.com/cosmos/cosmos-sdk/pull/13046) Fix missing return statement in BaseApp.Query.
408+
409+
## v0.45.7 - 2022-08-04
410+
411+
### Features
412+
413+
* (upgrade) [#12603](https://github.com/cosmos/cosmos-sdk/pull/12603) feat: Move AppModule.BeginBlock and AppModule.EndBlock to extension interfaces
414+
415+
### Improvements
416+
417+
* (events) [#12850](https://github.com/cosmos/cosmos-sdk/pull/12850) Add a new `fee_payer` attribute to the `tx` event that is emitted from the `DeductFeeDecorator` AnteHandler decorator.
418+
* (x/params) [#12724](https://github.com/cosmos/cosmos-sdk/pull/12724) Add `GetParamSetIfExists` function to params `Subspace` to prevent panics on breaking changes.
419+
* [#12668](https://github.com/cosmos/cosmos-sdk/pull/12668) Add `authz_msg_index` event attribute to message events emitted when executing via `MsgExec` through `x/authz`.
420+
* [#12697](https://github.com/cosmos/cosmos-sdk/pull/12697) Upgrade IAVL to v0.19.0 with fast index and error propagation. NOTE: first start will take a while to propagate into new model.
421+
* Note: after upgrading to this version it may take up to 15 minutes to migrate from 0.17 to 0.19. This time is used to create the fast cache introduced into IAVL for performance
422+
* [#12784](https://github.com/cosmos/cosmos-sdk/pull/12784) Upgrade Tendermint to 0.34.20.
423+
* (x/bank) [#12674](https://github.com/cosmos/cosmos-sdk/pull/12674) Add convenience function `CreatePrefixedAccountStoreKey()` to construct key to access account's balance for a given denom.
424+
425+
### Bug Fixes
426+
427+
* (x/mint) [#12384](https://github.com/cosmos/cosmos-sdk/pull/12384) Ensure `GoalBonded` must be positive when performing `x/mint` parameter validation.
428+
* (simapp) [#12437](https://github.com/cosmos/cosmos-sdk/pull/12437) fix the non-determinstic behavior in simulations caused by `GenTx` and check
429+
empty coins slice before it is used to create `banktype.MsgSend`.
430+
* (x/capability) [12818](https://github.com/cosmos/cosmos-sdk/pull/12818) Use fixed length hex for pointer at FwdCapabilityKey.
431+
432+
## [v0.45.6](https://github.com/cosmos/cosmos-sdk/releases/tag/v0.45.6) - 2022-06-28
433+
434+
### Improvements
435+
436+
* (simapp) [#12314](https://github.com/cosmos/cosmos-sdk/pull/12314) Increase `DefaultGenTxGas` from `1000000` to `10000000`
437+
* [#12371](https://github.com/cosmos/cosmos-sdk/pull/12371) Update min required Golang version to 1.18.
438+
439+
### Bug Fixes
440+
441+
* [#12317](https://github.com/cosmos/cosmos-sdk/pull/12317) Rename `edit-validator` command's `--moniker` flag to `--new-moniker`
442+
* (x/upgrade) [#12264](https://github.com/cosmos/cosmos-sdk/pull/12264) Fix `GetLastCompleteUpgrade` to properly return the latest upgrade.
443+
* (x/crisis) [#12208](https://github.com/cosmos/cosmos-sdk/pull/12208) Fix progress index of crisis invariant assertion logs.
444+
445+
### Features
446+
447+
* (query) [#12253](https://github.com/cosmos/cosmos-sdk/pull/12253) Add `GenericFilteredPaginate` to the `query` package to improve UX.
448+
449+
## [v0.45.5](https://github.com/cosmos/cosmos-sdk/releases/tag/v0.45.5) - 2022-06-09
450+
451+
### Improvements
452+
453+
* (x/feegrant) [#11813](https://github.com/cosmos/cosmos-sdk/pull/11813) Fix pagination total count in `AllowancesByGranter` query.
454+
* (errors) [#12002](https://github.com/cosmos/cosmos-sdk/pull/12002) Removed 'redacted' error message from defaultErrEncoder.
455+
* (ante) [#12017](https://github.com/cosmos/cosmos-sdk/pull/12017) Index ante events for failed tx (backport #12013).
456+
* [#12153](https://github.com/cosmos/cosmos-sdk/pull/12153) Add a new `NewSimulationManagerFromAppModules` constructor, to simplify simulation wiring.
457+
458+
### Bug Fixes
459+
460+
* [#11796](https://github.com/cosmos/cosmos-sdk/pull/11796) Handle EOF error case in `readLineFromBuf`, which allows successful reading of passphrases from STDIN.
461+
* [#11772](https://github.com/cosmos/cosmos-sdk/pull/11772) Limit types.Dec length to avoid overflow.
462+
* [#10947](https://github.com/cosmos/cosmos-sdk/pull/10947) Add `AllowancesByGranter` query to the feegrant module
463+
* [#9639](https://github.com/cosmos/cosmos-sdk/pull/9639) Check store keys length before accessing them by making sure that `key` is of length `m+1` (for `key[n:m]`)
464+
* [#11983](https://github.com/cosmos/cosmos-sdk/pull/11983) (x/feegrant, x/authz) rename grants query commands to `grants-by-grantee`, `grants-by-granter` cmds.
465+
466+
## Improvements
467+
468+
* [#11886](https://github.com/cosmos/cosmos-sdk/pull/11886) Improve error messages
469+
470+
## [v0.45.4](https://github.com/cosmos/cosmos-sdk/releases/tag/v0.45.4) - 2022-04-25
471+
472+
### Bug Fixes
473+
474+
* [#11624](https://github.com/cosmos/cosmos-sdk/pull/11624) Handle the error returned from `NewNode` in the `server` package.
475+
* [#11724](https://github.com/cosmos/cosmos-sdk/pull/11724) Fix data race issues with `api.Server`.
476+
477+
### Improvements
478+
479+
* (types) [#12201](https://github.com/cosmos/cosmos-sdk/pull/12201) Add `MustAccAddressFromBech32` util function
480+
* [#11693](https://github.com/cosmos/cosmos-sdk/pull/11693) Add validation for gentx cmd.
481+
* [#11686](https://github.com/cosmos/cosmos-sdk/pull/11686) Update the min required Golang version to `1.17`.
482+
* (x/auth/vesting) [#11652](https://github.com/cosmos/cosmos-sdk/pull/11652) Add util functions for `Period(s)`
394483

395484
## [v0.45.3](https://github.com/cosmos/cosmos-sdk/releases/tag/v0.45.3) - 2022-04-12
396485

types/tx_msg.go

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,12 @@
11
package types
22

33
import (
4+
"encoding/json"
5+
fmt "fmt"
6+
47
"github.com/gogo/protobuf/proto"
58

9+
"github.com/cosmos/cosmos-sdk/codec"
610
cryptotypes "github.com/cosmos/cosmos-sdk/crypto/types"
711
)
812

@@ -79,3 +83,22 @@ type TxEncoder func(tx Tx) ([]byte, error)
7983
func MsgTypeURL(msg Msg) string {
8084
return "/" + proto.MessageName(msg)
8185
}
86+
87+
// GetMsgFromTypeURL returns a `sdk.Msg` message type from a type URL
88+
func GetMsgFromTypeURL(cdc codec.Codec, input string) (Msg, error) {
89+
var msg Msg
90+
bz, err := json.Marshal(struct {
91+
Type string `json:"@type"`
92+
}{
93+
Type: input,
94+
})
95+
if err != nil {
96+
return nil, err
97+
}
98+
99+
if err := cdc.UnmarshalInterfaceJSON(bz, &msg); err != nil {
100+
return nil, fmt.Errorf("failed to determine sdk.Msg for %s URL : %w", input, err)
101+
}
102+
103+
return msg, nil
104+
}

types/tx_msg_test.go

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@ import (
55

66
"github.com/stretchr/testify/suite"
77

8+
"github.com/cosmos/cosmos-sdk/codec"
89
"github.com/cosmos/cosmos-sdk/testutil/testdata"
910
sdk "github.com/cosmos/cosmos-sdk/types"
1011
)
@@ -33,3 +34,12 @@ func (s *testMsgSuite) TestMsg() {
3334
func (s *testMsgSuite) TestMsgTypeURL() {
3435
s.Require().Equal("/testdata.TestMsg", sdk.MsgTypeURL(new(testdata.TestMsg)))
3536
}
37+
38+
func (s *testMsgSuite) TestGetMsgFromTypeURL() {
39+
msg := new(testdata.TestMsg)
40+
cdc := codec.NewProtoCodec(testdata.NewTestInterfaceRegistry())
41+
42+
result, err := sdk.GetMsgFromTypeURL(cdc, "/testdata.TestMsg")
43+
s.Require().NoError(err)
44+
s.Require().Equal(msg, result)
45+
}

x/gov/client/cli/prompt.go

Lines changed: 36 additions & 55 deletions
Original file line numberDiff line numberDiff line change
@@ -27,17 +27,6 @@ const (
2727
draftMetadataFileName = "draft_metadata.json"
2828
)
2929

30-
// ProposalMetadata is the metadata of a proposal
31-
// This metadata is supposed to live off-chain when submitted in a proposal
32-
type ProposalMetadata struct {
33-
Title string `json:"title"`
34-
Authors string `json:"authors"`
35-
Summary string `json:"summary"`
36-
Details string `json:"details"`
37-
ProposalForumUrl string `json:"proposal_forum_url"` // named 'Url' instead of 'URL' for avoiding the camel case split
38-
VoteOptionContext string `json:"vote_option_context"`
39-
}
40-
4130
// Prompt prompts the user for all values of the given type.
4231
// data is the struct to be filled
4332
// namePrefix is the name to be display as "Enter <namePrefix> <field>"
@@ -94,8 +83,17 @@ func Prompt[T any](data T, namePrefix string) (T, error) {
9483
case reflect.String:
9584
v.Field(i).SetString(result)
9685
case reflect.Int:
97-
resultInt, _ := strconv.Atoi(result)
98-
v.Field(i).SetInt(int64(resultInt))
86+
resultInt, err := strconv.ParseInt(result, 10, 0)
87+
if err != nil {
88+
return data, fmt.Errorf("invalid value for int: %w", err)
89+
}
90+
// If a value was successfully parsed the ranges of:
91+
// [minInt, maxInt]
92+
// are within the ranges of:
93+
// [minInt64, maxInt64]
94+
// of which on 64-bit machines, which are most common,
95+
// int==int64
96+
v.Field(i).SetInt(resultInt)
9997
default:
10098
// skip other types
10199
// possibly in the future we can add more types (like slices)
@@ -106,21 +104,22 @@ func Prompt[T any](data T, namePrefix string) (T, error) {
106104
return data, nil
107105
}
108106

109-
type proposalTypes struct {
110-
Type string
107+
type proposalType struct {
108+
Name string
111109
MsgType string
112110
Msg sdk.Msg
113111
}
114112

115113
// Prompt the proposal type values and return the proposal and its metadata
116-
func (p *proposalTypes) Prompt(cdc codec.Codec) (*proposal, ProposalMetadata, error) {
114+
func (p *proposalType) Prompt(cdc codec.Codec) (*proposal, types.ProposalMetadata, error) {
117115
proposal := &proposal{}
118116

119117
// set metadata
120-
metadata, err := Prompt(ProposalMetadata{}, "proposal")
118+
metadata, err := Prompt(types.ProposalMetadata{}, "proposal")
121119
if err != nil {
122120
return nil, metadata, fmt.Errorf("failed to set proposal metadata: %w", err)
123121
}
122+
// the metadata must be saved on IPFS, set placeholder
124123
proposal.Metadata = "ipfs://CID"
125124

126125
// set deposit
@@ -151,56 +150,38 @@ func (p *proposalTypes) Prompt(cdc codec.Codec) (*proposal, ProposalMetadata, er
151150
return proposal, metadata, nil
152151
}
153152

154-
var supportedProposalTypes = []proposalTypes{
153+
var suggestedProposalTypes = []proposalType{
155154
{
156-
Type: proposalText,
155+
Name: proposalText,
157156
MsgType: "", // no message for text proposal
158157
},
159158
{
160-
Type: "software-upgrade",
159+
Name: "software-upgrade",
161160
MsgType: "/cosmos.upgrade.v1beta1.MsgSoftwareUpgrade",
162161
},
163162
{
164-
Type: "cancel-software-upgrade",
163+
Name: "cancel-software-upgrade",
165164
MsgType: "/cosmos.upgrade.v1beta1.MsgCancelUpgrade",
166165
},
167166
{
168-
Type: proposalOther,
167+
Name: proposalOther,
169168
MsgType: "", // user will input the message type
170169
},
171170
}
172171

173-
func getProposalTypes() []string {
174-
types := make([]string, len(supportedProposalTypes))
175-
for i, p := range supportedProposalTypes {
176-
types[i] = p.Type
172+
func getProposalSuggestions() []string {
173+
types := make([]string, len(suggestedProposalTypes))
174+
for i, p := range suggestedProposalTypes {
175+
types[i] = p.Name
177176
}
178177
return types
179178
}
180179

181-
func getProposalMsg(cdc codec.Codec, input string) (sdk.Msg, error) {
182-
var msg sdk.Msg
183-
bz, err := json.Marshal(struct {
184-
Type string `json:"@type"`
185-
}{
186-
Type: input,
187-
})
188-
if err != nil {
189-
return nil, err
190-
}
191-
192-
if err := cdc.UnmarshalInterfaceJSON(bz, &msg); err != nil {
193-
return nil, fmt.Errorf("failed to determined sdk.Msg from %s proposal type : %w", input, err)
194-
}
195-
196-
return msg, nil
197-
}
198-
199180
// NewCmdDraftProposal let a user generate a draft proposal.
200181
func NewCmdDraftProposal() *cobra.Command {
201182
cmd := &cobra.Command{
202183
Use: "draft-proposal",
203-
Short: "Generate a draft proposal json file. The generated proposal json contains only one message.",
184+
Short: "Generate a draft proposal json file. The generated proposal json contains only one message (skeleton).",
204185
SilenceUsage: true,
205186
RunE: func(cmd *cobra.Command, _ []string) error {
206187
clientCtx, err := client.GetClientTxContext(cmd)
@@ -211,24 +192,24 @@ func NewCmdDraftProposal() *cobra.Command {
211192
// prompt proposal type
212193
proposalTypesPrompt := promptui.Select{
213194
Label: "Select proposal type",
214-
Items: getProposalTypes(),
195+
Items: getProposalSuggestions(),
215196
}
216197

217-
_, proposalType, err := proposalTypesPrompt.Run()
198+
_, selectedProposalType, err := proposalTypesPrompt.Run()
218199
if err != nil {
219200
return fmt.Errorf("failed to prompt proposal types: %w", err)
220201
}
221202

222-
var proposal proposalTypes
223-
for _, p := range supportedProposalTypes {
224-
if strings.EqualFold(p.Type, proposalType) {
203+
var proposal proposalType
204+
for _, p := range suggestedProposalTypes {
205+
if strings.EqualFold(p.Name, selectedProposalType) {
225206
proposal = p
226207
break
227208
}
228209
}
229210

230211
// create any proposal type
231-
if proposal.Type == proposalOther {
212+
if proposal.Name == proposalOther {
232213
// prompt proposal type
233214
msgPrompt := promptui.Select{
234215
Label: "Select proposal message type:",
@@ -248,23 +229,23 @@ func NewCmdDraftProposal() *cobra.Command {
248229
}
249230

250231
if proposal.MsgType != "" {
251-
proposal.Msg, err = getProposalMsg(clientCtx.Codec, proposal.MsgType)
232+
proposal.Msg, err = sdk.GetMsgFromTypeURL(clientCtx.Codec, proposal.MsgType)
252233
if err != nil {
253234
// should never happen
254235
panic(err)
255236
}
256237
}
257238

258-
prop, metadata, err := proposal.Prompt(clientCtx.Codec)
239+
result, metadata, err := proposal.Prompt(clientCtx.Codec)
259240
if err != nil {
260241
return err
261242
}
262243

263-
if err := writeFile(draftMetadataFileName, metadata); err != nil {
244+
if err := writeFile(draftProposalFileName, result); err != nil {
264245
return err
265246
}
266247

267-
if err := writeFile(draftProposalFileName, prop); err != nil {
248+
if err := writeFile(draftMetadataFileName, metadata); err != nil {
268249
return err
269250
}
270251

0 commit comments

Comments
 (0)