store

package
v0.6.6 Latest Latest
Warning

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

Go to latest
Published: Aug 28, 2022 License: AGPL-3.0 Imports: 9 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 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
	// Signer is an instance of the ethereum.Signer which will be used to
	// verify price signatures.
	Signer ethereum.Signer
	// Transport is an implementation of transport used to fetch prices from
	// feeders.
	Transport transport.Transport
	// Pairs is the list of asset pairs which are supported by the store.
	Pairs []string
	// Logger is a current logger interface used by the PriceStore.
	// The Logger is required to monitor asynchronous processes.
	Logger log.Logger
}

Config is the configuration for Storage.

type FeederPrice

type FeederPrice struct {
	AssetPair string
	Feeder    ethereum.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 ethereum.Address, price *messages.Price) error

Add implements the store.Storage interface.

func (*MemoryStorage) GetAll

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) GetByFeeder

func (p *MemoryStorage) GetByFeeder(_ context.Context, pair string, feeder ethereum.Address) (*messages.Price, error)

GetByFeeder 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 ethereum.Address, msg *messages.Price) error

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

func (*PriceStore) GetAll

func (p *PriceStore) GetAll(ctx context.Context) (map[FeederPrice]*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) GetByFeeder

func (p *PriceStore) GetByFeeder(ctx context.Context, pair string, feeder ethereum.Address) (*messages.Price, error)

GetByFeeder returns the latest price for given asset pair sent by given feeder.

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 ethereum.Address, msg *messages.Price) error
	// GetAll returns all prices. The method is thread-safe.
	GetAll(ctx context.Context) (map[FeederPrice]*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)
	// GetByFeeder returns the latest price for given asset pair sent by given
	// feeder. The method is thread-safe.
	GetByFeeder(ctx context.Context, pair string, feeder ethereum.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