worker

package
v0.8.5 Latest Latest
Warning

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

Go to latest
Published: Apr 10, 2024 License: Apache-2.0 Imports: 24 Imported by: 1

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

	// ErrInputOperationIsNotSupported is returned when the input operation
	// is not supported.
	ErrInputOperationIsNotSupported = errors.New("the input operation is not supported")
)

Functions

func AssertWorker added in v0.4.1

func AssertWorker(rawInput string) error

AssertWorker checks if an input is < 0.

func FindCurrencyAmountWorker added in v0.4.1

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 added in v0.4.5

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 added in v0.4.5

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 added in v0.4.9

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 added in v0.4.9

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 added in v0.6.6

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 added in v0.4.1

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 added in v0.6.6

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