Help us shape the future of Go! Take the 2026 Go Developer Survey

interpreter

package
v0.1.2 Latest Latest
Warning

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

Go to latest
Published: Oct 9, 2026 License: MIT Imports: 13 Imported by: 0

Documentation

Index

Constants

View Source
const KEPT_ADDR = "<kept>"

Variables

View Source
var ErrScalingNotSupported = errors.New("scaling is not supported")

Functions

func CompareBalances added in v0.0.19

func CompareBalances(b1 Balances, b2 Balances) bool

func CompareBalancesIncluding added in v0.0.20

func CompareBalancesIncluding(b1 Balances, b2 Balances) bool

Returns whether the first value is a subset of the second one.

func CompareSetAccountsMetadata added in v0.0.25

func CompareSetAccountsMetadata(a SetAccountsMetadata, b SetAccountsMetadata) bool

CompareSetAccountsMetadata reports whether two lists hold the same rows, ignoring order but respecting multiplicity (so [x, x] != [x, y]).

func MetaString added in v0.0.25

func MetaString(v Value) string

MetaString renders v as it appears in the metadata wire format: the value written the way it would be in source, with no added delimiters. This is deliberately not String(): String() delimits values so a reader can tell them apart (it quotes strings and writes accounts as @name), which suits diagnostics, but the metadata format is untyped by design — a value is stored as its rendered text and compared as that text, so e.g. set_tx_meta("k", "42") and set_tx_meta("k", 42) are indistinguishable here.

An account value is rendered as its bare name, dropping any scope. Nothing is lost in practice: a scoped account cannot reach metadata at all, since setTxMeta and setAccountMeta both reject one via rejectScopedAccountMeta — the panic below is a last-resort check on that invariant, not a real error path.

func NewAccountAddress added in v0.0.12

func NewAccountAddress(src string) (AccountAddress, InterpreterError)

func NewArgsParser

func NewArgsParser(args []Value) *argsParser

func NewAsset added in v0.0.21

func NewAsset(src string) (Asset, InterpreterError)

func PrettyPrintMeta added in v0.0.19

func PrettyPrintMeta(meta Metadata) string

func PrettyPrintPostings added in v0.0.19

func PrettyPrintPostings(postings []Posting) string

func RunProgram

func RunProgram(
	ctx context.Context,
	program parser.Program,
	vars map[string]string,
	store Store,
	featureFlags map[string]struct{},
) (*ExecutionResult, InterpreterError)

Types

type AccountAddress

type AccountAddress struct {
	Name  string
	Scope string
}

AccountAddress is an account, optionally partitioned by a scope. The scope is a separate dimension of the account rather than part of its name, so it is modeled as its own field instead of being encoded into the name string.

func (AccountAddress) String

func (v AccountAddress) String() string

type AccountBalance

type AccountBalance = funds.AccountBalance

AccountBalance is a single (asset, color, amount) balance entry for an account.

type AccountDependency added in v0.0.25

type AccountDependency struct {
	Account string
	Scope   string
	Color   string
	Asset   string
}

type AccountMetadataRow added in v0.0.25

type AccountMetadataRow struct {
	Account string `json:"account"`
	Key     string `json:"key"`
	Value   string `json:"value"`
	Scope   string `json:"scope,omitempty"`
}

type AccountsMetadata

type AccountsMetadata []AccountMetadataRow

AccountsMetadata is the external, serialized representation of account metadata. The runtime works with the in-memory InternalAccountsMetadata and converts to this at the boundaries (store queries, execution result).

func (AccountsMetadata) FirstDuplicate added in v0.0.25

func (rows AccountsMetadata) FirstDuplicate() (AccountMetadataRow, bool)

FirstDuplicate returns the first row whose (account, key, scope) key already appeared earlier in the list, if any. That triple is the identity of a metadata entry and the value is its content, so a repeated key is an ambiguous, malformed input.

func (AccountsMetadata) PrettyPrint added in v0.0.19

func (m AccountsMetadata) PrettyPrint() string

type Asset

type Asset string

func (Asset) String

func (v Asset) String() string

type BadArityErr

type BadArityErr struct {
	parser.Range
	ExpectedArity  int
	GivenArguments int
}

func (BadArityErr) Error

func (e BadArityErr) Error() string

type BadPortionParsingErr added in v0.0.10

type BadPortionParsingErr struct {
	parser.Range
	Source string
	Reason string
}

func (BadPortionParsingErr) Error added in v0.0.10

func (e BadPortionParsingErr) Error() string

type BalanceQuery

type BalanceQuery []BalanceQueryItem

type BalanceQueryItem added in v0.0.25

type BalanceQueryItem struct {
	Account string
	Asset   string
	Color   string
	Scope   string
}

For each account, list of the needed assets

type BalanceRow added in v0.0.25

type BalanceRow struct {
	Account string   `json:"account"`
	Asset   string   `json:"asset"`
	Amount  *big.Int `json:"amount"`
	Color   string   `json:"color,omitempty"`
	Scope   string   `json:"scope,omitempty"`
}

type Balances

type Balances []BalanceRow

func (Balances) FirstDuplicate added in v0.0.25

func (rows Balances) FirstDuplicate() (BalanceRow, bool)

FirstDuplicate returns the first row whose (account, asset, color) key already appeared earlier in the list, if any. That triple is the identity of a balance entry and the amount is its value, so a repeated key is an ambiguous, malformed input.

func (Balances) PrettyPrint added in v0.0.19

func (rows Balances) PrettyPrint() string

type CannotCastScopedAccountToString added in v0.0.25

type CannotCastScopedAccountToString struct {
	parser.Range
	Account string
	Scope   string
}

func (CannotCastScopedAccountToString) Error added in v0.0.25

type CannotCastToString added in v0.0.12

type CannotCastToString struct {
	parser.Range
	Value Value
}

func (CannotCastToString) Error added in v0.0.12

func (e CannotCastToString) Error() string

type CannotStoreScopedAccountInMeta added in v0.0.25

type CannotStoreScopedAccountInMeta struct {
	parser.Range
	Account string
	Scope   string
}

func (CannotStoreScopedAccountInMeta) Error added in v0.0.25

type DivideByZero added in v0.0.11

type DivideByZero struct {
	parser.Range
	Numerator *big.Int
}

func (DivideByZero) Error added in v0.0.11

func (e DivideByZero) Error() string

type ExecutionResult

type ExecutionResult struct {
	Postings []Posting `json:"postings"`

	Metadata Metadata `json:"txMeta"`

	AccountsMetadata SetAccountsMetadata `json:"accountsMeta"`
}

type ExperimentalFeature added in v0.0.10

type ExperimentalFeature struct {
	parser.Range
	FlagName string
}

func (ExperimentalFeature) Error added in v0.0.10

func (e ExperimentalFeature) Error() string

type InternalAccountsMetadata added in v0.0.25

type InternalAccountsMetadata map[AccountAddress]map[string]string

An internal representation of the account metadata. Used to cache metadata we get from external store. Whereas the external representation (interpreter.AccountsMetadata) is user-facing and a stable contract, this one is used internally by the runtime, and could change over time, for example to add more indexes for faster lookups. It is keyed by the (account, scope) pair, holding that account's (key -> value) entries.

func (InternalAccountsMetadata) Get added in v0.0.25

func (m InternalAccountsMetadata) Get(account AccountAddress, key string) (string, bool)

Get the (account, key) metadata value from the cache.

func (InternalAccountsMetadata) Merge added in v0.0.25

Merge the queried metadata rows into the cache.

func (InternalAccountsMetadata) Set added in v0.0.25

func (m InternalAccountsMetadata) Set(account AccountAddress, key string, value string)

Set assigns value to the (account, key) metadata entry.

type InternalError added in v0.0.21

type InternalError struct {
	parser.Range
	Posting Posting
}

func (InternalError) Error added in v0.0.21

func (e InternalError) Error() string

type InterpreterError

type InterpreterError interface {
	error
	parser.Ranged
}

func ParsePortionSpecific added in v0.0.10

func ParsePortionSpecific(input string) (*big.Rat, InterpreterError)

type InvalidAccountName added in v0.0.12

type InvalidAccountName struct {
	parser.Range
	Name string
}

func (InvalidAccountName) Error added in v0.0.12

func (e InvalidAccountName) Error() string

type InvalidAllotmentInSendAll

type InvalidAllotmentInSendAll struct {
	parser.Range
}

func (InvalidAllotmentInSendAll) Error

type InvalidAllotmentSum

type InvalidAllotmentSum struct {
	parser.Range
	ActualSum big.Rat
}

func (InvalidAllotmentSum) Error

func (e InvalidAllotmentSum) Error() string

type InvalidAsset added in v0.0.21

type InvalidAsset struct {
	parser.Range
	Name string
}

func (InvalidAsset) Error added in v0.0.21

func (e InvalidAsset) Error() string

type InvalidColor added in v0.0.17

type InvalidColor struct {
	parser.Range
	Color string
}

func (InvalidColor) Error added in v0.0.17

func (e InvalidColor) Error() string

type InvalidFeature added in v0.0.24

type InvalidFeature struct {
	parser.Range
	Feature string
}

func (InvalidFeature) Error added in v0.0.24

func (e InvalidFeature) Error() string

type InvalidMonetaryLiteral

type InvalidMonetaryLiteral struct {
	parser.Range
	Source string
}

func (InvalidMonetaryLiteral) Error

func (e InvalidMonetaryLiteral) Error() string

type InvalidNestedMeta added in v0.0.15

type InvalidNestedMeta struct {
	parser.Range
}

func (InvalidNestedMeta) Error added in v0.0.15

func (InvalidNestedMeta) Error() string

type InvalidNumberLiteral

type InvalidNumberLiteral struct {
	parser.Range
	Source string
}

func (InvalidNumberLiteral) Error

func (e InvalidNumberLiteral) Error() string

type InvalidOperatorErr added in v0.0.25

type InvalidOperatorErr struct {
	parser.Range
	Operator string
}

func (InvalidOperatorErr) Error added in v0.0.25

func (e InvalidOperatorErr) Error() string

type InvalidRemainingAllotment added in v0.0.25

type InvalidRemainingAllotment struct {
	parser.Range
}

func (InvalidRemainingAllotment) Error added in v0.0.25

type InvalidScope added in v0.0.25

type InvalidScope struct {
	parser.Range
	Scope string
}

func (InvalidScope) Error added in v0.0.25

func (e InvalidScope) Error() string

type InvalidTypeErr

type InvalidTypeErr struct {
	parser.Range
	Name string
}

func (InvalidTypeErr) Error

func (e InvalidTypeErr) Error() string

type InvalidUnboundedAddressInScalingAddress added in v0.0.24

type InvalidUnboundedAddressInScalingAddress struct {
	parser.Range
}

func (InvalidUnboundedAddressInScalingAddress) Error added in v0.0.24

type InvalidUnboundedInSendAll

type InvalidUnboundedInSendAll struct {
	parser.Range
	Name  string
	Scope string
}

func (InvalidUnboundedInSendAll) Error

type MetaDependency added in v0.0.25

type MetaDependency struct {
	Account string
	Scope   string
	Key     string
}

type Metadata

type Metadata = map[string]string

Metadata is the external representation of transaction metadata: keys mapped to their rendered value (see MetaString). The runtime keeps the typed values in programState.TxMeta and renders them when building the ExecutionResult.

type MetadataNotFound

type MetadataNotFound struct {
	parser.Range
	Account string
	Scope   string
	Key     string
}

func (MetadataNotFound) Error

func (e MetadataNotFound) Error() string

type MetadataQuery

type MetadataQuery []MetadataQueryItem

type MetadataQueryItem added in v0.0.25

type MetadataQueryItem = struct {
	Account string
	Scope   string
	Keys    []string
}

type MismatchedCurrencyError

type MismatchedCurrencyError struct {
	parser.Range
	Expected string
	Got      string
}

func (MismatchedCurrencyError) Error

func (e MismatchedCurrencyError) Error() string

type MissingFundsErr

type MissingFundsErr struct {
	parser.Range
	Asset     string
	Needed    big.Int
	Available big.Int
}

func (MissingFundsErr) Error

func (e MissingFundsErr) Error() string

func (MissingFundsErr) Is added in v0.0.21

func (e MissingFundsErr) Is(target error) bool

type MissingVariableErr

type MissingVariableErr struct {
	parser.Range
	Name string
}

func (MissingVariableErr) Error

func (e MissingVariableErr) Error() string

type Monetary

type Monetary struct {
	Amount MonetaryInt
	Asset  Asset
}

func NewMonetary added in v0.0.15

func NewMonetary(asset string, n int64) Monetary

func (Monetary) String

func (v Monetary) String() string

type MonetaryInt

type MonetaryInt big.Int

func NewMonetaryInt

func NewMonetaryInt(n int64) MonetaryInt

func NewMonetaryIntBig added in v0.0.25

func NewMonetaryIntBig(n *big.Int) MonetaryInt

func (MonetaryInt) Add added in v0.0.10

func (m MonetaryInt) Add(other MonetaryInt) MonetaryInt

func (MonetaryInt) String

func (v MonetaryInt) String() string

func (MonetaryInt) Sub added in v0.0.10

func (m MonetaryInt) Sub(other MonetaryInt) MonetaryInt

type NegativeAmountErr

type NegativeAmountErr struct {
	parser.Range
	Amount MonetaryInt
}

func (NegativeAmountErr) Error

func (e NegativeAmountErr) Error() string

type NegativeBalanceError

type NegativeBalanceError struct {
	parser.Range
	Account string
	Scope   string
	Asset   string
	Amount  big.Int
}

func (NegativeBalanceError) Error

func (e NegativeBalanceError) Error() string

type NegativePortion added in v0.1.1

type NegativePortion struct {
	parser.Range
	Portion big.Rat
}

func (NegativePortion) Error added in v0.1.1

func (e NegativePortion) Error() string

type Portion

type Portion big.Rat

func (Portion) String

func (p Portion) String() string

type Posting

type Posting = funds.Posting

type QueryBalanceError

type QueryBalanceError struct {
	parser.Range
	WrappedError error
}

func (QueryBalanceError) Error

func (e QueryBalanceError) Error() string

func (QueryBalanceError) Unwrap added in v0.0.25

func (e QueryBalanceError) Unwrap() error

type QueryMetadataError

type QueryMetadataError struct {
	parser.Range
	WrappedError error
}

func (QueryMetadataError) Error

func (e QueryMetadataError) Error() string

func (QueryMetadataError) Unwrap added in v0.0.25

func (e QueryMetadataError) Unwrap() error

type ResolvedDependencies added in v0.0.25

type ResolvedDependencies struct {
	AccountsReads  map[AccountDependency]struct{}
	AccountsWrites map[AccountDependency]struct{}
	MetaReads      map[MetaDependency]struct{}
	MetaWrites     map[MetaDependency]struct{}
	TxMetaWrites   map[string]struct{}
}

func ResolveDependencies added in v0.0.25

func ResolveDependencies(ctx context.Context, store Store, vars map[string]string, program parser.Program) (ResolvedDependencies, error)

type SetAccountMetadataRow added in v0.0.25

type SetAccountMetadataRow struct {
	Account string `json:"account"`
	Key     string `json:"key"`
	Value   string `json:"value"`
	Scope   string `json:"scope,omitempty"`
}

SetAccountMetadataRow is a single piece of account metadata set by the script during execution. The value is carried as the rendered text produced by MetaString, matching the input metadata: the wire format is untyped, so a value's type is not part of what gets stored or asserted.

type SetAccountsMetadata added in v0.0.25

type SetAccountsMetadata []SetAccountMetadataRow

SetAccountsMetadata is the account metadata produced by the script (the execution result's accountsMeta, and a spec's expect.metadata).

type StaticStore

type StaticStore struct {
	Balances Balances
	Meta     AccountsMetadata
}

func (StaticStore) GetAccountsMetadata

func (s StaticStore) GetAccountsMetadata(_ context.Context, q MetadataQuery) (AccountsMetadata, error)

func (StaticStore) GetBalances

func (s StaticStore) GetBalances(_ context.Context, q BalanceQuery) (Balances, error)

type Store

type Store interface {
	// Returns the batched balances for a given batched query.
	//
	// Note: the "Balances" result is expected not to have duplicate entries.
	// Malformed Balances will result it undefined behaviour, and the implementation doesn't guarantee keys are deduped.
	GetBalances(context.Context, BalanceQuery) (Balances, error)
	GetAccountsMetadata(context.Context, MetadataQuery) (AccountsMetadata, error)
}

type String

type String string

func (String) String

func (v String) String() string

type TypeError

type TypeError struct {
	parser.Range
	Expected string
	Value    Value
}

func (TypeError) Error

func (e TypeError) Error() string

type UnboundFunctionErr

type UnboundFunctionErr struct {
	parser.Range
	Name string
}

func (UnboundFunctionErr) Error

func (e UnboundFunctionErr) Error() string

type UnboundVariableErr

type UnboundVariableErr struct {
	parser.Range
	Name string
}

func (UnboundVariableErr) Error

func (e UnboundVariableErr) Error() string

type UnhandledError added in v0.0.25

type UnhandledError struct {
	parser.Range
	Node string
}

UnhandledError is returned instead of panicking when expression evaluation or dependency resolution meets an AST node it doesn't handle (e.g. a language construct added after this code was written).

func (UnhandledError) Error added in v0.0.25

func (e UnhandledError) Error() string

type Value

type Value interface {
	String() string
	// contains filtered or unexported methods
}

type VariablesMap

type VariablesMap map[string]string

Jump to

Keyboard shortcuts

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