common

package
v0.0.0-...-8682519 Latest Latest
Warning

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

Go to latest
Published: Mar 26, 2024 License: GPL-3.0 Imports: 16 Imported by: 0

Documentation

Index

Constants

View Source
const MaxWaitInSeconds = 10

Variables

This section is empty.

Functions

func GetDSN

func GetDSN() string

func GetDonationStats

func GetDonationStats(db *sqlx.DB) (decimal.Decimal, decimal.Decimal, error)

func GetETHPrice

func GetETHPrice(db *sqlx.DB, ts time.Time) (decimal.Decimal, error)

func GetLatestETHPrice

func GetLatestETHPrice(db *sqlx.DB) (decimal.Decimal, error)

func HTTPGet

func HTTPGet(params HTTPParams) ([]byte, error)

func HTTPPost

func HTTPPost(params HTTPParams) ([]byte, error)

func HexStringToDecimal

func HexStringToDecimal(hexValue string) (decimal.Decimal, error)

Types

type Block

type Block struct {
	Hash         string        `db:"block_hash" json:"hash"`
	Number       uint64        `db:"block_number" json:"-"`
	Timestamp    time.Time     `db:"block_time" json:"-"`
	Transactions []Transaction `db:"-" json:"transactions"`
}

func (*Block) UnmarshalJSON

func (b *Block) UnmarshalJSON(data []byte) error

type Context

type Context struct {
	ABI              map[string]abi.ABI
	BlockCache       string
	CrawlerType      CrawlerType
	DB               *sqlx.DB
	DebugDataStore   string
	ETHRPCURL        string
	MaxWaitInSeconds int
	ReceivingAddr    string
	SaleParams       []SaleParam
	StableCoins      map[string]ERC20
	UpdateLastBlock  bool
}

func GetContext

func GetContext(erc20Json, saleParamJSON string) (*Context, error)

func (Context) NewTokenPrice

func (c Context) NewTokenPrice(oldTokens, newTokens decimal.Decimal) (bool, decimal.Decimal)

func (Context) TokenSaleLimit

func (c Context) TokenSaleLimit() decimal.Decimal

type ContextKey

type ContextKey int
const (
	DBHandle ContextKey = iota
	BuckContext
)

func (ContextKey) String

func (ck ContextKey) String() string

type CrawlerType

type CrawlerType int
const (
	Latest CrawlerType = iota
	Finalized
	OldUnconfirmed
)

func (CrawlerType) String

func (ct CrawlerType) String() string

type ERC20

type ERC20 struct {
	Asset   string
	Address string
	Scale   int32
}

type Fetchable

type Fetchable interface {
	TxReceipt | TxByHash
}

type Fetcher

type Fetcher[R Fetchable] interface {
	Fetch(Context, []Hashable) ([]R, error)
}

type FinalizedBlock

type FinalizedBlock struct {
	BaseFeePerGas string    `db:"base_fee_per_gas" json:"baseFeePerGas"`
	GasLimit      string    `db:"gas_limit" json:"gasLimit"`
	GasUsed       string    `db:"gas_used" json:"gasUsed"`
	Hash          string    `db:"block_hash" json:"hash"`
	Number        uint64    `db:"block_number" json:"-"`
	ReceiptsRoot  string    `db:"receipts_root" json:"receiptsRoot"`
	Size          string    `db:"block_size" json:"size"`
	StateRoot     string    `db:"state_root" json:"stateRoot"`
	Timestamp     time.Time `db:"block_time" json:"-"`
	Transactions  []string  `db:"transactions" json:"transactions"`
}

func (*FinalizedBlock) TXMap

func (fb *FinalizedBlock) TXMap() map[string]bool

type HTTPParams

type HTTPParams struct {
	URL              string
	RequestBody      []byte
	MaxWaitInSeconds int
}

type Hashable

type Hashable interface {
	GetHash() string
}

func ToHashable

func ToHashable[H Hashable](hs []H) []Hashable

type SaleParam

type SaleParam struct {
	Limit int
	Price decimal.Decimal
}

type TXH

type TXH struct {
	Hash string `db:"tx_hash" json:"hash"`
}

func (TXH) GetHash

func (tx TXH) GetHash() string

type Transaction

type Transaction struct {
	TXH
	From        string          `db:"address" json:"from"`
	To          string          `db:"-" json:"to"`
	Value       string          `db:"amount" json:"value"`
	Gas         string          `db:"-" json:"gas"`
	Nonce       string          `db:"-" json:"nonce"`
	Input       string          `db:"-" json:"input"`
	Type        string          `db:"-" json:"type"`
	Status      string          `db:"status" json:"-"`
	Asset       string          `db:"asset" json:"-"`
	Price       string          `db:"price" json:"-"`
	Tokens      decimal.Decimal `db:"tokens" json:"-"`
	USDAmount   decimal.Decimal `db:"usd_amount" json:"-"`
	BlockNumber uint64          `db:"block_number" json:"-"`
	BlockHash   string          `db:"block_hash" json:"blockhash"`
	BlockTime   time.Time       `db:"block_time" json:"-"`
}

type TxByHash

type TxByHash struct {
	BlockHash        string `json:"blockHash"`
	BlockNumber      uint64 `json:"blockNumber"`
	From             string `json:"from"`
	Hash             string `json:"hash"`
	To               string `json:"to"`
	TransactionIndex uint64 `json:"transactionIndex"`
	FBBlockTime      time.Time
	FBBlockHash      string
	FBContainsTx     bool
}

func (*TxByHash) UnmarshalJSON

func (t *TxByHash) UnmarshalJSON(data []byte) error

type TxReceipt

type TxReceipt struct {
	BlockHash         string `json:"blockHash"`
	BlockNumber       string `json:"blockNumber"`
	ContractAddress   string `json:"contractAddress"`
	CumulativeGasUsed string `json:"cumulativeGasUsed"`
	EffectiveGasPrice string `json:"effectiveGasPrice"`
	From              string `json:"from"`
	GasUsed           string `json:"gasUsed"`
	Status            string `json:"status"`
	To                string `json:"to"`
	TransactionHash   string `json:"transactionHash"`
	TransactionIndex  string `json:"transactionIndex"`
	Type              string `json:"type"`
}

Jump to

Keyboard shortcuts

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