utils

package
v0.0.0-...-9f791b1 Latest Latest
Warning

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

Go to latest
Published: Jun 22, 2022 License: MIT Imports: 29 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

View Source
var BigInt0 = big.NewInt(0)

BigInt0 as name

View Source
var EmptyAddress = common.Address{}

EmptyAddress all zero,invalid

View Source
var EmptyHash = common.Hash{}

EmptyHash all zero,invalid

View Source
var MaxBigUInt256, _ = new(big.Int).SetString("0xffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff", 0)

MaxBigUInt256 as name

View Source
var RandSrc = rand.NewSource(time.Now().UnixNano())

RandSrc random source from math

Functions

func APex

func APex(data common.Address) string

APex pex for address

func APex2

func APex2(data common.Address) string

APex2 shorter than APex

func BPex

func BPex(data []byte) string

BPex bytes to string

func BigIntTo32Bytes

func BigIntTo32Bytes(i *big.Int) []byte

BigIntTo32Bytes convert a big int to bytes

func BytesToString

func BytesToString(b []byte) string

BytesToString accepts bytes and returns their string presentation instead of string() this method doesn't generate memory allocations, BUT it is not safe to use anywhere because it points this helps on 0 memory allocations

func CalcChannelID

func CalcChannelID(token, tokensNetwork, p1, p2 common.Address) common.Hash

CalcChannelID 计算ChannelID的方式,注意与合约上计算方式保持完全一致.

func Decrypt

func Decrypt(src, key []byte) ([]byte, error)

Decrypt use aes,cfb to decrypt

func DeepCopy

func DeepCopy(dst, src interface{}) error

DeepCopy use gob to copy

func Ecrecover

func Ecrecover(hash common.Hash, signature []byte) (addr common.Address, err error)

Ecrecover is a wrapper for crypto.Ecrecover

func Encrypt

func Encrypt(src, key []byte) ([]byte, error)

Encrypt use ase,cfb encrypt

func Exists

func Exists(dir string) bool

Exists returns true if directory||file exists

func GetHomePath

func GetHomePath() string

GetHomePath returns the user's $HOME directory

func HPex

func HPex(data common.Hash) string

HPex pex for hash

func HexToAddress

func HexToAddress(addr string) (address common.Address, err error)

HexToAddress convert hex encoded address string to common.Address, and verify it is in accordance with EIP55

func HexToAddressWithoutValidation

func HexToAddressWithoutValidation(addr string) (address common.Address, err error)

HexToAddressWithoutValidation disable EIP55 validation

func IsValidPositiveInt256

func IsValidPositiveInt256(i *big.Int) bool

IsValidPositiveInt256 returns true if i is a valid positive int256

func IsValidUint256

func IsValidUint256(i *big.Int) bool

IsValidUint256 retuns true if i is a valid uint256

func MakePrivateKeyAddress

func MakePrivateKeyAddress() (*ecdsa.PrivateKey, common.Address)

MakePrivateKeyAddress generate a private key and it's address

func MyCallerFuncHandler

func MyCallerFuncHandler(h log.Handler) log.Handler

MyCallerFuncHandler handler for log

func MyStreamHandler

func MyStreamHandler(wr io.Writer) log.Handler

MyStreamHandler handler for log

func NewRandomAddress

func NewRandomAddress() common.Address

NewRandomAddress generate a address,there maybe no corresponding priv key

func NewRandomHash

func NewRandomHash() common.Hash

NewRandomHash generate random hash,for testonly

func NewRandomInt

func NewRandomInt(n int) int

NewRandomInt generate a random int ,not more than n

func NewRandomInt64

func NewRandomInt64() int64

NewRandomInt64 generate a random int64

func PasswordDecrypt

func PasswordDecrypt(encpass string) (pass string, err error)

PasswordDecrypt decrypt arguments --password-file for arguments --password-file usage

func PasswordEncrypt

func PasswordEncrypt(pass string) (encstr string, err error)

PasswordEncrypt encrypt accounts password to base64 encoding for arguments --password-file use

func Pex

func Pex(data []byte) string

Pex short string stands for data

func PrintStack

func PrintStack()

PrintStack output stack to

func PubkeyToAddress

func PubkeyToAddress(pubkey []byte) common.Address

PubkeyToAddress convert pubkey bin to address

func Random

func Random(n int) []byte

Random takes a parameter (int) and returns random slice of byte ex: var randomstrbytes []byte; randomstrbytes = utils.Random(32)

func RandomString

func RandomString(n int) string

RandomString accepts a number(10 for example) and returns a random string using simple but fairly safe random algorithm

func ReadBigInt

func ReadBigInt(reader io.Reader) *big.Int

ReadBigInt read big.Int from buffer

func ReadVarInt

func ReadVarInt(r io.Reader) (uint64, error)

ReadVarInt reads a variable length integer from r and returns it as a uint64.

func Sha3

func Sha3(data ...[]byte) common.Hash

Sha3 is short for Keccak256Hash

func ShaSecret

func ShaSecret(data []byte) common.Hash

ShaSecret is short for sha256

func SignData

func SignData(privKey *ecdsa.PrivateKey, data []byte) (sig []byte, err error)

SignData sign with ethereum format

func Stack

func Stack() []byte

Stack returns a formatted stack trace of the goroutine that calls it. It calls runtime.Stack with a large enough buffer to capture the entire trace.

func StringInterface

func StringInterface(i interface{}, depth int) string

StringInterface use spew to string any object with max `depth`,it's not thread safe.

func StringInterface1

func StringInterface1(i interface{}) string

StringInterface1 use spew to string any object with depth 1,it's not thread safe.

func StringToBytes

func StringToBytes(s string) []byte

StringToBytes accepts string and returns their []byte presentation instead of byte() this method doesn't generate memory allocations, BUT it is not safe to use anywhere because it points this helps on 0 memory allocations

func SystemExit

func SystemExit(code int)

SystemExit quit and print stack

func ToJSONFormat

func ToJSONFormat(v interface{}) string

ToJSONFormat :

func WriteVarInt

func WriteVarInt(w io.Writer, val uint64) error

WriteVarInt serializes val to w using a variable number of bytes depending on its value.

Types

type AsyncResult

type AsyncResult struct {
	Result         chan error
	Tag            interface{}
	LockSecretHash common.Hash // only for /api/1/transfer use, return LockSecretHash to caller
}

AsyncResult is designed for async notify and Tag can be save anything by user.

func NewAsyncResult

func NewAsyncResult() *AsyncResult

NewAsyncResult create a AsyncResult

func NewAsyncResultWithError

func NewAsyncResultWithError(err error) *AsyncResult

NewAsyncResultWithError create AsyncResult with result

type DebugLock

type DebugLock struct {
	sync.Mutex
	// contains filtered or unexported fields
}

DebugLock a tool for dead lock detect

func (*DebugLock) Lock

func (m *DebugLock) Lock()

Lock with name for dead lock detect

func (*DebugLock) Unlock

func (m *DebugLock) Unlock()

Unlock with name for dead lock detect

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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