utils

package
v0.0.0-...-fbdb3c5 Latest Latest
Warning

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

Go to latest
Published: Jan 11, 2025 License: GPL-3.0 Imports: 15 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func Average

func Average(values []*big.Int) *big.Int

func BlockscanFormat

func BlockscanFormat(typ string, value string) string

format into block scanner URL, like etherscan should return unformatted value if blockscanner data for it doesnt exist `typ` - type of entity, such as address, block, tx, token

func CodeQuote

func CodeQuote(s string) string
func FormatBlockscanHyperlink(typ string, displayValue string, value string) string

func FormatDecimals

func FormatDecimals(n *big.Int, decimals uint8) string

formats n given its decimal places. truncate to 2 decimal places if formatted number > 0 returns 0 if number == 0

func FormatEventInfo

func FormatEventInfo(eventFields shared.EventFields, topics map[string]interface{}, data map[string]interface{}) (string, string)

func GetTxSender

func GetTxSender(tx *types.Transaction) *common.Address

returns who sent the transaction

func IsDeploymentTx

func IsDeploymentTx(tx *types.Transaction) bool

returns whether a tx is a deployment or not useful instead of `determineTxType` as it does not require a query

func RemoveDuplicates

func RemoveDuplicates[T comparable](sliceList []T) []T

func ShortenAddress

func ShortenAddress(addr common.Address) string

makes addresses hex shorter e.g. 0xf05285270B723f389803cf6dCf15d253d087782b becomes 0xf0528...7782b

func ShortenHash

func ShortenHash(hsh common.Hash) string

make hashes, e.g tx hashes shorter

func Sum

func Sum(values []*big.Int) *big.Int

func TrimFirstInstance

func TrimFirstInstance(s, prefix string) string

Types

type AddressBalanceRetriever

type AddressBalanceRetriever struct {
	// contains filtered or unexported fields
}

func NewAddressBalanceRetriever

func NewAddressBalanceRetriever(coinApiKey string, tokens []common.Address) *AddressBalanceRetriever

returns AddressBalanceRetriever can be used to get USD balance of an address, which is native ETH value + ERC20 token value you specify which ERC20 tokens to check balance for uses coinAPI to get token price, not all ERC20 tokens will have price data

func (*AddressBalanceRetriever) GetAddressUSDbalance

func (a *AddressBalanceRetriever) GetAddressUSDbalance(contract common.Address, blockNum *big.Int) float64

calculates balance of contract, in USD, balance = native ETH bal + token bal

func (*AddressBalanceRetriever) GetERC20BalanceOf

func (a *AddressBalanceRetriever) GetERC20BalanceOf(token common.Address, address common.Address) (*big.Int, error)

func (*AddressBalanceRetriever) UpdateTokenPrices

func (a *AddressBalanceRetriever) UpdateTokenPrices()

type CurrentRatesData

type CurrentRatesData struct {
	AssetIDBase string `json:"asset_id_base"`
	Rates       []Rate `json:"rates"`
}

type Rate

type Rate struct {
	Time         string  `json:"time"`
	AssetIDQuote string  `json:"asset_id_quote"`
	Rate         float64 `json:"rate"`
}

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL
JackTT - Gopher 🇻🇳