txvm

package
v0.1.0 Latest Latest
Warning

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

Go to latest
Published: Apr 20, 2018 License: Apache-2.0 Imports: 5 Imported by: 0

Documentation

Index

Constants

View Source
const (
	Op0 = iota
	OpData1
	OpData2
	OpData3
	OpData20 = 0x14
	OpData32 = 0x20
	OpData64 = 0x40
)

Enumerate of opcodes

View Source
const (
	OpIf = iota + 0x61
	OpElse
	OpEndIf
	OpNope
	OpDup
)

Enumerate of opcodes

View Source
const (
	OpVerify = iota + 0xa0
	OpEqualVerify
	OpScriptHashVerifyPop
)

Verify

View Source
const (
	OpHash160 = iota + 0xb0
	OpCheckSig
)

Hash

View Source
const (
	OpCheckLockTime = iota + 0xc0
	OpOtherSPVVerify
)

External Call

View Source
const (
	OpUnused = iota + 0xd0
)

Enumerate unused opcodes

Variables

This section is empty.

Functions

func PayToAddrScript

func PayToAddrScript(addr string) ([]byte, error)

PayToAddrScript creates a new script to pay a transaction output to a given address.

func RunOpNode

func RunOpNode(node *OpNode, vm *IVM) error

RunOpNode runs operation node. It is a specific implementation of RunFunc

func SignatureScript

func SignatureScript(txin []byte, pubkey []byte, privkey []byte) ([]byte, error)

SignatureScript creates an input signature script for a transaction.

Types

type ConstructFunc

type ConstructFunc func([]byte) (*OpNode, int, error)

ConstructFunc takes an array of bytecodes to build an opnode. Note that: 1. The bytecodes must start with a valid opcode byte. 2. The bytecodes must be longer than required. 3. If it is insufficient to constructing an OpNode, e.g., data length not met, OpEndIf not found, error is thrown. 4. If an OpNode is successfully created, an int offset tells how many bytes it consumes.

type ErrorCode

type ErrorCode int

ErrorCode identifies a kind of txvm error.

const (
	// ErrInternal is returned if internal consistency checks fail.
	ErrInternal ErrorCode = iota

	// Errors emitted by builder
	// ErrUnsupportedOpcode ...
	ErrUnsupportedOpcode
	// ErrInvalidOpcode ...
	ErrInvalidOpcode
	// ErrInvalidOpdata ...
	ErrInvalidOpdata

	// Errors emitted by IVM
	// ErrEqualVerify...
	ErrEqualVerify
	// ErrInvalidStackOperation ...
	ErrInvalidStackOperation
)

These constants are used to identify a specific Error.

type IAST

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

IAST is a Abstract Syntax Tree.

func ParseRaw

func ParseRaw(bytecodes []byte) (*IAST, error)

ParseRaw builds an AST from byte codes.

type IVM

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

IVM defines the struct of IoTeX Virtual Machine

func NewIVM

func NewIVM(txin, bytecodes []byte) (*IVM, error)

NewIVM creates a new IoTeX Virtual Machine

func (*IVM) Execute

func (vm *IVM) Execute() (err error)

Execute executes IoTeX Virtual Machine

type OpNode

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

OpNode defines the struct of operation node

func BuildOpNodeFromBytes

func BuildOpNodeFromBytes(bytecodes []byte) (*OpNode, int, error)

BuildOpNodeFromBytes builds operation node from bytes. It is a specific implementation of ConstructFunc

type RunFunc

type RunFunc func(*OpNode, *IVM) error

RunFunc declares a function type

type ScriptBuilder

type ScriptBuilder interface {
	// AddOp adds one opcode
	AddOp(op byte) error

	// AddOps adds several opcodes
	AddOps(op []byte) error

	// AddData adds data
	AddData(data []byte) error

	// Bytecodes returns byte codes built
	Bytecodes() []byte

	// Reset resets all internal states of the builder.
	Reset() error
}

ScriptBuilder builds a script using opcodes

func NewScriptBuilder

func NewScriptBuilder() ScriptBuilder

NewScriptBuilder creates an ScriptBuilder

type ScriptError

type ScriptError struct {
	ErrorCode ErrorCode
	Desc      string
}

ScriptError defines the struct of script error

func (ScriptError) Error

func (e ScriptError) Error() string

Jump to

Keyboard shortcuts

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