keeper

package
v1.0.0 Latest Latest
Warning

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

Go to latest
Published: Jan 6, 2023 License: Apache-2.0 Imports: 30 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

View Source
var (
	// Addrs store generated addresses for test
	Addrs = createTestAddrs(500)

	DefaultMSD = sdk.NewDecWithPrec(1, 3)
)

Functions

func CreateValidators

func CreateValidators(
	t *testing.T, stakingHandler sdk.Handler, ctx sdk.Context, addrs []sdk.ValAddress, powerAmt []int64,
)

CreateValidators creates validators according to arguments

func MakeTestCodec

func MakeTestCodec() *codec.Codec

MakeTestCodec creates a codec used only for testing

func NewQuerier

func NewQuerier(keeper Keeper) sdk.Querier

NewQuerier returns all query handlers

func Tally

func Tally(ctx sdk.Context, keeper Keeper, proposal types.Proposal, isExpireVoteEndTime bool,
) (types.ProposalStatus, bool, types.TallyResult)

Tally counts the votes for proposal

Types

type BankKeeper

type BankKeeper interface {
	GetCoins(ctx sdk.Context, addr sdk.AccAddress) sdk.Coins

	// TODO remove once governance doesn't require use of accounts
	SendCoins(ctx sdk.Context, fromAddr sdk.AccAddress, toAddr sdk.AccAddress, amt sdk.Coins) sdk.Error
	SetSendEnabled(ctx sdk.Context, enabled bool)
	SubtractCoins(ctx sdk.Context, addr sdk.AccAddress, amt sdk.Coins) (sdk.Coins, sdk.Error)
}

BankKeeper defines expected bank keeper

type Keeper

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

Keeper defines governance keeper

func CreateTestInput

func CreateTestInput(
	t *testing.T, isCheckTx bool, initBalance int64,
) (sdk.Context, auth.AccountKeeper, Keeper, staking.Keeper, crisis.Keeper)

CreateTestInput returns keepers for test

func NewKeeper

func NewKeeper(
	cdc *codec.Codec, key sdk.StoreKey, paramsKeeper params.Keeper, paramSpace params.Subspace,
	supplyKeeper SupplyKeeper, sk StakingKeeper, codespace string, rtr Router,
	ck BankKeeper, phr ProposalHandlerRouter, feeCollectorName 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.

func (Keeper) ActiveProposalQueueIterator

func (keeper Keeper) ActiveProposalQueueIterator(ctx sdk.Context, endTime time.Time) sdk.Iterator

ActiveProposalQueueIterator returns an sdk.Iterator for all the proposals in the Active Queue that expire by endTime

func (Keeper) AddDeposit

func (keeper Keeper) AddDeposit(
	ctx sdk.Context, proposalID uint64, depositorAddr sdk.AccAddress,
	depositAmount sdk.SysCoins, eventType string,
) sdk.Error

AddDeposit adds or updates a deposit of a specific depositor on a specific proposal Activates voting period when appropriate

func (Keeper) AddVote

func (keeper Keeper) AddVote(
	ctx sdk.Context, proposalID uint64, voterAddr sdk.AccAddress, option types.VoteOption,
) (sdk.Error, string)

AddVote adds a vote on a specific proposal

func (Keeper) AfterDepositPeriodPassed

func (keeper Keeper) AfterDepositPeriodPassed(ctx sdk.Context, proposal types.Proposal)

nolint

func (Keeper) AfterSubmitProposalHandler

func (keeper Keeper) AfterSubmitProposalHandler(ctx sdk.Context, proposal types.Proposal)

nolint

func (Keeper) BankKeeper

func (keeper Keeper) BankKeeper() BankKeeper

BankKeeper returns bank keeper in gov keeper

func (Keeper) Cdc

func (keeper Keeper) Cdc() *codec.Codec

func (Keeper) CheckMsgSubmitProposal

func (keeper Keeper) CheckMsgSubmitProposal(ctx sdk.Context, msg types.MsgSubmitProposal) sdk.Error

nolint

func (Keeper) DeleteDeposits

func (keeper Keeper) DeleteDeposits(ctx sdk.Context, proposalID uint64)

DeleteDeposits deletes all the deposits on a specific proposal without refunding them

func (Keeper) DeleteProposal

func (keeper Keeper) DeleteProposal(ctx sdk.Context, proposalID uint64)

DeleteProposal deletes a proposal from store

func (Keeper) DeleteVotes

func (keeper Keeper) DeleteVotes(ctx sdk.Context, proposalID uint64)

DeleteVotes deletes the votes of a specific proposal

func (Keeper) DistributeDeposits

func (keeper Keeper) DistributeDeposits(ctx sdk.Context, proposalID uint64)

DistributeDeposits distributes and deletes all the deposits on a specific proposal

func (Keeper) GetAllDeposits

func (keeper Keeper) GetAllDeposits(ctx sdk.Context) (deposits types.Deposits)

GetAllDeposits returns all the deposits from the store

func (Keeper) GetAllVotes

func (keeper Keeper) GetAllVotes(ctx sdk.Context) (votes types.Votes)

GetAllVotes returns all the votes from the store

func (Keeper) GetDeposit

func (keeper Keeper) GetDeposit(ctx sdk.Context, proposalID uint64, depositorAddr sdk.AccAddress) (deposit types.Deposit, found bool)

GetDeposit gets the deposit of a specific depositor on a specific proposal

func (Keeper) GetDepositParams

func (keeper Keeper) GetDepositParams(ctx sdk.Context) types.DepositParams

GetDepositParams returns the current DepositParams from the global param store

func (Keeper) GetDeposits

func (keeper Keeper) GetDeposits(ctx sdk.Context, proposalID uint64) (deposits types.Deposits)

GetDeposits returns all the deposits from a proposal

func (Keeper) GetDepositsIterator

func (keeper Keeper) GetDepositsIterator(ctx sdk.Context, proposalID uint64) sdk.Iterator

GetDepositsIterator gets all the deposits on a specific proposal as an sdk.Iterator

func (Keeper) GetGovernanceAccount

func (keeper Keeper) GetGovernanceAccount(ctx sdk.Context) supplyexported.ModuleAccountI

GetGovernanceAccount returns the governance ModuleAccount

func (Keeper) GetMaxDepositPeriod

func (keeper Keeper) GetMaxDepositPeriod(ctx sdk.Context, content types.Content) time.Duration

nolint

func (Keeper) GetMinDeposit

func (keeper Keeper) GetMinDeposit(ctx sdk.Context, content types.Content) sdk.SysCoins

GetMinDeposit implement ProposalHandler nolint

func (Keeper) GetProposal

func (keeper Keeper) GetProposal(ctx sdk.Context, proposalID uint64) (proposal types.Proposal, ok bool)

GetProposal get Proposal from store by ProposalID

func (Keeper) GetProposalID

func (keeper Keeper) GetProposalID(ctx sdk.Context) (proposalID uint64, err sdk.Error)

GetProposalID gets the highest proposal ID

func (Keeper) GetProposals

func (keeper Keeper) GetProposals(ctx sdk.Context) (proposals types.Proposals)

GetProposals returns all the proposals from store

func (Keeper) GetProposalsFiltered

func (keeper Keeper) GetProposalsFiltered(
	ctx sdk.Context, voterAddr sdk.AccAddress, depositorAddr sdk.AccAddress, status types.ProposalStatus,
	numLatest uint64,
) []types.Proposal

GetProposalsFiltered get Proposals from store by ProposalID voterAddr will filter proposals by whether or not that address has voted on them depositorAddr will filter proposals by whether or not that address has deposited to them status will filter proposals by status numLatest will fetch a specified number of the most recent proposals, or 0 for all proposals

func (Keeper) GetTallyParams

func (keeper Keeper) GetTallyParams(ctx sdk.Context) types.TallyParams

GetTallyParams returns the current TallyParams from the global param store

func (Keeper) GetVote

func (keeper Keeper) GetVote(ctx sdk.Context, proposalID uint64, voterAddr sdk.AccAddress) (vote types.Vote, found bool)

GetVote gets the vote from an address on a specific proposal

func (Keeper) GetVotes

func (keeper Keeper) GetVotes(ctx sdk.Context, proposalID uint64) (votes types.Votes)

GetVotes returns all the votes from a proposal

func (Keeper) GetVotesIterator

func (keeper Keeper) GetVotesIterator(ctx sdk.Context, proposalID uint64) sdk.Iterator

GetVotesIterator gets all the votes on a specific proposal as an sdk.Iterator

func (Keeper) GetVotingParams

func (keeper Keeper) GetVotingParams(ctx sdk.Context) types.VotingParams

GetVotingParams returns the current VotingParams from the global param store

func (Keeper) GetVotingPeriod

func (keeper Keeper) GetVotingPeriod(ctx sdk.Context, content types.Content) time.Duration

nolint

func (Keeper) InactiveProposalQueueIterator

func (keeper Keeper) InactiveProposalQueueIterator(ctx sdk.Context, endTime time.Time) sdk.Iterator

InactiveProposalQueueIterator returns an sdk.Iterator for all the proposals in the Inactive Queue that expire by endTime

func (Keeper) InsertActiveProposalQueue

func (keeper Keeper) InsertActiveProposalQueue(ctx sdk.Context, proposalID uint64, endTime time.Time)

InsertActiveProposalQueue inserts a ProposalID into the active proposal queue at endTime

func (Keeper) InsertInactiveProposalQueue

func (keeper Keeper) InsertInactiveProposalQueue(ctx sdk.Context, proposalID uint64, endTime time.Time)

InsertInactiveProposalQueue Inserts a ProposalID into the inactive proposal queue at endTime

func (Keeper) InsertWaitingProposalQueue

func (keeper Keeper) InsertWaitingProposalQueue(ctx sdk.Context, blockHeight, proposalID uint64)

InsertWaitingProposalQueue inserts a ProposalID into the waiting proposal queue at endTime

func (Keeper) IterateActiveProposalsQueue

func (keeper Keeper) IterateActiveProposalsQueue(
	ctx sdk.Context, endTime time.Time, cb func(proposal types.Proposal,
	) (stop bool))

IterateActiveProposalsQueue iterates over the proposals in the active proposal queue and performs a callback function

func (Keeper) IterateAllDeposits

func (keeper Keeper) IterateAllDeposits(ctx sdk.Context, cb func(deposit types.Deposit) (stop bool))

IterateAllDeposits iterates over the all the stored deposits and performs a callback function

func (Keeper) IterateAllVotes

func (keeper Keeper) IterateAllVotes(ctx sdk.Context, cb func(vote types.Vote) (stop bool))

IterateAllVotes iterates over the all the stored votes and performs a callback function

func (Keeper) IterateAllWaitingProposals

func (keeper Keeper) IterateAllWaitingProposals(ctx sdk.Context,
	cb func(proposal types.Proposal, proposalID, height uint64) (stop bool))

IterateAllWaitingProposals iterates over the all proposals in the waiting proposal queue and performs a callback function

func (Keeper) IterateDeposits

func (keeper Keeper) IterateDeposits(ctx sdk.Context, proposalID uint64, cb func(deposit types.Deposit) (stop bool))

IterateDeposits iterates over the all the proposals deposits and performs a callback function

func (Keeper) IterateInactiveProposalsQueue

func (keeper Keeper) IterateInactiveProposalsQueue(
	ctx sdk.Context, endTime time.Time, cb func(proposal types.Proposal,
	) (stop bool))

IterateInactiveProposalsQueue iterates over the proposals in the inactive proposal queue and performs a callback function

func (Keeper) IterateProposals

func (keeper Keeper) IterateProposals(ctx sdk.Context, cb func(proposal types.Proposal) (stop bool))

IterateProposals iterates over the all the proposals and performs a callback function

func (Keeper) IterateVotes

func (keeper Keeper) IterateVotes(ctx sdk.Context, proposalID uint64, cb func(vote types.Vote) (stop bool))

IterateVotes iterates over the all the proposals votes and performs a callback function

func (Keeper) IterateWaitingProposalsQueue

func (keeper Keeper) IterateWaitingProposalsQueue(
	ctx sdk.Context, height uint64, cb func(proposal types.Proposal,
	) (stop bool))

IterateWaitingProposalsQueue iterates over the proposals in the waiting proposal queue and performs a callback function

func (Keeper) Logger

func (keeper Keeper) Logger(ctx sdk.Context) log.Logger

Logger returns a module-specific logger.

func (Keeper) ProposalHandlerRouter

func (keeper Keeper) ProposalHandlerRouter() ProposalHandlerRouter

ProposalHandlerRouter returns proposal handler router in gov keeper

func (Keeper) RefundDeposits

func (keeper Keeper) RefundDeposits(ctx sdk.Context, proposalID uint64)

RefundDeposits refunds and deletes all the deposits on a specific proposal

func (Keeper) RejectedHandler

func (keeper Keeper) RejectedHandler(ctx sdk.Context, content types.Content)

nolint

func (Keeper) RemoveFromActiveProposalQueue

func (keeper Keeper) RemoveFromActiveProposalQueue(ctx sdk.Context, proposalID uint64, endTime time.Time)

RemoveFromActiveProposalQueue removes a proposalID from the Active Proposal Queue

func (Keeper) RemoveFromInactiveProposalQueue

func (keeper Keeper) RemoveFromInactiveProposalQueue(ctx sdk.Context, proposalID uint64, endTime time.Time)

RemoveFromInactiveProposalQueue removes a proposalID from the Inactive Proposal Queue

func (Keeper) RemoveFromWaitingProposalQueue

func (keeper Keeper) RemoveFromWaitingProposalQueue(ctx sdk.Context, blockHeight, proposalID uint64)

RemoveFromWaitingProposalQueue removes a proposalID from the waiting Proposal Queue

func (Keeper) Router

func (keeper Keeper) Router() Router

func (Keeper) SetDeposit

func (keeper Keeper) SetDeposit(ctx sdk.Context, deposit types.Deposit)

SetDeposit sets the deposit of a specific depositor on a specific proposal

func (Keeper) SetDepositParams

func (keeper Keeper) SetDepositParams(ctx sdk.Context, depositParams types.DepositParams)

SetDepositParams sets the current DepositParams to the global param store

func (Keeper) SetProposal

func (keeper Keeper) SetProposal(ctx sdk.Context, proposal types.Proposal)

SetProposal set a proposal to store

func (Keeper) SetProposalID

func (keeper Keeper) SetProposalID(ctx sdk.Context, proposalID uint64)

SetProposalID sets the proposal ID to gov store

func (Keeper) SetTallyParams

func (keeper Keeper) SetTallyParams(ctx sdk.Context, tallyParams types.TallyParams)

SetTallyParams sets the current TallyParams to the global param store

func (Keeper) SetVote

func (keeper Keeper) SetVote(ctx sdk.Context, proposalID uint64, vote types.Vote)

SetVote stores the vote of a specific voter on a specific proposal

func (Keeper) SetVotingParams

func (keeper Keeper) SetVotingParams(ctx sdk.Context, votingParams types.VotingParams)

SetVotingParams sets the current VotingParams to the global param store

func (Keeper) SubmitProposal

func (keeper Keeper) SubmitProposal(ctx sdk.Context, content types.Content) (types.Proposal, sdk.Error)

SubmitProposal creates new proposal given a content

func (Keeper) SupplyKeeper

func (keeper Keeper) SupplyKeeper() SupplyKeeper

func (Keeper) VoteHandler

func (keeper Keeper) VoteHandler(ctx sdk.Context, proposal types.Proposal, vote types.Vote) (string, sdk.Error)

nolint

func (Keeper) WaitingProposalQueueIterator

func (keeper Keeper) WaitingProposalQueueIterator(ctx sdk.Context, blockHeight uint64) sdk.Iterator

WaitingProposalQueueIterator returns an iterator for all the proposals in the Waiting Queue that expire by endTime

type ProposalHandler

type ProposalHandler interface {
	GetMinDeposit(ctx sdk.Context, content types.Content) sdk.SysCoins
	GetMaxDepositPeriod(ctx sdk.Context, content types.Content) time.Duration
	GetVotingPeriod(ctx sdk.Context, content types.Content) time.Duration
	CheckMsgSubmitProposal(ctx sdk.Context, msg types.MsgSubmitProposal) sdk.Error
	AfterSubmitProposalHandler(ctx sdk.Context, proposal types.Proposal)
	VoteHandler(ctx sdk.Context, proposal types.Proposal, vote types.Vote) (string, sdk.Error)
	AfterDepositPeriodPassed(ctx sdk.Context, proposal types.Proposal)
	RejectedHandler(ctx sdk.Context, content types.Content)
}

ProposalHandler defines the interface handler in different periods of proposal

type ProposalHandlerRouter

type ProposalHandlerRouter interface {
	AddRoute(r string, mp ProposalHandler) (mpr ProposalHandlerRouter)
	HasRoute(r string) bool
	GetRoute(path string) (h ProposalHandler)
	Seal()
}

ProposalHandlerRouter defines the interface of managing the proposal handler of proposal

func NewProposalHandlerRouter

func NewProposalHandlerRouter() ProposalHandlerRouter

nolint

type Router

type Router interface {
	AddRoute(r string, h types.Handler) (rtr Router)
	HasRoute(r string) bool
	GetRoute(path string) (h types.Handler)
	Seal()
}

Router implements a governance Handler router.

TODO: Use generic router (ref #3976).

func NewRouter

func NewRouter() Router

type StakingKeeper

type StakingKeeper interface {
	// iterate through bonded validators by operator address, execute func for each validator
	// gov use it for getting votes of validator
	IterateBondedValidatorsByPower(sdk.Context,
		func(index int64, validator stakingexported.ValidatorI) (stop bool))

	// gov use it for getting votes of delegator which has been voted to validator
	Delegator(ctx sdk.Context, delAddr sdk.AccAddress) stakingexported.DelegatorI
}

StakingKeeper defines expected staking keeper (Validator and Delegator sets)

type SupplyKeeper

type SupplyKeeper interface {
	GetModuleAddress(name string) sdk.AccAddress
	GetModuleAccount(ctx sdk.Context, name string) supplyexported.ModuleAccountI

	// TODO remove with genesis 2-phases refactor https://github.com/cosmos/cosmos-sdk/issues/2862
	SetModuleAccount(sdk.Context, supplyexported.ModuleAccountI)

	SendCoinsFromModuleToAccount(ctx sdk.Context, senderModule string, recipientAddr sdk.AccAddress, amt sdk.Coins) sdk.Error
	SendCoinsFromAccountToModule(ctx sdk.Context, senderAddr sdk.AccAddress, recipientModule string, amt sdk.Coins) sdk.Error
	SendCoinsFromModuleToModule(ctx sdk.Context, senderModule, recipientModule string, amt sdk.Coins) sdk.Error
	BurnCoins(ctx sdk.Context, name string, amt sdk.Coins) sdk.Error
}

SupplyKeeper defines the supply Keeper for module accounts

Jump to

Keyboard shortcuts

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