util

package
v1.2.8-testnet Latest Latest
Warning

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

Go to latest
Published: Dec 21, 2023 License: MIT Imports: 19 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func ConvertToHashSlice

func ConvertToHashSlice(ss []string) []types.Hash

ConvertToHashSlice convert string slice to hash slice

func ConvertToNumberedEpoch

func ConvertToNumberedEpoch(cfx sdk.ClientOperator, epoch *types.Epoch) (*types.Epoch, error)

ConvertToNumberedEpoch converts named epoch to numbered epoch if necessary

func GetEthHardforkBlockNumber

func GetEthHardforkBlockNumber(chainId uint64) web3goTypes.BlockNumber

GetEthHardforkBlockNumber gets eSpace hardfork block number by chain ID

func GetShortIdOfHash

func GetShortIdOfHash(hash string) uint64

func GetSummaryOfBlock

func GetSummaryOfBlock(block *types.Block) *types.BlockSummary

func IncludeCfxLogAddrs

func IncludeCfxLogAddrs(log *types.Log, addresses []cfxaddress.Address) bool

IncludeCfxLogAddrs checks if the core space event logs include any of the given addresses

func IncludeEthLogAddrs

func IncludeEthLogAddrs(log *web3goTypes.Log, addresses []common.Address) bool

IncludeEthLogAddrs checks if the eSpace event logs include any of the given addresses

func IsEip155Tx

func IsEip155Tx(tx *web3goTypes.TransactionDetail) bool

IsEip155Tx check if the EVM transaction is compliant to EIP155

func IsEmptyBlock

func IsEmptyBlock(block *types.Block) bool

IsEmptyBlock checks if block contains any executed transaction(s)

func IsInterfaceValNil

func IsInterfaceValNil(i interface{}) bool

Helper function to check if interface value is nil, since "i == nil" checks nil interface case only. Refer to https://mangatmodi.medium.com/go-check-nil-interface-the-right-way-d142776edef1 for more details.

func IsLegacyEthTx

func IsLegacyEthTx(tx *web3goTypes.TransactionDetail) bool

IsLegacyEthTx check if the EVM transaction is legacy (pre EIP155)

func IsSuccessEthTx

func IsSuccessEthTx(tx *web3goTypes.TransactionDetail) bool

IsSuccessEthTx check if the EVM transaction is success

func IsTxExecutedInBlock

func IsTxExecutedInBlock(tx *types.Transaction) bool

func IsValidHashStr

func IsValidHashStr(hashStr string) bool

IsValidHashStr validates if the search (block/tx) hash contains the right characters and in the right length.

func IsZeroHash

func IsZeroHash(hash *common.Hash) bool

func MatchCfxLogTopics

func MatchCfxLogTopics(log *types.Log, topics [][]types.Hash) bool

MatchCfxLogTopics checks if the core space event log matches with the given topics condition

func MatchEthLogTopics

func MatchEthLogTopics(log *web3goTypes.Log, topics [][]common.Hash) bool

MatchEthLogTopics checks if the eSpace event log matches with the given topics condition

func MaxInt

func MaxInt(a, b int) int

func MaxUint64

func MaxUint64(a, b uint64) uint64

func MinInt

func MinInt(a, b int) int

func MinUint32

func MinUint32(a, b uint32) uint32

func MinUint64

func MinUint64(a, b uint64) uint64

func MustMarshalJson

func MustMarshalJson(v interface{}) []byte

func MustMarshalRLP

func MustMarshalRLP(v interface{}) []byte

func MustUnmarshalJson

func MustUnmarshalJson(data []byte, v interface{})

func MustUnmarshalRLP

func MustUnmarshalRLP(data []byte, v interface{})

func NormalizeEthBlockNumber

func NormalizeEthBlockNumber(
	w3c *web3go.Client, blockNum *web3goTypes.BlockNumber, hardforkBlockNumber web3goTypes.BlockNumber,
) (*web3goTypes.BlockNumber, error)

NormalizeEthBlockNumber normalizes ETH block number to be positive if necessary

func RandUint64

func RandUint64(limit uint64) uint64

func StripLogExtraFieldsForRPC

func StripLogExtraFieldsForRPC(logs []types.Log)

StripLogExtraFields strips extra unnecessary fields from logs to comply with fullnode rpc

func WildCardToRegexp

func WildCardToRegexp(pattern string) string

WildCardToRegexp converts a wildcard pattern to a regular expression pattern.

Types

type ConcurrentMap

type ConcurrentMap struct {
	sync.Map
	// contains filtered or unexported fields
}

func (*ConcurrentMap) LoadOrStoreFn

func (m *ConcurrentMap) LoadOrStoreFn(
	key interface{}, factory func(k interface{}) interface{},
) (actual interface{}, loaded bool)

func (*ConcurrentMap) LoadOrStoreFnErr

func (m *ConcurrentMap) LoadOrStoreFnErr(
	key interface{}, factory func(k interface{}) (interface{}, error),
) (actual interface{}, loaded bool, err error)

type ExpirableLruCache

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

ExpirableLruCache naive implementation of LRU cache with fixed TTL expiration duration. This cache uses a lazy eviction policy, by which the expired entry will be purged when it's being looked up.

func NewExpirableLruCache

func NewExpirableLruCache(size int, ttl time.Duration) *ExpirableLruCache

func (*ExpirableLruCache) Add

func (c *ExpirableLruCache) Add(key, value interface{}) bool

Add adds a value to the cache. Returns true if an eviction occurred.

func (*ExpirableLruCache) Get

func (c *ExpirableLruCache) Get(key interface{}) (v interface{}, found bool)

Get looks up a key's value from the cache. Will purge the entry and return nil if the entry expired.

func (*ExpirableLruCache) GetNoExp

func (c *ExpirableLruCache) GetNoExp(key interface{}) (v interface{}, expired, found bool)

GetNoExp looks up a key's value from the cache without expiration action.

Directories

Path Synopsis
rpc

Jump to

Keyboard shortcuts

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