common

package
v0.0.0-...-fb278eb Latest Latest
Warning

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

Go to latest
Published: May 31, 2022 License: GPL-3.0 Imports: 14 Imported by: 0

Documentation

Index

Constants

View Source
const (
	REGULAR_TOTAL_BADGE_COUNT = 25 // this number should never be lower than the total count returned by default profile, so that new users can always save their initial profile
	PREMIUM_TOTAL_BADGE_COUNT = 50
)
View Source
const MAX_RETRIES float64 = 4

Variables

View Source
var (
	ContextKeyRequestId        = ContextKey("request id")
	ContextKeyAddress          = ContextKey("address")
	ContextKeyContract         = ContextKey("contract")
	ContextKeyTransaction      = ContextKey("transaction")
	ContextKeyRequestStartTime = ContextKey("request start time")
)
View Source
var (
	ErrNotFound   = errors.New("not found")
	ErrValidation = errors.New("validation")
	ErrRetryable  = errors.New("retryable")
)

Functions

func FunctionRetrier

func FunctionRetrier[T any](ctx context.Context, fn func() (T, error)) (result T, err error)

Invoke a function with exponential backoff when a retryable error is encountered. If fn returns an err that is wrapped in common.ErrRetyable, fn will be retried with exponential backoff. This was originally implemented to solve getting rate limited by the alchemy APIs

See: https://docs.alchemy.com/alchemy/documentation/rate-limits#retries

func ValidateField

func ValidateField(f interface{}, tag string) error

func ValidateStruct

func ValidateStruct(s interface{}) error

Types

type AchievementType

type AchievementType = string
const (
	INTERACTIONS AchievementType = "interactions"
)

type Address

type Address = string
const (
	ZERO_ADDRESS               Address = "0x0000000000000000000000000000000000000000"
	ENS_BASE_REGISTRAR_ADDRESS Address = "0x57f1887a8bf19b14fc0df6fd9b2acc9af147ea85"
)

type BadgeType

type BadgeType = string
const (
	NON_FUNGIBLE_TOKEN BadgeType = "non_fungible_tokens"
	FUNGIBLE_TOKEN     BadgeType = "fungible_tokens"
	STATISTICS         BadgeType = "statistics"
)

type Blockchain

type Blockchain = string
const (
	ETHEREUM Blockchain = "ethereum"
	POLYGON  Blockchain = "polygon"
	ARBITRUM Blockchain = "arbitrum"
	OPTIMISM Blockchain = "optimism"
)

type ContextKey

type ContextKey string

func (ContextKey) String

func (c ContextKey) String() string
type Header struct {
	Key   string
	Value string
}

type HttpOptions

type HttpOptions struct {
	Headers []Header
}

type IGraphQLClient

type IGraphQLClient interface {
	Query(ctx context.Context, url string, q interface{}, v map[string]interface{}) error
}

func NewGraphQLClient

func NewGraphQLClient(logger ILogger) IGraphQLClient

type IHttpClient

type IHttpClient interface {
	Do(ctx context.Context, method string, url string, options *HttpOptions) (*http.Response, error)
}

func NewHttpClient

func NewHttpClient(logger ILogger) IHttpClient

type ILogEvent

type ILogEvent interface {
	Send()
	Msg(msg string)
	Msgf(msg string, v ...any)
	Err(err error) ILogEvent
	Strs(strs []struct {
		Key   string
		Value string
	}) ILogEvent
}

type ILogger

type ILogger interface {
	Debug(ctx context.Context) ILogEvent
	Info(ctx context.Context) ILogEvent
	Warn(ctx context.Context) ILogEvent
	Error(ctx context.Context) ILogEvent
}

func NewLogger

func NewLogger(settings ISettings) ILogger

type ISettings

type ISettings interface {
	Appname() string
	Hostname() string
	Env() string
	IsDev() bool
	Port() string
	CacheAddr() string
	CacheDB() int
	CachePassword() string
	DatabaseURI() string
	Database() string
	StoreBlockchain() string
	StoreAddress() string
	StoreImageURI() string
	// This ethereum uri should be used for most workflows.
	EthereumMainURI() string
	// This ethereum secondary uri is intended to offload traffic from the main uri and avoid rate limiting for critical paths.
	// this URI should be used sparringly for critical workflows.
	EthereumSecondaryURI() string
	PolygonMainURI() string
	ArbitrumMainURI() string
	OptimismMainURI() string
	ENSMetadataURI() string
	// This ethereum uri is specific to alchemy and is intended for alchemy only apis (e.g. get all nfts).
	AlchemyEthereumURI() string
	CryptoKittiesMetadataURI() string
	IPFSURI() string
	TheGraphURI() string
	TheGraphHostedURI() string
	DefaultTokenAddresses() []string
}

func NewSettings

func NewSettings() ISettings

type Interaction

type Interaction = string
const (
	CONTRACT_CREATION Interaction = "CONTRACT_CREATION"
	SEND_ETHER        Interaction = "SEND_ETHER"
)

type Interface

type Interface = string
const (
	ERC721              Interface = "ERC721"
	ERC1155             Interface = "ERC1155"
	ERC20               Interface = "ERC20"
	ENS_REGISTRAR       Interface = "ENS_REGISTRAR"
	CRYPTO_KITTIES      Interface = "CRYPTO_KITTIES"
	CRYPTO_PUNKS        Interface = "CRYPTO_PUNKS"
	SUSHISWAP_EXCHANGE  Interface = "SUSHISWAP_EXCHANGE"
	UNISWAP_V2_EXCHANGE Interface = "UNISWAP_V2_EXCHANGE"
	UNISWAP_V3_EXCHANGE Interface = "UNISWAP_V3_EXCHANGE"
	ROCKET_POOL         Interface = "ROCKET_POOL"
)

type StatisticType

type StatisticType = string
const (
	SWAP  StatisticType = "SWAP"
	STAKE StatisticType = "STAKE"
)

type TokenIds

type TokenIds = string
const (
	STORE_PREMIUM     TokenIds = "1"
	STORE_BETA_TESTER TokenIds = "2"
)

type TotalBadgeLimit

type TotalBadgeLimit = uint

Jump to

Keyboard shortcuts

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