eni

package
v0.0.0 Latest Latest
Warning

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

Go to latest
Published: Nov 28, 2019 License: GPL-3.0 Imports: 18 Imported by: 0

Documentation

Index

Examples

Constants

View Source
const (
	BOOL = iota
	ADDRESS
	BYTES
	ENUM
	STRING
	FIX_ARRAY_START
	DYN_ARRAY_START
	STRUCT_START
	STRUCT_END
	INT
	INT8
	INT16
	INT24
	INT32
	INT40
	INT48
	INT56
	INT64
	INT72
	INT80
	INT88
	INT96
	INT104
	INT112
	INT120
	INT128
	INT136
	INT144
	INT152
	INT160
	INT168
	INT176
	INT184
	INT192
	INT200
	INT208
	INT216
	INT224
	INT232
	INT240
	INT248
	INT256
	UINT
	UINT8
	UINT16
	UINT24
	UINT32
	UINT40
	UINT48
	UINT56
	UINT64
	UINT72
	UINT80
	UINT88
	UINT96
	UINT104
	UINT112
	UINT120
	UINT128
	UINT136
	UINT144
	UINT152
	UINT160
	UINT168
	UINT176
	UINT184
	UINT192
	UINT200
	UINT208
	UINT216
	UINT224
	UINT232
	UINT240
	UINT248
	UINT256
	BYTE1
	BYTE2
	BYTE3
	BYTE4
	BYTE5
	BYTE6
	BYTE7
	BYTE8
	BYTE9
	BYTE10
	BYTE11
	BYTE12
	BYTE13
	BYTE14
	BYTE15
	BYTE16
	BYTE17
	BYTE18
	BYTE19
	BYTE20
	BYTE21
	BYTE22
	BYTE23
	BYTE24
	BYTE25
	BYTE26
	BYTE27
	BYTE28
	BYTE29
	BYTE30
	BYTE31
	BYTE32
	STRINGPTR
)

token constant

Variables

types that require parsing

Functions

func ConvertArguments

func ConvertArguments(typeInfo []byte, data []byte, memory Memory) (ret string, err error)

ConvertArguments converts arguments from ENI encoding to JSON

Example (Bool)
f := [1]byte{BOOL}
var d [32]byte

json, err := ConvertArguments(f[:], d[:])
printOrError(json, err)

for i := 0; i < 32; i++ {
	copy(d[:], make([]byte, 32, 32))
	d[i] = uint8(72) // 32-byte big endian
	json, err = ConvertArguments(f[:], d[:])
	printOrError(json, err)
}
Output:

[false]
[true]
[true]
[true]
[true]
[true]
[true]
[true]
[true]
[true]
[true]
[true]
[true]
[true]
[true]
[true]
[true]
[true]
[true]
[true]
[true]
[true]
[true]
[true]
[true]
[true]
[true]
[true]
[true]
[true]
[true]
[true]
[true]
Example (ControlEscapedString)
f := [1]byte{STRING}
var d [64]byte
d[31] = uint8(9) // 32-byte big endian
strA := "abc\"d\\\b\x00e"
copy(d[32:], []byte(strA))

json, _ := ConvertArguments(f[:], d[:])
fmt.Println(json)
Output:

["abc\"d\\\u0008\u0000e"]
Example (ErrorDataLength)

data length mismatches ENI type encoding This happens when Lity byte code generates wrong data length

// TODO
Output:

Example (ErrorEncoding1)

encoding grammaer error This happens when Lity byte code generates wrong encoding

f := [1]byte{155}
var d [70]byte
for i := 0; i < 32; i++ {
	d[i] = uint8(255)
}

json, err := ConvertArguments(f[:], d[:])

printOrError(json, err)
Output:

Argument Parser Error: encoding error - unknown or not implemented type: 155
Example (ErrorEncoding2)

encoding grammaer error This happens when Lity byte code generates wrong encoding

f := [2]byte{STRUCT_START, INT}
var d [70]byte
for i := 0; i < 32; i++ {
	d[i] = uint8(255)
}
json, err := ConvertArguments(f[:], d[:])

printOrError(json, err)
Output:

Argument Parser Error: runtime error: index out of range
Example (EscapedString)
f := [1]byte{STRING}
var d [64]byte
d[31] = uint8(7) // 32-byte big endian
strA := "abc\"d\\e"
copy(d[32:], []byte(strA))

json, _ := ConvertArguments(f[:], d[:])
fmt.Println(json)
Output:

["abc\"d\\e"]
Example (IntBool)

a int and a bool

f := [2]byte{INT, BOOL}
var d [70]byte
d[31] = uint8(72) // 32-byte big endian
json, err := ConvertArguments(f[:], d[:])
printOrError(json, err)
Output:

[72,false]
Example (NegInt)

a negative int

f := [1]byte{INT}
var d [70]byte
for i := 0; i < 32; i++ {
	d[i] = uint8(255)
}

json, err := ConvertArguments(f[:], d[:])

printOrError(json, err)
Output:

[-1]
Example (PosInt)

single positive integer (big endian)

var f, d []byte

f = make([]byte, 1, 1)
d = make([]byte, 70, 70)
f[0] = INT
d[31] = uint8(72) // 32-byte big endian
json, err := ConvertArguments(f, d)
printOrError(json, err)
Output:

[72]
Example (String)

two strings

f := [2]byte{STRING, STRING}
var d [160]byte
d[31] = uint8(3) // 32-byte big endian
strA := "abcd"
copy(d[32:], []byte(strA))
d[95] = uint8(50)
strB := "abcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyz"
copy(d[96:], []byte(strB))

json, err := ConvertArguments(f[:], d[:])

printOrError(json, err)
Output:

["abc","abcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwx"]

func ConvertReturnValue

func ConvertReturnValue(typeInfo []byte, jsonStr string) (ret []byte, err error)

ConvertReturnValue converts return value from JSON to ENI encoding

Example (ControlEscapedString)
f := [1]byte{STRING}
json := "[\"-123\\\"\\n\\u0010\"]"
d, err := ConvertReturnValue(f[:], json)

retPrintOrError(d, err)
Output:

[0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 7 45 49 50 51 34 10 16 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0]
Example (Error1)
f := [1]byte{INT}
d, err := ConvertReturnValue(f[:], "-123")

retPrintOrError(d, err)
Output:

Return Parser Error: expected '[', found '-'
Example (Error2)
f := [1]byte{UINT}
d, err := ConvertReturnValue(f[:], "[-123]")

retPrintOrError(d, err)
Output:

Return Parser Error: expected uint, found '-'
Example (Error3)
f := [1]byte{STRING}
d, err := ConvertReturnValue(f[:], "[-123]")

retPrintOrError(d, err)
Output:

Return Parser Error: expected '"', found '-'
Example (ErrorBool)
f := [1]byte{BOOL}
d, err := ConvertReturnValue(f[:], "[tree]")

retPrintOrError(d, err)
f = [1]byte{BOOL}
d, err = ConvertReturnValue(f[:], "[jizz]")

retPrintOrError(d, err)
Output:

Return Parser Error: expected 'u', found 'e'
Return Parser Error: expected boolean, found 'j'
Example (ErrorEcodingJsonMismatch)

Json not matched with ENI type encoding

// TODO:
Output:

Example (ErrorFixArray)
var f [34]byte
f[0] = FIX_ARRAY_START
f[32] = 4
f[33] = INT
d, err := ConvertReturnValue(f[:], "[[-123, 7122, a, 45]]")

retPrintOrError(d, err)
Output:

Return Parser Error: expected int, found 'a'
Example (ErrorInt)
f := [1]byte{INT}
d, err := ConvertReturnValue(f[:], "[-]")

retPrintOrError(d, err)
f = [1]byte{UINT}
d, err = ConvertReturnValue(f[:], "[-123]")

retPrintOrError(d, err)
Output:

Return Parser Error: expected int, found '-'
Return Parser Error: expected uint, found '-'
Example (ErrorJsonFormat1)

JSON format error This happens when libeni returns wrong JSON

// TODO:
Output:

Example (ErrorJsonFormat2)

JSON integer error This happens when libeni returns any too large integers

// TODO:
Output:

Example (EscapedString)
f := [1]byte{STRING}
json := "[\"-123\\\"\"]"
d, err := ConvertReturnValue(f[:], json)

retPrintOrError(d, err)
Output:

[0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 5 45 49 50 51 34 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0]
Example (FixArray)
var f [34]byte
f[0] = FIX_ARRAY_START
f[32] = 1
f[33] = INT
d, err := ConvertReturnValue(f[:], "[[-123]]")

retPrintOrError(d, err)
Output:

[255 255 255 255 255 255 255 255 255 255 255 255 255 255 255 255 255 255 255 255 255 255 255 255 255 255 255 255 255 255 255 133]
Example (NegInt)
f := [1]byte{INT}
d, _ := ConvertReturnValue(f[:], "[-123]")

fmt.Printf("%v\n", d)
Output:

[255 255 255 255 255 255 255 255 255 255 255 255 255 255 255 255 255 255 255 255 255 255 255 255 255 255 255 255 255 255 255 133]
Example (String)
f := [1]byte{STRING}
d, _ := ConvertReturnValue(f[:], "[\"-123abc1\"]")

fmt.Printf("%v\n", d)
Output:

[0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 8 45 49 50 51 97 98 99 49 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0]
Example (UnicodeEscapedString)
f := [1]byte{STRING}
json := "[\"-123\\\"\\n\\u7122\"]"
d, err := ConvertReturnValue(f[:], json)

retPrintOrError(d, err)
Output:

Return Parser Error: UTF-8 not implemented yet!

func IsBool

func IsBool(code byte) bool

func IsSint

func IsSint(code byte) bool

signed int

func IsUint

func IsUint(code byte) bool

Types

type ENI

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

func NewENI

func NewENI() *ENI

func (*ENI) ExecuteENI

func (eni *ENI) ExecuteENI() (string, error)

ExecuteENI executes current ENI operation a process is forked to achieve fault tolerance

func (*ENI) Gas

func (eni *ENI) Gas() (uint64, error)

Gas returns gas of current ENI operation a process is forked to achieve fault tolerance

func (*ENI) InitENI

func (eni *ENI) InitENI(eniFunction string, argsText string) (err error)

type Memory

type Memory interface {
	Get(int64, int64) []byte
}

type OTAInfo

type OTAInfo struct {
	LibName  string
	Version  string   // The format of version should be vX.Y.Z where X, Y, Z are all integers. E.g. v1.0.0, v3.2.0
	Url      []string // URL to retrieve the library file
	Checksum string   // SHA512 checksum to check the health of the library
}

type OTAInstance

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

func NewOTAInstance

func NewOTAInstance() *OTAInstance

func (*OTAInstance) Destroy

func (ota *OTAInstance) Destroy(info OTAInfo) (err error)

Remove unused libraries from lib, staging, and retired folder

func (*OTAInstance) DownloadInfo

func (ota *OTAInstance) DownloadInfo(info OTAInfo) (err error)

Download the library from given url. The library will be saved in ENI_LIBRARY_PATH/staging named OTAInfo.LibName.

func (*OTAInstance) IsValidNewLib

func (ota *OTAInstance) IsValidNewLib(info OTAInfo) (bool, error)

Check a given OTAInfo is valid to be register

func (*OTAInstance) Register

func (ota *OTAInstance) Register(info OTAInfo) (err error)

Register staging libraries to lib.

type Version

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

func NewVersion

func NewVersion() *Version

func (*Version) BuildFromString

func (v *Version) BuildFromString(version string) error

Convert version string to a Version struct

func (*Version) Compare

func (v *Version) Compare(a Version) int

Compare version between two OTAInfos Return:

this > version -> 1
this = version -> 0
this < version -> -1

Jump to

Keyboard shortcuts

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