Documentation
¶
Index ¶
- Constants
- Variables
- func CalculateMaxSafeWithdraw(balance *big.Int, overdraft *big.Int) *big.Int
- func CalculateSafeWithdraw(balance *big.Int, overdraft *big.Int, requestedAmount *big.Int) *big.Int
- func CompareBalances(b1 Balances, b2 Balances) bool
- func CompareBalancesIncluding(b1 Balances, b2 Balances) bool
- func CompareSetAccountsMetadata(a SetAccountsMetadata, b SetAccountsMetadata) bool
- func MetaString(v Value) string
- func NewAccountAddress(src string) (AccountAddress, InterpreterError)
- func NewArgsParser(args []Value) *argsParser
- func NewAsset(src string) (Asset, InterpreterError)
- func PrettyPrintMeta(meta Metadata) string
- func PrettyPrintPostings(postings []Posting) string
- func RunProgram(ctx context.Context, program parser.Program, vars map[string]string, ...) (*ExecutionResult, InterpreterError)
- type AccountAddress
- type AccountBalance
- type AccountDependency
- type AccountMetadataRow
- type AccountsMetadata
- type Asset
- type BadArityErr
- type BadPortionParsingErr
- type BalanceQuery
- type BalanceQueryItem
- type BalanceRow
- type Balances
- type CannotCastScopedAccountToString
- type CannotCastToString
- type CannotStoreScopedAccountInMeta
- type DivideByZero
- type ExecutionResult
- type ExperimentalFeature
- type InternalAccountsMetadata
- type InternalBalances
- type InternalError
- type InterpreterError
- type InvalidAccountName
- type InvalidAllotmentInSendAll
- type InvalidAllotmentSum
- type InvalidAsset
- type InvalidColor
- type InvalidFeature
- type InvalidMonetaryLiteral
- type InvalidNestedMeta
- type InvalidNumberLiteral
- type InvalidOperatorErr
- type InvalidRemainingAllotment
- type InvalidScope
- type InvalidTypeErr
- type InvalidUnboundedAddressInScalingAddress
- type InvalidUnboundedInSendAll
- type MetaDependency
- type Metadata
- type MetadataNotFound
- type MetadataQuery
- type MetadataQueryItem
- type MismatchedCurrencyError
- type MissingFundsErr
- type MissingVariableErr
- type Monetary
- type MonetaryInt
- type NegativeAmountErr
- type NegativeBalanceError
- type Portion
- type Posting
- type QueryBalanceError
- type QueryMetadataError
- type ResolvedDependencies
- type Sender
- type SetAccountMetadataRow
- type SetAccountsMetadata
- type StaticStore
- type Store
- type String
- type TypeError
- type UnboundFunctionErr
- type UnboundVariableErr
- type UnhandledError
- type Value
- type VariablesMap
Constants ¶
const KEPT_ADDR = "<kept>"
Variables ¶
var ErrScalingNotSupported = errors.New("scaling is not supported")
Functions ¶
func CalculateMaxSafeWithdraw ¶ added in v0.0.17
PRE: ovedraft != nil, balance != nil PRE: ovedraft >= 0 POST: $out >= 0
func CalculateSafeWithdraw ¶ added in v0.0.17
func CalculateSafeWithdraw( balance *big.Int, overdraft *big.Int, requestedAmount *big.Int, ) *big.Int
PRE: ovedraft != nil, balance != nil PRE: ovedraft >= 0 PRE: requestedAmount >= 0 POST: $out >= 0
func CompareBalances ¶ added in v0.0.19
func CompareBalancesIncluding ¶ added in v0.0.20
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
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 PrettyPrintPostings ¶ added in v0.0.19
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 ¶
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 ¶
A single balance entry for an account: an (asset, color) pair and its amount.
type AccountDependency ¶ added in v0.0.25
type AccountMetadataRow ¶ added in v0.0.25
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 BadArityErr ¶
func (BadArityErr) Error ¶
func (e BadArityErr) Error() string
type BadPortionParsingErr ¶ added in v0.0.10
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
For each account, list of the needed assets
type BalanceRow ¶ added in v0.0.25
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
type CannotCastScopedAccountToString ¶ added in v0.0.25
func (CannotCastScopedAccountToString) Error ¶ added in v0.0.25
func (e CannotCastScopedAccountToString) Error() string
type CannotCastToString ¶ added in v0.0.12
func (CannotCastToString) Error ¶ added in v0.0.12
func (e CannotCastToString) Error() string
type CannotStoreScopedAccountInMeta ¶ added in v0.0.25
func (CannotStoreScopedAccountInMeta) Error ¶ added in v0.0.25
func (e CannotStoreScopedAccountInMeta) Error() string
type DivideByZero ¶ added in v0.0.11
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
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 mirrors InternalBalances: 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
func (m InternalAccountsMetadata) Merge(rows AccountsMetadata)
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 InternalBalances ¶ added in v0.0.25
type InternalBalances map[AccountAddress][]AccountBalance
An internal representation of the balances. Used to cache balances we get from external store. Whereas the external representation (interpreter.Balances) is user-facing and be a stable contract, (for example, allowing more columns if we need an higher level of fungibility), this one is used internally by the runtime, and could change over time, for example to add more indexes for faster lookups
func FromBalancesRows ¶ added in v0.0.25
func FromBalancesRows(b Balances) InternalBalances
func (InternalBalances) DeepClone ¶ added in v0.0.25
func (b InternalBalances) DeepClone() InternalBalances
func (InternalBalances) Merge ¶ added in v0.0.25
func (b InternalBalances) Merge(update []BalanceRow)
Merge the queried balance rows into the cache
func (InternalBalances) Set ¶ added in v0.0.25
func (b InternalBalances) Set(account AccountAddress, asset string, color string, amount *big.Int)
Set assigns amount to the (account, asset, color) balance.
type InternalError ¶ added in v0.0.21
func (InternalError) Error ¶ added in v0.0.21
func (e InternalError) Error() string
type InterpreterError ¶
func ParsePortionSpecific ¶ added in v0.0.10
func ParsePortionSpecific(input string) (*big.Rat, InterpreterError)
type InvalidAccountName ¶ added in v0.0.12
func (InvalidAccountName) Error ¶ added in v0.0.12
func (e InvalidAccountName) Error() string
type InvalidAllotmentInSendAll ¶
func (InvalidAllotmentInSendAll) Error ¶
func (e InvalidAllotmentInSendAll) Error() string
type InvalidAllotmentSum ¶
func (InvalidAllotmentSum) Error ¶
func (e InvalidAllotmentSum) Error() string
type InvalidAsset ¶ added in v0.0.21
func (InvalidAsset) Error ¶ added in v0.0.21
func (e InvalidAsset) Error() string
type InvalidColor ¶ added in v0.0.17
func (InvalidColor) Error ¶ added in v0.0.17
func (e InvalidColor) Error() string
type InvalidFeature ¶ added in v0.0.24
func (InvalidFeature) Error ¶ added in v0.0.24
func (e InvalidFeature) Error() string
type InvalidMonetaryLiteral ¶
func (InvalidMonetaryLiteral) Error ¶
func (e InvalidMonetaryLiteral) Error() string
type InvalidNestedMeta ¶ added in v0.0.15
func (InvalidNestedMeta) Error ¶ added in v0.0.15
func (InvalidNestedMeta) Error() string
type InvalidNumberLiteral ¶
func (InvalidNumberLiteral) Error ¶
func (e InvalidNumberLiteral) Error() string
type InvalidOperatorErr ¶ added in v0.0.25
func (InvalidOperatorErr) Error ¶ added in v0.0.25
func (e InvalidOperatorErr) Error() string
type InvalidRemainingAllotment ¶ added in v0.0.25
func (InvalidRemainingAllotment) Error ¶ added in v0.0.25
func (e InvalidRemainingAllotment) Error() string
type InvalidScope ¶ added in v0.0.25
func (InvalidScope) Error ¶ added in v0.0.25
func (e InvalidScope) Error() string
type InvalidTypeErr ¶
func (InvalidTypeErr) Error ¶
func (e InvalidTypeErr) Error() string
type InvalidUnboundedAddressInScalingAddress ¶ added in v0.0.24
func (InvalidUnboundedAddressInScalingAddress) Error ¶ added in v0.0.24
func (InvalidUnboundedAddressInScalingAddress) Error() string
type InvalidUnboundedInSendAll ¶
func (InvalidUnboundedInSendAll) Error ¶
func (e InvalidUnboundedInSendAll) Error() string
type MetaDependency ¶ added in v0.0.25
type Metadata ¶
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 ¶
func (MetadataNotFound) Error ¶
func (e MetadataNotFound) Error() string
type MetadataQuery ¶
type MetadataQuery []MetadataQueryItem
type MetadataQueryItem ¶ added in v0.0.25
type MismatchedCurrencyError ¶
func (MismatchedCurrencyError) Error ¶
func (e MismatchedCurrencyError) Error() string
type MissingFundsErr ¶
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 ¶
func (MissingVariableErr) Error ¶
func (e MissingVariableErr) Error() string
type Monetary ¶
type Monetary struct {
Amount MonetaryInt
Asset Asset
}
func NewMonetary ¶ added in v0.0.15
type MonetaryInt ¶
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 ¶
func (NegativeBalanceError) Error ¶
func (e NegativeBalanceError) Error() string
type Posting ¶
type Posting struct {
Source string `json:"source"`
SourceScope string `json:"sourceScope,omitempty"`
Destination string `json:"destination"`
DestinationScope string `json:"destinationScope,omitempty"`
Amount *big.Int `json:"amount"`
Asset string `json:"asset"`
Color string `json:"color,omitempty"`
}
type QueryBalanceError ¶
func (QueryBalanceError) Error ¶
func (e QueryBalanceError) Error() string
func (QueryBalanceError) Unwrap ¶ added in v0.0.25
func (e QueryBalanceError) Unwrap() error
type QueryMetadataError ¶
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{}
}
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 UnboundFunctionErr ¶
func (UnboundFunctionErr) Error ¶
func (e UnboundFunctionErr) Error() string
type UnboundVariableErr ¶
func (UnboundVariableErr) Error ¶
func (e UnboundVariableErr) Error() string
type UnhandledError ¶ added in v0.0.25
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 VariablesMap ¶
Source Files
¶
- accounts_metadata.go
- args_parser.go
- asset_scaling.go
- balances.go
- batch_balances_query.go
- evaluate_expr.go
- function_exprs.go
- function_statements.go
- funds_queue.go
- infix_overloads.go
- internal_accounts_metadata.go
- internal_balances.go
- interpreter.go
- interpreter_error.go
- resolve_dependencies.go
- set_accounts_metadata.go
- store.go
- value.go