utils

package
v0.5.3 Latest Latest
Warning

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

Go to latest
Published: Nov 28, 2022 License: MIT Imports: 15 Imported by: 4

Documentation

Index

Constants

View Source
const (
	InfoColor    = "\033[1;34m%s\033[0m"
	NoticeColor  = "\033[1;36m%s\033[0m"
	WarningColor = "\033[1;33m%s\033[0m"
	ErrorColor   = "\033[1;31m%s\033[0m"
	DebugColor   = "\033[0;36m%s\033[0m"
)

Variables

View Source
var DebugEnabled bool = os.Getenv("DEBUG") != ""
View Source
var (
	ErrTargetTimestampAfterLatestBlock = errors.New("target timestamp after latest block")
)

Functions

func Abs

func Abs(x int64) int64

func BigFloatToHumanNumberString

func BigFloatToHumanNumberString(f *big.Float, decimals int) string

func BigIntToHumanNumberString

func BigIntToHumanNumberString(i *big.Int, decimals int) string

func ColorPrintf

func ColorPrintf(color string, format string, a ...interface{})

func DateToTime

func DateToTime(dayString string, hour int, min int, sec int) (time.Time, error)

func EstimateTargetBlocknumber

func EstimateTargetBlocknumber(utcTimestamp int64) int64

Roughly estimate a block number by target timestamp (might be off by a lot)

func FindBlockRange added in v0.3.0

func FindBlockRange(client *ethclient.Client, blockHeight int, date string, hour int, min int, length string) (startBlock int64, endBlock int64, err error)

GetBlockRangeFromArguments returns start and end blocks for a given block or date range. startBlock is first block at or after the given time, endBlock is the last before the given end time.

func GetBlocks added in v0.5.2

func GetBlocks(blockChan chan<- *types.Block, client *ethclient.Client, startBlock int64, endBlock int64, concurrency int)

GetBlocks is a fast block query pipeline. It queries blocks concurrently and pushes it into a channel for processing.

func GetErc20TokensInUnit added in v0.3.3

func GetErc20TokensInUnit(numTokens *big.Int, addrDetail addressdetail.AddressDetail) (amount *big.Float, symbol string)

func GetFirstBlockHeaderAtOrAfterTime

func GetFirstBlockHeaderAtOrAfterTime(client *ethclient.Client, targetTime time.Time) (header *types.Header, err error)

GetBlockHeaderAtTimestamp returns the header of the first block at or after the timestamp. If timestamp is after latest block, then return latest block. This function is a bit messy, but works. Improvements to this approach are welcome.

func GetTxSender

func GetTxSender(tx *types.Transaction) (from common.Address, err error)

func IsBigIntZero

func IsBigIntZero(n *big.Int) bool

func NumberToHumanReadableString

func NumberToHumanReadableString(value interface{}, decimals int) string

func Perror

func Perror(err error)

func PrintBlock

func PrintBlock(block *types.Block)

func WeiBigIntToEthString added in v0.3.2

func WeiBigIntToEthString(wei *big.Int, decimals int) string

// Returns bigint wei amount as comma-separated, human-readable string (eg. 1,435,332.71)

func WeiToEth added in v0.3.2

func WeiToEth(wei *big.Int) (ethValue *big.Float)

func WeiUintToEth added in v0.3.2

func WeiUintToEth(wei uint64) (ethValue float64)

Types

This section is empty.

Jump to

Keyboard shortcuts

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