keeper

package
v2.3.0 Latest Latest
Warning

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

Go to latest
Published: Jan 16, 2025 License: Apache-2.0 Imports: 11 Imported by: 26

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func NewMsgServer

func NewMsgServer(k Keeper) types.MsgServer

NewMsgServer returns the default implementation of the x/oracle message service.

func NewQueryServer

func NewQueryServer(k Keeper) types.QueryServer

NewQueryServer returns an implementation of the x/oracle QueryServer.

Types

type Hooks

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

Hooks is a wrapper struct around Keeper.

func (Hooks) AfterMarketCreated

func (h Hooks) AfterMarketCreated(ctx sdk.Context, market marketmaptypes.Market) error

AfterMarketCreated is the marketmap hook for x/oracle that is run after a market is created in the marketmap. After the market is created, a currency pair and its state are initialized in the oracle module.

func (Hooks) AfterMarketGenesis

func (h Hooks) AfterMarketGenesis(ctx sdk.Context, markets map[string]marketmaptypes.Market) error

AfterMarketGenesis verifies that all markets set in the x/marketmap genesis are registered in the x/oracle module.

func (Hooks) AfterMarketRemoved

func (h Hooks) AfterMarketRemoved(ctx sdk.Context, key string) error

AfterMarketRemoved is the marketmap hook for x/oracle that is run after a market is removed in the marketmap.

func (Hooks) AfterMarketUpdated

func (h Hooks) AfterMarketUpdated(ctx sdk.Context, market marketmaptypes.Market) error

AfterMarketUpdated is the marketmap hook for x/oracle that is run after a market is updated in the marketmap.

type Keeper

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

Keeper is the base keeper for the x/oracle module.

func NewKeeper

func NewKeeper(
	ss store.KVStoreService,
	cdc codec.BinaryCodec,
	mmKeeper types.MarketMapKeeper,
	authority sdk.AccAddress,
) Keeper

NewKeeper constructs a new keeper from a store-key + authority account address.

func (*Keeper) BeginBlocker

func (k *Keeper) BeginBlocker(ctx context.Context) error

BeginBlocker is called at the beginning of every block. It resets the count of removed currency pairs.

func (*Keeper) CreateCurrencyPair

func (k *Keeper) CreateCurrencyPair(ctx context.Context, cp connecttypes.CurrencyPair) error

CreateCurrencyPair creates a CurrencyPair in state, and sets its ID to the next available ID. If the CurrencyPair already exists, return an error. the nonce for the CurrencyPair is set to 0.

func (*Keeper) ExportGenesis

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

ExportGenesis retrieve all CurrencyPairs + QuotePrices set for the module, and return them as a genesis state. This module panics on any errors encountered in execution.

func (*Keeper) GetAllCurrencyPairs

func (k *Keeper) GetAllCurrencyPairs(ctx context.Context) []connecttypes.CurrencyPair

GetAllCurrencyPairs returns all CurrencyPairs that have currently been stored to state.

func (*Keeper) GetCurrencyPairFromID

func (k *Keeper) GetCurrencyPairFromID(ctx context.Context, id uint64) (connecttypes.CurrencyPair, bool)

GetCurrencyPairFromID returns the CurrencyPair for a given ID. If the ID does not exist, return an error and an empty CurrencyPair. Otherwise, return the currency pair and no error.

func (*Keeper) GetCurrencyPairMapping

func (k *Keeper) GetCurrencyPairMapping(ctx context.Context) (map[uint64]connecttypes.CurrencyPair, error)

GetCurrencyPairMapping returns a CurrencyPair mapping by ID that have currently been stored to state. NOTE: this map[] type should not be used by on-chain code.

func (*Keeper) GetCurrencyPairMappingList

func (k *Keeper) GetCurrencyPairMappingList(ctx context.Context) ([]types.CurrencyPairMapping, error)

GetCurrencyPairMappingList returns a CurrencyPair mapping by ID that have currently been stored to state as a list.

func (*Keeper) GetDecimalsForCurrencyPair

func (k *Keeper) GetDecimalsForCurrencyPair(ctx context.Context, cp connecttypes.CurrencyPair) (decimals uint64, err error)

GetDecimalsForCurrencyPair gets the decimals used for the given currency pair. If the market map is not enabled with the x/oracle module, the legacy Decimals function is used.

func (*Keeper) GetIDForCurrencyPair

func (k *Keeper) GetIDForCurrencyPair(ctx context.Context, cp connecttypes.CurrencyPair) (uint64, bool)

GetIDForCurrencyPair returns the ID for a given CurrencyPair. If the CurrencyPair does not exist, return 0, false, if it does, return true and the ID.

func (*Keeper) GetNonceForCurrencyPair

func (k *Keeper) GetNonceForCurrencyPair(ctx context.Context, cp connecttypes.CurrencyPair) (uint64, error)

GetNonceForCurrencyPair returns the nonce for a given CurrencyPair. If one has not been stored, return an error.

func (*Keeper) GetNumCurrencyPairs

func (k *Keeper) GetNumCurrencyPairs(ctx context.Context) (uint64, error)

GetNumCurrencyPairs returns the number of currency pairs currently in state.

func (*Keeper) GetNumRemovedCurrencyPairs

func (k *Keeper) GetNumRemovedCurrencyPairs(ctx context.Context) (uint64, error)

GetNumRemovedCurrencyPairs gets the counter of removed currency pairs in the previous block.

func (*Keeper) GetPriceForCurrencyPair

func (k *Keeper) GetPriceForCurrencyPair(ctx context.Context, cp connecttypes.CurrencyPair) (types.QuotePrice, error)

GetPriceForCurrencyPair retrieves the QuotePrice for a given CurrencyPair. if a QuotePrice does not exist for the given CurrencyPair, this function errors and returns an empty QuotePrice.

func (*Keeper) GetPriceWithNonceForCurrencyPair

func (k *Keeper) GetPriceWithNonceForCurrencyPair(ctx context.Context, cp connecttypes.CurrencyPair) (types.QuotePriceWithNonce, error)

GetPriceWithNonceForCurrencyPair returns a QuotePriceWithNonce for a given CurrencyPair. The nonce for the QuotePrice represents the number of times that a given QuotePrice has been updated. Notice: prefer GetPriceWithNonceForCurrencyPair over GetPriceForCurrencyPair.

func (*Keeper) HasCurrencyPair

func (k *Keeper) HasCurrencyPair(ctx context.Context, cp connecttypes.CurrencyPair) bool

HasCurrencyPair returns true if a given CurrencyPair is stored in state, false otherwise.

func (*Keeper) Hooks

func (k *Keeper) Hooks() Hooks

Hooks returns registered hooks for x/oracle.

func (*Keeper) InitGenesis

func (k *Keeper) InitGenesis(ctx sdk.Context, gs types.GenesisState)

InitGenesis initializes the set of CurrencyPairs + their genesis prices (if any) for the x/oracle module. this function panics on any errors, i.e. if the genesis state is invalid, or any state-modifications fail.

func (*Keeper) IterateCurrencyPairs

func (k *Keeper) IterateCurrencyPairs(ctx context.Context, cb func(cp connecttypes.CurrencyPair, cps types.CurrencyPairState)) error

IterateCurrencyPairs iterates over all CurrencyPairs in the store, and executes a callback for each CurrencyPair.

func (*Keeper) NextCurrencyPairID

func (k *Keeper) NextCurrencyPairID(ctx context.Context) (uint64, error)

NextCurrencyPairID returns the next ID to be assigned to a currency-pair.

func (*Keeper) RemoveCurrencyPair

func (k *Keeper) RemoveCurrencyPair(ctx context.Context, cp connecttypes.CurrencyPair) error

RemoveCurrencyPair removes a given CurrencyPair from state, i.e. removes its nonce + QuotePrice from the module's store.

func (*Keeper) SetPriceForCurrencyPair

func (k *Keeper) SetPriceForCurrencyPair(ctx context.Context, cp connecttypes.CurrencyPair, qp types.QuotePrice) error

SetPriceForCurrencyPair sets the given QuotePrice for a given CurrencyPair, and updates the CurrencyPair's nonce. Note, no validation is performed on either the CurrencyPair or the QuotePrice (it is expected the caller performs this validation). If the CurrencyPair does not exist, create the currency-pair and set its nonce to 0.

Jump to

Keyboard shortcuts

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