-
Notifications
You must be signed in to change notification settings - Fork 3.8k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
0e24bad
commit 8670f49
Showing
10 changed files
with
3,374 additions
and
24 deletions.
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,58 @@ | ||
// Package v040 is copy-pasted from: | ||
// https://github.com/cosmos/cosmos-sdk/blob/v0.41.1/x/gov/types/content.go | ||
package v040 | ||
|
||
import ( | ||
"strings" | ||
|
||
sdk "github.com/cosmos/cosmos-sdk/types" | ||
sdkerrors "github.com/cosmos/cosmos-sdk/types/errors" | ||
"github.com/cosmos/cosmos-sdk/x/gov/types" | ||
) | ||
|
||
// Constants pertaining to a Content object | ||
const ( | ||
MaxDescriptionLength int = 5000 | ||
MaxTitleLength int = 140 | ||
) | ||
|
||
// Content defines an interface that a proposal must implement. It contains | ||
// information such as the title and description along with the type and routing | ||
// information for the appropriate handler to process the proposal. Content can | ||
// have additional fields, which will handled by a proposal's Handler. | ||
// TODO Try to unify this interface with types/module/simulation | ||
// https://github.com/cosmos/cosmos-sdk/issues/5853 | ||
type Content interface { | ||
GetTitle() string | ||
GetDescription() string | ||
ProposalRoute() string | ||
ProposalType() string | ||
ValidateBasic() error | ||
String() string | ||
} | ||
|
||
// Handler defines a function that handles a proposal after it has passed the | ||
// governance process. | ||
type Handler func(ctx sdk.Context, content Content) error | ||
|
||
// ValidateAbstract validates a proposal's abstract contents returning an error | ||
// if invalid. | ||
func ValidateAbstract(c Content) error { | ||
title := c.GetTitle() | ||
if len(strings.TrimSpace(title)) == 0 { | ||
return sdkerrors.Wrap(types.ErrInvalidProposalContent, "proposal title cannot be blank") | ||
} | ||
if len(title) > MaxTitleLength { | ||
return sdkerrors.Wrapf(types.ErrInvalidProposalContent, "proposal title is longer than max length of %d", MaxTitleLength) | ||
} | ||
|
||
description := c.GetDescription() | ||
if len(description) == 0 { | ||
return sdkerrors.Wrap(types.ErrInvalidProposalContent, "proposal description cannot be blank") | ||
} | ||
if len(description) > MaxDescriptionLength { | ||
return sdkerrors.Wrapf(types.ErrInvalidProposalContent, "proposal description is longer than max length of %d", MaxDescriptionLength) | ||
} | ||
|
||
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,56 @@ | ||
// Package v040 is copy-pasted from: | ||
// https://github.com/cosmos/cosmos-sdk/blob/v0.41.1/x/gov/types/deposit.go | ||
package v040 | ||
|
||
import ( | ||
"fmt" | ||
|
||
yaml "gopkg.in/yaml.v2" | ||
|
||
sdk "github.com/cosmos/cosmos-sdk/types" | ||
) | ||
|
||
// NewDeposit creates a new Deposit instance | ||
//nolint:interfacer | ||
func NewDeposit(proposalID uint64, depositor sdk.AccAddress, amount sdk.Coins) Deposit { | ||
return Deposit{proposalID, depositor.String(), amount} | ||
} | ||
|
||
func (d Deposit) String() string { | ||
out, _ := yaml.Marshal(d) | ||
return string(out) | ||
} | ||
|
||
// Deposits is a collection of Deposit objects | ||
type Deposits []Deposit | ||
|
||
// Equal returns true if two slices (order-dependant) of deposits are equal. | ||
func (d Deposits) Equal(other Deposits) bool { | ||
if len(d) != len(other) { | ||
return false | ||
} | ||
|
||
for i, deposit := range d { | ||
if deposit.String() != other[i].String() { | ||
return false | ||
} | ||
} | ||
|
||
return true | ||
} | ||
|
||
func (d Deposits) String() string { | ||
if len(d) == 0 { | ||
return "[]" | ||
} | ||
out := fmt.Sprintf("Deposits for Proposal %d:", d[0].ProposalId) | ||
for _, dep := range d { | ||
out += fmt.Sprintf("\n %s: %s", dep.Depositor, dep.Amount) | ||
} | ||
return out | ||
} | ||
|
||
// Empty returns whether a deposit is empty. | ||
func (d Deposit) Empty() bool { | ||
return d.String() == Deposit{}.String() | ||
} |
Oops, something went wrong.