fulfillment

package
v1.10.21-0...-c669c00 Latest Latest
Warning

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

Go to latest
Published: Nov 21, 2025 License: MIT Imports: 7 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

View Source
var (
	ErrFulfillmentNotFound = errors.New("no fulfillment could be found")
	ErrFulfillmentExists   = errors.New("fulfillment exists")
	ErrStaleVersion        = errors.New("fulfillment version is stale")
)

Functions

This section is empty.

Types

type BySchedulingOrder

type BySchedulingOrder []*Record

func (BySchedulingOrder) Len

func (a BySchedulingOrder) Len() int

func (BySchedulingOrder) Less

func (a BySchedulingOrder) Less(i, j int) bool

func (BySchedulingOrder) Swap

func (a BySchedulingOrder) Swap(i, j int)

type Record

type Record struct {
	Id uint64

	Intent     string
	IntentType intent.Type

	ActionId   uint32
	ActionType action.Type

	FulfillmentType Type
	Data            []byte
	Signature       *string

	Nonce     *string
	Blockhash *string

	// todo: For virtual instructions, assumes a single one per fulfillment.
	//       We'll need new modelling when we get around to batching virtual
	//       instructions, but we're starting with the easiest implementation.
	VirtualSignature *string
	VirtualNonce     *string
	VirtualBlockhash *string

	Source      string  // Source token account involved in the transaction
	Destination *string // Destination token account involved in the transaction, when it makes sense (eg. transfers)

	// Metadata required to pre-sort fulfillments for scheduling
	//
	// This is a 3-tiered sorting heurstic. At each tier, f1 < f2 when index1 < index2.
	// We move down in tiers when the current level tier matches. The order of tiers is
	// intent, then action, then fullfillment.
	IntentOrderingIndex      uint64 // Typically, but not always, the FK to the intent ID
	ActionOrderingIndex      uint32 // Typically, but not always, the FK of the action ID
	FulfillmentOrderingIndex uint32

	// Does the fulfillment worker poll for this record? If true, it's up to other
	// systems to hint as to when polling can occur. This is primarily an optimization
	// to reduce redundant processing. This doesn't affect correctness of scheduling
	// (eg. depedencies), so accidentally making some actively scheduled is ok.
	DisableActiveScheduling bool

	State State

	Version uint64

	CreatedAt time.Time
}

func (*Record) Clone

func (r *Record) Clone() Record

func (*Record) CopyTo

func (r *Record) CopyTo(dst *Record)

func (*Record) IsFulfilled

func (r *Record) IsFulfilled() bool

func (*Record) ScheduledBefore

func (r *Record) ScheduledBefore(other *Record) bool

func (*Record) Validate

func (r *Record) Validate() error

type State

type State uint8
const (
	StateUnknown   State = iota // not scheduled
	StatePending                // submitted to the solana network
	StateRevoked                // tx not submitted and revoked
	StateConfirmed              // tx confirmed
	StateFailed                 // tx failed
)

func (State) IsTerminal

func (s State) IsTerminal() bool

func (State) String

func (s State) String() string

type Store

type Store interface {
	// Count returns the total count of fulfillment records.
	Count(ctx context.Context) (uint64, error)

	// Count returns the total count of fulfillments in the provided state.
	CountByState(ctx context.Context, state State) (uint64, error)

	// CountByStateGroupedByType returns the total count of fulfillments, grouped
	// by type, in the provided state.
	CountByStateGroupedByType(ctx context.Context, state State) (map[Type]uint64, error)

	// CountForMetrics is like CountByStateGroupedByType for metrics. Partial data may be provided.
	CountForMetrics(ctx context.Context, state State) (map[Type]uint64, error)

	// CountByStateAndAddress returns the total count of fulfillments for the provided account and state.
	CountByStateAndAddress(ctx context.Context, state State, address string) (uint64, error)

	// CountByStateAndAddress returns the total count of fulfillments for the provided type, state and account (as a source an destination).
	CountByTypeStateAndAddress(ctx context.Context, fulfillmentType Type, state State, address string) (uint64, error)

	// CountByStateAndAddress returns the total count of fulfillments for the provided type, state and account as a source.
	CountByTypeStateAndAddressAsSource(ctx context.Context, fulfillmentType Type, state State, address string) (uint64, error)

	// Count returns the total count of fulfillments for the provided intent and state.
	CountByIntentAndState(ctx context.Context, intent string, state State) (uint64, error)

	// Count returns the total count of fulfillments for the provided intent.
	CountByIntent(ctx context.Context, intent string) (uint64, error)

	// CountByTypeActionAndState returns the total count of fulfillments with a
	// given type, action and state.
	CountByTypeActionAndState(ctx context.Context, intentId string, actionId uint32, fulfillmentType Type, state State) (uint64, error)

	// CountPendingByType gets the count of pending transactions by type.
	// This is particularly useful for estimating fees that will be consumed
	// by our subsidizer.
	CountPendingByType(ctx context.Context) (map[Type]uint64, error)

	// PutAll creates all fulfillments in one transaction
	PutAll(ctx context.Context, records ...*Record) error

	// Update updates an existing fulfillment record
	//
	// Note 1: Updating pre-sorting metadata is allowed but limited to certain fulfillment types
	Update(ctx context.Context, record *Record) error

	// GetById find the fulfillment recofd for a given ID
	GetById(ctx context.Context, id uint64) (*Record, error)

	// GetBySignature finds the fulfillment record for a given signature.
	GetBySignature(ctx context.Context, signature string) (*Record, error)

	// GetByVirtualSignature finds the fulfillment record for a given virtual signature.
	GetByVirtualSignature(ctx context.Context, signature string) (*Record, error)

	// GetAllByState returns all fulfillment records for a given state.
	//
	// Returns ErrNotFound if no records are found.
	GetAllByState(ctx context.Context, state State, includeDisabledActiveScheduling bool, cursor query.Cursor, limit uint64, direction query.Ordering) ([]*Record, error)

	// GetAllByIntent returns all fulfillment records for a given intent.
	//
	// Returns ErrNotFound if no records are found.
	GetAllByIntent(ctx context.Context, intent string, cursor query.Cursor, limit uint64, direction query.Ordering) ([]*Record, error)

	// GetAllByAction returns all fulfillment records for a given action
	//
	// Returns ErrNotFound if no records are found.
	GetAllByAction(ctx context.Context, intentId string, actionId uint32) ([]*Record, error)

	// GetAllByTypeAndAction returns all fulfillment records for a given type and action
	//
	// Returns ErrNotFound if no records are found.
	GetAllByTypeAndAction(ctx context.Context, fulfillmentType Type, intentId string, actionId uint32) ([]*Record, error)

	// GetFirstSchedulableByAddressAsSource returns the earliest fulfillment
	// that can be scheduled for an account as a source given the total ordering
	// of all fulfillments.
	//
	// Returns ErrNotFound if no records are found.
	GetFirstSchedulableByAddressAsSource(ctx context.Context, address string) (*Record, error)

	// GetFirstSchedulableByAddressAsDestination returns the earliest fulfillment
	// that can be scheduled for an account as a destination given the total ordering
	// of all fulfillments.
	//
	// Returns ErrNotFound if no records are found.
	GetFirstSchedulableByAddressAsDestination(ctx context.Context, address string) (*Record, error)

	// GetFirstSchedulableByType returns the earliest fulfillment that can be scheduled
	// for fulfillments of the provided type.
	//
	// Returns ErrNotFound if no records are found.
	GetFirstSchedulableByType(ctx context.Context, fulfillmentType Type) (*Record, error)

	// GetNextSchedulableByAddress gets the next schedulable fulfillment for an account after
	// a point in time defined by ordering indices.
	//
	// Returns ErrNotFound if no records are found.
	GetNextSchedulableByAddress(ctx context.Context, address string, intentOrderingIndex uint64, actionOrderingIndex, fulfillmentOrderingIndex uint32) (*Record, error)
}

type Type

type Type uint8
const (
	UnknownType Type = iota
	InitializeLockedTimelockAccount
	NoPrivacyTransferWithAuthority
	NoPrivacyWithdraw
	TemporaryPrivacyTransferWithAuthority // Deprecated privacy flow
	PermanentPrivacyTransferWithAuthority // Deprecated privacy flow
	TransferWithCommitment                // Deprecated privacy flow
	CloseEmptyTimelockAccount             // Technically a compression with the new VM flows
	CloseDormantTimelockAccount           // Deprecated by the VM
	SaveRecentRoot                        // Deprecated privacy flow
	InitializeCommitmentProof             // Deprecated with new VM flows
	UploadCommitmentProof                 // Deprecated with new VM flows
	VerifyCommitmentProof                 // Deprecated with new VM flows
	OpenCommitmentVault                   // Deprecated with new VM flows
	CloseCommitment                       // Deprecated privacy flow
)

func (Type) String

func (s Type) String() string

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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