store

package
v0.13.0 Latest Latest
Warning

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

Go to latest
Published: Aug 22, 2023 License: AGPL-3.0 Imports: 10 Imported by: 0

Documentation

Index

Constants

View Source
const LoggerTag = "PRICE_STORE"

Variables

View Source
var ErrInvalidPrice = errors.New("received price is invalid")
View Source
var ErrInvalidSignature = errors.New("received price has an invalid signature")
View Source
var ErrUnknownFeed = errors.New("messages from feed are not allowed")
View Source
var ErrUnknownPair = errors.New("received pair is not configured")

Functions

This section is empty.

Types

type Config

type Config struct {
	// Storage is the storage implementation.
	Storage Storage

	// Transport is an implementation of transport used to fetch prices from
	// feeds.
	Transport transport.Service

	// Pairs is the list of asset pairs which are supported by the store.
	Pairs []string

	// Feeds is the list of feeds which are supported by the store.
	Feeds []types.Address

	// Logger is a current logger interface used by the PriceStore.
	// The Logger is required to monitor asynchronous processes.
	Logger log.Logger

	// Recoverer provides a method to recover the public key from a signature.
	// The default is crypto.ECREcoverer.
	Recoverer crypto.Recoverer
}

Config is the configuration for Storage.

type FeedPrice added in v0.11.0

type FeedPrice struct {
	AssetPair string
	Feed      types.Address
}

type MemoryStorage

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

func NewMemoryStorage

func NewMemoryStorage() *MemoryStorage

NewMemoryStorage creates a new store instance.

func (*MemoryStorage) Add

func (p *MemoryStorage) Add(_ context.Context, from types.Address, price *messages.Price) error

Add implements the store.Storage interface.

func (*MemoryStorage) GetAll

func (p *MemoryStorage) GetAll(_ context.Context) (map[FeedPrice]*messages.Price, error)

GetAll implements the store.Storage interface.

func (*MemoryStorage) GetByAssetPair

func (p *MemoryStorage) GetByAssetPair(_ context.Context, pair string) ([]*messages.Price, error)

GetByAssetPair implements the store.Storage interface.

func (*MemoryStorage) GetByFeed added in v0.11.0

func (p *MemoryStorage) GetByFeed(_ context.Context, pair string, feed types.Address) (*messages.Price, error)

GetByFeed implements the store.Storage interface.

type PriceStore

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

PriceStore contains a list of prices.

func New

func New(cfg Config) (*PriceStore, error)

New creates a new store instance.

func (*PriceStore) Add

func (p *PriceStore) Add(ctx context.Context, from types.Address, msg *messages.Price) error

Add adds a new price to the list. If a price from same feed already exists, the newer one will be used.

func (*PriceStore) GetAll

func (p *PriceStore) GetAll(ctx context.Context) (map[FeedPrice]*messages.Price, error)

GetAll returns all prices.

func (*PriceStore) GetByAssetPair

func (p *PriceStore) GetByAssetPair(ctx context.Context, pair string) ([]*messages.Price, error)

GetByAssetPair returns all prices for given asset pair.

func (*PriceStore) GetByFeed added in v0.11.0

func (p *PriceStore) GetByFeed(ctx context.Context, pair string, feed types.Address) (*messages.Price, error)

GetByFeed returns the latest price for given asset pair sent by given feed.

func (*PriceStore) Start

func (p *PriceStore) Start(ctx context.Context) error

Start implements the supervisor.Service interface.

func (*PriceStore) Wait

func (p *PriceStore) Wait() <-chan error

Wait implements the supervisor.Service interface.

type Storage

type Storage interface {
	// Add adds a price to the store. The method is thread-safe.
	Add(ctx context.Context, from types.Address, msg *messages.Price) error

	// GetAll returns all prices. The method is thread-safe.
	GetAll(ctx context.Context) (map[FeedPrice]*messages.Price, error)

	// GetByAssetPair returns all prices for given asset pair. The method is
	// thread-safe.
	GetByAssetPair(ctx context.Context, pair string) ([]*messages.Price, error)

	// GetByFeed returns the latest price for given asset pair sent by given
	// feed. The method is thread-safe.
	GetByFeed(ctx context.Context, pair string, feed types.Address) (*messages.Price, error)
}

Storage provides an interface to the price storage.

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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