actions

package
v1.5.0 Latest Latest
Warning

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

Go to latest
Published: Feb 3, 2023 License: GPL-3.0 Imports: 14 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

View Source
var (
	RuntimeV1          = "v1"
	RuntimeV2          = "v2"
	SupportedRuntimes  = []string{RuntimeV1, RuntimeV2}
	TriggerTypes       = []string{"periodic", "webhook", "block", "transaction", "alert"}
	PeriodicType       = "periodic"
	WebhookType        = "webhook"
	BlockType          = "block"
	TransactionType    = "transaction"
	AlertType          = "alert"
	Invocations        = []string{"any", "direct", "internal"}
	InvocationAny      = "any"
	InvocationDirect   = "direct"
	InvocationInternal = "internal"

	Intervals      = []string{"5m", "10m", "15m", "30m", "1h", "3h", "6h", "12h", "1d"}
	IntervalToCron = map[string]string{
		"5m":  "*/5 * * * *",
		"10m": "*/10 * * * *",
		"15m": "*/15 * * * *",
		"30m": "*/30 * * * *",
		"1h":  "0 * * * *",
		"3h":  "0 */3 * * *",
		"6h":  "0 */6 * * *",
		"12h": "0 */12 * * *",
		"1d":  "0 0 * * *",
	}

	CronParser = cron.NewParser(cron.Minute | cron.Hour | cron.Dom | cron.Month | cron.Dow)

	AddressRegex = "^0x[0-9a-f]{40}$"
	AddressRe    = regexp.MustCompile(AddressRegex)
	SigRegex     = "^0x[0-9a-f]{8}$"
	SigRe        = regexp.MustCompile(SigRegex)

	MsgTriggerTypeNotSupported             = "trigger type '%s' not supported, supported types %s"
	MsgTriggerTypeMismatch                 = "trigger type '%s' different from configured trigger"
	MsgNetworkNotSupported                 = "network '%s' is not supported"
	MsgStatusNotSupported                  = "status '%s' is not supported, supported statuses %s"
	MsgAddressDoesNotMatchRegex            = "address '%s' does not match regex %s"
	MsgSignatureDoesNotMatchRegex          = "signature '%s' does not match regex '%s'"
	MsgDefaultToAuthenticated              = "authenticated not set, defaulting to true"
	MsgIntervalOrCronRequired              = "one of 'cron' or 'interval' is required"
	MsgIntervalAndCronForbidden            = "both 'cron' and 'interval' is forbidden"
	MsgIntervalNotSupported                = "interval '%s' not supported, supported intervals %s"
	MsgCronNotSupported                    = "cron '%s' is not supported, got error %s"
	MsgBlocksNegative                      = "blocks must be greater than 0, found %d"
	MsgDefaultToAnyInvocation              = "invocation not set for contract, defaulting to any"
	MsgInvocationNotSupported              = "invocation '%s' not supported, supported invocations %s"
	MsgAccountOrContractRequired           = "one of 'account' or 'contract' is required"
	MsgAccountAndContractForbidden         = "both 'account' and 'contract' is forbidden"
	MsgContractRequired                    = "'contract' is required"
	MsgSignatureOrNameRequired             = "one of 'signature' or 'name' is required"
	MsgSignatureAndNameForbidden           = "both 'signature' and 'name' is forbidden"
	MsgSignatureAndParameterForbidden      = "'parameter' can not be used with 'signature'"
	MsgIdOrNameRequired                    = "one of 'id' or 'name' is required"
	MsgIdAndNameForbidden                  = "both 'id' and 'name' is forbidden"
	MsgIdAndParameterForbidden             = "'parameter' can not be used with 'id'"
	MsgKeyOrFieldRequired                  = "one of 'key' or 'field' is required"
	MsgKeyAndFieldForbidden                = "both 'key' and 'field' is forbidden"
	MsgKeyAndValueOrPreviousValueForbidden = "'value' or 'previousValue' can not be used with 'key'"
	MsgValueAndPreviousValueForbidden      = "both 'value' and 'previousValue' is forbidden"
	MsgTxStatusNotSupported                = "transaction status '%s' not supported, supported %s"
	MsgStatusRequired                      = "'status' must have at least one element"
	MsgFiltersRequired                     = "'filters' must have at least one element"
	MsgStartsWithEmpty                     = "'startsWith' must have at least one element"
	MsgStartsWithInvalid                   = "'startsWith' element must be hex encoded and start with 0x"
	MsgHexValueEmpty                       = "expected non-empty hex value"
	MsgHexValueInvalid                     = "hex value must start with 0x, got %s"
	MsgMinFilterConstraint                 = "constraint for minimum transaction filters must be fulfilled"
)

Functions

func IsRuntimeSupported added in v1.4.9

func IsRuntimeSupported(runtime string) bool

Types

type AccountValue

type AccountValue struct {
	Address AddressValue `yaml:"address" json:"address"`
}

func (*AccountValue) Validate

func (a *AccountValue) Validate(ctx ValidatorContext) (response ValidateResponse)

type ActionSpec

type ActionSpec struct {
	Description *string `json:"description,omitempty" yaml:"description,omitempty"`
	Function    string  `json:"function" yaml:"function"`
	// Parsing and validation of trigger happens later, and Trigger field is set
	Trigger       TriggerUnparsed `json:"trigger" yaml:"trigger"`
	TriggerParsed *Trigger        `json:"-" yaml:"-"`
}

func (*ActionSpec) Parse

func (a *ActionSpec) Parse() error

type AddressField

type AddressField struct {
	Values []AddressValue
}

func (*AddressField) ToRequest

func (a *AddressField) ToRequest() (response []actions.ComparableStr)

func (*AddressField) UnmarshalJSON

func (a *AddressField) UnmarshalJSON(bytes []byte) error

func (*AddressField) Validate

func (a *AddressField) Validate(ctx ValidatorContext) (response ValidateResponse)

type AddressValue

type AddressValue struct {
	Value string
}

func (AddressValue) String

func (a AddressValue) String() string

func (*AddressValue) UnmarshalJSON

func (a *AddressValue) UnmarshalJSON(bytes []byte) error

func (*AddressValue) Validate

func (a *AddressValue) Validate(ctx ValidatorContext) (response ValidateResponse)

type AlertTrigger

type AlertTrigger struct{}

func (*AlertTrigger) ToRequest

func (a *AlertTrigger) ToRequest() actions.Trigger

func (*AlertTrigger) Validate

func (a *AlertTrigger) Validate(ctx ValidatorContext) (response ValidateResponse)

type AnyValue

type AnyValue struct {
	Str *string
	Int *IntValue
	Map *MapValue
}

func (*AnyValue) ToRequest

func (a *AnyValue) ToRequest() actions.ComparableAny

func (*AnyValue) UnmarshalJSON

func (a *AnyValue) UnmarshalJSON(bytes []byte) error

type BlockTrigger

type BlockTrigger struct {
	Network NetworkField `yaml:"network"`
	Blocks  int          `yaml:"blocks"`
}

func (*BlockTrigger) ToRequest

func (t *BlockTrigger) ToRequest() actions.Trigger

func (*BlockTrigger) Validate

func (t *BlockTrigger) Validate(ctx ValidatorContext) (response ValidateResponse)

type ContractValue

type ContractValue struct {
	Address    AddressValue `yaml:"address" json:"address"`
	Invocation *string      `yaml:"invocation" json:"invocation"`
}

func (*ContractValue) ToRequest

func (c *ContractValue) ToRequest() actions.ContractReference

func (*ContractValue) Validate

func (c *ContractValue) Validate(ctx ValidatorContext) (response ValidateResponse)

type EthBalanceField

type EthBalanceField struct {
	Values []EthBalanceValue
}

func (*EthBalanceField) ToRequest

func (e *EthBalanceField) ToRequest() (response []actions.EthBalanceFilter)

func (*EthBalanceField) UnmarshalJSON

func (e *EthBalanceField) UnmarshalJSON(bytes []byte) error

func (*EthBalanceField) Validate

func (e *EthBalanceField) Validate(ctx ValidatorContext) (response ValidateResponse)

type EthBalanceValue

type EthBalanceValue struct {
	Value IntValue `yaml:"value" json:"value"`
	// Exactly one of
	Account  *AccountValue  `yaml:"account" json:"account"`
	Contract *ContractValue `yaml:"contract" json:"contract"`
}

func (*EthBalanceValue) ToRequest

func (e *EthBalanceValue) ToRequest() actions.EthBalanceFilter

func (*EthBalanceValue) Validate

func (e *EthBalanceValue) Validate(ctx ValidatorContext) (response ValidateResponse)

type EventEmittedField

type EventEmittedField struct {
	Values []EventEmittedValue
}

func (*EventEmittedField) ToRequest

func (e *EventEmittedField) ToRequest() (response []actions.EventEmittedFilter)

func (*EventEmittedField) UnmarshalJSON

func (e *EventEmittedField) UnmarshalJSON(bytes []byte) error

func (*EventEmittedField) Validate

func (e *EventEmittedField) Validate(ctx ValidatorContext) (response ValidateResponse)

type EventEmittedValue

type EventEmittedValue struct {
	Contract *ContractValue `yaml:"contract" json:"contract"`
	// Exactly one of
	Id   *string `yaml:"id" json:"id"`
	Name *string `yaml:"name" json:"name"`
	// Optional, only with Name
	Parameter *MapValue `yaml:"parameter" json:"parameter"`
}

func (*EventEmittedValue) ToRequest

func (*EventEmittedValue) Validate

func (r *EventEmittedValue) Validate(ctx ValidatorContext) (response ValidateResponse)

type FunctionField

type FunctionField struct {
	Values []FunctionValue
}

func (*FunctionField) ToRequest

func (f *FunctionField) ToRequest() (response []actions.FunctionFilter)

func (*FunctionField) UnmarshalJSON

func (f *FunctionField) UnmarshalJSON(bytes []byte) error

func (*FunctionField) Validate

func (f *FunctionField) Validate(ctx ValidatorContext) (response ValidateResponse)

type FunctionValue

type FunctionValue struct {
	Contract *ContractValue `yaml:"contract" json:"contract"`
	// Exactly one of
	Signature *SignatureValue `yaml:"signature" json:"signature"`
	Name      *string         `yaml:"name" json:"name"`
	// Optional, only with Name
	Parameter *MapValue `yaml:"parameter" json:"parameter"`
}

func (*FunctionValue) ToRequest

func (f *FunctionValue) ToRequest() actions.FunctionFilter

func (*FunctionValue) Validate

func (f *FunctionValue) Validate(ctx ValidatorContext) (response ValidateResponse)

type Hex64 added in v1.3.2

type Hex64 struct {
	Value string
}

func (*Hex64) UnmarshalJSON added in v1.3.2

func (h *Hex64) UnmarshalJSON(bytes []byte) error

func (*Hex64) Validate added in v1.3.2

func (h *Hex64) Validate(ctx ValidatorContext) (response ValidateResponse)

type IntField

type IntField struct {
	Values []IntValue
}

func (*IntField) ToRequest

func (i *IntField) ToRequest() (response []actions.ComparableInt)

func (*IntField) UnmarshalJSON

func (i *IntField) UnmarshalJSON(bytes []byte) error

type IntValue

type IntValue struct {
	GTE *int `yaml:"gte" json:"gte"`
	LTE *int `yaml:"lte" json:"lte"`
	EQ  *int `yaml:"eq"  json:"eq"`
	GT  *int `yaml:"gt"  json:"gt"`
	LT  *int `yaml:"lt"  json:"lt"`
}

func (IntValue) ToRequest

func (v IntValue) ToRequest() actions.ComparableInt

type InternalLocator

type InternalLocator struct {
	Path         string
	FunctionName string
}

func NewInternalLocator

func NewInternalLocator(function string) (*InternalLocator, error)

type LogEmittedField added in v1.3.0

type LogEmittedField struct {
	Values []LogEmittedValue
}

func (*LogEmittedField) ToRequest added in v1.3.0

func (l *LogEmittedField) ToRequest() (response []actions.LogEmittedFilter)

func (*LogEmittedField) UnmarshalJSON added in v1.3.0

func (l *LogEmittedField) UnmarshalJSON(bytes []byte) error

func (*LogEmittedField) Validate added in v1.3.0

func (l *LogEmittedField) Validate(ctx ValidatorContext) (response ValidateResponse)

type LogEmittedValue added in v1.3.0

type LogEmittedValue struct {
	StartsWith []Hex64        `yaml:"startsWith" json:"startsWith"`
	Contract   *ContractValue `yaml:"contract" json:"contract"`
}

func (*LogEmittedValue) ToRequest added in v1.3.0

func (l *LogEmittedValue) ToRequest() actions.LogEmittedFilter

func (*LogEmittedValue) Validate added in v1.3.0

func (l *LogEmittedValue) Validate(ctx ValidatorContext) (response ValidateResponse)

type MapValue

type MapValue struct {
	Key   string   `yaml:"key" json:"key"`
	Value AnyValue `yaml:"value" json:"value"`
}

func (MapValue) ToRequest

func (f MapValue) ToRequest() actions.ComparableMap

type NamedActionSpecs

type NamedActionSpecs map[string]*ActionSpec

NamedActionSpecs is a map from action name to action spec

type NetworkField

type NetworkField struct {
	Value StrField
}

func (*NetworkField) ToRequest

func (n *NetworkField) ToRequest() (response []string)

func (*NetworkField) UnmarshalJSON

func (n *NetworkField) UnmarshalJSON(bytes []byte) error

func (*NetworkField) Validate

func (n *NetworkField) Validate(ctx ValidatorContext) (response ValidateResponse)

type PeriodicTrigger

type PeriodicTrigger struct {
	// One of must be present
	Interval *string `yaml:"interval" json:"interval"`
	Cron     *string `yaml:"cron" json:"cron"`
}

func (*PeriodicTrigger) ToRequest

func (t *PeriodicTrigger) ToRequest() actions.Trigger

func (*PeriodicTrigger) Validate

func (t *PeriodicTrigger) Validate(ctx ValidatorContext) (response ValidateResponse)

type ProjectActions

type ProjectActions struct {
	Runtime      string           `json:"runtime" yaml:"runtime"`
	Sources      string           `json:"sources" yaml:"sources"`
	Dependencies *string          `json:"dependencies,omitempty" yaml:"dependencies,omitempty"`
	Specs        NamedActionSpecs `json:"specs" yaml:"specs"`
}

func (*ProjectActions) ToRequest

func (s *ProjectActions) ToRequest(sources map[string]string) map[string]actions.ActionSpec

type SignatureValue

type SignatureValue struct {
	Value string
}

func (SignatureValue) String

func (s SignatureValue) String() string

func (*SignatureValue) UnmarshalJSON

func (s *SignatureValue) UnmarshalJSON(bytes []byte) error

func (*SignatureValue) Validate

func (s *SignatureValue) Validate(ctx ValidatorContext) (response ValidateResponse)

type StateChangedField

type StateChangedField struct {
	Values []StateChangedValue
}

func (*StateChangedField) ToRequest

func (s *StateChangedField) ToRequest() (response []actions.StateChangedFilter)

func (*StateChangedField) UnmarshalJSON

func (s *StateChangedField) UnmarshalJSON(bytes []byte) error

func (*StateChangedField) Validate

func (s *StateChangedField) Validate(ctx ValidatorContext) (response ValidateResponse)

type StateChangedValue

type StateChangedValue struct {
	Contract *ContractValue `yaml:"contract" json:"contract"`
	// Exactly one of
	Key   *string `yaml:"key" json:"key"`
	Field *string `yaml:"field" json:"field"`
	// At most one of, only with Field
	// If none, any state changed at given key is considered
	Value         *AnyValue `yaml:"value" json:"value"`
	PreviousValue *AnyValue `yaml:"previousValue" json:"previousValue"`
}

func (*StateChangedValue) ToRequest

func (*StateChangedValue) Validate

func (r *StateChangedValue) Validate(ctx ValidatorContext) (response ValidateResponse)

type StatusField

type StatusField struct {
	Value StrField
}

func (*StatusField) ToRequest

func (s *StatusField) ToRequest() (response []actions.Status)

func (*StatusField) UnmarshalJSON

func (s *StatusField) UnmarshalJSON(bytes []byte) error

func (*StatusField) Validate

func (s *StatusField) Validate(ctx ValidatorContext) (response ValidateResponse)

type StrField

type StrField struct {
	Values []string
}

func (*StrField) Lower

func (s *StrField) Lower()

func (*StrField) ToRequest

func (s *StrField) ToRequest() (response []actions.ComparableStr)

func (*StrField) UnmarshalJSON

func (s *StrField) UnmarshalJSON(bytes []byte) error

type Template

type Template struct {
	Files []string      `yaml:"files"`
	Args  []TemplateArg `yaml:"args"`
	// contains filtered or unexported fields
}

func LoadTemplate

func LoadTemplate(ctx context.Context, templateName string) (*Template, error)

func (*Template) Create

func (t *Template) Create(ctx context.Context, destinationDir string, args map[string]string) error

func (*Template) LoadSpecs

func (t *Template) LoadSpecs(ctx context.Context, args map[string]string) (map[string]*ActionSpec, error)

type TemplateArg

type TemplateArg struct {
	Name        string `yaml:"name"`
	Description string `yaml:"description"`
}

type TransactionFilter

type TransactionFilter struct {
	Network *NetworkField `yaml:"network" json:"network"`
	Status  *StatusField  `yaml:"status" json:"status"`

	From *AddressField `yaml:"from" json:"from"`
	To   *AddressField `yaml:"to" json:"to"`

	Value *IntField `yaml:"value" json:"value"`

	GasLimit *IntField `yaml:"gasLimit" json:"gasLimit"`
	GasUsed  *IntField `yaml:"gasUsed" json:"gasUsed"`

	Fee *IntField `yaml:"fee" json:"fee"`

	// If set, applies to all underlying fields that need contract, but those can override this one
	Contract *ContractValue `yaml:"contract" json:"contract"`

	Function     *FunctionField     `yaml:"function" json:"function"`
	EventEmitted *EventEmittedField `yaml:"eventEmitted" json:"eventEmitted"`
	LogEmitted   *LogEmittedField   `yaml:"logEmitted" json:"logEmitted"`

	EthBalance   *EthBalanceField   `yaml:"ethBalance" json:"ethBalance"`
	StateChanged *StateChangedField `yaml:"stateChanged" json:"stateChanged"`
}

func (*TransactionFilter) ToRequest

func (t *TransactionFilter) ToRequest() (response actions.Filter)

func (*TransactionFilter) Validate

func (t *TransactionFilter) Validate(ctx ValidatorContext) (response ValidateResponse)

type TransactionStatus

type TransactionStatus struct {
	Value StrField
}

func (*TransactionStatus) ToRequest

func (s *TransactionStatus) ToRequest() (response []actions.TransactionStatus)

func (*TransactionStatus) UnmarshalJSON

func (s *TransactionStatus) UnmarshalJSON(bytes []byte) error

func (*TransactionStatus) Validate

func (s *TransactionStatus) Validate(ctx ValidatorContext) (response ValidateResponse)

type TransactionTrigger

type TransactionTrigger struct {
	Status  TransactionStatus   `yaml:"status" json:"status"`
	Filters []TransactionFilter `yaml:"filters" json:"filters"`
}

func (*TransactionTrigger) ToRequest

func (t *TransactionTrigger) ToRequest() actions.Trigger

func (*TransactionTrigger) Validate

func (t *TransactionTrigger) Validate(ctx ValidatorContext) (response ValidateResponse)

type Trigger

type Trigger struct {
	Type        string              `json:"type" yaml:"type"`
	Periodic    *PeriodicTrigger    `json:"periodic" yaml:"periodic,omitempty"`
	Webhook     *WebhookTrigger     `json:"webhook" yaml:"webhook,omitempty"`
	Block       *BlockTrigger       `json:"block" yaml:"block,omitempty"`
	Transaction *TransactionTrigger `json:"transaction" yaml:"transaction,omitempty"`
	Alert       *AlertTrigger       `json:"alert" yaml:"alert,omitempty"`
}

func (Trigger) ToRequest

func (a Trigger) ToRequest() *actions.Trigger

func (Trigger) ToRequestType

func (a Trigger) ToRequestType() actions.TriggerType

func (Trigger) Validate

func (a Trigger) Validate(ctx ValidatorContext) (response ValidateResponse)

type TriggerUnparsed

type TriggerUnparsed struct {
	Type        string      `json:"type" yaml:"type"`
	Block       interface{} `json:"block,omitempty" yaml:"block,omitempty"`
	Webhook     interface{} `json:"webhook,omitempty" yaml:"webhook,omitempty"`
	Periodic    interface{} `json:"periodic,omitempty" yaml:"periodic,omitempty"`
	Transaction interface{} `json:"transaction,omitempty" yaml:"transaction,omitempty"`
	Alert       interface{} `json:"alert,omitempty" yaml:"alert,omitempty"`
}

type ValidateResponse

type ValidateResponse struct {
	Infos  []string
	Errors []string
}

func (*ValidateResponse) Error

func (v *ValidateResponse) Error(c ValidatorContext, msg string, args ...interface{}) ValidateResponse

func (*ValidateResponse) Info

func (v *ValidateResponse) Info(c ValidatorContext, msg string, args ...interface{}) ValidateResponse

func (*ValidateResponse) Merge

type Validator

type Validator interface {
	Validate(ValidatorContext) (response ValidateResponse)
}

type ValidatorContext

type ValidatorContext string

func (ValidatorContext) With

func (c ValidatorContext) With(element string) ValidatorContext

type WebhookTrigger

type WebhookTrigger struct {
	Authenticated *bool `yaml:"authenticated" json:"authenticated"`
}

func (*WebhookTrigger) ToRequest

func (t *WebhookTrigger) ToRequest() actions.Trigger

func (*WebhookTrigger) Validate

func (t *WebhookTrigger) Validate(ctx ValidatorContext) (response ValidateResponse)

Jump to

Keyboard shortcuts

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