keeper

package
v0.2.0-rc.1 Latest Latest
Warning

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

Go to latest
Published: Dec 18, 2024 License: Apache-2.0 Imports: 19 Imported by: 10

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func AllInvariants

func AllInvariants(k Keeper) sdk.Invariant

AllInvariants runs all invariants of the X/bank module.

func NewMsgServerImpl

func NewMsgServerImpl(keeper Keeper) types.MsgServer

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

func NonnegativeBalanceInvariant

func NonnegativeBalanceInvariant(k ViewKeeper) sdk.Invariant

NonnegativeBalanceInvariant checks that all accounts in the application have non-negative balances

func RegisterInvariants

func RegisterInvariants(ir sdk.InvariantRegistry, k Keeper)

RegisterInvariants registers the bank module invariants

func TotalSupply

func TotalSupply(k Keeper) sdk.Invariant

TotalSupply checks that the total supply reflects all the coins held in accounts

Types

type BalancesIndexes

type BalancesIndexes struct {
	Denom *indexes.ReversePair[sdk.AccAddress, string, math.Int]
}

func (BalancesIndexes) IndexesList

type BaseKeeper

type BaseKeeper struct {
	appmodule.Environment
	BaseSendKeeper
	// contains filtered or unexported fields
}

BaseKeeper manages transfers between accounts. It implements the Keeper interface.

func NewBaseKeeper

func NewBaseKeeper(
	env appmodule.Environment,
	cdc codec.BinaryCodec,
	ak types.AccountKeeper,
	blockedAddrs map[string]bool,
	authority string,
) BaseKeeper

NewBaseKeeper returns a new BaseKeeper object with a given codec, dedicated store key, an AccountKeeper implementation, and a parameter Subspace used to store and fetch module parameters. The BaseKeeper also accepts a blocklist map. This blocklist describes the set of addresses that are not allowed to receive funds through direct and explicit actions, for example, by using a MsgSend or by using a SendCoinsFromModuleToAccount execution.

func (BaseKeeper) AllBalances

AllBalances implements the Query/AllBalances gRPC method

func (BaseKeeper) Balance

Balance implements the Query/Balance gRPC method

func (BaseKeeper) BurnCoins

func (k BaseKeeper) BurnCoins(ctx context.Context, address []byte, amounts sdk.Coins) error

BurnCoins burns coins deletes coins from the balance of an account. An error is returned if the module account does not exist or is unauthorized.

func (BaseKeeper) DelegateCoins

func (k BaseKeeper) DelegateCoins(ctx context.Context, delegatorAddr, moduleAccAddr sdk.AccAddress, amt sdk.Coins) error

DelegateCoins performs delegation by deducting amt coins from an account with address addr. For vesting accounts, delegations amounts are tracked for both vesting and vested coins. The coins are then transferred from the delegator address to a ModuleAccount address. If any of the delegation amounts are negative, an error is returned.

func (BaseKeeper) DelegateCoinsFromAccountToModule

func (k BaseKeeper) DelegateCoinsFromAccountToModule(
	ctx context.Context, senderAddr sdk.AccAddress, recipientModule string, amt sdk.Coins,
) error

DelegateCoinsFromAccountToModule delegates coins and transfers them from a delegator account to a module account. An error is returned if the module account does not exist or is unauthorized.

func (BaseKeeper) DenomMetadata

DenomMetadata implements Query/DenomMetadata gRPC method.

func (BaseKeeper) DenomMetadataByQueryString

DenomMetadataByQueryString is identical to DenomMetadata query, but receives request via query string.

func (BaseKeeper) DenomMetadataV2

DenomMetadataV2 is identical to DenomMetadata but receives protoreflect types instead of gogo types. It exists to resolve a cyclic dependency existent between x/auth and x/bank, so that x/auth may call this keeper without depending on x/bank.

func (BaseKeeper) DenomOwners

DenomOwners returns all the account address that own a requested token denom.

func (BaseKeeper) DenomOwnersByQuery

DenomOwnersByQuery is identical to DenomOwner query, but receives denom values via query string.

func (BaseKeeper) DenomsMetadata

DenomsMetadata implements Query/DenomsMetadata gRPC method.

func (BaseKeeper) ExportGenesis

func (k BaseKeeper) ExportGenesis(ctx context.Context) (*types.GenesisState, error)

ExportGenesis returns the bank module's genesis state.

func (BaseKeeper) GetAllDenomMetaData

func (k BaseKeeper) GetAllDenomMetaData(ctx context.Context) []types.Metadata

GetAllDenomMetaData retrieves all denominations metadata

func (BaseKeeper) GetDenomMetaData

func (k BaseKeeper) GetDenomMetaData(ctx context.Context, denom string) (types.Metadata, bool)

GetDenomMetaData retrieves the denomination metadata. returns the metadata and true if the denom exists, false otherwise.

func (BaseKeeper) GetPaginatedTotalSupply

func (k BaseKeeper) GetPaginatedTotalSupply(ctx context.Context, pagination *query.PageRequest) (sdk.Coins, *query.PageResponse, error)

GetPaginatedTotalSupply queries for the supply, ignoring 0 coins, with a given pagination

func (BaseKeeper) GetSupply

func (k BaseKeeper) GetSupply(ctx context.Context, denom string) sdk.Coin

GetSupply retrieves the Supply from store

func (BaseKeeper) HasDenomMetaData

func (k BaseKeeper) HasDenomMetaData(ctx context.Context, denom string) bool

HasDenomMetaData checks if the denomination metadata exists in store.

func (BaseKeeper) HasSupply

func (k BaseKeeper) HasSupply(ctx context.Context, denom string) bool

HasSupply checks if the supply coin exists in store.

func (BaseKeeper) InitGenesis

func (k BaseKeeper) InitGenesis(ctx context.Context, genState *types.GenesisState) error

InitGenesis initializes the bank module's state from a given genesis state.

func (BaseKeeper) IterateAllDenomMetaData

func (k BaseKeeper) IterateAllDenomMetaData(ctx context.Context, cb func(types.Metadata) bool)

IterateAllDenomMetaData iterates over all the denominations metadata and provides the metadata to a callback. If true is returned from the callback, iteration is halted.

func (BaseKeeper) MintCoins

func (k BaseKeeper) MintCoins(ctx context.Context, moduleName string, amounts sdk.Coins) error

MintCoins creates new coins from thin air and adds it to the module account. An error is returned if the module account does not exist or is unauthorized.

func (BaseKeeper) Params

Params implements the gRPC service handler for querying x/bank parameters.

func (BaseKeeper) SendCoinsFromAccountToModule

func (k BaseKeeper) SendCoinsFromAccountToModule(
	ctx context.Context, senderAddr sdk.AccAddress, recipientModule string, amt sdk.Coins,
) error

SendCoinsFromAccountToModule transfers coins from an AccAddress to a ModuleAccount. An error is returned if the module account does not exist.

func (BaseKeeper) SendCoinsFromModuleToAccount

func (k BaseKeeper) SendCoinsFromModuleToAccount(
	ctx context.Context, senderModule string, recipientAddr sdk.AccAddress, amt sdk.Coins,
) error

SendCoinsFromModuleToAccount transfers coins from a ModuleAccount to an AccAddress. An error is returned if the module account does not exist or if the recipient address is black-listed or if sending the tokens fails.

func (BaseKeeper) SendCoinsFromModuleToModule

func (k BaseKeeper) SendCoinsFromModuleToModule(
	ctx context.Context, senderModule, recipientModule string, amt sdk.Coins,
) error

SendCoinsFromModuleToModule transfers coins from a ModuleAccount to another. An error is returned if either module accounts does not exist.

func (BaseKeeper) SetDenomMetaData

func (k BaseKeeper) SetDenomMetaData(ctx context.Context, denomMetaData types.Metadata)

SetDenomMetaData sets the denominations metadata

func (BaseKeeper) SpendableBalanceByDenom

SpendableBalanceByDenom implements a gRPC query handler for retrieving an account's spendable balance for a specific denom.

func (BaseKeeper) SpendableBalances

SpendableBalances implements a gRPC query handler for retrieving an account's spendable balances.

func (BaseKeeper) SupplyOf

SupplyOf implements the Query/SupplyOf gRPC method

func (BaseKeeper) TotalSupply

TotalSupply implements the Query/TotalSupply gRPC method

func (BaseKeeper) UndelegateCoins

func (k BaseKeeper) UndelegateCoins(ctx context.Context, moduleAccAddr, delegatorAddr sdk.AccAddress, amt sdk.Coins) error

UndelegateCoins performs undelegation by crediting amt coins to an account with address addr. For vesting accounts, undelegation amounts are tracked for both vesting and vested coins. The coins are then transferred from a ModuleAccount address to the delegator address. If any of the undelegation amounts are negative, an error is returned.

func (BaseKeeper) UndelegateCoinsFromModuleToAccount

func (k BaseKeeper) UndelegateCoinsFromModuleToAccount(
	ctx context.Context, senderModule string, recipientAddr sdk.AccAddress, amt sdk.Coins,
) error

UndelegateCoinsFromModuleToAccount undelegates the unbonding coins and transfers them from a module account to the delegator account. An error is returned if the module account does not exist or is unauthorized.

func (BaseKeeper) WithMintCoinsRestriction

func (k BaseKeeper) WithMintCoinsRestriction(check types.MintingRestrictionFn) BaseKeeper

WithMintCoinsRestriction restricts the bank Keeper used within a specific module to have restricted permissions on minting via function passed in parameter. Previous restriction functions can be nested as such:

bankKeeper.WithMintCoinsRestriction(restriction1).WithMintCoinsRestriction(restriction2)

type BaseSendKeeper

type BaseSendKeeper struct {
	appmodule.Environment
	BaseViewKeeper
	// contains filtered or unexported fields
}

BaseSendKeeper only allows transfers between accounts without the possibility of creating coins. It implements the SendKeeper interface.

func NewBaseSendKeeper

func NewBaseSendKeeper(
	env appmodule.Environment,
	cdc codec.BinaryCodec,
	ak types.AccountKeeper,
	blockedAddrs map[string]bool,
	authority string,
) BaseSendKeeper

func (BaseSendKeeper) AppendSendRestriction

func (k BaseSendKeeper) AppendSendRestriction(restriction types.SendRestrictionFn)

AppendSendRestriction adds the provided SendRestrictionFn to run after previously provided restrictions.

func (BaseSendKeeper) BlockedAddr

func (k BaseSendKeeper) BlockedAddr(addr sdk.AccAddress) bool

BlockedAddr checks if a given address is restricted from receiving funds.

func (BaseSendKeeper) ClearSendRestriction

func (k BaseSendKeeper) ClearSendRestriction()

ClearSendRestriction removes the send restriction (if there is one).

func (BaseSendKeeper) DeleteSendEnabled

func (k BaseSendKeeper) DeleteSendEnabled(ctx context.Context, denoms ...string)

DeleteSendEnabled deletes the SendEnabled flags for one or more denoms. If a denom is provided that doesn't have a SendEnabled entry, it is ignored.

func (BaseSendKeeper) GetAllSendEnabledEntries

func (k BaseSendKeeper) GetAllSendEnabledEntries(ctx context.Context) []types.SendEnabled

GetAllSendEnabledEntries gets all the SendEnabled entries that are stored. Any denominations not returned use the default value (set in Params).

func (BaseSendKeeper) GetAuthority

func (k BaseSendKeeper) GetAuthority() string

GetAuthority returns the x/bank module's authority.

func (BaseSendKeeper) GetBlockedAddresses

func (k BaseSendKeeper) GetBlockedAddresses() map[string]bool

GetBlockedAddresses returns the full list of addresses restricted from receiving funds.

func (BaseSendKeeper) GetParams

func (k BaseSendKeeper) GetParams(ctx context.Context) (params types.Params)

GetParams returns the total set of bank parameters.

func (BaseSendKeeper) GetSendEnabledEntry

func (k BaseSendKeeper) GetSendEnabledEntry(ctx context.Context, denom string) (types.SendEnabled, bool)

GetSendEnabledEntry gets a SendEnabled entry for the given denom. The second return argument is true iff a specific entry exists for the given denom.

func (BaseSendKeeper) InputOutputCoins

func (k BaseSendKeeper) InputOutputCoins(ctx context.Context, input types.Input, outputs []types.Output) error

InputOutputCoins performs multi-send functionality. It accepts an input that corresponds to a series of outputs. It returns an error if the input and outputs don't line up or if any single transfer of tokens fails.

func (BaseSendKeeper) IsSendEnabledCoin

func (k BaseSendKeeper) IsSendEnabledCoin(ctx context.Context, coin sdk.Coin) bool

IsSendEnabledCoin returns the current SendEnabled status of the provided coin's denom

func (BaseSendKeeper) IsSendEnabledCoins

func (k BaseSendKeeper) IsSendEnabledCoins(ctx context.Context, coins ...sdk.Coin) error

IsSendEnabledCoins checks the coins provided and returns an ErrSendDisabled if any of the coins are not configured for sending. Returns nil if sending is enabled for all provided coins.

func (BaseSendKeeper) IsSendEnabledDenom

func (k BaseSendKeeper) IsSendEnabledDenom(ctx context.Context, denom string) bool

IsSendEnabledDenom returns the current SendEnabled status of the provided denom.

func (BaseSendKeeper) IterateSendEnabledEntries

func (k BaseSendKeeper) IterateSendEnabledEntries(ctx context.Context, cb func(denom string, sendEnabled bool) bool)

IterateSendEnabledEntries iterates over all the SendEnabled entries.

func (BaseSendKeeper) PrependSendRestriction

func (k BaseSendKeeper) PrependSendRestriction(restriction types.SendRestrictionFn)

PrependSendRestriction adds the provided SendRestrictionFn to run before previously provided restrictions.

func (BaseSendKeeper) SendCoins

func (k BaseSendKeeper) SendCoins(ctx context.Context, fromAddr, toAddr sdk.AccAddress, amt sdk.Coins) error

SendCoins transfers amt coins from a sending account to a receiving account. An error is returned upon failure.

func (BaseSendKeeper) SetAllSendEnabled

func (k BaseSendKeeper) SetAllSendEnabled(ctx context.Context, entries []*types.SendEnabled)

SetAllSendEnabled sets all the provided SendEnabled entries in the bank store.

func (BaseSendKeeper) SetParams

func (k BaseSendKeeper) SetParams(ctx context.Context, params types.Params) error

SetParams sets the total set of bank parameters.

Note: params.SendEnabled is deprecated but it should be here regardless.

func (BaseSendKeeper) SetSendEnabled

func (k BaseSendKeeper) SetSendEnabled(ctx context.Context, denom string, value bool)

SetSendEnabled sets the SendEnabled flag for a denom to the provided value.

type BaseViewKeeper

type BaseViewKeeper struct {
	appmodule.Environment

	Schema        collections.Schema
	Supply        collections.Map[string, math.Int]
	DenomMetadata collections.Map[string, types.Metadata]
	SendEnabled   collections.Map[string, bool]
	Balances      *collections.IndexedMap[collections.Pair[sdk.AccAddress, string], math.Int, BalancesIndexes]
	Params        collections.Item[types.Params]
	// contains filtered or unexported fields
}

BaseViewKeeper implements a read only keeper implementation of ViewKeeper.

func NewBaseViewKeeper

NewBaseViewKeeper returns a new BaseViewKeeper.

func (BaseViewKeeper) GetAccountsBalances

func (k BaseViewKeeper) GetAccountsBalances(ctx context.Context) []types.Balance

GetAccountsBalances returns all the accounts balances from the store.

func (BaseViewKeeper) GetAllBalances

func (k BaseViewKeeper) GetAllBalances(ctx context.Context, addr sdk.AccAddress) sdk.Coins

GetAllBalances returns all the account balances for the given account address.

func (BaseViewKeeper) GetBalance

func (k BaseViewKeeper) GetBalance(ctx context.Context, addr sdk.AccAddress, denom string) sdk.Coin

GetBalance returns the balance of a specific denomination for a given account by address.

func (BaseViewKeeper) HasBalance

func (k BaseViewKeeper) HasBalance(ctx context.Context, addr sdk.AccAddress, amt sdk.Coin) bool

HasBalance returns whether or not an account has at least amt balance.

func (BaseViewKeeper) IterateAccountBalances

func (k BaseViewKeeper) IterateAccountBalances(ctx context.Context, addr sdk.AccAddress, cb func(sdk.Coin) bool)

IterateAccountBalances iterates over the balances of a single account and provides the token balance to a callback. If true is returned from the callback, iteration is halted.

func (BaseViewKeeper) IterateAllBalances

func (k BaseViewKeeper) IterateAllBalances(ctx context.Context, cb func(sdk.AccAddress, sdk.Coin) bool)

IterateAllBalances iterates over all the balances of all accounts and denominations that are provided to a callback. If true is returned from the callback, iteration is halted.

func (BaseViewKeeper) IterateTotalSupply

func (k BaseViewKeeper) IterateTotalSupply(ctx context.Context, cb func(sdk.Coin) bool)

IterateTotalSupply iterates over the total supply calling the given cb (callback) function with the balance of each coin. The iteration stops if the callback returns true.

func (BaseViewKeeper) LockedCoins

func (k BaseViewKeeper) LockedCoins(ctx context.Context, addr sdk.AccAddress) sdk.Coins

LockedCoins returns all the coins that are not spendable (i.e. locked) for an account by address. For standard accounts, the result will always be no coins. For vesting accounts, LockedCoins is delegated to the concrete vesting account type.

func (BaseViewKeeper) SpendableCoin

func (k BaseViewKeeper) SpendableCoin(ctx context.Context, addr sdk.AccAddress, denom string) sdk.Coin

SpendableCoin returns the balance of specific denomination of spendable coins for an account by address. If the account has no spendable coin, a zero Coin is returned.

func (BaseViewKeeper) SpendableCoins

func (k BaseViewKeeper) SpendableCoins(ctx context.Context, addr sdk.AccAddress) sdk.Coins

SpendableCoins returns the total balances of spendable coins for an account by address. If the account has no spendable coins, an empty Coins slice is returned.

func (BaseViewKeeper) ValidateBalance

func (k BaseViewKeeper) ValidateBalance(ctx context.Context, addr sdk.AccAddress) error

ValidateBalance validates all balances for a given account address returning an error if any balance is invalid. It will check for vesting account types and validate the balances against the original vesting balances.

CONTRACT: ValidateBalance should only be called upon genesis state. In the case of vesting accounts, balances may change in a valid manner that would otherwise yield an error from this call.

type Keeper

type Keeper interface {
	SendKeeper
	WithMintCoinsRestriction(types.MintingRestrictionFn) BaseKeeper

	InitGenesis(context.Context, *types.GenesisState) error
	ExportGenesis(context.Context) (*types.GenesisState, error)

	GetSupply(ctx context.Context, denom string) sdk.Coin
	HasSupply(ctx context.Context, denom string) bool
	GetPaginatedTotalSupply(ctx context.Context, pagination *query.PageRequest) (sdk.Coins, *query.PageResponse, error)
	IterateTotalSupply(ctx context.Context, cb func(sdk.Coin) bool)
	GetDenomMetaData(ctx context.Context, denom string) (types.Metadata, bool)
	HasDenomMetaData(ctx context.Context, denom string) bool
	SetDenomMetaData(ctx context.Context, denomMetaData types.Metadata)
	GetAllDenomMetaData(ctx context.Context) []types.Metadata
	IterateAllDenomMetaData(ctx context.Context, cb func(types.Metadata) bool)

	SendCoinsFromModuleToAccount(ctx context.Context, senderModule string, recipientAddr sdk.AccAddress, amt sdk.Coins) error
	SendCoinsFromModuleToModule(ctx context.Context, senderModule, recipientModule string, amt sdk.Coins) error
	SendCoinsFromAccountToModule(ctx context.Context, senderAddr sdk.AccAddress, recipientModule string, amt sdk.Coins) error
	DelegateCoinsFromAccountToModule(ctx context.Context, senderAddr sdk.AccAddress, recipientModule string, amt sdk.Coins) error
	UndelegateCoinsFromModuleToAccount(ctx context.Context, senderModule string, recipientAddr sdk.AccAddress, amt sdk.Coins) error
	MintCoins(ctx context.Context, moduleName string, amt sdk.Coins) error
	BurnCoins(ctx context.Context, address []byte, amt sdk.Coins) error

	DelegateCoins(ctx context.Context, delegatorAddr, moduleAccAddr sdk.AccAddress, amt sdk.Coins) error
	UndelegateCoins(ctx context.Context, moduleAccAddr, delegatorAddr sdk.AccAddress, amt sdk.Coins) error

	types.QueryServer
}

Keeper defines a module interface that facilitates the transfer of coins between accounts.

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 BaseKeeper) 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 x/bank storage from version 2 to 3.

func (Migrator) Migrate3to4

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

Migrate3to4 migrates x/bank storage from version 3 to 4.

type Querier

type Querier struct {
	BaseKeeper
}

func NewQuerier

func NewQuerier(keeper *BaseKeeper) Querier

type SendKeeper

type SendKeeper interface {
	ViewKeeper

	AppendSendRestriction(restriction types.SendRestrictionFn)
	PrependSendRestriction(restriction types.SendRestrictionFn)
	ClearSendRestriction()

	InputOutputCoins(ctx context.Context, input types.Input, outputs []types.Output) error
	SendCoins(ctx context.Context, fromAddr, toAddr sdk.AccAddress, amt sdk.Coins) error

	GetParams(ctx context.Context) types.Params
	SetParams(ctx context.Context, params types.Params) error

	IsSendEnabledDenom(ctx context.Context, denom string) bool
	GetSendEnabledEntry(ctx context.Context, denom string) (types.SendEnabled, bool)
	SetSendEnabled(ctx context.Context, denom string, value bool)
	SetAllSendEnabled(ctx context.Context, sendEnableds []*types.SendEnabled)
	DeleteSendEnabled(ctx context.Context, denoms ...string)
	IterateSendEnabledEntries(ctx context.Context, cb func(denom string, sendEnabled bool) (stop bool))
	GetAllSendEnabledEntries(ctx context.Context) []types.SendEnabled

	IsSendEnabledCoin(ctx context.Context, coin sdk.Coin) bool
	IsSendEnabledCoins(ctx context.Context, coins ...sdk.Coin) error

	BlockedAddr(addr sdk.AccAddress) bool
	GetBlockedAddresses() map[string]bool

	GetAuthority() string
}

SendKeeper defines a module interface that facilitates the transfer of coins between accounts without the possibility of creating coins.

type ViewKeeper

type ViewKeeper interface {
	ValidateBalance(ctx context.Context, addr sdk.AccAddress) error
	HasBalance(ctx context.Context, addr sdk.AccAddress, amt sdk.Coin) bool

	GetAllBalances(ctx context.Context, addr sdk.AccAddress) sdk.Coins
	GetAccountsBalances(ctx context.Context) []types.Balance
	GetBalance(ctx context.Context, addr sdk.AccAddress, denom string) sdk.Coin
	LockedCoins(ctx context.Context, addr sdk.AccAddress) sdk.Coins
	SpendableCoins(ctx context.Context, addr sdk.AccAddress) sdk.Coins
	SpendableCoin(ctx context.Context, addr sdk.AccAddress, denom string) sdk.Coin

	IterateAccountBalances(ctx context.Context, addr sdk.AccAddress, cb func(coin sdk.Coin) (stop bool))
	IterateAllBalances(ctx context.Context, cb func(address sdk.AccAddress, coin sdk.Coin) (stop bool))
}

ViewKeeper defines a module interface that facilitates read only access to account balances.

Jump to

Keyboard shortcuts

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