base

package
v6.0.0-...-bd7a03d Latest Latest
Warning

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

Go to latest
Published: Nov 2, 2025 License: GPL-3.0 Imports: 17 Imported by: 0

Documentation

Overview

Package base implements various base functions

Index

Constants

View Source
const NOPOS = uint64(^uint64(0))
View Source
const NOPOSI = Timestamp(0xdeadbeef)
View Source
const NOPOSN = Value(^uint64(0))

Variables

View Source
var (
	NotAMonitor  = HexToAddress("0x1234deaddeaddead98766789deaddeaddead4321")
	SentinelAddr = HexToAddress("0xdeaddeaddeaddeaddeaddeaddeaddeaddeaddead")
	ZeroAddr     = HexToAddress("0x0")
)

A few well-known address. ZeroAddr, of course, is 0x0. NotAMonitor is a marker to signify the end of the monitor list produced by ListMonitors. SentinelAddr is for misconfigured miner appearances

View Source
var (
	// FAKE_ETH_ADDRESS is the address we use to represent ETH in the ledgers
	FAKE_ETH_ADDRESS = HexToAddress("0xeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeee")
	// EndOfBlockSentinel is used in some streaming instances to make the end of a block
	EndOfBlockSentinel = HexToAddress("0xdeadbeefdeadbeefdeadbeefdeadbeefdeadbeef")
	// EndOfStreamSentinel is used in some streaming instances to make the end of the stream
	EndOfStreamSentinel = HexToAddress("0xbeefdeadbeefdeadbeefdeadbeefdeadbeefdead")
)
View Source
var (
	PrefundSender     = HexToAddress("0x0000000000000000000000000050726566756e64") // The word "Prefund" in hex
	BlockRewardSender = HexToAddress("0x0000000000000000000000000000004d696e6572") // The word "Miner" in hex
	UncleRewardSender = HexToAddress("0x000000000000000000000000000000556e636c65") // The word "Uncle" in hex
	WithdrawalSender  = HexToAddress("0x000000000000000000005769746864726177616C") // The word "Withdrawal" in hex
	SkippedSender     = HexToAddress("0x00000000000000000000000000536B6970706564") // The word "Skipped" in hex
)

These purposefully chosen baddresses are used to indicate that the transaction is a prefund and uncle reward, or a mining reward. They are not real addresses, but are used to indicate that the transaction is not a normal transaction. They are not (currently) indexed.

View Source
var (
	Byzantium      = "byzantium"
	Constantinople = "constantinople"
	London         = "london"
	Merge          = "merge"
	Shanghai       = "shanghai"
	FirstTrace     = "first_trace"
)
View Source
var (
	ZeroFloat = NewFloat(0)
	OneFloat  = NewFloat(1)
)
View Source
var ErrInvalidHex = errors.New("hex string must contain only hex characters")
View Source
var ErrInvalidLength = errors.New("hex string must be an even length")
View Source
var ErrNoLeading0x = errors.New("hex string must start with 0x")
View Source
var (
	ZeroWei = NewWei(0)
)

Functions

func BiFromBn

func BiFromBn(bn Blknum) *big.Int

func Bytes2Hex

func Bytes2Hex(d []byte) string

Bytes2Hex duplicates the same-named function found in common, because we want to better control dependencies

func FormattedDate

func FormattedDate(ts Timestamp) string

func GetDateKey

func GetDateKey(period string, date DateTime) string

func Hex2Bytes

func Hex2Bytes(str string) []byte

Hex2Bytes duplicates the same-named function found in common, because we want to better control dependencies

func IsFinal

func IsFinal(latestTs, blockTs Timestamp) bool

func IsHex

func IsHex(str string) bool

func IsTestMode

func IsTestMode() bool

func IsValidAddress

func IsValidAddress(val string) bool

func IsValidAddressE

func IsValidAddressE(val string) (bool, error)

func IsValidHex

func IsValidHex(typ string, val string, nBytes int) (bool, error)

func IsValidPeriod

func IsValidPeriod(period string) bool

func MustParseFloat64

func MustParseFloat64(val string) float64

func MustParseInt64

func MustParseInt64(input string) int64

func MustParseUint64

func MustParseUint64(input string) uint64

func ReadValue

func ReadValue(reader io.Reader, dest any, fileVersion uint64) (err error)

ReadValue reads binary representation of fixed-size values, strings, big.Int, Unmarshaler and slices of these values. Version number is passed to any Unmarshaler to ease reading older formats.

func ValidHex

func ValidHex(val string, nBytes int) (bool, error)

func WeiToHash

func WeiToHash(wei *Wei) (string, error)

func WriteValue

func WriteValue(writer io.Writer, value any) (err error)

WriteValue writes binary representation of fixed-size values, strings, big.Int, Marshaler and slices of these values. Contrary to ReadValue, it doesn't support versioning, because it is expected that only the most recent data format is used when writing.

Types

type Address

type Address struct {
	common.Address `json:"address"`
}

Address is a wrapper for go-ethereum's Address type that always return lower case hex.

func AddressFromPath

func AddressFromPath(path, fileType string) (Address, error)

AddressFromPath returns an address from a path -- is assumes the filename is a valid address starting with 0x and ends with the fileType. if the path does not contain an address, an error is returned. If the path does not end with the given fileType, it panics.

func BytesToAddress

func BytesToAddress(b []byte) (addr Address)

func GetTestPublisher

func GetTestPublisher() Address

GetTestPublisher does not get customized per chain. We can only test against mainnet currently

func HexToAddress

func HexToAddress(hex string) (addr Address)

HexToAddress returns new address with the given string as value.

func (*Address) CheckSum

func (a *Address) CheckSum() string

CheckSum returns the checksum address of the given address. We might want this, for example, to pick up ABIs and source code from Sourcify which requires checksum addresses.

func (*Address) Common

func (a *Address) Common() common.Address

func (*Address) DefaultSymbol

func (a *Address) DefaultSymbol() string

func (*Address) Display

func (a *Address) Display(left, right int) string

Display returns a string representation of the address with the left and right most characters displayed. If left is 0, only the `right` trailing characters are display. If right is 0, only the `left` leading characters are displayed. Otherwise, all the characters between left and right are replaced with three dots.

func (*Address) Equal

func (a *Address) Equal(b Address) bool

func (Address) Format

func (a Address) Format(s fmt.State, c rune)

Format is used by Stringer don't remove

func (*Address) GreaterThan

func (a *Address) GreaterThan(b Address) bool

func (*Address) GreaterThanOrEqual

func (a *Address) GreaterThanOrEqual(b Address) bool

func (*Address) Hex

func (a *Address) Hex() string

Hex returns string representation of an address

func (*Address) IsPrecompile

func (a *Address) IsPrecompile() bool

IsPrecompile Returns true if the address is not a precompile (and not the zero address by extension)

func (*Address) IsZero

func (a *Address) IsZero() bool

IsZero returns true if an address is a zero value or 0x0.

func (*Address) LessThan

func (a *Address) LessThan(b Address) bool

func (*Address) LessThanOrEqual

func (a *Address) LessThanOrEqual(b Address) bool

func (Address) MarshalText

func (a Address) MarshalText() ([]byte, error)

MarshalText is used by Stringer don't remove

func (*Address) NotEqual

func (a *Address) NotEqual(b Address) bool

func (*Address) Pad32

func (a *Address) Pad32() string

func (*Address) SetCommon

func (a *Address) SetCommon(c *common.Address) Address

func (*Address) SetHex

func (a *Address) SetHex(hexStr string)

SetHex sets the address based on the provided string

func (Address) String

func (a Address) String() string

func (*Address) UnmarshalCSV

func (a *Address) UnmarshalCSV(hex string) error

func (*Address) UnmarshalJSON

func (e *Address) UnmarshalJSON(data []byte) error

UnmarshalJSON implements the json.Unmarshaler interface for Address. It supports multiple representations of a "zero" or uninitialized address. If the JSON input is "0x0", an empty string, or the literal null, the Address is set to ZeroAddr. Otherwise, it delegates to the embedded Address type's UnmarshalJSON method to handle a full-length hexadecimal address.

type Blknum

type Blknum = Value

func KnownBlock

func KnownBlock(chain, blockName string) Blknum

func MustParseBlknum

func MustParseBlknum(input string) Blknum

type DateTime

type DateTime struct {
	time.Time
}

func NewDateTime

func NewDateTime(fields ...int) DateTime

func NewDateTimeTs

func NewDateTimeTs(ts Timestamp) DateTime

func (*DateTime) After

func (dt *DateTime) After(test *DateTime) bool

func (*DateTime) Before

func (dt *DateTime) Before(test *DateTime) bool

func (*DateTime) EndOfMonth

func (dt *DateTime) EndOfMonth() DateTime

func (*DateTime) EndOfYear

func (dt *DateTime) EndOfYear() DateTime

func (*DateTime) MarshalCSV

func (dt *DateTime) MarshalCSV() (string, error)

func (*DateTime) String

func (dt *DateTime) String() string

func (*DateTime) UnmarshalCSV

func (dt *DateTime) UnmarshalCSV(csv string) (err error)

type Float

type Float big.Float

func NewFloat

func NewFloat(f float64) *Float

func ToFloat

func ToFloat(wei *Wei) *Float

func ToFloatWithDecimals

func ToFloatWithDecimals(wei *Wei, decimals int) *Float

func (*Float) Cmp

func (f *Float) Cmp(other *Float) int

func (*Float) Equal

func (f *Float) Equal(other *Float) bool

func (*Float) Float64

func (f *Float) Float64() float64

func (*Float) GreaterThan

func (f *Float) GreaterThan(other *Float) bool

func (*Float) GreaterThanOrEqual

func (f *Float) GreaterThanOrEqual(other *Float) bool

func (*Float) IsZero

func (f *Float) IsZero() bool

func (*Float) LessThan

func (f *Float) LessThan(other *Float) bool

func (*Float) LessThanOrEqual

func (f *Float) LessThanOrEqual(other *Float) bool

func (*Float) MarshalCache

func (f *Float) MarshalCache(writer io.Writer) error

func (*Float) MarshalJSON

func (f *Float) MarshalJSON() ([]byte, error)

func (*Float) Mul

func (f *Float) Mul(a, b *Float) *Float

func (*Float) NotEqual

func (f *Float) NotEqual(other *Float) bool

func (*Float) Quo

func (f *Float) Quo(a, b *Float) *Float

func (*Float) SetFloat64

func (f *Float) SetFloat64(fl float64) *Float

func (*Float) SetInt64

func (f *Float) SetInt64(i int64) *Float

func (*Float) SetRawWei

func (f *Float) SetRawWei(i *Wei) *Float

SetRawWei sets the Ether’s value directly from the Wei’s big.Int. No scaling is done – it simply copies the Wei value into a big.Float.

func (*Float) SetString

func (f *Float) SetString(s string) (*Float, bool)

func (*Float) SetUint64

func (f *Float) SetUint64(i uint64) *Float

func (*Float) SetWei

func (f *Float) SetWei(i *Wei) *Float

func (*Float) String

func (f *Float) String() string

func (*Float) Text

func (f *Float) Text(format byte, prec int) string

func (*Float) ToBigFloat

func (f *Float) ToBigFloat() *big.Float

func (*Float) UnmarshalCache

func (f *Float) UnmarshalCache(fileVersion uint64, reader io.Reader) error

func (*Float) UnmarshalJSON

func (f *Float) UnmarshalJSON(data []byte) error

type Gas

type Gas = Value

func MustParseGas

func MustParseGas(input string) Gas

type Hash

type Hash struct {
	common.Hash `json:"hash"`
}

Hash is a wrapper for go-ethereum's Hash type that always return lower case hex.

func BytesToHash

func BytesToHash(b []byte) (hash Hash)

func HexToHash

func HexToHash(hex string) (hash Hash)

HexToHash returns new hash with the given string as value.

func (*Hash) Common

func (h *Hash) Common() common.Hash

func (Hash) Format

func (h Hash) Format(s fmt.State, c rune)

Format is used by Stringer don't remove

func (*Hash) Hex

func (h *Hash) Hex() string

Hex returns string representation of an hash. Unlike addresses, we do not shorten zero hashes.

func (*Hash) IsZero

func (h *Hash) IsZero() bool

IsZero returns true if an hash is a zero value or 0x0.

func (Hash) MarshalText

func (h Hash) MarshalText() ([]byte, error)

MarshalText is used by Stringer don't remove

func (*Hash) SetCommon

func (h *Hash) SetCommon(c *common.Hash) Hash

func (*Hash) SetHex

func (h *Hash) SetHex(hexStr string)

SetHex sets the hash based on the provided string

func (*Hash) String

func (h *Hash) String() string

func (*Hash) UnmarshalCache

func (h *Hash) UnmarshalCache(fileVersion uint64, reader io.Reader) error

func (*Hash) UnmarshalJSON

func (h *Hash) UnmarshalJSON(data []byte) error

type IpfsHash

type IpfsHash string

func (IpfsHash) String

func (h IpfsHash) String() string

type Lognum

type Lognum = Value

type Marshaler

type Marshaler interface {
	MarshalCache(writer io.Writer) error
}

type Pair

type Pair[T, U any] struct {
	First  T
	Second U
}

type Timestamp

type Timestamp int64

func MustParseTimestamp

func MustParseTimestamp(input string) Timestamp

func (*Timestamp) Int64

func (t *Timestamp) Int64() int64

func (*Timestamp) UnmarshalJSON

func (t *Timestamp) UnmarshalJSON(data []byte) error

type Topic

type Topic = string

type Tracenum

type Tracenum = Value

type Txnum

type Txnum = Value

func MustParseTxnum

func MustParseTxnum(input string) Txnum

type Unmarshaler

type Unmarshaler interface {
	UnmarshalCache(vers uint64, reader io.Reader) error
}

type Value

type Value uint64 // allows for json parsing

type Value = uint64 // as an alias

func MustParseValue

func MustParseValue(input string) Value

func (*Value) UnmarshalJSON

func (v *Value) UnmarshalJSON(data []byte) error

type Wei

type Wei big.Int

Wei is a type in its own right. This means we can extend it by adding our own methods, such as UnMarshalJSON and MarshalJSON which are required because our Json encodes big.Ints as strings. Note that

func HexToWei

func HexToWei(hex string) *Wei

func MustParseWei

func MustParseWei(input string) Wei

func NewWei

func NewWei(x int64) *Wei

func NewWeiStr

func NewWeiStr(x string) *Wei

func (*Wei) Abs

func (w *Wei) Abs() *Wei

Abs returns the absolute value of w. Returns nil if w is nil.

func (*Wei) Add

func (w *Wei) Add(x, y *Wei) *Wei

func (*Wei) BigInt

func (w *Wei) BigInt() *big.Int

func (*Wei) Bytes

func (w *Wei) Bytes() []byte

func (*Wei) Cmp

func (w *Wei) Cmp(y *Wei) int

func (*Wei) Div

func (w *Wei) Div(x, y *Wei) *Wei

func (*Wei) Equal

func (w *Wei) Equal(other *Wei) bool

func (*Wei) Float64

func (w *Wei) Float64() float64

func (*Wei) GreaterThan

func (w *Wei) GreaterThan(other *Wei) bool

func (*Wei) GreaterThanOrEqual

func (w *Wei) GreaterThanOrEqual(other *Wei) bool

func (*Wei) IsZero

func (w *Wei) IsZero() bool

func (*Wei) LessThan

func (w *Wei) LessThan(other *Wei) bool

func (*Wei) LessThanOrEqual

func (w *Wei) LessThanOrEqual(other *Wei) bool

func (*Wei) MarshalCache

func (w *Wei) MarshalCache(writer io.Writer) error

func (*Wei) MarshalText

func (w *Wei) MarshalText() (text []byte, err error)

func (*Wei) Mul

func (w *Wei) Mul(x, y *Wei) *Wei

func (*Wei) Neg

func (w *Wei) Neg() *Wei

Neg returns a new Wei that is the negation (i.e., multiplication by -1) of w.

func (*Wei) NotEqual

func (w *Wei) NotEqual(other *Wei) bool

func (*Wei) Quo

func (w *Wei) Quo(x, y *Wei) *Wei

func (*Wei) SetInt64

func (w *Wei) SetInt64(x int64) *Wei

func (*Wei) SetString

func (w *Wei) SetString(s string, base int) (*Wei, bool)

func (*Wei) SetUint64

func (w *Wei) SetUint64(x uint64) *Wei

func (*Wei) Sign

func (w *Wei) Sign() int

Sign returns -1 if the Wei is negative, 0 if it is zero, and 1 if it is positive.

func (*Wei) String

func (w *Wei) String() string

func (*Wei) Sub

func (w *Wei) Sub(x, y *Wei) *Wei

func (*Wei) Text

func (w *Wei) Text(base int) string

func (*Wei) ToBigInt

func (b *Wei) ToBigInt() *big.Int

func (*Wei) ToFloatString

func (w *Wei) ToFloatString(decimals int) string

func (*Wei) Uint64

func (w *Wei) Uint64() uint64

func (*Wei) UnmarshalCache

func (w *Wei) UnmarshalCache(fileVersion uint64, reader io.Reader) error

func (*Wei) UnmarshalJSON

func (e *Wei) UnmarshalJSON(data []byte) error

func (*Wei) UnmarshalText

func (w *Wei) UnmarshalText(text []byte) error

Jump to

Keyboard shortcuts

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