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: 19 Imported by: 0

Documentation

Index

Constants

This section is empty.

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 ErrNullPassphrase = errors.New("passphrase is null")
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 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 GetFileByKey

func GetFileByKey(fileDirt, key string) (string, error)

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 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 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 PromptPassphrase

func PromptPassphrase(confirmation bool) string

todo: change prompt to --password flag? promptPassphrase prompt the hint in the terminal to let user to input the password

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 Keyfile

type Keyfile struct {
	Address    string `json:"address"`
	Json       []byte
	Passphrase string
	// contains filtered or unexported fields
}

func NewKeyfile

func NewKeyfile(keyfilePath string) (*Keyfile, error)

func (*Keyfile) GetPrivateKey

func (k *Keyfile) GetPrivateKey() *ecdsa.PrivateKey

func (*Keyfile) ParsePrivateKey

func (k *Keyfile) ParsePrivateKey() error

GetPrivateKey gets the private key by decrypting the keystore file

Jump to

Keyboard shortcuts

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