Skip to content

Commit

Permalink
Add weighted votes migration
Browse files Browse the repository at this point in the history
  • Loading branch information
amaury1093 committed Feb 22, 2021
1 parent 0e24bad commit 8670f49
Show file tree
Hide file tree
Showing 10 changed files with 3,374 additions and 24 deletions.
2 changes: 1 addition & 1 deletion x/gov/keeper/migrations.go
Original file line number Diff line number Diff line change
Expand Up @@ -16,5 +16,5 @@ var _ MigrationKeeper = (*Keeper)(nil)

// Migrate1 implements MigrationKeeper.Migrate1 method.
func (keeper Keeper) Migrate1(ctx sdk.Context) error {
return v042.MigrateStore(ctx, keeper.storeKey)
return v042.MigrateStore(ctx, keeper.storeKey, keeper.cdc)
}
58 changes: 58 additions & 0 deletions x/gov/legacy/v040/content.go
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
}
56 changes: 56 additions & 0 deletions x/gov/legacy/v040/deposit.go
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()
}
Loading

0 comments on commit 8670f49

Please sign in to comment.