vm

package
v1.11.2 Latest Latest
Warning

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

Go to latest
Published: Apr 4, 2024 License: MIT Imports: 8 Imported by: 0

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