worker

package
v0.0.0-...-02d6beb Latest Latest
Warning

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

Go to latest
Published: Dec 10, 2021 License: Apache-2.0 Imports: 23 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

View Source
var (
	// ErrInvalidJSON is returned when a populated value is not valid JSON.
	ErrInvalidJSON = errors.New("populated input is not valid JSON")

	// ErrVariableNotFound is returned when a variable is not
	// present in a Job's state.
	ErrVariableNotFound = errors.New("variable not found")

	// ErrJobComplete is returned when there are no more scenarios
	// to process in a Job.
	ErrJobComplete = errors.New("job complete")

	// ErrInvalidInput is returned when the input for an Action
	// cannot be parsed.
	ErrInvalidInput = errors.New("invalid input")

	// ErrInvalidActionType is returned when an Action has an unsupported
	// type.
	ErrInvalidActionType = errors.New("invalid action type")

	// ErrActionFailed is returned when Action exeuction fails with a valid input.
	ErrActionFailed = errors.New("action execution failed")

	// ErrCreateAccount is returned when a new account should
	// be created using the `create_account` workflow.
	ErrCreateAccount = errors.New("create account")

	// ErrUnsatisfiable is returned when there is no available
	// balance that can satisfy a FindBalance request. If there
	// are no pending broadcasts, this usually means that we need
	// to request funds.
	ErrUnsatisfiable = errors.New("unsatisfiable balance")
)

Functions

func AssertWorker

func AssertWorker(rawInput string) error

AssertWorker checks if an input is < 0.

func FindCurrencyAmountWorker

func FindCurrencyAmountWorker(rawInput string) (string, error)

FindCurrencyAmountWorker finds a *types.Amount with a specific *types.Currency in a []*types.Amount.

func GenerateKeyWorker

func GenerateKeyWorker(rawInput string) (string, error)

GenerateKeyWorker attempts to generate a key given a *GenerateKeyInput input.

func HTTPRequestWorker

func HTTPRequestWorker(rawInput string) (string, error)

HTTPRequestWorker makes an HTTP request and returns the response to store in a variable. This is useful for algorithmic fauceting.

func LoadEnvWorker

func LoadEnvWorker(rawInput string) (string, error)

LoadEnvWorker loads an environment variable and stores it in state. This is useful for algorithmic fauceting.

func MathWorker

func MathWorker(rawInput string) (string, error)

MathWorker performs some MathOperation on 2 numbers.

func PopulateInput

func PopulateInput(state string, input string) (string, error)

PopulateInput populates user defined variables in the input with their corresponding values from the execution state.

func PrintMessageWorker

func PrintMessageWorker(message string)

PrintMessageWorker logs some message to stdout.

func RandomNumberWorker

func RandomNumberWorker(rawInput string) (string, error)

RandomNumberWorker generates a random number in the range [minimum,maximum).

func RandomStringWorker

func RandomStringWorker(rawInput string) (string, error)

RandomStringWorker generates a string that complies with the provided regex input.

Types

type Error

type Error struct {
	Workflow string `json:"workflow"`
	Job      string `json:"job"`

	Scenario      string `json:"scenario"`
	ScenarioIndex int    `json:"scenario_index"`
	ActionIndex   int    `json:"action_index"`

	Action *job.Action `json:"action,omitempty"`

	ProcessedInput string `json:"processed_input,omitempty"`
	Output         string `json:"output,omitempty"`

	State string `json:"state"`

	Err error `json:"err"`
}

Error is returned by worker execution.

func (*Error) Log

func (e *Error) Log()

Log prints the error to the console in a human readable format.

type Helper

type Helper interface {
	// StoreKey is called to persist a
	// *types.AccountIdentifier + KeyPair.
	StoreKey(
		context.Context,
		database.Transaction,
		*types.AccountIdentifier,
		*keys.KeyPair,
	) error

	// AllAccounts returns a slice of all known *types.AccountIdentifier.
	AllAccounts(
		context.Context,
		database.Transaction,
	) ([]*types.AccountIdentifier, error)

	// LockedAccounts is a slice of all *types.AccountIdentifier currently sending or receiving
	// funds.
	LockedAccounts(
		context.Context,
		database.Transaction,
	) ([]*types.AccountIdentifier, error)

	// Balance returns the balance
	// for a provided address and currency.
	Balance(
		context.Context,
		database.Transaction,
		*types.AccountIdentifier,
		*types.Currency,
	) (*types.Amount, error)

	// Coins returns all *types.Coin owned by an address.
	Coins(
		context.Context,
		database.Transaction,
		*types.AccountIdentifier,
		*types.Currency,
	) ([]*types.Coin, error)

	// Derive returns a new *types.AccountIdentifier for a provided publicKey.
	Derive(
		context.Context,
		*types.NetworkIdentifier,
		*types.PublicKey,
		map[string]interface{},
	) (*types.AccountIdentifier, map[string]interface{}, error)

	// SetBlob transactionally persists
	// a key and value.
	SetBlob(
		ctx context.Context,
		dbTx database.Transaction,
		key string,
		value []byte,
	) error

	// GetBlob transactionally retrieves
	// a key and value.
	GetBlob(
		ctx context.Context,
		dbTx database.Transaction,
		key string,
	) (bool, []byte, error)
}

Helper is used by the worker to process Jobs.

type Worker

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

Worker processes jobs.

func New

func New(helper Helper) *Worker

New returns a new *Worker.

func (*Worker) DeriveWorker

func (w *Worker) DeriveWorker(
	ctx context.Context,
	rawInput string,
) (string, error)

DeriveWorker attempts to derive an account given a *types.ConstructionDeriveRequest input.

func (*Worker) FindBalanceWorker

func (w *Worker) FindBalanceWorker(
	ctx context.Context,
	dbTx database.Transaction,
	rawInput string,
) (string, error)

FindBalanceWorker attempts to find an account (and coin) with some minimum balance in a particular currency.

func (*Worker) GetBlobWorker

func (w *Worker) GetBlobWorker(
	ctx context.Context,
	dbTx database.Transaction,
	rawInput string,
) (string, error)

GetBlobWorker transactionally retrieves a value associated with a key, if it exists.

func (*Worker) Process

func (w *Worker) Process(
	ctx context.Context,
	dbTx database.Transaction,
	j *job.Job,
) (*job.Broadcast, *Error)

Process is called on a Job to execute the next available scenario. If no scenarios are remaining, this will return an error.

func (*Worker) ProcessNextScenario

func (w *Worker) ProcessNextScenario(
	ctx context.Context,
	dbTx database.Transaction,
	j *job.Job,
) *Error

ProcessNextScenario performs the actions in the next available scenario.

func (*Worker) SaveAccountWorker

func (w *Worker) SaveAccountWorker(
	ctx context.Context,
	dbTx database.Transaction,
	rawInput string,
) error

SaveAccountWorker saves a *types.AccountIdentifier and associated KeyPair in KeyStorage.

func (*Worker) SetBlobWorker

func (w *Worker) SetBlobWorker(
	ctx context.Context,
	dbTx database.Transaction,
	rawInput string,
) error

SetBlobWorker transactionally saves a key and value for use across workflows.

Jump to

Keyboard shortcuts

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