vm

package
v0.0.0-...-5e63da4 Latest Latest
Warning

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

Go to latest
Published: Mar 17, 2019 License: Apache-2.0 Imports: 9 Imported by: 0

Documentation

Index

Constants

View Source
const (
	PUSH = iota
	DUP
	ROLL
	POP
	ADD
	SUB
	MULT
	DIV
	MOD
	NEG
	EQ
	NEQ
	LT
	GT
	LTE
	GTE
	SHIFTL
	SHIFTR
	NOP
	JMP
	JMPIF
	CALL
	CALLIF
	CALLEXT
	RET
	SIZE
	STORE
	SSTORE
	LOAD
	SLOAD
	ADDRESS // Address of account
	ISSUER  // Owner of smart contract account
	BALANCE // Balance of account
	CALLER
	CALLVAL  // Amount of bazo coins transacted in transaction
	CALLDATA // Parameters and function signature hash
	NEWMAP
	MAPHASKEY
	MAPPUSH
	MAPGETVAL
	MAPSETVAL
	MAPREMOVE
	NEWARR
	ARRAPPEND
	ARRINSERT
	ARRREMOVE
	ARRAT
	SHA3
	CHECKSIG
	ERRHALT
	HALT
)
View Source
const (
	BYTES = iota + 1
	BYTE
	LABEL
	ADDR
)
View Source
const UINT16_MAX uint16 = 65535

Variables

View Source
var OpCodes = []OpCode{
	{PUSH, "push", 1, []int{BYTES}, 1, 1},
	{DUP, "dup", 0, nil, 1, 2},
	{ROLL, "roll", 1, []int{BYTE}, 1, 2},
	{POP, "pop", 0, nil, 1, 1},
	{ADD, "add", 0, nil, 1, 2},
	{SUB, "sub", 0, nil, 1, 2},
	{MULT, "mult", 0, nil, 1, 2},
	{DIV, "div", 0, nil, 1, 2},
	{MOD, "mod", 0, nil, 1, 2},
	{NEG, "neg", 0, nil, 1, 2},
	{EQ, "eq", 0, nil, 1, 2},
	{NEQ, "neq", 0, nil, 1, 2},
	{LT, "lt", 0, nil, 1, 2},
	{GT, "gt", 0, nil, 1, 2},
	{LTE, "lte", 0, nil, 1, 2},
	{GTE, "gte", 0, nil, 1, 2},
	{SHIFTL, "shiftl", 1, []int{BYTE}, 1, 2},
	{SHIFTR, "shiftl", 1, []int{BYTE}, 1, 2},
	{NOP, "nop", 0, nil, 1, 1},
	{JMP, "jmp", 1, []int{LABEL}, 1, 1},
	{JMPIF, "jmpif", 1, []int{LABEL}, 1, 1},
	{CALL, "call", 2, []int{LABEL, BYTE}, 1, 1},
	{CALLIF, "callif", 2, []int{LABEL, BYTE}, 1, 1},
	{CALLEXT, "callext", 3, []int{ADDR, BYTE, BYTE, BYTE, BYTE, BYTE}, 1000, 2},
	{RET, "ret", 0, nil, 1, 1},
	{SIZE, "size", 0, nil, 1, 1},
	{STORE, "store", 0, nil, 1, 2},
	{SSTORE, "sstore", 1, []int{BYTE}, 1000, 2},
	{LOAD, "load", 1, []int{BYTE}, 1, 2},
	{SLOAD, "sload", 1, []int{BYTE}, 10, 2},
	{ADDRESS, "address", 0, nil, 1, 1},
	{ISSUER, "issuer", 0, nil, 1, 1},
	{BALANCE, "balance", 0, nil, 1, 1},
	{CALLER, "caller", 0, nil, 1, 1},
	{CALLVAL, "callval", 0, nil, 1, 1},
	{CALLDATA, "calldata", 0, nil, 1, 1},
	{NEWMAP, "newmap", 0, nil, 1, 2},
	{MAPHASKEY, "maphaskey", 0, nil, 1, 2},
	{MAPPUSH, "mappush", 0, nil, 1, 2},
	{MAPGETVAL, "mapgetval", 0, nil, 1, 2},
	{MAPSETVAL, "mapsetval", 0, nil, 1, 2},
	{MAPREMOVE, "mapremove", 0, nil, 1, 2},
	{NEWARR, "newarr", 0, nil, 1, 2},
	{ARRAPPEND, "arrappend", 0, nil, 1, 2},
	{ARRINSERT, "arrinsert", 0, nil, 1, 2},
	{ARRREMOVE, "arrremove", 0, nil, 1, 2},
	{ARRAT, "arrat", 0, nil, 1, 2},
	{SHA3, "sha3", 0, nil, 1, 2},
	{CHECKSIG, "checksig", 0, nil, 1, 2},
	{ERRHALT, "errhalt", 0, nil, 0, 1},
	{HALT, "halt", 0, nil, 0, 1},
}

Functions

func BigIntToString

func BigIntToString(element big.Int) string

func BoolToByteArray

func BoolToByteArray(value bool) []byte

func ByteArrayToBool

func ByteArrayToBool(ba []byte) bool

func ByteArrayToInt

func ByteArrayToInt(element []byte) int

func ByteArrayToUI16

func ByteArrayToUI16(element []byte) (uint16, error)

func SignedBigIntConversion

func SignedBigIntConversion(ba []byte, err error) (big.Int, error)

func SignedByteArrayConversion

func SignedByteArrayConversion(bi big.Int) []byte

func StrToBigInt

func StrToBigInt(element string) big.Int

func UInt16ToByteArray

func UInt16ToByteArray(element uint16) []byte

func UInt64ToByteArray

func UInt64ToByteArray(element uint64) []byte

func UnsignedBigIntConversion

func UnsignedBigIntConversion(ba []byte, err error) (big.Int, error)

Types

type Array

type Array []byte

func ArrayFromByteArray

func ArrayFromByteArray(arr []byte) (Array, error)

func NewArray

func NewArray() Array

func (*Array) Append

func (a *Array) Append(ba []byte) error

func (*Array) At

func (a *Array) At(index uint16) ([]byte, error)

func (*Array) DecrementSize

func (a *Array) DecrementSize() error

func (*Array) IncrementSize

func (a *Array) IncrementSize() error

func (*Array) Insert

func (a *Array) Insert(index uint16, element []byte) error

func (*Array) Remove

func (a *Array) Remove(index uint16) error

type CallStack

type CallStack struct {
	// contains filtered or unexported fields
}

func NewCallStack

func NewCallStack() *CallStack

func (CallStack) GetLength

func (cs CallStack) GetLength() int

func (*CallStack) Peek

func (cs *CallStack) Peek() (frame *Frame, err error)

func (*CallStack) Pop

func (cs *CallStack) Pop() (frame *Frame, err error)

func (*CallStack) Push

func (cs *CallStack) Push(element *Frame)

type Context

type Context interface {
	GetContract() []byte
	GetContractVariable(index int) ([]byte, error)
	SetContractVariable(index int, value []byte) error
	GetAddress() [32]byte
	GetIssuer() [32]byte
	GetBalance() uint64
	GetSender() [32]byte
	GetAmount() uint64
	GetTransactionData() []byte
	GetFee() uint64
	GetSig() [64]byte
}

type Frame

type Frame struct {
	// contains filtered or unexported fields
}

type Map

type Map []byte

func MapFromByteArray

func MapFromByteArray(m []byte) (Map, error)

func NewMap

func NewMap() Map

func (*Map) Append

func (m *Map) Append(key []byte, value []byte) error

func (*Map) DecrementSize

func (m *Map) DecrementSize() error

func (*Map) GetVal

func (m *Map) GetVal(key []byte) ([]byte, error)

func (*Map) IncrementSize

func (m *Map) IncrementSize()

func (*Map) MapContainsKey

func (m *Map) MapContainsKey(key []byte) (bool, error)

func (*Map) Remove

func (m *Map) Remove(key []byte) error

func (*Map) SetVal

func (m *Map) SetVal(key []byte, value []byte) error

type MockContext

type MockContext struct {
	protocol.Context
}

func NewMockContext

func NewMockContext(byteCode []byte) *MockContext

func (*MockContext) SetContract

func (mc *MockContext) SetContract(contract []byte)

type OpCode

type OpCode struct {
	Name     string
	Nargs    int
	ArgTypes []int
	// contains filtered or unexported fields
}

type Stack

type Stack struct {
	Stack []protocol.ByteArray
	// contains filtered or unexported fields
}

func NewStack

func NewStack() *Stack

func (Stack) GetLength

func (s Stack) GetLength() int

func (*Stack) PeekBytes

func (s *Stack) PeekBytes() (element []byte, err error)

func (*Stack) Pop

func (s *Stack) Pop() (element []byte, err error)

func (*Stack) PopIndexAt

func (s *Stack) PopIndexAt(index int) ([]byte, error)

func (*Stack) Push

func (s *Stack) Push(element []byte) error

type VM

type VM struct {
	// contains filtered or unexported fields
}

func NewTestVM

func NewTestVM(byteCode []byte) VM

func NewVM

func NewVM(context Context) VM

func (*VM) Exec

func (vm *VM) Exec(trace bool) bool

func (*VM) GetErrorMsg

func (vm *VM) GetErrorMsg() string

func (*VM) PopBytes

func (vm *VM) PopBytes(opCode OpCode) (elements []byte, err error)

func (*VM) PopSignedBigInt

func (vm *VM) PopSignedBigInt(opCode OpCode) (bigInt big.Int, err error)

func (*VM) PopUnsignedBigInt

func (vm *VM) PopUnsignedBigInt(opCode OpCode) (bigInt big.Int, err error)

Jump to

Keyboard shortcuts

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