pin

package
v1.0.4 Latest Latest
Warning

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

Go to latest
Published: Mar 27, 2024 License: MIT Imports: 9 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func ConvertCurrencyToSC

func ConvertCurrencyToSC(target decimal.Decimal, rate decimal.Decimal) (types.Currency, error)

ConvertCurrencyToSC converts a value in an external currency and an exchange rate to Siacoins.

Types

type ExchangeRateRetriever

type ExchangeRateRetriever interface {
	SiacoinExchangeRate(ctx context.Context, currency string) (float64, error)
}

An ExchangeRateRetriever retrieves the current exchange rate from an external source.

type Manager

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

A Manager manages the host's pinned settings and updates the host's settings based on the current exchange rate.

func NewManager

func NewManager(opts ...Option) (*Manager, error)

NewManager creates a new pin manager.

func (*Manager) Pinned

Pinned returns the host's pinned settings.

func (*Manager) Run

func (m *Manager) Run(ctx context.Context) error

Run starts the PinManager's update loop.

func (*Manager) Update

func (m *Manager) Update(ctx context.Context, p PinnedSettings) error

Update updates the host's pinned settings.

type Option

type Option func(*Manager)

An Option is a functional option for configuring a pin Manager.

func WithAverageRateWindow

func WithAverageRateWindow(window time.Duration) Option

WithAverageRateWindow sets the window over which the manager calculates the average exchange rate.

func WithExchangeRateRetriever

func WithExchangeRateRetriever(e ExchangeRateRetriever) Option

WithExchangeRateRetriever sets the exchange rate retriever for the manager.

func WithFrequency

func WithFrequency(frequency time.Duration) Option

WithFrequency sets the frequency at which the manager updates the host's settings based on the current exchange rate.

func WithLogger

func WithLogger(log *zap.Logger) Option

WithLogger sets the logger for the manager.

func WithSettings

func WithSettings(s SettingsManager) Option

WithSettings sets the settings manager for the manager.

func WithStore

func WithStore(s Store) Option

WithStore sets the store for the manager.

type Pin

type Pin struct {
	Pinned bool    `json:"pinned"`
	Value  float64 `json:"value"`
}

A Pin is a pinned price in an external currency.

func (Pin) IsPinned

func (p Pin) IsPinned() bool

IsPinned returns true if the pin is enabled and the value is greater than 0.

type PinnedSettings

type PinnedSettings struct {
	// Currency is the external three letter currency code. If empty,
	// pinning is disabled. If the explorer does not support the
	// currency an error is returned.
	Currency string `json:"currency"`

	// Threshold is a percentage from 0 to 1 that determines when the
	// host's settings are updated based on the current exchange rate.
	Threshold float64 `json:"threshold"`

	// Storage, Ingress, and Egress are the pinned prices in the
	// external currency.
	Storage Pin `json:"storage"`
	Ingress Pin `json:"ingress"`
	Egress  Pin `json:"egress"`

	// MaxCollateral is the maximum collateral that the host will
	// accept in the external currency.
	MaxCollateral Pin `json:"maxCollateral"`
}

PinnedSettings contains the settings that can be optionally pinned to an external currency. This uses an external explorer to retrieve the current exchange rate.

type SettingsManager

type SettingsManager interface {
	Settings() settings.Settings
	UpdateSettings(settings.Settings) error
}

A SettingsManager updates and retrieves the host's settings.

type Store

type Store interface {
	PinnedSettings(context.Context) (PinnedSettings, error)
	UpdatePinnedSettings(context.Context, PinnedSettings) error
}

A Store stores and retrieves pinned settings.

Jump to

Keyboard shortcuts

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