keeper

package
v0.55.0 Latest Latest
Warning

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

Go to latest
Published: Jul 28, 2026 License: Apache-2.0 Imports: 24 Imported by: 2,166

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func ExportGenesis added in v0.54.0

func ExportGenesis(ctx sdk.Context, k *Keeper) (*v1.GenesisState, error)

ExportGenesis - output genesis parameters

func InitGenesis added in v0.54.0

func InitGenesis(ctx sdk.Context, ak types.AccountKeeper, bk types.BankKeeper, k *Keeper, data *v1.GenesisState)

InitGenesis - store genesis parameters

func NewLegacyMsgServerImpl added in v0.46.0

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 NewMsgServerImpl added in v0.40.0

func NewMsgServerImpl(keeper *Keeper) v1.MsgServer

NewMsgServerImpl returns an implementation of the gov MsgServer interface for the provided Keeper.

func NewQueryServer added in v0.50.1

func NewQueryServer(k *Keeper) v1.QueryServer

Types

type CalculateVoteResultsAndVotingPowerFn added in v0.53.0

type CalculateVoteResultsAndVotingPowerFn func(
	ctx context.Context,
	k Keeper,
	proposal v1.Proposal,
) (totalVoterPower math.LegacyDec, totalValPower math.Int, 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 must fetch validators, calculate total validator power, and return vote results totalVoterPower is the sum of voting power that actually voted totalValPower is the sum of all active validator power (for quorum calculation)

func NewDefaultCalculateVoteResultsAndVotingPower added in v0.54.0

func NewDefaultCalculateVoteResultsAndVotingPower(sk types.StakingKeeper) CalculateVoteResultsAndVotingPowerFn

NewDefaultCalculateVoteResultsAndVotingPower returns a CalculateVoteResultsAndVotingPowerFn that uses the provided StakingKeeper to calculate voting power

type Keeper

type Keeper struct {
	Schema                 collections.Schema
	Constitution           collections.Item[string]
	Params                 collections.Item[v1.Params]
	Deposits               collections.Map[collections.Pair[uint64, sdk.AccAddress], v1.Deposit]
	Votes                  collections.Map[collections.Pair[uint64, sdk.AccAddress], v1.Vote]
	ProposalID             collections.Sequence
	Proposals              collections.Map[uint64, v1.Proposal]
	ActiveProposalsQueue   collections.Map[collections.Pair[time.Time, uint64], uint64] // TODO(tip): this should be simplified and go into an index.
	InactiveProposalsQueue collections.Map[collections.Pair[time.Time, uint64], uint64] // TODO(tip): this should be simplified and go into an index.
	VotingPeriodProposals  collections.Map[uint64, []byte]                              // TODO(tip): this could be a keyset or index.
	// contains filtered or unexported fields
}

Keeper defines the governance module Keeper

func NewKeeper

func NewKeeper(
	cdc codec.Codec,
	storeService corestoretypes.KVStoreService,
	authKeeper types.AccountKeeper,
	bankKeeper types.BankKeeper,
	distrKeeper types.DistributionKeeper,
	router baseapp.MessageRouter,
	config types.Config,
	authority string,
	calculateVoteResultsAndVotingPowerFn CalculateVoteResultsAndVotingPowerFn,
) *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 added in v0.50.1

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

CancelProposal will cancel proposal before the voting period ends

func (Keeper) ChargeDeposit added in v0.50.1

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 added in v0.46.0

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) GetAuthority added in v0.47.0

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 added in v0.47.0

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

Hooks gets the hooks for governance.

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 added in v0.46.0

func (k Keeper) LegacyRouter() v1beta1.Router

LegacyRouter returns the gov keeper's legacy router

func (Keeper) Logger

func (k Keeper) Logger(ctx context.Context) log.Logger

Logger returns a module-specific logger.

func (Keeper) ModuleAccountAddress added in v0.50.1

func (k Keeper) ModuleAccountAddress() sdk.AccAddress

ModuleAccountAddress returns gov module account address

func (Keeper) RefundAndDeleteDeposits added in v0.46.0

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

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

func (Keeper) Router

func (k Keeper) Router() baseapp.MessageRouter

Router returns the gov keeper's router

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 added in v0.43.0

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

SetHooks sets the hooks for governance

func (*Keeper) SetLegacyRouter added in v0.47.0

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

SetLegacyRouter sets the legacy router for governance

func (Keeper) SetProposal

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

SetProposal sets a proposal to store.

func (Keeper) SubmitProposal

func (k Keeper) SubmitProposal(ctx context.Context, messages []sdk.Msg, metadata, title, summary string, proposer sdk.AccAddress, expedited bool) (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 added in v0.43.0

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

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

func NewMigrator added in v0.43.0

func NewMigrator(keeper *Keeper) Migrator

NewMigrator returns a new Migrator.

Jump to

Keyboard shortcuts

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