Documentation
¶
Overview ¶
nolint
Index ¶
- Constants
- Variables
- func ErrAddressNotStaked(codespace sdk.CodespaceType, address sdk.AccAddress) sdk.Error
- func ErrAlreadyActiveProposal(codespace sdk.CodespaceType, proposalID uint64) sdk.Error
- func ErrAlreadyFinishedProposal(codespace sdk.CodespaceType, proposalID uint64) sdk.Error
- func ErrInactiveProposal(codespace sdk.CodespaceType, proposalID uint64) sdk.Error
- func ErrInvalidGenesis(codespace sdk.CodespaceType, msg string) sdk.Error
- func ErrInvalidProposalContent(cs sdk.CodespaceType, msg string) sdk.Error
- func ErrInvalidProposalType(codespace sdk.CodespaceType, proposalType string) sdk.Error
- func ErrInvalidVote(codespace sdk.CodespaceType, voteOption VoteOption) sdk.Error
- func ErrNoProposalHandlerExists(codespace sdk.CodespaceType, content interface{}) sdk.Error
- func ErrUnknownProposal(codespace sdk.CodespaceType, proposalID uint64) sdk.Error
- func IsValidProposalType(ty string) bool
- func KeyActiveProposalQueueProposal(endTime time.Time, proposalID uint64) []byte
- func KeyDeposit(proposalID uint64, depositorAddr sdk.AccAddress) []byte
- func KeyDepositsSubspace(proposalID uint64) []byte
- func KeyInactiveProposalQueueProposal(endTime time.Time, proposalID uint64) []byte
- func KeyProposal(proposalID uint64) []byte
- func KeyVote(proposalID uint64, voterAddr sdk.AccAddress) []byte
- func KeyVotesSubspace(proposalID uint64) []byte
- func PrefixActiveProposalQueueTime(endTime time.Time) []byte
- func PrefixInactiveProposalQueueTime(endTime time.Time) []byte
- func ProposalHandler(_ sdk.Context, c Content) sdk.Error
- func RegisterCodec(cdc *codec.Codec)
- func RegisterProposalType(ty string)
- func RegisterProposalTypeCodec(o interface{}, name string)
- func ValidProposalStatus(status ProposalStatus) bool
- func ValidVoteOption(option VoteOption) bool
- func ValidateAbstract(codespace sdk.CodespaceType, c Content) sdk.Error
- type Content
- type Deposit
- type Deposits
- type Handler
- type MsgDeposit
- type MsgSubmitProposal
- type MsgVote
- type Proposal
- type ProposalQueue
- type ProposalStatus
- func (status ProposalStatus) Format(s fmt.State, verb rune)
- func (status ProposalStatus) Marshal() ([]byte, error)
- func (status ProposalStatus) MarshalJSON() ([]byte, error)
- func (status ProposalStatus) String() string
- func (status *ProposalStatus) Unmarshal(data []byte) error
- func (status *ProposalStatus) UnmarshalJSON(data []byte) error
- type Proposals
- type SoftwareUpgradeProposal
- func (sup SoftwareUpgradeProposal) GetDescription() string
- func (sup SoftwareUpgradeProposal) GetTitle() string
- func (sup SoftwareUpgradeProposal) ProposalRoute() string
- func (sup SoftwareUpgradeProposal) ProposalType() string
- func (sup SoftwareUpgradeProposal) String() string
- func (sup SoftwareUpgradeProposal) ValidateBasic() sdk.Error
- type TallyResult
- type TextProposal
- type Vote
- type VoteOption
- type Votes
Constants ¶
const ( MaxDescriptionLength int = 5000 MaxTitleLength int = 140 )
Constants pertaining to a Content object
const ( DefaultCodespace sdk.CodespaceType = "gov" 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 )
const ( // ModuleKey is the name of the module ModuleName = "gov" // StoreKey is the store key string for gov StoreKey = ModuleName // RouterKey is the message route for gov RouterKey = ModuleName // QuerierRoute is the querier route for gov QuerierRoute = ModuleName // Parameter store default namestore DefaultParamspace = ModuleName )
const ( TypeMsgDeposit = "deposit" TypeMsgVote = "vote" TypeMsgSubmitProposal = "submit_proposal" )
Governance message types and routes
const ( ProposalTypeText string = "Text" ProposalTypeSoftwareUpgrade string = "SoftwareUpgrade" )
Proposal types
Variables ¶
var ( KeyDelimiter = []byte(":") KeyNextProposalID = []byte("newProposalID") PrefixActiveProposalQueue = []byte("activeProposalQueue") PrefixInactiveProposalQueue = []byte("inactiveProposalQueue") )
Key for getting a the next available proposalID from the store
var ModuleCdc = codec.New()
module codec
Functions ¶
func ErrAddressNotStaked ¶
func ErrAddressNotStaked(codespace sdk.CodespaceType, address sdk.AccAddress) sdk.Error
func ErrAlreadyActiveProposal ¶
func ErrAlreadyActiveProposal(codespace sdk.CodespaceType, proposalID uint64) sdk.Error
func ErrAlreadyFinishedProposal ¶
func ErrAlreadyFinishedProposal(codespace sdk.CodespaceType, proposalID uint64) sdk.Error
func ErrInactiveProposal ¶
func ErrInactiveProposal(codespace sdk.CodespaceType, proposalID uint64) sdk.Error
func ErrInvalidGenesis ¶
func ErrInvalidGenesis(codespace sdk.CodespaceType, msg string) sdk.Error
func ErrInvalidProposalContent ¶
func ErrInvalidProposalContent(cs sdk.CodespaceType, msg string) sdk.Error
func ErrInvalidProposalType ¶
func ErrInvalidProposalType(codespace sdk.CodespaceType, proposalType string) sdk.Error
func ErrInvalidVote ¶
func ErrInvalidVote(codespace sdk.CodespaceType, voteOption VoteOption) sdk.Error
func ErrNoProposalHandlerExists ¶
func ErrNoProposalHandlerExists(codespace sdk.CodespaceType, content interface{}) sdk.Error
func ErrUnknownProposal ¶
func ErrUnknownProposal(codespace sdk.CodespaceType, proposalID uint64) sdk.Error
func IsValidProposalType ¶
IsValidProposalType returns a boolean determining if the proposal type is valid.
NOTE: Modules with their own proposal types must register them.
func KeyActiveProposalQueueProposal ¶
Returns the key for a proposalID in the activeProposalQueue
func KeyDeposit ¶
func KeyDeposit(proposalID uint64, depositorAddr sdk.AccAddress) []byte
Key for getting a specific deposit from the store
func KeyDepositsSubspace ¶
Key for getting all deposits on a proposal from the store
func KeyInactiveProposalQueueProposal ¶
Returns the key for a proposalID in the activeProposalQueue
func KeyProposal ¶
Key for getting a specific proposal from the store
func KeyVote ¶
func KeyVote(proposalID uint64, voterAddr sdk.AccAddress) []byte
Key for getting a specific vote from the store
func KeyVotesSubspace ¶
Key for getting all votes on a proposal from the store
func PrefixActiveProposalQueueTime ¶
Returns the key for a proposalID in the activeProposalQueue
func PrefixInactiveProposalQueueTime ¶
Returns the key for a proposalID in the activeProposalQueue
func ProposalHandler ¶
ProposalHandler implements the Handler interface for governance module-based proposals (ie. TextProposal and SoftwareUpgradeProposal). Since these are merely signaling mechanisms at the moment and do not affect state, it performs a no-op.
func RegisterCodec ¶
RegisterCodec registers all the necessary types and interfaces for governance.
func RegisterProposalType ¶
func RegisterProposalType(ty string)
RegisterProposalType registers a proposal type. It will panic if the type is already registered.
func RegisterProposalTypeCodec ¶
func RegisterProposalTypeCodec(o interface{}, name string)
RegisterProposalTypeCodec registers an external proposal content type defined in another module for the internal ModuleCdc. This allows the MsgSubmitProposal to be correctly Amino encoded and decoded.
func ValidProposalStatus ¶
func ValidProposalStatus(status ProposalStatus) bool
ValidProposalStatus returns true if the proposal status is valid and false otherwise.
func ValidVoteOption ¶
func ValidVoteOption(option VoteOption) bool
ValidVoteOption returns true if the vote option is valid and false otherwise.
func ValidateAbstract ¶
func ValidateAbstract(codespace sdk.CodespaceType, c Content) sdk.Error
ValidateAbstract validates a proposal's abstract contents returning an error if invalid.
Types ¶
type Content ¶
type Content interface { GetTitle() string GetDescription() string ProposalRoute() string ProposalType() string ValidateBasic() sdk.Error String() string }
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.
func ContentFromProposalType ¶
ContentFromProposalType returns a Content object based on the proposal type.
func NewTextProposal ¶
type Deposit ¶
type Deposit struct { Depositor sdk.AccAddress `json:"depositor"` // Address of the depositor ProposalID uint64 `json:"proposal_id"` // proposalID of the proposal Amount sdk.Coins `json:"amount"` // Deposit amount }
Deposit
type Handler ¶
Handler defines a function that handles a proposal after it has passed the governance process.
type MsgDeposit ¶
type MsgDeposit struct { ProposalID uint64 `json:"proposal_id"` // ID of the proposal Depositor sdk.AccAddress `json:"depositor"` // Address of the depositor Amount sdk.Coins `json:"amount"` // Coins to add to the proposal's deposit }
MsgDeposit
func NewMsgDeposit ¶
func NewMsgDeposit(depositor sdk.AccAddress, proposalID uint64, amount sdk.Coins) MsgDeposit
func (MsgDeposit) String ¶
func (msg MsgDeposit) String() string
func (MsgDeposit) Type ¶
func (msg MsgDeposit) Type() string
type MsgSubmitProposal ¶
type MsgSubmitProposal struct { Content Content `json:"content"` InitialDeposit sdk.Coins `json:"initial_deposit"` // Initial deposit paid by sender. Must be strictly positive Proposer sdk.AccAddress `json:"proposer"` // Address of the proposer }
MsgSubmitProposal
func NewMsgSubmitProposal ¶
func NewMsgSubmitProposal(content Content, initialDeposit sdk.Coins, proposer sdk.AccAddress) MsgSubmitProposal
func (MsgSubmitProposal) GetSignBytes ¶
func (msg MsgSubmitProposal) GetSignBytes() []byte
Implements Msg.
func (MsgSubmitProposal) GetSigners ¶
func (msg MsgSubmitProposal) GetSigners() []sdk.AccAddress
Implements Msg.
func (MsgSubmitProposal) String ¶
func (msg MsgSubmitProposal) String() string
func (MsgSubmitProposal) Type ¶
func (msg MsgSubmitProposal) Type() string
func (MsgSubmitProposal) ValidateBasic ¶
func (msg MsgSubmitProposal) ValidateBasic() sdk.Error
Implements Msg.
type MsgVote ¶
type MsgVote struct { ProposalID uint64 `json:"proposal_id"` // ID of the proposal Voter sdk.AccAddress `json:"voter"` // address of the voter Option VoteOption `json:"option"` // option from OptionSet chosen by the voter }
MsgVote
func NewMsgVote ¶
func NewMsgVote(voter sdk.AccAddress, proposalID uint64, option VoteOption) MsgVote
type Proposal ¶
type Proposal struct { Content `json:"content"` // Proposal content interface ProposalID uint64 `json:"id"` // ID of the proposal Status ProposalStatus `json:"proposal_status"` // Status of the Proposal {Pending, Active, Passed, Rejected} FinalTallyResult TallyResult `json:"final_tally_result"` // Result of Tallys SubmitTime time.Time `json:"submit_time"` // Time of the block where TxGovSubmitProposal was included DepositEndTime time.Time `json:"deposit_end_time"` // Time that the Proposal would expire if deposit amount isn't met TotalDeposit sdk.Coins `json:"total_deposit"` // Current deposit on this proposal. Initial value is set at InitialDeposit VotingStartTime time.Time `json:"voting_start_time"` // Time of the block where MinDeposit was reached. -1 if MinDeposit is not reached VotingEndTime time.Time `json:"voting_end_time"` // Time that the VotingPeriod for this proposal will end and votes will be tallied }
Proposal defines a struct used by the governance module to allow for voting on network changes.
func NewProposal ¶
type ProposalStatus ¶
type ProposalStatus byte
ProposalStatus is a type alias that represents a proposal status as a byte
const ( StatusNil ProposalStatus = 0x00 StatusDepositPeriod ProposalStatus = 0x01 StatusVotingPeriod ProposalStatus = 0x02 StatusPassed ProposalStatus = 0x03 StatusRejected ProposalStatus = 0x04 StatusFailed ProposalStatus = 0x05 )
nolint
func ProposalStatusFromString ¶
func ProposalStatusFromString(str string) (ProposalStatus, error)
ProposalStatusToString turns a string into a ProposalStatus
func (ProposalStatus) Format ¶
func (status ProposalStatus) Format(s fmt.State, verb rune)
Format implements the fmt.Formatter interface. nolint: errcheck
func (ProposalStatus) Marshal ¶
func (status ProposalStatus) Marshal() ([]byte, error)
Marshal needed for protobuf compatibility
func (ProposalStatus) MarshalJSON ¶
func (status ProposalStatus) MarshalJSON() ([]byte, error)
Marshals to JSON using string
func (ProposalStatus) String ¶
func (status ProposalStatus) String() string
String implements the Stringer interface.
func (*ProposalStatus) Unmarshal ¶
func (status *ProposalStatus) Unmarshal(data []byte) error
Unmarshal needed for protobuf compatibility
func (*ProposalStatus) UnmarshalJSON ¶
func (status *ProposalStatus) UnmarshalJSON(data []byte) error
Unmarshals from JSON assuming Bech32 encoding
type SoftwareUpgradeProposal ¶
type SoftwareUpgradeProposal struct { Title string `json:"title"` Description string `json:"description"` }
Software Upgrade Proposals TODO: We have to add fields for SUP specific arguments e.g. commit hash, upgrade date, etc.
func (SoftwareUpgradeProposal) GetDescription ¶
func (sup SoftwareUpgradeProposal) GetDescription() string
func (SoftwareUpgradeProposal) GetTitle ¶
func (sup SoftwareUpgradeProposal) GetTitle() string
nolint
func (SoftwareUpgradeProposal) ProposalRoute ¶
func (sup SoftwareUpgradeProposal) ProposalRoute() string
func (SoftwareUpgradeProposal) ProposalType ¶
func (sup SoftwareUpgradeProposal) ProposalType() string
func (SoftwareUpgradeProposal) String ¶
func (sup SoftwareUpgradeProposal) String() string
func (SoftwareUpgradeProposal) ValidateBasic ¶
func (sup SoftwareUpgradeProposal) ValidateBasic() sdk.Error
type TallyResult ¶
type TallyResult struct { Yes sdk.Int `json:"yes"` Abstain sdk.Int `json:"abstain"` No sdk.Int `json:"no"` NoWithVeto sdk.Int `json:"no_with_veto"` }
Tally Results
func EmptyTallyResult ¶
func EmptyTallyResult() TallyResult
EmptyTallyResult returns an empty TallyResult.
func NewTallyResult ¶
func NewTallyResult(yes, abstain, no, noWithVeto sdk.Int) TallyResult
func NewTallyResultFromMap ¶
func NewTallyResultFromMap(results map[VoteOption]sdk.Dec) TallyResult
func (TallyResult) Equals ¶
func (tr TallyResult) Equals(comp TallyResult) bool
Equals returns if two proposals are equal.
func (TallyResult) String ¶
func (tr TallyResult) String() string
type TextProposal ¶
Text Proposal
func (TextProposal) GetDescription ¶
func (tp TextProposal) GetDescription() string
func (TextProposal) ProposalRoute ¶
func (tp TextProposal) ProposalRoute() string
func (TextProposal) ProposalType ¶
func (tp TextProposal) ProposalType() string
func (TextProposal) String ¶
func (tp TextProposal) String() string
func (TextProposal) ValidateBasic ¶
func (tp TextProposal) ValidateBasic() sdk.Error
type Vote ¶
type Vote struct { Voter sdk.AccAddress `json:"voter"` // address of the voter ProposalID uint64 `json:"proposal_id"` // proposalID of the proposal Option VoteOption `json:"option"` // option from OptionSet chosen by the voter }
Vote
type VoteOption ¶
type VoteOption byte
VoteOption defines a vote option
const ( OptionEmpty VoteOption = 0x00 OptionYes VoteOption = 0x01 OptionAbstain VoteOption = 0x02 OptionNo VoteOption = 0x03 OptionNoWithVeto VoteOption = 0x04 )
Vote options
func VoteOptionFromString ¶
func VoteOptionFromString(str string) (VoteOption, error)
VoteOptionFromString returns a VoteOption from a string. It returns an error if the string is invalid.
func (VoteOption) Format ¶
func (vo VoteOption) Format(s fmt.State, verb rune)
Format implements the fmt.Formatter interface. nolint: errcheck
func (VoteOption) Marshal ¶
func (vo VoteOption) Marshal() ([]byte, error)
Marshal needed for protobuf compatibility.
func (VoteOption) MarshalJSON ¶
func (vo VoteOption) MarshalJSON() ([]byte, error)
Marshals to JSON using string.
func (VoteOption) String ¶
func (vo VoteOption) String() string
String implements the Stringer interface.
func (*VoteOption) Unmarshal ¶
func (vo *VoteOption) Unmarshal(data []byte) error
Unmarshal needed for protobuf compatibility.
func (*VoteOption) UnmarshalJSON ¶
func (vo *VoteOption) UnmarshalJSON(data []byte) error
UnmarshalJSON decodes from JSON assuming Bech32 encoding.