parsecode

package
v0.0.0-...-24d451d Latest Latest
Warning

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

Go to latest
Published: Jul 2, 2020 License: Apache-2.0 Imports: 19 Imported by: 2

Documentation

Index

Constants

This section is empty.

Variables

View Source
var LiteralTypes = map[string]struct{}{
	"int":      {},
	"int8":     {},
	"int16":    {},
	"int32":    {},
	"int64":    {},
	"uint":     {},
	"uint8":    {},
	"uint16":   {},
	"uint32":   {},
	"uint64":   {},
	"float32":  {},
	"float64":  {},
	"bool":     {},
	"string":   {},
	"byte":     {},
	"Address":  {},
	"Hash":     {},
	"HexBytes": {},
	"PubKey":   {},
}

LiteralTypes - primitive type

View Source
var NumberType = "Number"
View Source
var WhiteListPKG = map[string]struct{}{

	"\"bytes\"":             {},
	"\"container/heap\"":    {},
	"\"container/list\"":    {},
	"\"container/ring\"":    {},
	"\"crypto\"":            {},
	"\"crypto/aes\"":        {},
	"\"crypto/cipher\"":     {},
	"\"crypto/des\"":        {},
	"\"crypto/dsa\"":        {},
	"\"crypto/ecdsa\"":      {},
	"\"crypto/elliptic\"":   {},
	"\"crypto/hmac\"":       {},
	"\"crypto/md5\"":        {},
	"\"crypto/rc4\"":        {},
	"\"crypto/rsa\"":        {},
	"\"crypto/sha1\"":       {},
	"\"crypto/sha256\"":     {},
	"\"crypto/sha512\"":     {},
	"\"encoding\"":          {},
	"\"encoding/ascii85\"":  {},
	"\"encoding/asn1\"":     {},
	"\"encoding/base32\"":   {},
	"\"encoding/base64\"":   {},
	"\"encoding/binary\"":   {},
	"\"encoding/csv\"":      {},
	"\"encoding/gob\"":      {},
	"\"encoding/hex\"":      {},
	"\"encoding/json\"":     {},
	"\"encoding/pem\"":      {},
	"\"encoding/xml\"":      {},
	"\"errors\"":            {},
	"\"fmt\"":               {},
	"\"hash\"":              {},
	"\"hash/adler32\"":      {},
	"\"hash/crc32\"":        {},
	"\"hash/crc64\"":        {},
	"\"hash/fnv\"":          {},
	"\"index/suffixarray\"": {},
	"\"math\"":              {},
	"\"math/big\"":          {},
	"\"math/bits\"":         {},
	"\"math/cmplx\"":        {},
	"\"reflect\"":           {},
	"\"regexp\"":            {},
	"\"regexp/syntax\"":     {},
	"\"sort\"":              {},
	"\"strconv\"":           {},
	"\"strings\"":           {},
	"\"unicode\"":           {},
	"\"unicode/utf8\"":      {},
	"\"unicode/utf16\"":     {},
}

WhiteListPKG - these packages can be imported

View Source
var WhiteListPkgPrefix = []string{
	"\"blockchain/smcsdk/sdk",
	"\"github.com/bcbchain/sdk/sdk",
}

WhiteListPkgPrefix - packages start with these paths are all allowed

Functions

func CalcContractAddress

func CalcContractAddress(name string, version string, owner types.Address) types.Address

nolint unhandled CalcContractAddress calculate contract address from name、version and owner

func CalcMethodID

func CalcMethodID(protoType string) int64

CalcMethodID - calculate method id with method prototype

func CheckOrgID

func CheckOrgID(addr string) error

nolint unhandled CheckAddress check address and return result

func CheckVersions

func CheckVersions(firstContractPath string, res *Result) types.Error

Versions - 返回合约版本列表

func CreatePrototype

func CreatePrototype(item Method) string

CreatePrototype - create method prototype

func ErrorTransfer

func ErrorTransfer(err0 error, err *types.Error)

ErrorTransfer - transform common err to types.Error

func ExpandMapFieldKey

func ExpandMapFieldKey(f Field, index int) string

ExpandMapFieldKey - write map field key type to string

func ExpandMapFieldKeyToKey

func ExpandMapFieldKeyToKey(f Field, index int) string

ExpandMapFieldKeyToKey - write map field key make to string as access key

func ExpandMapFieldVal

func ExpandMapFieldVal(f Field) string

ExpandMapFieldVal - write map field val type to string

func ExpandMapFieldValNoStar

func ExpandMapFieldValNoStar(f Field) string

ExpandMapFieldValNoStar - write map field val type to string but not star, ...

func ExpandMethodPrototype

func ExpandMethodPrototype(f Function) string

nolint unhandled

func ExpandNames

func ExpandNames(t Field) string

ExpandNames - write field names to string nolint unhandled ..

func ExpandStruct

func ExpandStruct(s ast.GenDecl) string

ExpandStruct - actually expand GenDecl nolint unhandled ..

func ExpandType

func ExpandType(t Field) string

ExpandType - write field type to string nolint unhandled ..

func ExpandTypeNoStar

func ExpandTypeNoStar(t Field) string

ExpandTypeNoStar - write field type to string without star, ...

func FilterImports

func FilterImports(importPath string) bool

FilterImports filter import

func FmtAndWrite

func FmtAndWrite(filename, content string) error

FmtAndWrite - go fmt content and write to filename

func GetContractAddress

func GetContractAddress(name string, version string) types.Address

GetContractAddress get contract address from name、version and owner

func GetGas

func GetGas(comment string) string

GetGas - get gas value

func HaveUserDefinedStruct

func HaveUserDefinedStruct(method Method) bool

func LowerFirst

func LowerFirst(word string) string

LowerFirst - first letter to lower

func ParamsLen

func ParamsLen(item Method) int

CreatePrototype - create method prototype

func UpperFirst

func UpperFirst(word string) string

UpperFirst - first letter to upper

Types

type CallNode

type CallNode struct {
	RecvName string // receiver struct name
	FuncName string // func name
}

type Callee

type Callee struct {
	Select     []string
	LastImport Import
}

Callee 被調用的方法

type Field

type Field struct {
	Names         []string // names have 0 to n member(s)
	FieldType     ast.Expr
	RelatedImport map[Import]struct{} // the field type imported package
}

Field - describe the Field of go ast

func FieldsExpand

func FieldsExpand(f Field) []Field

FieldsExpand - expand a multi name field to multi single name field

type Function

type Function struct {
	Method
	Comments string
	Receiver Field // go Function's receiver is an array, but I doubt how it works.
	MGas     int64
	IGas     int64
	TGas     int64

	GetTransferToMe bool
	// contains filtered or unexported fields
}

Function - describe the function in go ast

type Import

type Import struct {
	Name string
	Path string
}

Import - ..

type ImportContract

type ImportContract struct {
	Name       string
	Interfaces []Method
	Pos        token.Pos
}

type Method

type Method struct {
	Name    string
	Params  []Field
	Results []Field
}

Method - the interface's method member has no receiver

type Report

type Report struct {
	Count   int64    `json:"count"`
	Flag    string   `json:"flag"`
	ErrDesc string   `json:"errDesc"`
	File    []string `json:"file"`
	Pos     []int64  `json:"pos"`
}

type Result

type Result struct {
	DirectionName string
	PackageName   string
	Imports       map[Import]struct{} // current file parsed,
	AllImports    map[Import]struct{} // imports of all files, see function importsCollector

	ContractName      string
	OrgID             string
	Version           string
	Versions          []string
	Author            string
	ContractStructure string

	Stores      []Field
	StoreCaches []Field

	InitChain          Function
	IsExistInitChain   bool
	UpdateChain        Function
	IsExistUpdateChain bool
	Mine               Function
	IsExistMine        bool
	Functions          []Function // all function
	MFunctions         []Function // methods
	IFunctions         []Function // interfaces
	TFunctions         []Function // ibcs

	Receipts        []Method
	ImportContracts []ImportContract

	UserStruct map[string]ast.GenDecl

	ErrFlag   bool
	ErrorDesc []string
	ErrorPos  []token.Pos
}

Result is the parse result

func Check

func Check(inPath string) (res *Result, err types.Error)

Check 分析该目录下的合约代码,进行各种规范检查,提取关键信息

func CheckEX

func CheckEX(inPath string) (res *Result, paramsTypes map[string]string, err types.Error)

Jump to

Keyboard shortcuts

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