functions

package
v2.8.1-mercury-20240123 Latest Latest
Warning

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

Go to latest
Published: Jan 23, 2024 License: MIT Imports: 33 Imported by: 1

Documentation

Index

Constants

View Source
const (
	MethodSecretsSet  = "secrets_set"
	MethodSecretsList = "secrets_list"
	MethodHeartbeat   = "heartbeat"
)

Variables

View Source
var (
	ErrNotAllowlisted    = errors.New("sender not allowlisted")
	ErrRateLimited       = errors.New("rate-limited")
	ErrUnsupportedMethod = errors.New("unsupported method")
)
View Source
var (
	ErrInvalidParameters = errors.New("invalid parameters provided to create a subscription cache ORM")
)
View Source
var ErrUserHasNoSubscription = errors.New("user has no subscriptions")

Functions

func NewFunctionsHandler

func NewFunctionsHandler(
	cfg FunctionsHandlerConfig,
	donConfig *config.DONConfig,
	don handlers.DON,
	pendingRequestsCache hc.RequestCache[PendingRequest],
	allowlist OnchainAllowlist,
	subscriptions OnchainSubscriptions,
	minimumBalance *assets.Link,
	userRateLimiter *hc.RateLimiter,
	nodeRateLimiter *hc.RateLimiter,
	allowedHeartbeatInitiators map[string]struct{},
	lggr logger.Logger) handlers.Handler

func NewFunctionsHandlerFromConfig added in v2.4.0

func NewFunctionsHandlerFromConfig(handlerConfig json.RawMessage, donConfig *config.DONConfig, don handlers.DON, legacyChains legacyevm.LegacyChainContainer, db *sqlx.DB, qcfg pg.QConfig, lggr logger.Logger) (handlers.Handler, error)

Types

type CachedSubscription

type CachedSubscription struct {
	SubscriptionID uint64
	functions_router.IFunctionsSubscriptionsSubscription
}

CachedSubscription is used to populate the user subscription maps from a persistent layer like postgres.

type CombinedResponse added in v2.8.0

type CombinedResponse struct {
	ResponseBase
	NodeResponses []*api.Message `json:"node_responses"`
}

Gateway -> User response, which combines responses from several nodes

type FunctionsHandlerConfig

type FunctionsHandlerConfig struct {
	ChainID string `json:"chainId"`
	// Not specifying OnchainAllowlist config disables allowlist checks
	OnchainAllowlist *OnchainAllowlistConfig `json:"onchainAllowlist"`
	// Not specifying OnchainSubscriptions config disables minimum balance checks
	OnchainSubscriptions       *OnchainSubscriptionsConfig `json:"onchainSubscriptions"`
	MinimumSubscriptionBalance *assets.Link                `json:"minimumSubscriptionBalance"`
	// Not specifying RateLimiter config disables rate limiting
	UserRateLimiter            *hc.RateLimiterConfig `json:"userRateLimiter"`
	NodeRateLimiter            *hc.RateLimiterConfig `json:"nodeRateLimiter"`
	MaxPendingRequests         uint32                `json:"maxPendingRequests"`
	RequestTimeoutMillis       int64                 `json:"requestTimeoutMillis"`
	AllowedHeartbeatInitiators []string              `json:"allowedHeartbeatInitiators"`
}

type ORM

type ORM interface {
	GetSubscriptions(offset, limit uint, qopts ...pg.QOpt) ([]CachedSubscription, error)
	UpsertSubscription(subscription CachedSubscription, qopts ...pg.QOpt) error
}

func NewORM

func NewORM(db *sqlx.DB, lggr logger.Logger, cfg pg.QConfig, routerContractAddress common.Address) (ORM, error)

type OnchainAllowlist

type OnchainAllowlist interface {
	job.ServiceCtx

	Allow(common.Address) bool
	UpdateFromContract(ctx context.Context) error
}

OnchainAllowlist maintains an allowlist of addresses fetched from the blockchain (EVM-only). Use UpdateFromContract() for a one-time update or set OnchainAllowlistConfig.UpdateFrequencySec for repeated updates. All methods are thread-safe.

func NewOnchainAllowlist

func NewOnchainAllowlist(client evmclient.Client, config OnchainAllowlistConfig, lggr logger.Logger) (OnchainAllowlist, error)

type OnchainAllowlistConfig added in v2.4.0

type OnchainAllowlistConfig struct {
	// ContractAddress is required
	ContractAddress    common.Address `json:"contractAddress"`
	ContractVersion    uint32         `json:"contractVersion"`
	BlockConfirmations uint           `json:"blockConfirmations"`
	// UpdateFrequencySec can be zero to disable periodic updates
	UpdateFrequencySec uint `json:"updateFrequencySec"`
	UpdateTimeoutSec   uint `json:"updateTimeoutSec"`
}

type OnchainSubscriptions added in v2.6.0

type OnchainSubscriptions interface {
	job.ServiceCtx

	// GetMaxUserBalance returns a maximum subscription balance (juels), or error if user has no subscriptions.
	GetMaxUserBalance(common.Address) (*big.Int, error)
}

OnchainSubscriptions maintains a mirror of all subscriptions fetched from the blockchain (EVM-only). All methods are thread-safe.

func NewOnchainSubscriptions added in v2.6.0

func NewOnchainSubscriptions(client evmclient.Client, config OnchainSubscriptionsConfig, orm ORM, lggr logger.Logger) (OnchainSubscriptions, error)

type OnchainSubscriptionsConfig added in v2.6.0

type OnchainSubscriptionsConfig struct {
	ContractAddress    common.Address `json:"contractAddress"`
	BlockConfirmations uint           `json:"blockConfirmations"`
	UpdateFrequencySec uint           `json:"updateFrequencySec"`
	UpdateTimeoutSec   uint           `json:"updateTimeoutSec"`
	UpdateRangeSize    uint           `json:"updateRangeSize"`
	CacheBatchSize     uint           `json:"cacheBatchSize"`
}

type PendingRequest added in v2.8.0

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

type ResponseBase added in v2.8.0

type ResponseBase struct {
	Success      bool   `json:"success"`
	ErrorMessage string `json:"error_message,omitempty"`
}

type SecretsListResponse added in v2.4.0

type SecretsListResponse struct {
	ResponseBase
	Rows []SecretsListRow `json:"rows,omitempty"`
}

type SecretsListRow added in v2.4.0

type SecretsListRow struct {
	SlotID     uint   `json:"slot_id"`
	Version    uint64 `json:"version"`
	Expiration int64  `json:"expiration"`
}

type SecretsSetRequest added in v2.4.0

type SecretsSetRequest struct {
	SlotID     uint   `json:"slot_id"`
	Version    uint64 `json:"version"`
	Expiration int64  `json:"expiration"`
	Payload    []byte `json:"payload"`
	Signature  []byte `json:"signature"`
}

type SecretsSetResponse added in v2.4.0

type SecretsSetResponse struct {
	ResponseBase
}

type UserSubscriptions added in v2.6.0

type UserSubscriptions interface {
	UpdateSubscription(subscriptionId uint64, subscription *functions_router.IFunctionsSubscriptionsSubscription) bool
	GetMaxUserBalance(user common.Address) (*big.Int, error)
}

func NewUserSubscriptions added in v2.6.0

func NewUserSubscriptions() UserSubscriptions

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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