util

package
v0.0.0-...-3b2d471 Latest Latest
Warning

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

Go to latest
Published: Nov 10, 2023 License: MIT Imports: 18 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 GetShortIdOfHash

func GetShortIdOfHash(hash string) uint64

func GetSummaryOfBlock

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

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 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 *rpc.BlockNumber, hardforkBlockNumber rpc.BlockNumber,
) (*rpc.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

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{}) (interface{}, bool)

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

Directories

Path Synopsis
rpc

Jump to

Keyboard shortcuts

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