2019-04-30 09:31:38 -07:00
|
|
|
package types
|
|
|
|
|
2019-08-08 12:51:18 -07:00
|
|
|
// DONTCOVER
|
|
|
|
|
2019-04-30 09:31:38 -07:00
|
|
|
import (
|
|
|
|
"fmt"
|
|
|
|
|
|
|
|
sdk "github.com/cosmos/cosmos-sdk/types"
|
|
|
|
)
|
|
|
|
|
2019-08-08 12:51:18 -07:00
|
|
|
// Codes for governance errors
|
2019-04-30 09:31:38 -07:00
|
|
|
const (
|
2019-08-08 12:51:18 -07:00
|
|
|
DefaultCodespace sdk.CodespaceType = ModuleName
|
2019-04-30 09:31:38 -07:00
|
|
|
|
|
|
|
CodeUnknownProposal sdk.CodeType = 1
|
|
|
|
CodeInactiveProposal sdk.CodeType = 2
|
|
|
|
CodeAlreadyActiveProposal sdk.CodeType = 3
|
|
|
|
CodeAlreadyFinishedProposal sdk.CodeType = 4
|
|
|
|
CodeAddressNotStaked sdk.CodeType = 5
|
|
|
|
CodeInvalidContent sdk.CodeType = 6
|
|
|
|
CodeInvalidProposalType sdk.CodeType = 7
|
|
|
|
CodeInvalidVote sdk.CodeType = 8
|
|
|
|
CodeInvalidGenesis sdk.CodeType = 9
|
|
|
|
CodeInvalidProposalStatus sdk.CodeType = 10
|
|
|
|
CodeProposalHandlerNotExists sdk.CodeType = 11
|
|
|
|
)
|
|
|
|
|
2019-08-08 12:51:18 -07:00
|
|
|
// ErrUnknownProposal error for unknown proposals
|
2019-04-30 09:31:38 -07:00
|
|
|
func ErrUnknownProposal(codespace sdk.CodespaceType, proposalID uint64) sdk.Error {
|
|
|
|
return sdk.NewError(codespace, CodeUnknownProposal, fmt.Sprintf("unknown proposal with id %d", proposalID))
|
|
|
|
}
|
|
|
|
|
2019-08-08 12:51:18 -07:00
|
|
|
// ErrInactiveProposal error for inactive (i.e finalized) proposals
|
2019-04-30 09:31:38 -07:00
|
|
|
func ErrInactiveProposal(codespace sdk.CodespaceType, proposalID uint64) sdk.Error {
|
|
|
|
return sdk.NewError(codespace, CodeInactiveProposal, fmt.Sprintf("inactive proposal with id %d", proposalID))
|
|
|
|
}
|
|
|
|
|
2019-08-08 12:51:18 -07:00
|
|
|
// ErrAlreadyActiveProposal error for proposals that are already active
|
2019-04-30 09:31:38 -07:00
|
|
|
func ErrAlreadyActiveProposal(codespace sdk.CodespaceType, proposalID uint64) sdk.Error {
|
|
|
|
return sdk.NewError(codespace, CodeAlreadyActiveProposal, fmt.Sprintf("proposal %d has been already active", proposalID))
|
|
|
|
}
|
|
|
|
|
2019-08-08 12:51:18 -07:00
|
|
|
// ErrInvalidProposalContent error for invalid proposal title or description
|
2019-04-30 09:31:38 -07:00
|
|
|
func ErrInvalidProposalContent(cs sdk.CodespaceType, msg string) sdk.Error {
|
|
|
|
return sdk.NewError(cs, CodeInvalidContent, fmt.Sprintf("invalid proposal content: %s", msg))
|
|
|
|
}
|
|
|
|
|
2019-08-08 12:51:18 -07:00
|
|
|
// ErrInvalidProposalType error for non registered proposal types
|
2019-04-30 09:31:38 -07:00
|
|
|
func ErrInvalidProposalType(codespace sdk.CodespaceType, proposalType string) sdk.Error {
|
|
|
|
return sdk.NewError(codespace, CodeInvalidProposalType, fmt.Sprintf("proposal type '%s' is not valid", proposalType))
|
|
|
|
}
|
|
|
|
|
2019-08-08 12:51:18 -07:00
|
|
|
// ErrInvalidVote error for an invalid vote option
|
2019-10-17 06:47:35 -07:00
|
|
|
func ErrInvalidVote(codespace sdk.CodespaceType, voteOption string) sdk.Error {
|
|
|
|
return sdk.NewError(codespace, CodeInvalidVote, fmt.Sprintf("'%v' is not a valid voting option", voteOption))
|
2019-04-30 09:31:38 -07:00
|
|
|
}
|
|
|
|
|
2019-08-08 12:51:18 -07:00
|
|
|
// ErrInvalidGenesis error for an invalid governance GenesisState
|
2019-04-30 09:31:38 -07:00
|
|
|
func ErrInvalidGenesis(codespace sdk.CodespaceType, msg string) sdk.Error {
|
|
|
|
return sdk.NewError(codespace, CodeInvalidVote, msg)
|
|
|
|
}
|
|
|
|
|
2019-08-08 12:51:18 -07:00
|
|
|
// ErrNoProposalHandlerExists error when proposal handler is not defined
|
2019-04-30 09:31:38 -07:00
|
|
|
func ErrNoProposalHandlerExists(codespace sdk.CodespaceType, content interface{}) sdk.Error {
|
|
|
|
return sdk.NewError(codespace, CodeProposalHandlerNotExists, fmt.Sprintf("'%T' does not have a corresponding handler", content))
|
|
|
|
}
|