common

package
v1.0.0 Latest Latest
Warning

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

Go to latest
Published: Sep 20, 2023 License: Apache-2.0 Imports: 17 Imported by: 185

Documentation

Overview

Copyright 2021 Erigon contributors

Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the License. You may obtain a copy of the License at

http://www.apache.org/licenses/LICENSE-2.0

Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the specific language governing permissions and limitations under the License.

Index

Constants

View Source
const (
	Wei   = 1
	GWei  = 1e9
	Ether = 1e18
)

Variables

View Source
var (
	Big0   = big.NewInt(0)
	Big1   = big.NewInt(1)
	Big2   = big.NewInt(2)
	Big3   = big.NewInt(3)
	Big32  = big.NewInt(32)
	Big256 = big.NewInt(256)
	Big257 = big.NewInt(257)
)
View Source
var ErrStopped = errors.New("stopped")
View Source
var ErrUnwind = errors.New("unwound")

Functions

func BitLenToByteLen

func BitLenToByteLen(bitLen int) (byteLen int)

func ByteCount

func ByteCount(b uint64) string

func CliString2Array

func CliString2Array(input string) []string

func Copy

func Copy(b []byte) []byte

func EnsureEnoughSize

func EnsureEnoughSize(in []byte, size int) []byte

func FromHex

func FromHex(in string) []byte

func IsHexAddress

func IsHexAddress(s string) bool

IsHexAddress verifies whether a string can represent a valid hex-encoded Ethereum address or not.

func MBToGB

func MBToGB(b uint64) (float64, int)

func PrioritizedSend

func PrioritizedSend[t any](ch chan t, msg t)

PrioritizedSend message to channel, but if channel is full (slow consumer) - drop half of old messages (not new)

func RootContext

func RootContext() (context.Context, context.CancelFunc)

func SafeClose

func SafeClose(ch chan struct{})

func Stopped

func Stopped(ch <-chan struct{}) error

Types

type Address

type Address [length.Addr]byte

Address represents the 20 byte address of an Ethereum account.

func BigToAddress

func BigToAddress(b *big.Int) Address

BigToAddress returns Address with byte values of b. If b is larger than len(h), b will be cropped from the left.

func BytesToAddress

func BytesToAddress(b []byte) Address

BytesToAddress returns Address with value b. If b is larger than len(h), b will be cropped from the left.

func HexToAddress

func HexToAddress(s string) Address

HexToAddress returns Address with byte values of s. If s is larger than len(h), s will be cropped from the left.

func (Address) Bytes

func (a Address) Bytes() []byte

Bytes gets the string representation of the underlying address.

func (Address) Format

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

Format implements fmt.Formatter. Address supports the %v, %s, %v, %x, %X and %d format verbs.

func (Address) Hash

func (a Address) Hash() Hash

Hash converts an address to a hash by left-padding it with zeros.

func (Address) Hex

func (a Address) Hex() string

Hex returns an EIP55-compliant hex string representation of the address.

func (Address) MarshalText

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

MarshalText returns the hex representation of a.

func (*Address) Scan

func (a *Address) Scan(src interface{}) error

Scan implements Scanner for database/sql.

func (*Address) SetBytes

func (a *Address) SetBytes(b []byte)

SetBytes sets the address to the value of b. If b is larger than len(a), b will be cropped from the left.

func (Address) String

func (a Address) String() string

String implements fmt.Stringer.

func (*Address) UnmarshalJSON

func (a *Address) UnmarshalJSON(input []byte) error

UnmarshalJSON parses a hash in hex syntax.

func (*Address) UnmarshalText

func (a *Address) UnmarshalText(input []byte) error

UnmarshalText parses a hash in hex syntax.

func (Address) Value

func (a Address) Value() (driver.Value, error)

Value implements valuer for database/sql.

type Bytes4

type Bytes4 [length.Bytes4]byte

func (Bytes4) Format

func (b Bytes4) Format(s fmt.State, c rune)

Format implements fmt.Formatter. Hash supports the %v, %s, %v, %x, %X and %d format verbs.

func (Bytes4) Generate

func (b Bytes4) Generate(rand *rand.Rand, size int) reflect.Value

Generate implements testing/quick.Generator.

func (Bytes4) Hex

func (b Bytes4) Hex() string

Hex converts a hash to a hex string.

func (Bytes4) MarshalText

func (b Bytes4) MarshalText() ([]byte, error)

MarshalText returns the hex representation of a.

func (*Bytes4) SetBytes

func (b *Bytes4) SetBytes(i []byte)

SetBytes sets the hash to the value of i. If b is larger than len(h), b will be cropped from the left.

func (Bytes4) String

func (b Bytes4) String() string

String implements the stringer interface and is used also by the logger when doing full logging into a file.

func (Bytes4) TerminalString

func (b Bytes4) TerminalString() string

TerminalString implements log.TerminalStringer, formatting a string for console output during logging.

func (*Bytes4) UnmarshalJSON

func (b *Bytes4) UnmarshalJSON(input []byte) error

UnmarshalJSON parses a hash in hex syntax.

func (*Bytes4) UnmarshalText

func (b *Bytes4) UnmarshalText(input []byte) error

UnmarshalText parses a hash in hex syntax.

func (Bytes4) Value

func (b Bytes4) Value() (driver.Value, error)

Value implements valuer for database/sql.

type Bytes48

type Bytes48 [length.Bytes48]byte

func (Bytes48) Format

func (b Bytes48) Format(s fmt.State, c rune)

Format implements fmt.Formatter. Hash supports the %v, %s, %v, %x, %X and %d format verbs.

func (Bytes48) Generate

func (b Bytes48) Generate(rand *rand.Rand, size int) reflect.Value

Generate implements testing/quick.Generator.

func (Bytes48) Hex

func (b Bytes48) Hex() string

Hex converts a hash to a hex string.

func (Bytes48) MarshalText

func (b Bytes48) MarshalText() ([]byte, error)

MarshalText returns the hex representation of a.

func (*Bytes48) SetBytes

func (b *Bytes48) SetBytes(i []byte)

SetBytes sets the hash to the value of i. If b is larger than len(h), b will be cropped from the left.

func (Bytes48) String

func (b Bytes48) String() string

String implements the stringer interface and is used also by the logger when doing full logging into a file.

func (Bytes48) TerminalString

func (b Bytes48) TerminalString() string

TerminalString implements log.TerminalStringer, formatting a string for console output during logging.

func (*Bytes48) UnmarshalJSON

func (b *Bytes48) UnmarshalJSON(input []byte) error

UnmarshalJSON parses a hash in hex syntax.

func (*Bytes48) UnmarshalText

func (b *Bytes48) UnmarshalText(input []byte) error

UnmarshalText parses a hash in hex syntax.

func (Bytes48) Value

func (b Bytes48) Value() (driver.Value, error)

Value implements valuer for database/sql.

type Bytes64

type Bytes64 [length.Bytes64]byte

func (Bytes64) Format

func (b Bytes64) Format(s fmt.State, c rune)

Format implements fmt.Formatter. Hash supports the %v, %s, %v, %x, %X and %d format verbs.

func (Bytes64) Hex

func (b Bytes64) Hex() string

Hex converts a hash to a hex string.

func (Bytes64) MarshalText

func (b Bytes64) MarshalText() ([]byte, error)

MarshalText returns the hex representation of a.

func (*Bytes64) SetBytes

func (b *Bytes64) SetBytes(i []byte)

SetBytes sets the hash to the value of i. If b is larger than len(h), b will be cropped from the left.

func (Bytes64) String

func (b Bytes64) String() string

String implements the stringer interface and is used also by the logger when doing full logging into a file.

func (Bytes64) TerminalString

func (b Bytes64) TerminalString() string

TerminalString implements log.TerminalStringer, formatting a string for console output during logging.

func (*Bytes64) UnmarshalJSON

func (b *Bytes64) UnmarshalJSON(input []byte) error

UnmarshalJSON parses a hash in hex syntax.

func (*Bytes64) UnmarshalText

func (b *Bytes64) UnmarshalText(input []byte) error

UnmarshalText parses a hash in hex syntax.

func (Bytes64) Value

func (b Bytes64) Value() (driver.Value, error)

Value implements valuer for database/sql.

type Bytes96

type Bytes96 [length.Bytes96]byte

func (Bytes96) Format

func (b Bytes96) Format(s fmt.State, c rune)

Format implements fmt.Formatter. Hash supports the %v, %s, %v, %x, %X and %d format verbs.

func (Bytes96) Generate

func (b Bytes96) Generate(rand *rand.Rand, size int) reflect.Value

Generate implements testing/quick.Generator.

func (Bytes96) Hex

func (b Bytes96) Hex() string

Hex converts a hash to a hex string.

func (Bytes96) MarshalText

func (b Bytes96) MarshalText() ([]byte, error)

MarshalText returns the hex representation of a.

func (*Bytes96) SetBytes

func (b *Bytes96) SetBytes(i []byte)

SetBytes sets the hash to the value of i. If b is larger than len(h), b will be cropped from the left.

func (Bytes96) String

func (b Bytes96) String() string

String implements the stringer interface and is used also by the logger when doing full logging into a file.

func (Bytes96) TerminalString

func (b Bytes96) TerminalString() string

TerminalString implements log.TerminalStringer, formatting a string for console output during logging.

func (*Bytes96) UnmarshalJSON

func (b *Bytes96) UnmarshalJSON(input []byte) error

UnmarshalJSON parses a hash in hex syntax.

func (*Bytes96) UnmarshalText

func (b *Bytes96) UnmarshalText(input []byte) error

UnmarshalText parses a hash in hex syntax.

func (Bytes96) Value

func (b Bytes96) Value() (driver.Value, error)

Value implements valuer for database/sql.

type CodeRecord

type CodeRecord struct {
	BlockNumber uint64
	TxNumber    uint64
	CodeHash    Hash
}

type Hash

type Hash [length.Hash]byte

Hash represents the 32 byte Keccak256 hash of arbitrary data.

func BigToHash

func BigToHash(b *big.Int) Hash

BigToHash sets byte representation of b to hash. If b is larger than len(h), b will be cropped from the left.

func BytesToHash

func BytesToHash(b []byte) Hash

BytesToHash sets b to hash. If b is larger than len(h), b will be cropped from the left.

func CastToHash

func CastToHash(b []byte) Hash

CastToHash - sets b to hash If b is larger than len(h), b will be cropped from the left. panics if input is shorter than 32 bytes, see https://go.dev/doc/go1.17#language faster than BytesToHash

func HexToHash

func HexToHash(s string) Hash

HexToHash sets byte representation of s to hash. If b is larger than len(h), b will be cropped from the left.

func (Hash) Big

func (h Hash) Big() *big.Int

Big converts a hash to a big integer.

func (Hash) Bytes

func (h Hash) Bytes() []byte

Bytes gets the byte representation of the underlying hash.

func (Hash) Format

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

Format implements fmt.Formatter. Hash supports the %v, %s, %v, %x, %X and %d format verbs.

func (Hash) Generate

func (h Hash) Generate(rand *rand.Rand, size int) reflect.Value

Generate implements testing/quick.Generator.

func (Hash) Hex

func (h Hash) Hex() string

Hex converts a hash to a hex string.

func (Hash) MarshalText

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

MarshalText returns the hex representation of h.

func (*Hash) Scan

func (h *Hash) Scan(src interface{}) error

Scan implements Scanner for database/sql.

func (*Hash) SetBytes

func (h *Hash) SetBytes(b []byte)

SetBytes sets the hash to the value of b. If b is larger than len(h), b will be cropped from the left.

func (Hash) String

func (h Hash) String() string

String implements the stringer interface and is used also by the logger when doing full logging into a file.

func (Hash) TerminalString

func (h Hash) TerminalString() string

TerminalString implements log.TerminalStringer, formatting a string for console output during logging.

func (*Hash) UnmarshalJSON

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

UnmarshalJSON parses a hash in hex syntax.

func (*Hash) UnmarshalText

func (h *Hash) UnmarshalText(input []byte) error

UnmarshalText parses a hash in hex syntax.

func (Hash) Value

func (h Hash) Value() (driver.Value, error)

Value implements valuer for database/sql.

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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