base

package
v0.0.0-...-aac2901 Latest Latest
Warning

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

Go to latest
Published: Jun 6, 2024 License: GPL-3.0 Imports: 14 Imported by: 23

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")
	SentinalAddr = 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. SentinalAddr is for misconfigured miner appearances

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
)

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 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 FAKE_ETH_ADDRESS = HexToAddress("0xeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeee")

FAKE_ETH_ADDRESS is the address we use to represent ETH in the ledgers

View Source
var NotARange = FileRange{First: NOPOSN, Last: NOPOSN}

Functions

func AddrToPetname

func AddrToPetname(address string, separator string) string

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 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 IsPrecompile

func IsPrecompile(addr string) bool

IsPrecompile Returns true if the address is not a precompile and not the zero address

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 Max

func Max[T Value | int | float64 | uint32 | int64](x, y T) T

Max calculates the max between two unsigned integers (golang has no such function)

func Min

func Min[T Value | int | float64 | uint32 | int64](x, y T) T

Min calculates the minimum between two unsigned integers (golang has no such function)

func MustParseFloat64

func MustParseFloat64(val string) float64

func MustParseInt64

func MustParseInt64(input string) int64

func MustParseUint64

func MustParseUint64(input string) uint64

func ValidHex

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

Types

type Address

type Address struct {
	common.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) Common

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

func (*Address) Encoded32

func (a *Address) Encoded32() string

func (Address) Format

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

Format is used by Stringer don't remove

func (*Address) Hex

func (a *Address) Hex() string

Hex returns string representation of an address

func (*Address) IsZero

func (a *Address) IsZero() bool

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

func (Address) MarshalText

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

MarshalText is used by Stringer don't remove

func (*Address) Pad32

func (a *Address) Pad32() string

func (*Address) Prefix

func (a *Address) Prefix(n int) 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) UnmarshalJSON

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

type Blknum

type Blknum = Value

func KnownBlock

func KnownBlock(chain, blockName string) Blknum

func MustParseBlknum

func MustParseBlknum(input string) Blknum

type BlockRange

type BlockRange FileRange // sugar

type Ether

type Ether big.Float

Ether encapsulates big.Float so we can Unmarshal strings into various of our types. This is necessary because we export big.Floats to Json strings so we don't lose precision. The types mostly just cast to the big.Float and call in to the identical functions.

func NewEther

func NewEther(f float64) *Ether

func ToEther

func ToEther(wei *Wei) *Ether

func (*Ether) Cmp

func (e *Ether) Cmp(other *Ether) int

func (*Ether) Float64

func (e *Ether) Float64() float64

func (*Ether) MarshalJSON

func (e *Ether) MarshalJSON() ([]byte, error)

func (*Ether) Quo

func (e *Ether) Quo(a, b *Ether) *Ether

func (*Ether) SetFloat64

func (e *Ether) SetFloat64(f float64) *Ether

func (*Ether) SetInt64

func (e *Ether) SetInt64(i int64) *Ether

func (*Ether) SetString

func (e *Ether) SetString(s string) (*Ether, bool)

func (*Ether) SetUint64

func (e *Ether) SetUint64(i uint64) *Ether

func (*Ether) SetWei

func (e *Ether) SetWei(i *Wei) *Ether

func (*Ether) String

func (e *Ether) String() string

func (*Ether) Text

func (x *Ether) Text(format byte, prec int) string

func (*Ether) UnmarshalJSON

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

type FileRange

type FileRange struct {
	First Blknum
	Last  Blknum
}

func RangeFromFilename

func RangeFromFilename(path string) (blkRange FileRange)

RangeFromFilename returns a FileRange and ignore any errors

func RangeFromFilenameE

func RangeFromFilenameE(path string) (blkRange FileRange, err error)

RangeFromFilenameE returns a block range given a chunk filename. The format of filenames may be start-end.bin (start and end are nine digit and zero-padded to the left) or start.txt

func RangeFromRangeString

func RangeFromRangeString(rngStr string) FileRange

RangeFromRangeString returns a file range from a string

func (*FileRange) EarlierThan

func (r *FileRange) EarlierThan(needle FileRange) bool

EarlierThan returns true if range is strictly before the given needle range

func (*FileRange) EarlierThanB

func (r *FileRange) EarlierThanB(bn Blknum) bool

EarlierThanB returns true if the range is strictly before the given block

func (*FileRange) Equals

func (r *FileRange) Equals(needle FileRange) bool

Equals returns true if the two ranges are equal

func (*FileRange) Follows

func (r *FileRange) Follows(needle FileRange, sequential bool) bool

Follows returns true if the range is strictly after the needle range. (If 'sequential' is true, then the first block in the range must be one more than the last block in the needle range.)

func (*FileRange) Intersects

func (r *FileRange) Intersects(needle FileRange) bool

Intersects returns true if the two ranges intersect

func (*FileRange) IntersectsB

func (r *FileRange) IntersectsB(bn Blknum) bool

IntersectsB returns true if the block is inside the range (inclusive on both ends)

func (*FileRange) LaterThan

func (r *FileRange) LaterThan(needle FileRange) bool

LaterThan returns true if range is strictly after the given needle range

func (*FileRange) LaterThanB

func (r *FileRange) LaterThanB(bn Blknum) bool

LaterThanB returns true if the range is strictly after the given block

func (*FileRange) Overlaps

func (r *FileRange) Overlaps(test FileRange) (rd RangeDiff)

func (*FileRange) Preceeds

func (r *FileRange) Preceeds(needle FileRange, sequential bool) bool

Preceeds returns true if the range is strictly before the needle range. (If 'sequential' is true, then the last block in the range must be one less than the first block in the needle range.) If the needle range starts at zero, returns false (nothing is before the first range)

func (*FileRange) RangeToFilename

func (r *FileRange) RangeToFilename(chain string) string

RangeToFilename returns a fileName and existence bool given a file range and a type

func (*FileRange) Span

func (r *FileRange) Span() Blknum

func (FileRange) String

func (r FileRange) String() string

type Float

type Float float64

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
}

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(version 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 Pair

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

type RangeDiff

type RangeDiff struct {
	Min Blknum
	In  Blknum
	Mid Blknum
	Out Blknum
	Max Blknum
}

type RecordRange

type RecordRange struct {
	First uint64
	Last  uint64
}

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 TimestampRange

type TimestampRange struct {
	First Timestamp
	Last  Timestamp
}

type Topic

type Topic = string

type Tracenum

type Tracenum = Value

type Txnum

type Txnum = Value

func MustParseTxnum

func MustParseTxnum(input string) Txnum

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 (*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) Float64

func (w *Wei) Float64() float64

func (*Wei) IsZero

func (w *Wei) IsZero() 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) 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) String

func (w *Wei) String() string

func (*Wei) Sub

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

func (*Wei) Text

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

func (*Wei) ToEtherStr

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

func (*Wei) ToInt

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

func (*Wei) Uint64

func (w *Wei) Uint64() uint64

func (*Wei) UnmarshalCache

func (w *Wei) UnmarshalCache(version 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