Documentation
¶
Index ¶
- Constants
- Variables
- func BigIntToByteArray(value big.Int) []byte
- func BigIntToPushableBytes(element big.Int) []byte
- func BigIntToString(element big.Int) string
- func BigIntToUInt(value big.Int) (uint, error)
- func BigIntToUInt16(value big.Int) (uint16, error)
- func BoolToByteArray(value bool) []byte
- func ByteArrayToBool(ba []byte) bool
- func ByteArrayToInt(element []byte) int
- func ByteArrayToUI16(element []byte) (uint16, error)
- func SignedBigIntConversion(ba []byte, err error) (big.Int, error)
- func SignedByteArrayConversion(bi big.Int) []byte
- func StrToBigInt(element string) big.Int
- func UInt16ToBigInt(value uint16) big.Int
- func UInt16ToByteArray(element uint16) []byte
- func UInt64ToByteArray(element uint64) []byte
- func UnsignedBigIntConversion(ba []byte, err error) (big.Int, error)
- type Array
- func (a *Array) Append(ba []byte) error
- func (a *Array) At(index uint16) ([]byte, error)
- func (a *Array) DecrementSize() error
- func (a *Array) GetSize() (uint16, error)
- func (a *Array) IncrementSize() error
- func (a *Array) Insert(index uint16, element []byte) error
- func (a *Array) Remove(index uint16) error
- type CallStack
- type Context
- type Frame
- type Map
- func (m *Map) Append(key []byte, value []byte) error
- func (m *Map) DecrementSize() error
- func (m *Map) GetVal(key []byte) ([]byte, error)
- func (m *Map) IncrementSize()
- func (m *Map) MapContainsKey(key []byte) (bool, error)
- func (m *Map) Remove(key []byte) error
- func (m *Map) SetVal(key []byte, value []byte) error
- type MockContext
- type OpCode
- type Stack
- type Struct
- type VM
- func (vm *VM) Exec(trace bool) bool
- func (vm *VM) GetErrorMsg() string
- func (vm *VM) PeekEvalStack() [][]byte
- func (vm *VM) PeekResult() (element []byte, err error)
- func (vm *VM) PopBytes(opCode OpCode) (elements []byte, err error)
- func (vm *VM) PopSignedBigInt(opCode OpCode) (bigInt big.Int, err error)
- func (vm *VM) PopUnsignedBigInt(opCode OpCode) (bigInt big.Int, err error)
Constants ¶
const ( PushInt = iota PushBool PushChar PushStr Push Dup Roll Swap Pop Add Sub Mul Div Mod Exp Neg Eq NotEq Lt Gt LtEq GtEq ShiftL ShiftR BitwiseAnd BitwiseOr BitwiseXor BitwiseNot NoOp Jmp JmpTrue JmpFalse Call CallTrue CallExt Ret Size StoreLoc StoreSt LoadLoc LoadSt 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 MapGetVal MapSetVal MapRemove NewArr ArrAppend ArrInsert ArrRemove ArrAt ArrLen NewStr StoreFld LoadFld SHA3 CheckSig ErrHalt Halt )
Supported Bazo OpCodes.
const ( BYTES = iota + 1 BYTE LABEL ADDR )
Supported OpCode argument types
const UINT16_MAX uint16 = 65535
Variables ¶
var OpCodes = []OpCode{ {PushInt, "pushint", 1, []int{BYTES}, 1, 1}, {PushBool, "pushbool", 1, []int{BYTE}, 1, 1}, {PushChar, "pushchar", 1, []int{BYTE}, 1, 1}, {PushStr, "pushstr", 1, []int{BYTES}, 1, 1}, {Push, "push", 1, []int{BYTES}, 1, 1}, {Dup, "dup", 0, nil, 1, 2}, {Roll, "roll", 1, []int{BYTE}, 1, 2}, {Swap, "swap", 0, nil, 1, 2}, {Pop, "pop", 0, nil, 1, 1}, {Add, "add", 0, nil, 1, 2}, {Sub, "sub", 0, nil, 1, 2}, {Mul, "mult", 0, nil, 1, 2}, {Div, "div", 0, nil, 1, 2}, {Mod, "mod", 0, nil, 1, 2}, {Exp, "exp", 0, nil, 1, 2}, {Neg, "neg", 0, nil, 1, 2}, {Eq, "eq", 0, nil, 1, 2}, {NotEq, "neq", 0, nil, 1, 2}, {Lt, "lt", 0, nil, 1, 2}, {Gt, "gt", 0, nil, 1, 2}, {LtEq, "lte", 0, nil, 1, 2}, {GtEq, "gte", 0, nil, 1, 2}, {ShiftL, "shiftl", 0, nil, 1, 2}, {ShiftR, "shiftr", 0, nil, 1, 2}, {BitwiseAnd, "bitwiseand", 0, nil, 1, 2}, {BitwiseOr, "bitwiseor", 0, nil, 1, 2}, {BitwiseXor, "bitwisexor", 0, nil, 1, 2}, {BitwiseNot, "bitwisenot", 0, nil, 1, 2}, {NoOp, "nop", 0, nil, 1, 1}, {Jmp, "jmp", 1, []int{LABEL}, 1, 1}, {JmpTrue, "jmptrue", 1, []int{LABEL}, 1, 1}, {JmpFalse, "jmpfalse", 1, []int{LABEL}, 1, 1}, {Call, "call", 2, []int{LABEL, BYTE}, 1, 1}, {CallTrue, "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}, {StoreLoc, "storeloc", 1, []int{BYTE}, 1, 2}, {StoreSt, "storest", 1, []int{BYTE}, 1000, 2}, {LoadLoc, "loadloc", 1, []int{BYTE}, 1, 2}, {LoadSt, "loadst", 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}, {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}, {ArrLen, "arrlen", 0, nil, 1, 2}, {NewStr, "newstr", 1, []int{BYTE}, 1, 2}, {StoreFld, "storefld", 1, []int{BYTE}, 1, 2}, {LoadFld, "loadfld", 1, []int{BYTE}, 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}, }
OpCodes contains all OpCode definitions
Functions ¶
func BigIntToByteArray ¶ added in v1.4.1
func BigIntToPushableBytes ¶
func BigIntToString ¶
func BoolToByteArray ¶
func ByteArrayToBool ¶
func ByteArrayToInt ¶
func ByteArrayToUI16 ¶
func StrToBigInt ¶
func UInt16ToBigInt ¶ added in v1.4.1
func UInt16ToByteArray ¶
func UInt64ToByteArray ¶
Types ¶
type Array ¶
type Array []byte
func ArrayFromByteArray ¶
func (*Array) DecrementSize ¶
func (*Array) IncrementSize ¶
type CallStack ¶
type CallStack struct {
// contains filtered or unexported fields
}
func NewCallStack ¶
func NewCallStack() *CallStack
type Context ¶
type Context interface { GetContract() []byte GetContractVariable(index int) ([]byte, error) SetContractVariable(index int, value []byte) error GetAddress() [64]byte GetIssuer() [32]byte GetBalance() uint64 GetSender() [32]byte GetAmount() uint64 GetTransactionData() []byte GetFee() uint64 GetSig1() [64]byte }
Context is the VM execution context which is composed with data coming from the transaction and the account. Context interface declares functions required to start the execution of the contract.
type Map ¶
type Map []byte
func MapFromByteArray ¶
func (*Map) DecrementSize ¶
func (*Map) IncrementSize ¶
func (m *Map) IncrementSize()
type MockContext ¶
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 }
OpCode contains the code, name, number of arguments, argument types, gas price and gas factor of the opcode
type Struct ¶ added in v1.4.1
type Struct Array
Struct type represents the composite data type declaration that defines a group of variables.
type VM ¶
type VM struct {
// contains filtered or unexported fields
}
VM is a stack-based virtual machine and executes the contract code sequentially.
func (*VM) GetErrorMsg ¶
GetErrorMsg peeks bytes from evaluation stack and returns the error message.
func (*VM) PeekEvalStack ¶ added in v1.4.1
PeekEvalStack returns a copy of the complete evaluation stack
func (*VM) PeekResult ¶
PeekResult returns the element on top of the stack
func (*VM) PopSignedBigInt ¶
PopSignedBigInt pops bytes from evaluation stack and convert it to a big integer with sign.