utils

package
v1.1.2 Latest Latest
Warning

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

Go to latest
Published: Jul 4, 2022 License: GPL-3.0 Imports: 21 Imported by: 0

Documentation

Index

Constants

View Source
const (
	CnsIsName int32 = iota
	CnsIsAddress
	CnsIsUndefined
)

Variables

View Source
var (
	ErrParamTypeFormat = "incorrect param type: %s, index: %d.\n"

	ErrReadFileFormat  = "read %s file error: %s\n"
	ErrOpenFileFormat  = "open %s file error: %s\n"
	ErrFindFileFormat  = "find file error: %s\n"
	ErrWriteFileFormat = "write file error: %s"

	//----------------------------------------------------------------
	ErrSendTransacionFormat = "send Transaction through http error: %s"
	ErrPackFunctionFormat   = "packet functions err: %s\n"
	ErrPackDataFormat       = "packet data err: %s\n"

	ErrParamCheckFormat    = "the input <%s> cannot be empty.\n"
	ErrParamNumCheckFormat = "param check error, required %d inputs, recieved %d.\n"
	//ErrParamValidFormat = "%s param is not valid: %s\n"
	ErrParamInValidSyntax = "invalid %s syntax.\n"
	ErrParamParseFormat   = "parse %s param error: %s\n"

	ErrParseFileFormat      = "parse %s file error: %s"
	ErrUnmarshalBytesFormat = "unmarshal %s bytes error: %s"

	ErrInputNullFormat = "the %s cannot be empty.\n"

	ErrRlpEncodeFormat = "rlp encode error: %s"
	ErrRlpDecodeFormat = "%s rlp decode error: %s"

	ErrGetFromChainFormat = "get %s from chain error: %s"

	ErrHttpSendFormat           = "send http post error:\n%s"
	ErrHttpNoResponseFormat     = "no response from node: %s"
	ErrHttpResponseStatusFormat = "http response status: %s"
	ErrRpcExecuationFormat      = "execute %s rpc call error: %s\n"

	ErrTODO = "something wrong, see more details in %s"

	PanicUnexpSituation = "unexpected situation in function %s\n"
)
View Source
var (
	ErrFileNull = errors.New("file path cannot be empty")
)
View Source
var LogDeg *log.Logger
View Source
var LogErr *log.Logger
View Source
var Logger *log.Logger

Functions

func AddressConvert

func AddressConvert(address string) (interface{}, error)

AddressConvert converts hex string format address to byte format address when the input is null, the output address is [0 0 ... 0]

func BytesConverter

func BytesConverter(source []byte, t string) interface{}

BytesConverter converts the bytes to the specific data type it is the same as the BytesConverter in ctool/core/bytes_util.go

func DeleteOldFile

func DeleteOldFile(fileDirt string) error

func FileDirectoryInit

func FileDirectoryInit(filedirt string)

FileDirectoryInit creates a new folder if the file directory is not exist

func FuncParse

func FuncParse(funcName string, funcParams []string) (string, []string)

FuncParse wraps the GetFuncNameAndParams it separates the function method name and the parameters

func GetFileByKey

func GetFileByKey(fileDirt, key string) string

GetFileByKey search the file in the file directory by the search keywords provided if found, return the file name

func GetFileInDirt

func GetFileInDirt(fileDirt string) (string, error)

GetFileInDirt get the first file at the file directory

func GetFuncNameAndParams

func GetFuncNameAndParams(funcAndParams string) (string, []string)

GetFuncNameAndParams parse the function params from the input string

func GetFuncParams

func GetFuncParams(paramString string) []string

deprecated, see abi/temp.go

func GetPrivateKey

func GetPrivateKey(keyJson []byte) *ecdsa.PrivateKey

GetPrivateKey gets the private key by decrypting the keystore file

func GetRunningTimePath

func GetRunningTimePath() string

get the path where the executable is executed

func IntValueConvert

func IntValueConvert(value string) (string, error)

TODO optimize ?

func IsInRange

func IsInRange(value string, num uint64) bool

IsInRange check the value is in the range selected

func IsMatch

func IsMatch(param, paramName string) bool

IsMatch selects different patterns by the paramName

func IsNameOrAddress

func IsNameOrAddress(str string) int32

TODO refactory IsNameOrAddress Judge whether the input string is an address or a name

func IsRoleMatch

func IsRoleMatch(role string) bool

isRoleMatch checks if the input role is valid

func IsRoleMatchV2

func IsRoleMatchV2(role string) bool

func IsUrl

func IsUrl(url string) bool

IsUrl check if the input is an Url, for examplt 127.0.0.1:6791

func IsValidRoles

func IsValidRoles(roles string) bool

isValidRoles wraps isRoleMatch, it extracts the roles in the array and validates the roles

func LogInit

func LogInit()

LogInit is used while debugging utils, packet packages

func ParseFileToBytes

func ParseFileToBytes(filePath string) ([]byte, error)

ParseFileToBytes read the file and return the file bytes

func PrintJson

func PrintJson(marshalJson []byte) string

PrintJson reformats the json printing style, easier for users to read

func PrintRequest

func PrintRequest(params interface{})

PrintRequest print the request to terminal or log for debugging usage it will limit the printing length if the request is too long

func TrimSpace

func TrimSpace(str string) string

TrimSpace trims all the space in the string

func UintValueConvert

func UintValueConvert(value string) (string, error)

func WriteFile

func WriteFile(fileBytes []byte, filePath string) error

WriteFile writes the new data in the file, the old data will be override

Types

type KeystoreJson

type KeystoreJson struct {
	Address string `json:"address"`
	Json    []byte
}

Jump to

Keyboard shortcuts

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