worker

package
v1.1.1 Latest Latest
Warning

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

Go to latest
Published: Dec 17, 2024 License: MIT Imports: 17 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

View Source
var (
	ErrAccountNotFound = errors.New("account doesn't exist")
)

Functions

This section is empty.

Types

type Account added in v1.1.0

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

func (*Account) ID added in v1.1.0

func (a *Account) ID() rhpv3.Account

func (*Account) Key added in v1.1.0

func (a *Account) Key() types.PrivateKey

func (*Account) ScheduleSync added in v1.1.0

func (a *Account) ScheduleSync()

scheduleSync sets the requiresSync flag of an account.

func (*Account) WithDeposit added in v1.1.0

func (a *Account) WithDeposit(amtFn func(types.Currency) (types.Currency, error)) error

WithDeposit increases the balance of an account by the amount returned by amtFn if amtFn doesn't return an error.

func (*Account) WithSync added in v1.1.0

func (a *Account) WithSync(balanceFn func() (types.Currency, error)) error

WithSync syncs an accounts balance with the bus. To do so, the account is locked while the balance is fetched through balanceFn.

func (*Account) WithWithdrawal added in v1.1.0

func (a *Account) WithWithdrawal(amtFn func() (types.Currency, error)) error

WithWithdrawal decreases the balance of an account by the amount returned by amtFn. The amount is still withdrawn if amtFn returns an error since some costs are non-refundable.

type AccountFunder added in v1.1.0

type AccountFunder interface {
	FundAccount(ctx context.Context, fcid types.FileContractID, hk types.PublicKey, desired types.Currency) error
}

type AccountMgr added in v1.1.0

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

func NewAccountManager added in v1.1.0

func NewAccountManager(key utils.AccountsKey, owner string, alerter alerts.Alerter, funder AccountFunder, syncer AccountSyncer, cs ConsensusState, dc DownloadContracts, s AccountStore, refillInterval time.Duration, l *zap.Logger) (*AccountMgr, error)

NewAccountManager creates a new account manager. It will load all accounts from the given store and mark the shutdown as unclean. When Shutdown is called it will save all accounts.

func (*AccountMgr) Account added in v1.1.0

func (a *AccountMgr) Account(hostKey types.PublicKey) api.Account

Account returns the account with the given id.

func (*AccountMgr) Accounts added in v1.1.0

func (a *AccountMgr) Accounts() []api.Account

Accounts returns all accounts.

func (*AccountMgr) ForHost added in v1.1.0

func (a *AccountMgr) ForHost(hk types.PublicKey) *Account

ForHost returns an account to use for a given host. If the account doesn't exist, a new one is created.

func (*AccountMgr) ResetDrift added in v1.1.0

func (a *AccountMgr) ResetDrift(id rhpv3.Account) error

ResetDrift resets the drift on an account.

func (*AccountMgr) Shutdown added in v1.1.0

func (a *AccountMgr) Shutdown(ctx context.Context) error

type AccountStore added in v1.1.0

type AccountStore interface {
	Accounts(context.Context, string) ([]api.Account, error)
	UpdateAccounts(context.Context, []api.Account) error
}

type AccountSyncer added in v1.1.0

type AccountSyncer interface {
	SyncAccount(ctx context.Context, fcid types.FileContractID, hk types.PublicKey, siamuxAddr string) error
}

type Bus

type Bus interface {
	Contracts(ctx context.Context, opts api.ContractsOpts) ([]api.ContractMetadata, error)
	GougingParams(ctx context.Context) (api.GougingParams, error)
}

type ConsensusState added in v1.1.0

type ConsensusState interface {
	ConsensusState(ctx context.Context) (api.ConsensusState, error)
}

type DownloadContracts added in v1.1.0

type DownloadContracts interface {
	DownloadContracts(ctx context.Context) ([]api.ContractMetadata, error)
}

type EventHandler added in v1.1.0

type EventHandler interface {
	HandleEvent(event webhooks.Event) error
	Subscribe(e EventSubscriber) error
}

type EventSubscriber added in v1.1.0

type EventSubscriber interface {
	AddEventHandler(id string, h EventHandler) (chan struct{}, error)
	ProcessEvent(event webhooks.Event)
	Register(ctx context.Context, eventURL string, opts ...webhooks.HeaderOption) error
	Shutdown(context.Context) error
}

func NewEventSubscriber added in v1.1.0

func NewEventSubscriber(a alerts.Alerter, w WebhookManager, l *zap.Logger, registerInterval time.Duration) EventSubscriber

type WebhookManager added in v1.1.0

type WebhookManager interface {
	RegisterWebhook(ctx context.Context, wh webhooks.Webhook) error
	UnregisterWebhook(ctx context.Context, wh webhooks.Webhook) error
}

type WorkerCache

type WorkerCache interface {
	DownloadContracts(ctx context.Context) ([]api.ContractMetadata, error)
	GougingParams(ctx context.Context) (api.GougingParams, error)
	HandleEvent(event webhooks.Event) error
	Subscribe(e EventSubscriber) error
}

func NewCache

func NewCache(b Bus, logger *zap.Logger) WorkerCache

Jump to

Keyboard shortcuts

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