keeper

package
v1.19.0-rc2 Latest Latest
Warning

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

Go to latest
Published: Jun 25, 2024 License: Apache-2.0 Imports: 19 Imported by: 0

Documentation

Index

Constants

View Source
const (
	ParamNameImmediateSanctionMinDeposit   = "immediate_sanction_min_deposit"
	ParamNameImmediateUnsanctionMinDeposit = "immediate_unsanction_min_deposit"
)
View Source
const (
	// SanctionB is a byte representing a sanction (either temporary or permanent).
	SanctionB = 0x01
	// UnsanctionB is a byte representing an unsanction (probably temporary).
	UnsanctionB = 0x00
)

Variables

View Source
var (
	ParamsPrefix        = []byte{0x00}
	SanctionedPrefix    = []byte{0x01}
	TemporaryPrefix     = []byte{0x02}
	ProposalIndexPrefix = []byte{0x03}
)

Keys for store prefixes Items are stored with the following keys:

Params entry: - 0x00<name> -> <value> Sanctioned addresses: - 0x01<addr len (1 byte)><addr> -> 0x01 Temporarily sanctioned or unsanctioned addresses: - 0x02<addr len (1 byte)><addr><gov prop id (8 bytes)> -> 0x01 or 0x00 Proposal id temp sanction index: - 0x03<proposal id (8 bytes)><addr len (1 byte)><addr> -> 0x00 or 0x01

Functions

func ConcatBz

func ConcatBz(bz1, bz2 []byte) []byte

ConcatBz creates a single byte slice consisting of the two provided byte slices. Like append() but always returns a new slice with its own underlying array.

func CreateParamKey

func CreateParamKey(name string) []byte

CreateParamKey creates the key to use for a param with the given name.

- 0x00<name> -> <value>

func CreateProposalTempIndexKey

func CreateProposalTempIndexKey(govPropID uint64, addr sdk.AccAddress) []byte

CreateProposalTempIndexKey creates a key for a proposal id + addr temporary index entry.

0x03<proposal id (8 bytes)><addr len (1 byte)><addr>

func CreateProposalTempIndexPrefix

func CreateProposalTempIndexPrefix(govPropID *uint64) []byte

CreateProposalTempIndexPrefix creates a key prefix for a proposal temporary index key.

If a govPropID is provided: - 0x03<proposal id (8 bytes)> If a govPropID isn't provided: - 0x03

func CreateSanctionedAddrKey

func CreateSanctionedAddrKey(addr sdk.AccAddress) []byte

CreateSanctionedAddrKey creates the sanctioned address key for the provided address.

- 0x01<addr len (1 byte)><addr>

func CreateTemporaryAddrPrefix

func CreateTemporaryAddrPrefix(addr sdk.AccAddress) []byte

CreateTemporaryAddrPrefix creates a key prefix for a temporarily sanctioned/unsanctioned address.

If an address is provided: - 0x02<addr len(1 byte)><addr> If an address isn't provided: - 0x02

func CreateTemporaryKey

func CreateTemporaryKey(addr sdk.AccAddress, govPropID uint64) []byte

CreateTemporaryKey creates a key for a temporarily sanctioned/unsanctioned address associated with the given governance proposal id.

- 0x02<addr len (1 byte)><addr><gov prop id (8 bytes)>

func IsSanctionBz

func IsSanctionBz(bz []byte) bool

IsSanctionBz returns true if the provided byte slice indicates a temporary sanction.

func IsUnsanctionBz

func IsUnsanctionBz(bz []byte) bool

IsUnsanctionBz returns true if the provided byte slice indicates a temporary unsanction.

func NewTempEvent

func NewTempEvent(typeVal byte, addr sdk.AccAddress) proto.Message

NewTempEvent creates the temp event for the given type val (e.g. SanctionB or UnsanctionB) with the given address.

func ParseLengthPrefixedBz

func ParseLengthPrefixedBz(bz []byte) ([]byte, []byte)

ParseLengthPrefixedBz parses a length-prefixed byte slice into those bytes and any leftover bytes.

func ParseParamKey

func ParseParamKey(bz []byte) string

ParseParamKey extracts the param name from the provided key.

func ParseProposalTempIndexKey

func ParseProposalTempIndexKey(key []byte) (uint64, sdk.AccAddress)

ParseProposalTempIndexKey extracts the gov prop id and address from the provided proposal temp index key.

func ParseSanctionedAddrKey

func ParseSanctionedAddrKey(key []byte) sdk.AccAddress

ParseSanctionedAddrKey extracts the address from the provided sanctioned address key.

func ParseTemporaryKey

func ParseTemporaryKey(key []byte) (sdk.AccAddress, uint64)

ParseTemporaryKey extracts the address and gov prop id from the provided temporary key.

func ToTempStatus

func ToTempStatus(bz []byte) sanction.TempStatus

ToTempStatus converts a temporary entry value byte slice into a TempStatus value.

Types

type Keeper

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

func NewKeeper

func NewKeeper(
	cdc codec.BinaryCodec,
	storeKey storetypes.StoreKey,
	bankKeeper sanction.BankKeeper,
	govKeeper *govkeeper.Keeper,
	authority string,
	unsanctionableAddrs []sdk.AccAddress,
) Keeper

func (Keeper) AddTemporarySanction

func (k Keeper) AddTemporarySanction(ctx sdk.Context, govPropID uint64, addrs ...sdk.AccAddress) error

AddTemporarySanction adds a temporary sanction with the given gov prop id for each of the provided addresses.

func (Keeper) AddTemporaryUnsanction

func (k Keeper) AddTemporaryUnsanction(ctx sdk.Context, govPropID uint64, addrs ...sdk.AccAddress) error

AddTemporaryUnsanction adds a temporary unsanction with the given gov prop id for each of the provided addresses.

func (Keeper) AfterProposalDeposit

func (k Keeper) AfterProposalDeposit(ctx context.Context, proposalID uint64, _ sdk.AccAddress) error

AfterProposalDeposit is called after a deposit is made. If there's enough deposit, temporary entries are created.

func (Keeper) AfterProposalFailedMinDeposit

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

AfterProposalFailedMinDeposit is called when proposal fails to reach min deposit. Cleans up any possible temporary entries.

func (Keeper) AfterProposalSubmission

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

AfterProposalSubmission is called after proposal is submitted. If there's enough deposit, temporary entries are created.

func (Keeper) AfterProposalVote

func (k Keeper) AfterProposalVote(_ context.Context, _ uint64, _ sdk.AccAddress) error

AfterProposalVote is called after a vote on a proposal is cast. This one does nothing.

func (Keeper) AfterProposalVotingPeriodEnded

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

AfterProposalVotingPeriodEnded is called when proposal's finishes it's voting period. Cleans up temporary entries.

func (Keeper) DeleteAddrTempEntries

func (k Keeper) DeleteAddrTempEntries(ctx sdk.Context, addrs ...sdk.AccAddress)

DeleteAddrTempEntries deletes all temporary entries for each given address.

func (Keeper) DeleteGovPropTempEntries

func (k Keeper) DeleteGovPropTempEntries(ctx sdk.Context, govPropID uint64)

DeleteGovPropTempEntries deletes the temporary entries for the given proposal id.

func (Keeper) ExportGenesis

func (k Keeper) ExportGenesis(ctx sdk.Context) *sanction.GenesisState

ExportGenesis reads this keeper's entire state and returns it as a GenesisState.

func (Keeper) GetAllSanctionedAddresses

func (k Keeper) GetAllSanctionedAddresses(ctx sdk.Context) []string

GetAllSanctionedAddresses gets the bech32 string of every account that is sanctioned. This is designed for use with ExportGenesis. See also IterateSanctionedAddresses.

func (Keeper) GetAllTemporaryEntries

func (k Keeper) GetAllTemporaryEntries(ctx sdk.Context) []*sanction.TemporaryEntry

GetAllTemporaryEntries gets all the Temporary entries. This is designed for use with ExportGenesis. See also IterateTemporaryEntries.

func (Keeper) GetAuthority

func (k Keeper) GetAuthority() string

GetAuthority returns this module's authority string.

func (Keeper) GetImmediateSanctionMinDeposit

func (k Keeper) GetImmediateSanctionMinDeposit(ctx sdk.Context) sdk.Coins

GetImmediateSanctionMinDeposit gets the minimum deposit for a sanction to happen immediately.

func (Keeper) GetImmediateUnsanctionMinDeposit

func (k Keeper) GetImmediateUnsanctionMinDeposit(ctx sdk.Context) sdk.Coins

GetImmediateUnsanctionMinDeposit gets the minimum deposit for an unsanction to happen immediately.

func (Keeper) GetParams

func (k Keeper) GetParams(ctx sdk.Context) *sanction.Params

GetParams gets the sanction module's params. If there isn't anything set in state, the defaults are returned.

func (Keeper) InitGenesis

func (k Keeper) InitGenesis(origCtx sdk.Context, genState *sanction.GenesisState)

InitGenesis updates this keeper's store using the provided GenesisState.

func (Keeper) IsAddrThatCannotBeSanctioned

func (k Keeper) IsAddrThatCannotBeSanctioned(addr sdk.AccAddress) bool

IsAddrThatCannotBeSanctioned returns true if the provided address is one of the ones that cannot be sanctioned. Returns false if the addr can be sanctioned.

func (Keeper) IsSanctionedAddr

func (k Keeper) IsSanctionedAddr(goCtx context.Context, addr sdk.AccAddress) bool

IsSanctionedAddr returns true if the provided address is currently sanctioned (either permanently or temporarily).

func (Keeper) IterateParams

func (k Keeper) IterateParams(ctx sdk.Context, cb func(name, value string) (stop bool))

IterateParams iterates over all params entries. The callback takes in the name and value, and should return whether to stop iteration (true = stop, false = keep going).

func (Keeper) IterateProposalIndexEntries

func (k Keeper) IterateProposalIndexEntries(ctx sdk.Context, govPropID *uint64, cb func(govPropID uint64, addr sdk.AccAddress) (stop bool))

IterateProposalIndexEntries iterates over all of the index entries for temp entries. The callback takes in the gov prop id and address. The callback should return whether to stop iteration (true = stop, false = keep going).

func (Keeper) IterateSanctionedAddresses

func (k Keeper) IterateSanctionedAddresses(ctx sdk.Context, cb func(addr sdk.AccAddress) (stop bool))

IterateSanctionedAddresses iterates over all of the permanently sanctioned addresses. The callback takes in the sanctioned address and should return whether to stop iteration (true = stop, false = keep going).

func (Keeper) IterateTemporaryEntries

func (k Keeper) IterateTemporaryEntries(ctx sdk.Context, addr sdk.AccAddress, cb func(addr sdk.AccAddress, govPropID uint64, isSanction bool) (stop bool))

IterateTemporaryEntries iterates over each of the temporary entries. If an address is provided, only the temporary entries for that address are iterated, otherwise all entries are iterated. The callback takes in the address in question, the governance proposal associated with it, and whether it's a sanction (true) or unsanction (false). The callback should return whether to stop iteration (true = stop, false = keep going).

func (Keeper) Sanction

func (Keeper) SanctionAddresses

func (k Keeper) SanctionAddresses(ctx sdk.Context, addrs ...sdk.AccAddress) error

SanctionAddresses creates permanent sanctioned address entries for each of the provided addresses. Also deletes any temporary entries for each address.

func (Keeper) SendRestrictionFn

func (k Keeper) SendRestrictionFn(ctx context.Context, fromAddr, toAddr sdk.AccAddress, _ sdk.Coins) (sdk.AccAddress, error)

func (Keeper) SetParams

func (k Keeper) SetParams(ctx sdk.Context, params *sanction.Params) error

SetParams sets the sanction module's params. Providing a nil params will cause all params to be deleted (so that defaults are used).

func (Keeper) Unsanction

func (Keeper) UnsanctionAddresses

func (k Keeper) UnsanctionAddresses(ctx sdk.Context, addrs ...sdk.AccAddress) error

UnsanctionAddresses deletes any sanctioned address entries for each provided address. Also deletes any temporary entries for each address.

func (Keeper) UpdateParams

type WrappedGovKeeper

type WrappedGovKeeper struct {
	Keeper *govkeeper.Keeper
}

A WrappedGovKeeper implements the sanction.GovKeeper interface, allowing for mocking of some of the stuff that the gov keeper keeps in fields now.

func WrapGovKeeper

func WrapGovKeeper(keeper *govkeeper.Keeper) *WrappedGovKeeper

WrapGovKeeper creates a new WrappedGovKeeper around the provided keeper.

func (WrappedGovKeeper) GetProposal

func (w WrappedGovKeeper) GetProposal(ctx context.Context, propID uint64) *govv1.Proposal

Jump to

Keyboard shortcuts

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