keeper

package
v0.0.0-...-a6871c7 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Apr 26, 2024 License: Apache-2.0 Imports: 29 Imported by: 2

Documentation

Index

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

func NewLegacyMsgServerImpl(govAcct string, v1Server v1.MsgServer) v1beta1.MsgServer

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

func NewMsgServerImpl(keeper *Keeper) v1.MsgServer

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.

func DefaultConfig

func DefaultConfig() Config

DefaultConfig returns the default config for gov.

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

func (k Keeper) ActivateVotingPeriod(ctx context.Context, proposal v1.Proposal) error

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

func (k Keeper) CancelProposal(ctx context.Context, proposalID uint64, proposer string) error

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

func (k Keeper) DeleteAndBurnDeposits(ctx context.Context, proposalID uint64) error

DeleteAndBurnDeposits deletes and burns all the deposits on a specific proposal.

func (Keeper) DeleteProposal

func (k Keeper) DeleteProposal(ctx context.Context, proposalID uint64) error

DeleteProposal deletes a proposal from store.

func (Keeper) EndBlocker

func (k Keeper) EndBlocker(ctx context.Context) error

EndBlocker is called every block.

func (Keeper) GetAuthority

func (k Keeper) GetAuthority() string

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

func (k *Keeper) Hooks() types.GovHooks

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

func (k Keeper) LegacyRouter() v1beta1.Router

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

func (k Keeper) RefundAndDeleteDeposits(ctx context.Context, proposalID uint64) error

RefundAndDeleteDeposits refunds and deletes all the deposits on a specific proposal.

func (Keeper) SetDeposit

func (k Keeper) SetDeposit(ctx context.Context, deposit v1.Deposit) error

SetDeposit sets a Deposit to the gov store

func (*Keeper) SetHooks

func (k *Keeper) SetHooks(gh types.GovHooks) *Keeper

SetHooks sets the hooks for governance

func (*Keeper) SetLegacyRouter

func (k *Keeper) SetLegacyRouter(router v1beta1.Router)

SetLegacyRouter sets the legacy router for governance

func (Keeper) SubmitProposal

func (k Keeper) SubmitProposal(ctx context.Context, messages []sdk.Msg, metadata, title, summary string, proposer sdk.AccAddress, proposalType v1.ProposalType) (v1.Proposal, error)

SubmitProposal creates a new proposal given an array of messages

func (Keeper) Tally

func (k Keeper) Tally(ctx context.Context, proposal v1.Proposal) (passes, burnDeposits bool, tallyResults v1.TallyResult, err error)

Tally iterates over the votes and updates the tally of a proposal based on the voting power of the voters

type Migrator

type Migrator struct {
	// contains filtered or unexported fields
}

Migrator is a struct for handling in-place store migrations.

func NewMigrator

func NewMigrator(keeper *Keeper) Migrator

NewMigrator returns a new Migrator.

func (Migrator) Migrate1to2

func (m Migrator) Migrate1to2(ctx context.Context) error

Migrate1to2 migrates from version 1 to 2.

func (Migrator) Migrate2to3

func (m Migrator) Migrate2to3(ctx context.Context) error

Migrate2to3 migrates from version 2 to 3.

func (Migrator) Migrate3to4

func (m Migrator) Migrate3to4(ctx context.Context) error

Migrate3to4 migrates from version 3 to 4.

func (Migrator) Migrate4to5

func (m Migrator) Migrate4to5(ctx context.Context) error

Migrate4to5 migrates from version 4 to 5.

func (Migrator) Migrate5to6

func (m Migrator) Migrate5to6(ctx context.Context) error

Migrate4to5 migrates from version 5 to 6.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL