vm

package
v1.12.0 Latest Latest
Warning

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

Go to latest
Published: Aug 27, 2024 License: MIT Imports: 8 Imported by: ? modules, 0 packages

The first number is the count of modules that contain a package that imports this one. The module count is a better indicator of popularity than the package count. A module with 100 importing packages is counted only once instead of 100 times, reflecting the fact that the choice to use the package was likely made only once, not 100 times.
A '?' means that the value hasn't been computed yet.

Documentation

Overview

Provides `Machine`, which executes programs and outputs postings. 1: Create New Machine 2: Set Variables (with `core.Value`s or JSON) 3: Resolve Resources (answer requests on channel) 4: Resolve Balances (answer requests on channel) 6: Execute

Index

Constants

View Source
const (
	EXIT_OK = byte(iota + 1)
	EXIT_FAIL
	EXIT_FAIL_INVALID
	EXIT_FAIL_INSUFFICIENT_FUNDS
)

Variables

This section is empty.

Functions

func StdOutPrinter

func StdOutPrinter(c chan core.Value)

Types

type BalanceRequest

type BalanceRequest struct {
	Account  string
	Asset    string
	Response chan *core.MonetaryInt
	Error    error
}

type Machine

type Machine struct {
	P                   uint
	Program             program.Program
	Vars                map[string]core.Value
	UnresolvedResources []program.Resource
	Resources           []core.Value // Constants and Variables

	Balances map[core.AccountAddress]map[core.Asset]*core.MonetaryInt // keeps track of balances throughout execution

	Stack        []core.Value
	Postings     []Posting                                     // accumulates postings throughout execution
	TxMeta       map[string]core.Value                         // accumulates transaction meta throughout execution
	AccountsMeta map[core.AccountAddress]map[string]core.Value // accumulates accounts meta throughout execution
	Printer      func(chan core.Value)

	Debug bool
	// contains filtered or unexported fields
}

func NewMachine

func NewMachine(p program.Program) *Machine

func (*Machine) Execute

func (m *Machine) Execute() (byte, error)

func (*Machine) GetAccountsMetaJSON

func (m *Machine) GetAccountsMetaJSON() Metadata

func (*Machine) GetTxMetaJSON

func (m *Machine) GetTxMetaJSON() Metadata

func (*Machine) ResolveBalances

func (m *Machine) ResolveBalances() (chan BalanceRequest, error)

func (*Machine) ResolveResources

func (m *Machine) ResolveResources() (chan ResourceRequest, error)

func (*Machine) SetVars

func (m *Machine) SetVars(vars map[string]core.Value) error

func (*Machine) SetVarsFromJSON

func (m *Machine) SetVarsFromJSON(vars map[string]json.RawMessage) error

type Metadata

type Metadata map[string]any

type Posting

type Posting struct {
	Source      string            `json:"source"`
	Destination string            `json:"destination"`
	Amount      *core.MonetaryInt `json:"amount"`
	Asset       string            `json:"asset"`
}

type ResourceRequest

type ResourceRequest struct {
	Account  string
	Key      string
	Asset    string
	Response chan core.Value
	Error    error
}

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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