store

package
v0.0.0-...-9e55092 Latest Latest
Warning

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

Go to latest
Published: Apr 16, 2024 License: AGPL-3.0 Imports: 15 Imported by: 0

Documentation

Index

Constants

View Source
const LoggerTag = "DATA_POINT_STORE"

Variables

This section is empty.

Functions

func StoredDataPointLogFields

func StoredDataPointLogFields(o StoredDataPoint) log.Fields

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

	// Models is the list of models which are supported by the store.
	Models []string

	// Recoverers is the list of recoverers which are used to recover the
	// feed's address from the data point.
	Recoverers []datapoint.Recoverer

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

Config is the configuration for Storage.

type DataPointProvider

type DataPointProvider interface {
	// LatestFrom returns the latest data point from a given address.
	LatestFrom(ctx context.Context, from types.Address, model string) (StoredDataPoint, bool, error)

	// Latest returns the latest data points from all addresses.
	Latest(ctx context.Context, model string) (map[types.Address]StoredDataPoint, error)
}

DataPointProvider is an interface which provides latest data points from feeds.

type MemoryStorage

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

MemoryStorage is an in-memory implementation of Storage.

func NewMemoryStorage

func NewMemoryStorage() *MemoryStorage

NewMemoryStorage creates a new MemoryStorage.

func (*MemoryStorage) Add

Add implements the Storage interface.

func (*MemoryStorage) Latest

Latest implements the Storage interface.

func (*MemoryStorage) LatestFrom

func (m *MemoryStorage) LatestFrom(_ context.Context, from types.Address, model string) (StoredDataPoint, bool, error)

LatestFrom implements the Storage interface.

type Storage

type Storage interface {
	// Add adds a data point to the store.
	//
	// Adding a data point with a timestamp older than the latest data point
	// for the same address and model will be ignored.
	Add(ctx context.Context, point StoredDataPoint) error

	// LatestFrom returns the latest data point from a given address.
	LatestFrom(ctx context.Context, from types.Address, model string) (point StoredDataPoint, ok bool, err error)

	// Latest returns the latest data points from all addresses.
	Latest(ctx context.Context, model string) (points map[types.Address]StoredDataPoint, err error)
}

Storage is underlying storage implementation for the Store.

It must be thread-safe.

type Store

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

Store stores latest data points from feeds.

func New

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

New creates a new Store.

func (*Store) Latest

func (p *Store) Latest(ctx context.Context, model string) (map[types.Address]StoredDataPoint, error)

Latest implements the DataPointProvider interface.

func (*Store) LatestFrom

func (p *Store) LatestFrom(ctx context.Context, from types.Address, model string) (StoredDataPoint, bool, error)

LatestFrom implements the DataPointProvider interface.

func (*Store) Start

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

Start implements the supervisor.Service interface.

func (*Store) Wait

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

Wait implements the supervisor.Service interface.

type StoredDataPoint

type StoredDataPoint struct {
	Model     string
	DataPoint datapoint.Point
	From      types.Address
	Signature types.Signature
}

StoredDataPoint is a struct which represents a data point stored in the Store.

Jump to

Keyboard shortcuts

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