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 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 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 ¶
PRE: ovedraft != nil, balance != nil PRE: ovedraft >= 0 POST: $out >= 0
func CalculateSafeWithdraw ¶
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 ¶
func CompareBalancesIncluding ¶
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]). Values are compared on their canonical source form.
func NewAccountAddress ¶
func NewAccountAddress(src string) (AccountAddress, InterpreterError)
func NewArgsParser ¶
func NewArgsParser(args []Value) *argsParser
func NewAsset ¶
func NewAsset(src string) (Asset, InterpreterError)
func PrettyPrintMeta ¶
func PrettyPrintPostings ¶
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) MarshalJSON ¶ added in v0.0.25
func (v AccountAddress) MarshalJSON() ([]byte, error)
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 ¶
func (m AccountsMetadata) PrettyPrint() string
type Asset ¶
type Asset string
func (Asset) GetBaseAndScale ¶ added in v0.0.25
func (Asset) MarshalJSON ¶ added in v0.0.25
type BadArityErr ¶
func (BadArityErr) Error ¶
func (e BadArityErr) Error() string
type BadPortionParsingErr ¶
func (BadPortionParsingErr) Error ¶
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 ¶
type CannotCastScopedAccountToString ¶ added in v0.0.25
func (CannotCastScopedAccountToString) Error ¶ added in v0.0.25
func (e CannotCastScopedAccountToString) Error() string
type CannotCastToString ¶
func (CannotCastToString) Error ¶
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 ¶
func (DivideByZero) Error ¶
func (e DivideByZero) Error() string
type ExecutionResult ¶
type ExecutionResult struct {
Postings []Posting `json:"postings"`
Metadata Metadata `json:"txMeta"`
AccountsMetadata SetAccountsMetadata `json:"accountsMeta"`
}
type ExperimentalFeature ¶
func (ExperimentalFeature) Error ¶
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 ¶
func (InternalError) Error ¶
func (e InternalError) Error() string
type InterpreterError ¶
func ParsePortionSpecific ¶
func ParsePortionSpecific(input string) (*big.Rat, InterpreterError)
type InvalidAccountName ¶
func (InvalidAccountName) Error ¶
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 ¶
func (InvalidAsset) Error ¶
func (e InvalidAsset) Error() string
type InvalidColor ¶
func (InvalidColor) Error ¶
func (e InvalidColor) Error() string
type InvalidFeature ¶
func (InvalidFeature) Error ¶
func (e InvalidFeature) Error() string
type InvalidMonetaryLiteral ¶
func (InvalidMonetaryLiteral) Error ¶
func (e InvalidMonetaryLiteral) Error() string
type InvalidNestedMeta ¶
func (InvalidNestedMeta) Error ¶
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 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 ¶
func (InvalidUnboundedAddressInScalingAddress) Error ¶
func (InvalidUnboundedAddressInScalingAddress) Error() string
type InvalidUnboundedInSendAll ¶
func (InvalidUnboundedInSendAll) Error ¶
func (e InvalidUnboundedInSendAll) Error() string
type MetaDependency ¶ added in v0.0.25
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 ¶
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 ¶
func (Monetary) MarshalJSON ¶
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 ¶
func (m MonetaryInt) Add(other MonetaryInt) MonetaryInt
func (MonetaryInt) MarshalJSON ¶
func (v MonetaryInt) MarshalJSON() ([]byte, error)
func (MonetaryInt) String ¶
func (v MonetaryInt) String() string
func (MonetaryInt) Sub ¶
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 Portion ¶
func (Portion) MarshalJSON ¶
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 Value `json:"value"`
Scope string `json:"scope,omitempty"`
}
SetAccountMetadataRow is a single piece of account metadata set by the script during execution. Unlike the input metadata (which is opaque and string-valued, since its serialization format isn't always known), the set value's type is known, so it is carried as a typed Value and serialized in the tagged form.
func (*SetAccountMetadataRow) UnmarshalJSON ¶ added in v0.0.25
func (r *SetAccountMetadataRow) UnmarshalJSON(data []byte) error
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 Value ¶
type Value interface {
String() string
// contains filtered or unexported methods
}
func ParseTaggedValue ¶ added in v0.0.25
ParseTaggedValue decodes the tagged-JSON representation of a Value. It reads the "type" discriminator (json can't unmarshal directly into the Value interface), then decodes into the struct shared with that type's MarshalJSON.
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