Documentation
¶
Overview ¶
Package base implements various base functions
Index ¶
- Constants
- Variables
- func BiFromBn(bn Blknum) *big.Int
- func Bytes2Hex(d []byte) string
- func FormattedDate(ts Timestamp) string
- func GetDateKey(period string, date DateTime) string
- func Hex2Bytes(str string) []byte
- func IsFinal(latestTs, blockTs Timestamp) bool
- func IsHex(str string) bool
- func IsTestMode() bool
- func IsValidAddress(val string) bool
- func IsValidAddressE(val string) (bool, error)
- func IsValidHex(typ string, val string, nBytes int) (bool, error)
- func IsValidPeriod(period string) bool
- func MustParseFloat64(val string) float64
- func MustParseInt64(input string) int64
- func MustParseUint64(input string) uint64
- func ReadValue(reader io.Reader, dest any, fileVersion uint64) (err error)
- func ValidHex(val string, nBytes int) (bool, error)
- func WeiToHash(wei *Wei) (string, error)
- func WriteValue(writer io.Writer, value any) (err error)
- type Address
- func (a *Address) CheckSum() string
- func (a *Address) Common() common.Address
- func (a *Address) DefaultSymbol() string
- func (a *Address) Display(left, right int) string
- func (a *Address) Equal(b Address) bool
- func (a Address) Format(s fmt.State, c rune)
- func (a *Address) GreaterThan(b Address) bool
- func (a *Address) GreaterThanOrEqual(b Address) bool
- func (a *Address) Hex() string
- func (a *Address) IsPrecompile() bool
- func (a *Address) IsZero() bool
- func (a *Address) LessThan(b Address) bool
- func (a *Address) LessThanOrEqual(b Address) bool
- func (a Address) MarshalText() ([]byte, error)
- func (a *Address) NotEqual(b Address) bool
- func (a *Address) Pad32() string
- func (a *Address) SetCommon(c *common.Address) Address
- func (a *Address) SetHex(hexStr string)
- func (a Address) String() string
- func (a *Address) UnmarshalCSV(hex string) error
- func (e *Address) UnmarshalJSON(data []byte) error
- type Blknum
- type DateTime
- func (dt *DateTime) After(test *DateTime) bool
- func (dt *DateTime) Before(test *DateTime) bool
- func (dt *DateTime) EndOfMonth() DateTime
- func (dt *DateTime) EndOfYear() DateTime
- func (dt *DateTime) MarshalCSV() (string, error)
- func (dt *DateTime) String() string
- func (dt *DateTime) UnmarshalCSV(csv string) (err error)
- type Float
- func (f *Float) Cmp(other *Float) int
- func (f *Float) Equal(other *Float) bool
- func (f *Float) Float64() float64
- func (f *Float) GreaterThan(other *Float) bool
- func (f *Float) GreaterThanOrEqual(other *Float) bool
- func (f *Float) IsZero() bool
- func (f *Float) LessThan(other *Float) bool
- func (f *Float) LessThanOrEqual(other *Float) bool
- func (f *Float) MarshalCache(writer io.Writer) error
- func (f *Float) MarshalJSON() ([]byte, error)
- func (f *Float) Mul(a, b *Float) *Float
- func (f *Float) NotEqual(other *Float) bool
- func (f *Float) Quo(a, b *Float) *Float
- func (f *Float) SetFloat64(fl float64) *Float
- func (f *Float) SetInt64(i int64) *Float
- func (f *Float) SetRawWei(i *Wei) *Float
- func (f *Float) SetString(s string) (*Float, bool)
- func (f *Float) SetUint64(i uint64) *Float
- func (f *Float) SetWei(i *Wei) *Float
- func (f *Float) String() string
- func (f *Float) Text(format byte, prec int) string
- func (f *Float) ToBigFloat() *big.Float
- func (f *Float) UnmarshalCache(fileVersion uint64, reader io.Reader) error
- func (f *Float) UnmarshalJSON(data []byte) error
- type Gas
- type Hash
- func (h *Hash) Common() common.Hash
- func (h Hash) Format(s fmt.State, c rune)
- func (h *Hash) Hex() string
- func (h *Hash) IsZero() bool
- func (h Hash) MarshalText() ([]byte, error)
- func (h *Hash) SetCommon(c *common.Hash) Hash
- func (h *Hash) SetHex(hexStr string)
- func (h *Hash) String() string
- func (h *Hash) UnmarshalCache(fileVersion uint64, reader io.Reader) error
- func (h *Hash) UnmarshalJSON(data []byte) error
- type IpfsHash
- type Lognum
- type Marshaler
- type Pair
- type Timestamp
- type Topic
- type Tracenum
- type Txnum
- type Unmarshaler
- type Value
- type Wei
- func (w *Wei) Abs() *Wei
- func (w *Wei) Add(x, y *Wei) *Wei
- func (w *Wei) BigInt() *big.Int
- func (w *Wei) Bytes() []byte
- func (w *Wei) Cmp(y *Wei) int
- func (w *Wei) Div(x, y *Wei) *Wei
- func (w *Wei) Equal(other *Wei) bool
- func (w *Wei) Float64() float64
- func (w *Wei) GreaterThan(other *Wei) bool
- func (w *Wei) GreaterThanOrEqual(other *Wei) bool
- func (w *Wei) IsZero() bool
- func (w *Wei) LessThan(other *Wei) bool
- func (w *Wei) LessThanOrEqual(other *Wei) bool
- func (w *Wei) MarshalCache(writer io.Writer) error
- func (w *Wei) MarshalText() (text []byte, err error)
- func (w *Wei) Mul(x, y *Wei) *Wei
- func (w *Wei) Neg() *Wei
- func (w *Wei) NotEqual(other *Wei) bool
- func (w *Wei) Quo(x, y *Wei) *Wei
- func (w *Wei) SetInt64(x int64) *Wei
- func (w *Wei) SetString(s string, base int) (*Wei, bool)
- func (w *Wei) SetUint64(x uint64) *Wei
- func (w *Wei) Sign() int
- func (w *Wei) String() string
- func (w *Wei) Sub(x, y *Wei) *Wei
- func (w *Wei) Text(base int) string
- func (b *Wei) ToBigInt() *big.Int
- func (w *Wei) ToFloatString(decimals int) string
- func (w *Wei) Uint64() uint64
- func (w *Wei) UnmarshalCache(fileVersion uint64, reader io.Reader) error
- func (e *Wei) UnmarshalJSON(data []byte) error
- func (w *Wei) UnmarshalText(text []byte) error
Constants ¶
const NOPOS = uint64(^uint64(0))
const NOPOSI = Timestamp(0xdeadbeef)
const NOPOSN = Value(^uint64(0))
Variables ¶
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
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") )
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.
var ( Byzantium = "byzantium" Constantinople = "constantinople" London = "london" Merge = "merge" Shanghai = "shanghai" FirstTrace = "first_trace" )
var ( ZeroFloat = NewFloat(0) OneFloat = NewFloat(1) )
var ErrInvalidHex = errors.New("hex string must contain only hex characters")
var ErrInvalidLength = errors.New("hex string must be an even length")
var ErrNoLeading0x = errors.New("hex string must start with 0x")
var (
ZeroWei = NewWei(0)
)
Functions ¶
func Bytes2Hex ¶
Bytes2Hex duplicates the same-named function found in common, because we want to better control dependencies
func FormattedDate ¶
func GetDateKey ¶
func Hex2Bytes ¶
Hex2Bytes duplicates the same-named function found in common, because we want to better control dependencies
func IsTestMode ¶
func IsTestMode() bool
func IsValidAddress ¶
func IsValidAddressE ¶
func IsValidPeriod ¶
func MustParseFloat64 ¶
func MustParseInt64 ¶
func MustParseUint64 ¶
func ReadValue ¶
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 WriteValue ¶
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 ¶
Address is a wrapper for go-ethereum's Address type that always return lower case hex.
func AddressFromPath ¶
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 GetTestPublisher ¶
func GetTestPublisher() Address
GetTestPublisher does not get customized per chain. We can only test against mainnet currently
func HexToAddress ¶
HexToAddress returns new address with the given string as value.
func (*Address) CheckSum ¶
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) DefaultSymbol ¶
func (*Address) Display ¶
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) GreaterThan ¶
func (*Address) GreaterThanOrEqual ¶
func (*Address) IsPrecompile ¶
IsPrecompile Returns true if the address is not a precompile (and not the zero address by extension)
func (*Address) LessThanOrEqual ¶
func (Address) MarshalText ¶
MarshalText is used by Stringer don't remove
func (*Address) UnmarshalCSV ¶
func (*Address) UnmarshalJSON ¶
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 DateTime ¶
func NewDateTime ¶
func NewDateTimeTs ¶
func (*DateTime) EndOfMonth ¶
func (*DateTime) MarshalCSV ¶
func (*DateTime) UnmarshalCSV ¶
type Float ¶
func ToFloatWithDecimals ¶
func (*Float) GreaterThan ¶
func (*Float) GreaterThanOrEqual ¶
func (*Float) LessThanOrEqual ¶
func (*Float) MarshalJSON ¶
func (*Float) SetFloat64 ¶
func (*Float) SetRawWei ¶
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) ToBigFloat ¶
func (*Float) UnmarshalCache ¶
func (*Float) UnmarshalJSON ¶
type Hash ¶
Hash is a wrapper for go-ethereum's Hash type that always return lower case hex.
func BytesToHash ¶
func (*Hash) Hex ¶
Hex returns string representation of an hash. Unlike addresses, we do not shorten zero hashes.
func (Hash) MarshalText ¶
MarshalText is used by Stringer don't remove
func (*Hash) UnmarshalCache ¶
func (*Hash) UnmarshalJSON ¶
type Unmarshaler ¶
type Value ¶
type Value uint64 // allows for json parsing
type Value = uint64 // as an alias
func MustParseValue ¶
func (*Value) UnmarshalJSON ¶
type Wei ¶
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 MustParseWei ¶
func (*Wei) GreaterThan ¶
func (*Wei) GreaterThanOrEqual ¶
func (*Wei) LessThanOrEqual ¶
func (*Wei) MarshalText ¶
func (*Wei) Sign ¶
Sign returns -1 if the Wei is negative, 0 if it is zero, and 1 if it is positive.