Skip to content

Commit

Permalink
feat: apply PR comments
Browse files Browse the repository at this point in the history
  • Loading branch information
emidev98 committed Nov 10, 2023
1 parent 866ee14 commit 4167f5f
Show file tree
Hide file tree
Showing 4 changed files with 15 additions and 6 deletions.
2 changes: 1 addition & 1 deletion x/gov/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -309,7 +309,7 @@ the following `JSON` template:
This makes it far easier for clients to support multiple networks.

Fields metadata, title and summary have a maximum length that is chosen by the app developer, and
passed into the gov keeper as a config. The default maximum length are: for the title 100 characters, for the metadata 255 characters and for summary 10200 characters (40 times the one of the title).
passed into the gov keeper as a config. The default maximum length are: for the title 255 characters, for the metadata 255 characters and for summary 10200 characters (40 times the one of the title).

#### Writing a module that uses governance

Expand Down
2 changes: 2 additions & 0 deletions x/gov/keeper/keeper.go
Original file line number Diff line number Diff line change
Expand Up @@ -190,6 +190,8 @@ func (k Keeper) ModuleAccountAddress() sdk.AccAddress {
return k.authKeeper.GetModuleAddress(types.ModuleName)
}

// validateProposalLengths checks message metadata, summary and title
// to have the expected length otherwise returns an error.
func (k Keeper) validateProposalLengths(metadata, title, summary string) error {
if err := k.assertMetadataLength(metadata); err != nil {
return err
Expand Down
5 changes: 3 additions & 2 deletions x/gov/keeper/proposal.go
Original file line number Diff line number Diff line change
Expand Up @@ -20,8 +20,9 @@ import (
func (keeper Keeper) SubmitProposal(ctx context.Context, messages []sdk.Msg, metadata, title, summary string, proposer sdk.AccAddress, expedited bool) (v1.Proposal, error) {
sdkCtx := sdk.UnwrapSDKContext(ctx)

// This method checks that all the message metadata, summary and title
// has te expected length defined in the module configuration.

// This method checks that all message metadata, summary and title
// has te expected length defined in the module configuration.
if err := keeper.validateProposalLengths(metadata, title, summary); err != nil {
return v1.Proposal{}, err
}
Expand Down
12 changes: 9 additions & 3 deletions x/gov/module.go
Original file line number Diff line number Diff line change
Expand Up @@ -182,9 +182,15 @@ type ModuleOutputs struct {

func ProvideModule(in ModuleInputs) ModuleOutputs {
defaultConfig := govtypes.DefaultConfig()
defaultConfig.MaxTitleLen = max(in.Config.MaxTitleLen, defaultConfig.MaxTitleLen)
defaultConfig.MaxMetadataLen = max(in.Config.MaxMetadataLen, defaultConfig.MaxMetadataLen)
defaultConfig.MaxSummaryLen = max(in.Config.MaxSummaryLen, defaultConfig.MaxSummaryLen)
if in.Config.MaxTitleLen != 0 {
defaultConfig.MaxTitleLen = in.Config.MaxTitleLen
}
if in.Config.MaxMetadataLen != 0 {
defaultConfig.MaxMetadataLen = in.Config.MaxMetadataLen
}
if in.Config.MaxSummaryLen != 0 {
defaultConfig.MaxSummaryLen = in.Config.MaxSummaryLen
}

// default to governance authority if not provided
authority := authtypes.NewModuleAddress(govtypes.ModuleName)
Expand Down

0 comments on commit 4167f5f

Please sign in to comment.