Documentation ¶
Index ¶
- func ModuleAccountInvariant(keeper *Keeper, bk types.BankKeeper) sdk.Invariant
- func NewLegacyMsgServerImpl(govAcct string, v1Server v1.MsgServer) v1beta1.MsgServer
- func NewLegacyQueryServer(k *Keeper) v1beta1.QueryServer
- func NewMsgServerImpl(keeper *Keeper) v1.MsgServer
- func NewQueryServer(k *Keeper) v1.QueryServer
- func RegisterInvariants(ir sdk.InvariantRegistry, keeper *Keeper, bk types.BankKeeper)
- type CalculateVoteResultsAndVotingPowerFn
- type Config
- type Keeper
- func (k Keeper) ActivateVotingPeriod(ctx context.Context, proposal v1.Proposal) error
- func (k Keeper) AddDeposit(ctx context.Context, proposalID uint64, depositorAddr sdk.AccAddress, ...) (bool, error)
- func (k Keeper) AddVote(ctx context.Context, proposalID uint64, voterAddr sdk.AccAddress, ...) error
- func (k Keeper) CancelProposal(ctx context.Context, proposalID uint64, proposer string) error
- func (k Keeper) ChargeDeposit(ctx context.Context, proposalID uint64, destAddress, proposalCancelRate string) error
- func (k Keeper) DeleteAndBurnDeposits(ctx context.Context, proposalID uint64) error
- func (k Keeper) DeleteProposal(ctx context.Context, proposalID uint64) error
- func (k Keeper) EndBlocker(ctx context.Context) error
- func (k Keeper) GetAuthority() string
- func (k Keeper) GetDeposits(ctx context.Context, proposalID uint64) (deposits v1.Deposits, err error)
- func (k Keeper) GetGovernanceAccount(ctx context.Context) sdk.ModuleAccountI
- func (k *Keeper) Hooks() types.GovHooks
- func (k Keeper) IterateDeposits(ctx context.Context, proposalID uint64, ...) error
- func (k Keeper) LegacyRouter() v1beta1.Router
- func (k Keeper) ModuleAccountAddress() sdk.AccAddress
- func (k Keeper) RefundAndDeleteDeposits(ctx context.Context, proposalID uint64) error
- func (k Keeper) SetDeposit(ctx context.Context, deposit v1.Deposit) error
- func (k *Keeper) SetHooks(gh types.GovHooks) *Keeper
- func (k *Keeper) SetLegacyRouter(router v1beta1.Router)
- func (k Keeper) SubmitProposal(ctx context.Context, messages []sdk.Msg, metadata, title, summary string, ...) (v1.Proposal, error)
- func (k Keeper) Tally(ctx context.Context, proposal v1.Proposal) (passes, burnDeposits bool, tallyResults v1.TallyResult, err error)
- type Migrator
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func ModuleAccountInvariant ¶
func ModuleAccountInvariant(keeper *Keeper, bk types.BankKeeper) sdk.Invariant
ModuleAccountInvariant checks that the module account coins reflects the sum of deposit amounts held on store.
func NewLegacyMsgServerImpl ¶
NewLegacyMsgServerImpl returns an implementation of the v1beta1 legacy MsgServer interface. It wraps around the current MsgServer
func NewLegacyQueryServer ¶
func NewLegacyQueryServer(k *Keeper) v1beta1.QueryServer
NewLegacyQueryServer returns an implementation of the v1beta1 legacy QueryServer interface.
func NewMsgServerImpl ¶
NewMsgServerImpl returns an implementation of the gov MsgServer interface for the provided Keeper.
func NewQueryServer ¶
func NewQueryServer(k *Keeper) v1.QueryServer
func RegisterInvariants ¶
func RegisterInvariants(ir sdk.InvariantRegistry, keeper *Keeper, bk types.BankKeeper)
RegisterInvariants registers all governance invariants
Types ¶
type CalculateVoteResultsAndVotingPowerFn ¶
type CalculateVoteResultsAndVotingPowerFn func( ctx context.Context, keeper Keeper, proposalID uint64, validators map[string]v1.ValidatorGovInfo, ) (totalVoterPower math.LegacyDec, results map[v1.VoteOption]math.LegacyDec, err error)
CalculateVoteResultsAndVotingPowerFn is a function signature for calculating vote results and voting power It can be overridden to customize the voting power calculation for proposals It gets the proposal tallied and the validators governance infos (bonded tokens, voting power, etc.) It must return the total voting power and the results of the vote
type Config ¶
type Config struct { // MaxTitleLen defines the amount of characters that can be used for proposal title MaxTitleLen uint64 // MaxMetadataLen defines the amount of characters that can be used for proposal metadata MaxMetadataLen uint64 // MaxSummaryLen defines the amount of characters that can be used for proposal summary MaxSummaryLen uint64 // MaxVoteOptionsLen defines the maximum number of vote options a proposal can have. // This only applies to WeightedVoteOption messages and not to the VoteOption messages // 0 means this param is disabled, hence all supported options are allowed MaxVoteOptionsLen uint64 // CalculateVoteResultsAndVotingPowerFn is a function signature for calculating vote results and voting power // Keeping it nil will use the default implementation CalculateVoteResultsAndVotingPowerFn CalculateVoteResultsAndVotingPowerFn }
Config is a config struct used for initializing the gov module to avoid using globals.
type Keeper ¶
type Keeper struct { appmodule.Environment Schema collections.Schema // Constitution value: constitution Constitution collections.Item[string] // Params stores the governance parameters Params collections.Item[v1.Params] // MessageBasedParams store message-based governance parameters // key:proposal-msg-url | value MessageBasedParams MessageBasedParams collections.Map[string, v1.MessageBasedParams] // Deposits key: proposalID+depositorAddr | value: Deposit Deposits collections.Map[collections.Pair[uint64, sdk.AccAddress], v1.Deposit] // Votes key: proposalID+voterAddr | value: Vote Votes collections.Map[collections.Pair[uint64, sdk.AccAddress], v1.Vote] // ProposalID is a counter for proposals. It tracks the next proposal ID to be issued. ProposalID collections.Sequence // Proposals key:proposalID | value: Proposal Proposals collections.Map[uint64, v1.Proposal] // ProposalVoteOptions key: proposalID | value: // This is used to store multiple choice vote options ProposalVoteOptions collections.Map[uint64, v1.ProposalVoteOptions] // ActiveProposalsQueue key: votingEndTime+proposalID | value: proposalID ActiveProposalsQueue collections.Map[collections.Pair[time.Time, uint64], uint64] // TODO(tip): this should be simplified and go into an index. // InactiveProposalsQueue key: depositEndTime+proposalID | value: proposalID InactiveProposalsQueue collections.Map[collections.Pair[time.Time, uint64], uint64] // TODO(tip): this should be simplified and go into an index. // contains filtered or unexported fields }
Keeper defines the governance module Keeper
func NewKeeper ¶
func NewKeeper( cdc codec.Codec, env appmodule.Environment, authKeeper types.AccountKeeper, bankKeeper types.BankKeeper, sk types.StakingKeeper, pk types.PoolKeeper, config Config, authority string, ) *Keeper
NewKeeper returns a governance keeper. It handles: - submitting governance proposals - depositing funds into proposals, and activating upon sufficient funds being deposited - users voting on proposals, with weight proportional to stake in the system - and tallying the result of the vote.
CONTRACT: the parameter Subspace must have the param key table already initialized
func (Keeper) ActivateVotingPeriod ¶
ActivateVotingPeriod activates the voting period of a proposal
func (Keeper) AddDeposit ¶
func (k Keeper) AddDeposit(ctx context.Context, proposalID uint64, depositorAddr sdk.AccAddress, depositAmount sdk.Coins) (bool, error)
AddDeposit adds or updates a deposit of a specific depositor on a specific proposal. Activates voting period when appropriate and returns true in that case, else returns false.
func (Keeper) AddVote ¶
func (k Keeper) AddVote(ctx context.Context, proposalID uint64, voterAddr sdk.AccAddress, options v1.WeightedVoteOptions, metadata string) error
AddVote adds a vote on a specific proposal
func (Keeper) CancelProposal ¶
CancelProposal will cancel proposal before the voting period ends
func (Keeper) ChargeDeposit ¶
func (k Keeper) ChargeDeposit(ctx context.Context, proposalID uint64, destAddress, proposalCancelRate string) error
ChargeDeposit will charge proposal cancellation fee (deposits * proposal_cancel_burn_rate) and send to a destAddress if defined or burn otherwise. Remaining funds are send back to the depositor.
func (Keeper) DeleteAndBurnDeposits ¶
DeleteAndBurnDeposits deletes and burns all the deposits on a specific proposal.
func (Keeper) DeleteProposal ¶
DeleteProposal deletes a proposal from store.
func (Keeper) EndBlocker ¶
EndBlocker is called every block.
func (Keeper) GetAuthority ¶
GetAuthority returns the x/gov module's authority.
func (Keeper) GetDeposits ¶
func (k Keeper) GetDeposits(ctx context.Context, proposalID uint64) (deposits v1.Deposits, err error)
GetDeposits returns all the deposits of a proposal
func (Keeper) GetGovernanceAccount ¶
func (k Keeper) GetGovernanceAccount(ctx context.Context) sdk.ModuleAccountI
GetGovernanceAccount returns the governance ModuleAccount
func (*Keeper) Hooks ¶
Hooks gets the hooks for governance Keeper
func (Keeper) IterateDeposits ¶
func (k Keeper) IterateDeposits(ctx context.Context, proposalID uint64, cb func(key collections.Pair[uint64, sdk.AccAddress], value v1.Deposit) (bool, error)) error
IterateDeposits iterates over all the proposals deposits and performs a callback function
func (Keeper) LegacyRouter ¶
LegacyRouter returns the gov keeper's legacy router
func (Keeper) ModuleAccountAddress ¶
func (k Keeper) ModuleAccountAddress() sdk.AccAddress
ModuleAccountAddress returns gov module account address
func (Keeper) RefundAndDeleteDeposits ¶
RefundAndDeleteDeposits refunds and deletes all the deposits on a specific proposal.
func (Keeper) SetDeposit ¶
SetDeposit sets a Deposit to the gov store
func (*Keeper) SetHooks ¶
SetHooks sets the hooks for governance
func (*Keeper) SetLegacyRouter ¶
SetLegacyRouter sets the legacy router for governance
type Migrator ¶
type Migrator struct {
// contains filtered or unexported fields
}
Migrator is a struct for handling in-place store migrations.
func (Migrator) Migrate1to2 ¶
Migrate1to2 migrates from version 1 to 2.
func (Migrator) Migrate2to3 ¶
Migrate2to3 migrates from version 2 to 3.
func (Migrator) Migrate3to4 ¶
Migrate3to4 migrates from version 3 to 4.
func (Migrator) Migrate4to5 ¶
Migrate4to5 migrates from version 4 to 5.