execution

package
v0.0.0-...-22b4465 Latest Latest
Warning

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

Go to latest
Published: Sep 28, 2026 License: Apache-2.0, MIT Imports: 11 Imported by: 0

Documentation

Index

Constants

View Source
const ExecutionFailureErrorName = "ExecutionFailure"
View Source
const HandlerExecutionErrorName = "HandlerExecutionError"
View Source
const InvalidAudienceErrorName = "InvalidAudience"

Variables

This section is empty.

Functions

func NewExecutionFailureError

func NewExecutionFailureError(cmd ucan.Command) error

NewExecutionFailureError is the failure a receipt carries when executing the invocation panicked, in the handler or in validation code such as a DID resolver or verifier factory. The receipt says only that execution failed; the panic value and the fact that it was a panic stay on the server.

func NewHandlerExecutionError

func NewHandlerExecutionError(cmd ucan.Command, cause error) error

func NewInvalidAudienceError

func NewInvalidAudienceError(expected did.DID, actual did.DID) error

Types

type ExecRequest

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

func NewRequest

func NewRequest(ctx context.Context, inv ucan.Invocation, options ...RequestOption) *ExecRequest

func (*ExecRequest) Context

func (r *ExecRequest) Context() context.Context

func (*ExecRequest) Invocation

func (r *ExecRequest) Invocation() ucan.Invocation

func (*ExecRequest) Metadata

func (r *ExecRequest) Metadata() ucan.Container

type ExecResponse

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

func NewResponse

func NewResponse(task cid.Cid, options ...ResponseOption) (*ExecResponse, error)

NewResponse creates a new response object, representing the result of executing a task.

func (*ExecResponse) Metadata

func (r *ExecResponse) Metadata() ucan.Container

func (*ExecResponse) Receipt

func (r *ExecResponse) Receipt() ucan.Receipt

func (*ExecResponse) SetFailure

func (r *ExecResponse) SetFailure(x error) error

func (*ExecResponse) SetIssuer

func (r *ExecResponse) SetIssuer(issuer ucan.Issuer) error

func (*ExecResponse) SetMetadata

func (r *ExecResponse) SetMetadata(meta ucan.Container) error

func (*ExecResponse) SetReceipt

func (r *ExecResponse) SetReceipt(receipt ucan.Receipt) error

func (*ExecResponse) SetSuccess

func (r *ExecResponse) SetSuccess(ok cbg.CBORMarshaler) error

type Executor

type Executor interface {
	Execute(Request) (Response, error)
}

Executor executes UCAN invocations. In order to execute an invocation, proof chains must be validated and delegation policies matched. Hence a UCAN executor is responsible for both validation and execution of invocations.

type HandlerFunc

type HandlerFunc = func(Request, Response) error

HandlerFunc is a function that can handle a specific UCAN invocation.

A server calls handlers concurrently: across requests, as any HTTP handler, and within one request, since the invocations of a batch execute at the same time. A handler must not rely on another invocation of the same request having run before it, and any state it shares needs its own locking.

type Request

type Request interface {
	Context() context.Context
	// Invocation that should be executed.
	Invocation() ucan.Invocation
	// Metadata provides additional information about the invocation.
	Metadata() ucan.Container
}

type RequestOption

type RequestOption = func(cfg *requestConfig)

func WithDelegations

func WithDelegations(delegations ...ucan.Delegation) RequestOption

WithDelegations adds delegations to the execution request. They should be linked from the invocation to be executed.

func WithInvocations

func WithInvocations(invocations ...ucan.Invocation) RequestOption

WithInvocations adds additional invocations to the execution request.

func WithReceipts

func WithReceipts(receipts ...ucan.Receipt) RequestOption

WithReceipts adds receipts to the execution request.

func WithRequestMetadata

func WithRequestMetadata(metadata ucan.Container) RequestOption

WithRequestMetadata sets a ready-made container as the request metadata, so an executor running many invocations against the same tokens builds the container once and shares it.

The container is shared by every request it is passed to, and container.Container returns its internal slices. Handlers must treat the metadata as read-only and clone a slice before modifying it.

Tokens given through WithInvocations, WithDelegations and WithReceipts are merged into a new container after the tokens of this one, de-duplicated by CID. The given container is used as is only when no token option is passed.

type Response

type Response interface {
	// Receipt for the executed task.
	Receipt() ucan.Receipt
	// SetReceipt sets the receipt for the executed task.
	SetReceipt(ucan.Receipt) error
	// SetSuccess issues a receipt with a successful result for the executed
	// task and sets it on the response. The ok value is any
	// cborgen-marshalable type whose schema matches what the task expects to
	// produce.
	SetSuccess(ok cbg.CBORMarshaler) error
	// SetFailure issues a receipt with a failure result for the executed task
	// and sets it on the response.
	SetFailure(error) error
	// Metadata provides additional information about the response.
	Metadata() ucan.Container
	// SetMetadata sets additional information about the response.
	SetMetadata(ucan.Container) error
}

type ResponseOption

type ResponseOption func(r *ExecResponse) error

func WithFailure

func WithFailure(x error) ResponseOption

WithFailure issues and sets a receipt for a failed execution of a task.

func WithIssuer

func WithIssuer(issuer ucan.Issuer) ResponseOption

func WithMetadata

func WithMetadata(m ucan.Container) ResponseOption

func WithReceipt

func WithReceipt(receipt ucan.Receipt) ResponseOption

func WithReceiptExpiration

func WithReceiptExpiration(exp ucan.UnixTimestamp) ResponseOption

WithReceiptExpiration configures the response to issue receipts with the given expiration. Note: this option should be ordered before WithSuccess or WithFailure, since these options issue a receipt.

func WithReceiptTimestamp

func WithReceiptTimestamp(enabled bool) ResponseOption

WithReceiptTimestamp configures the response to issue receipts with issuance timestamps. Note: this option should be ordered before WithSuccess or WithFailure, since these options issue a receipt.

func WithSuccess

func WithSuccess(o cbg.CBORMarshaler) ResponseOption

WithSuccess issues and sets a receipt for a successful execution of a task.

Directories

Path Synopsis
Package batch executes many UCAN invocations in one round trip.
Package batch executes many UCAN invocations in one round trip.

Jump to

Keyboard shortcuts

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