utils

package
v0.11.7 Latest Latest
Warning

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

Go to latest
Published: Apr 26, 2024 License: Apache-2.0 Imports: 23 Imported by: 0

Documentation

Index

Constants

View Source
const (
	Megabyte = 1024 * 1024
)

Variables

View Source
var (

	// The docs states the addresses for each network: https://docs.starknet.io/documentation/useful_info/
	Mainnet = Network{
		Name:                "mainnet",
		FeederURL:           "https://alpha-mainnet.starknet.io/feeder_gateway/",
		GatewayURL:          "https://alpha-mainnet.starknet.io/gateway/",
		L2ChainID:           "SN_MAIN",
		L1ChainID:           big.NewInt(1),
		CoreContractAddress: common.HexToAddress("0xc662c410C0ECf747543f5bA90660f6ABeBD9C8c4"),
		BlockHashMetaInfo: &BlockHashMetaInfo{
			First07Block:             833,
			FallBackSequencerAddress: fallBackSequencerAddressMainnet,
			ForceFetchingTracesForBlocks: []uint64{
				611294, 611505, 612469, 613231, 614631, 614849, 615085,
				615449, 615839, 615978, 616658, 617479, 617507, 617582,
				617593, 617828, 618166, 618260, 618320, 618406, 618423,
				618776, 618884, 618975, 619052, 619128, 619171, 619467,
				619513, 619553, 619596, 619631, 619721, 619951, 619960,
				620018, 620066, 620235, 620423, 620530, 620678, 620749,
				620847, 621350, 621369, 621843, 621897, 621995, 622027,
				622063, 622244, 622768, 622786, 622873, 622930, 623034,
				623156, 623252, 623372, 623428, 623562, 623736, 623792,
				624045, 624082, 624114, 624236, 624378, 624487, 624690,
				624757, 624812, 624875, 624894, 624905, 624929, 625300,
				625403, 625441, 625525, 625741, 625767, 625794, 625802,
				625820, 625849, 625851, 625879, 625935, 625971, 626008,
				626019, 626176, 626193, 626204, 626236, 626285, 626335,
				626370, 626371, 626457, 626683, 626738, 626792, 626820,
				626835, 626962, 627015, 627049, 627100, 627135, 627138,
				627164, 627186, 627243, 627246, 627276, 627291, 627322,
				627351, 627389, 627404, 627428, 627591, 627623, 627624,
				627640, 627645, 627676, 627968, 628183, 628425, 628449,
				628511, 628561, 628682, 628746, 628772, 628778, 628819,
				628915, 628944, 629003, 629122, 629382, 629397, 629432,
				629484, 629500, 629831, 629853, 629893, 629908, 629916,
				630423, 631040, 631041, 631091, 631136, 631142, 631144,
				631149, 631155, 631204, 631269, 631368, 631602, 631685,
				631739, 631741, 631760, 631811, 631861, 631927, 632072,
				632073, 632074, 632075, 632076, 632077, 632078, 632079,
				632081, 632202, 632206, 632237, 632241, 632271, 632845,
			},
		},
	}
	Goerli = Network{
		Name:       "goerli",
		FeederURL:  "https://alpha4.starknet.io/feeder_gateway/",
		GatewayURL: "https://alpha4.starknet.io/gateway/",
		L2ChainID:  "SN_GOERLI",

		L1ChainID:           big.NewInt(5),
		CoreContractAddress: common.HexToAddress("0xde29d060D45901Fb19ED6C6e959EB22d8626708e"),
		BlockHashMetaInfo: &BlockHashMetaInfo{
			First07Block:             47028,
			UnverifiableRange:        []uint64{119802, 148428},
			FallBackSequencerAddress: fallBackSequencerAddress,
		},
	}
	Goerli2 = Network{
		Name:       "goerli2",
		FeederURL:  "https://alpha4-2.starknet.io/feeder_gateway/",
		GatewayURL: "https://alpha4-2.starknet.io/gateway/",
		L2ChainID:  "SN_GOERLI2",

		L1ChainID:           big.NewInt(5),
		CoreContractAddress: common.HexToAddress("0xa4eD3aD27c294565cB0DCc993BDdCC75432D498c"),
		BlockHashMetaInfo: &BlockHashMetaInfo{
			First07Block:             0,
			FallBackSequencerAddress: fallBackSequencerAddress,
		},
	}
	Integration = Network{
		Name:       "integration",
		FeederURL:  "https://external.integration.starknet.io/feeder_gateway/",
		GatewayURL: "https://external.integration.starknet.io/gateway/",
		L2ChainID:  "SN_GOERLI",

		L1ChainID:           big.NewInt(5),
		CoreContractAddress: common.HexToAddress("0xd5c325D183C592C94998000C5e0EED9e6655c020"),
		BlockHashMetaInfo: &BlockHashMetaInfo{
			First07Block:             110511,
			UnverifiableRange:        []uint64{0, 110511},
			FallBackSequencerAddress: fallBackSequencerAddress,
		},
	}
	Sepolia = Network{
		Name:       "sepolia",
		FeederURL:  "https://alpha-sepolia.starknet.io/feeder_gateway/",
		GatewayURL: "https://alpha-sepolia.starknet.io/gateway/",
		L2ChainID:  "SN_SEPOLIA",

		L1ChainID:           big.NewInt(11155111),
		CoreContractAddress: common.HexToAddress("0xE2Bb56ee936fd6433DC0F6e7e3b8365C906AA057"),
		BlockHashMetaInfo: &BlockHashMetaInfo{
			First07Block:             0,
			FallBackSequencerAddress: fallBackSequencerAddress,
		},
	}
	SepoliaIntegration = Network{
		Name:       "sepolia-integration",
		FeederURL:  "https://integration-sepolia.starknet.io/feeder_gateway/",
		GatewayURL: "https://integration-sepolia.starknet.io/gateway/",
		L2ChainID:  "SN_INTEGRATION_SEPOLIA",

		L1ChainID:           big.NewInt(11155111),
		CoreContractAddress: common.HexToAddress("0x4737c0c1B4D5b1A687B42610DdabEE781152359c"),
		BlockHashMetaInfo: &BlockHashMetaInfo{
			First07Block:             0,
			FallBackSequencerAddress: fallBackSequencerAddress,
		},
	}
)
View Source
var ErrResourceBusy = errors.New("resource busy, try again")
View Source
var ErrUnknownLogLevel = fmt.Errorf(
	"unknown log level (known: %s, %s, %s, %s)",
	DEBUG, INFO, WARN, ERROR,
)

Functions

func All added in v0.6.0

func All[T any](slice []T, f func(T) bool) bool

All returns true if all elements match the given predicate

func DerefSlice added in v0.8.0

func DerefSlice[T any](v *[]T) []T

func Filter added in v0.6.0

func Filter[T any](slice []T, f func(T) bool) []T

func Gzip64Decode added in v0.4.0

func Gzip64Decode(data string) ([]byte, error)

func Gzip64Encode added in v0.4.0

func Gzip64Encode(data []byte) (string, error)

func HexToFelt added in v0.2.1

func HexToFelt(t testing.TB, hex string) *felt.Felt

func HexToUint64 added in v0.8.0

func HexToUint64(t testing.TB, hexStr string) uint64

func Map added in v0.6.0

func Map[T1, T2 any](slice []T1, f func(T1) T2) []T2

func MapKeys added in v0.10.0

func MapKeys[K comparable, V any](m map[K]V) []K

func MapValues added in v0.10.0

func MapValues[K comparable, V any](m map[K]V) []V

func NonNilSlice added in v0.8.0

func NonNilSlice[T any](sl []T) []T

func Ptr added in v0.6.0

func Ptr[T any](v T) *T

func RunAndWrapOnError added in v0.6.2

func RunAndWrapOnError(runnable func() error, existingErr error) error

func ToMap added in v0.10.0

func ToMap[T any, K comparable, V any](sl []T, f func(T) (K, V)) map[K]V

func ToSlice added in v0.10.0

func ToSlice[K comparable, V any, T any](m map[K]V, f func(K, V) T) []T

Types

type BlockHashMetaInfo added in v0.9.3

type BlockHashMetaInfo struct {
	// The sequencer address to use for blocks that do not have one
	FallBackSequencerAddress *felt.Felt `json:"fallback_sequencer_address" validate:"required"`
	// First block that uses the post-0.7.0 block hash algorithm
	First07Block uint64 `json:"first_07_block" validate:"required"`
	// Range of blocks that are not verifiable
	UnverifiableRange []uint64 `json:"unverifiable_range" validate:"required"`
	// Block ids for which we fetch traces from feeder gateway instead of getting them from blockifier
	ForceFetchingTracesForBlocks []uint64 `json:"force_fetching_traces_for_blocks"`
}

type LogLevel

type LogLevel int
const (
	DEBUG LogLevel = iota
	INFO
	WARN
	ERROR
)

func (*LogLevel) MarshalText added in v0.11.0

func (l *LogLevel) MarshalText() ([]byte, error)

func (LogLevel) MarshalYAML added in v0.6.0

func (l LogLevel) MarshalYAML() (interface{}, error)

func (*LogLevel) Set added in v0.2.1

func (l *LogLevel) Set(s string) error

func (LogLevel) String

func (l LogLevel) String() string

func (*LogLevel) Type added in v0.2.1

func (l *LogLevel) Type() string

func (*LogLevel) UnmarshalText added in v0.2.1

func (l *LogLevel) UnmarshalText(text []byte) error

type Logger

type Logger interface {
	SimpleLogger
	pebble.Logger
}

type Network

type Network struct {
	Name                string             `json:"name" validate:"required"`
	FeederURL           string             `json:"feeder_url" validate:"required"`
	GatewayURL          string             `json:"gateway_url" validate:"required"`
	L1ChainID           *big.Int           `json:"l1_chain_id" validate:"required"`
	L2ChainID           string             `json:"l2_chain_id" validate:"required"`
	CoreContractAddress common.Address     `json:"core_contract_address" validate:"required"`
	BlockHashMetaInfo   *BlockHashMetaInfo `json:"block_hash_meta_info"`
}

func (*Network) L2ChainIDFelt added in v0.9.3

func (n *Network) L2ChainIDFelt() *felt.Felt

func (*Network) MarshalText added in v0.11.0

func (n *Network) MarshalText() ([]byte, error)

func (*Network) MarshalYAML added in v0.6.0

func (n *Network) MarshalYAML() (any, error)

func (*Network) ProtocolID added in v0.6.0

func (n *Network) ProtocolID() protocol.ID

func (*Network) Set added in v0.2.1

func (n *Network) Set(s string) error

func (*Network) String

func (n *Network) String() string

func (*Network) Type added in v0.2.1

func (n *Network) Type() string

func (*Network) UnmarshalText added in v0.2.1

func (n *Network) UnmarshalText(text []byte) error

type SimpleLogger

type SimpleLogger interface {
	Debugw(msg string, keysAndValues ...any)
	Infow(msg string, keysAndValues ...any)
	Warnw(msg string, keysAndValues ...any)
	Errorw(msg string, keysAndValues ...any)
}

type Throttler added in v0.7.4

type Throttler[T any] struct {
	// contains filtered or unexported fields
}

func NewThrottler added in v0.7.4

func NewThrottler[T any](concurrencyBudget uint, resource *T) *Throttler[T]

func (*Throttler[T]) Do added in v0.7.4

func (t *Throttler[T]) Do(doer func(resource *T) error) error

Do lets caller acquire the resource within the context of a callback

func (*Throttler[T]) JobsRunning added in v0.10.0

func (t *Throttler[T]) JobsRunning() int

JobsRunning returns the number of Do calls that are running at the moment

func (*Throttler[T]) QueueLen added in v0.7.4

func (t *Throttler[T]) QueueLen() int

QueueLen returns the number of Do calls that is blocked on the resource

func (*Throttler[T]) WithMaxQueueLen added in v0.7.4

func (t *Throttler[T]) WithMaxQueueLen(maxQueueLen int32) *Throttler[T]

WithMaxQueueLen sets the maximum length the queue can grow to

type ZapLogger

type ZapLogger struct {
	*zap.SugaredLogger
}

func NewNopZapLogger

func NewNopZapLogger() *ZapLogger

func NewZapLogger

func NewZapLogger(logLevel LogLevel, colour bool) (*ZapLogger, error)

func (*ZapLogger) Warningf

func (l *ZapLogger) Warningf(msg string, args ...any)

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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