Documentation ¶
Overview ¶
Package common contains common functions and variables used by various scripts and services
Index ¶
- Constants
- Variables
- func FmtDateDay(t time.Time) string
- func FmtDateDayTime(t time.Time) string
- func FmtDuration(d time.Duration) string
- func GetAuthTokenAndURL(auth string) (string, string)
- func GetCSV(filename string) (rows [][]string, err error)
- func GetCSVFromFiles(filenames []string) (rows [][]string, err error)
- func GetEnv(key, defaultValue string) string
- func GetEnvInt(key string, defaultValue int) int
- func GetLogger(debug, prod bool) *zap.SugaredLogger
- func GetMemUsageHuman() string
- func GetMemUsageMb() uint64
- func HumanBytes(n uint64) string
- func Int64DiffPercentFmt(a, b int64, decimals uint) string
- func Int64DiffPercentFmtC(a, b int64, decimals uint, fmtSuffix string) string
- func IntDiffPercentFmt(a, b int, decimals uint) string
- func IntDiffPercentFmtC(a, b int, decimals uint, fmtSuffix string) string
- func IsWebsocketProtocol(url string) bool
- func LoadSourcelogFiles(log *zap.SugaredLogger, files []string) (txs map[string]map[string]int64, cntProcessedRecords int64)
- func LoadTransactionCSVFiles(log *zap.SugaredLogger, txInputFiles, txBlacklistFiles []string) (txs map[string]*TxSummaryEntry, err error)
- func LoadTrashFiles(log *zap.SugaredLogger, files []string) (txs map[string]map[string]*TrashEntry, err error)
- func LoadTxHashesFromMetadataCSVFiles(log *zap.SugaredLogger, files []string) (txs map[string]bool, err error)
- func MustBeCSVFile(log *zap.SugaredLogger, fn string)
- func MustBeFile(log *zap.SugaredLogger, fn string, extensions []string)
- func MustBeParquetFile(log *zap.SugaredLogger, fn string)
- func MustNotExist(log *zap.SugaredLogger, fn string)
- func PrettyInt(i int) string
- func PrettyInt64(i int64) string
- func PrintMemUsage()
- func RLPDecode(rlpBytes []byte) (*types.Transaction, error)
- func RLPStringToTx(rlpHex string) (*types.Transaction, error)
- func SetupMarkdownTableWriter(table *tablewriter.Table)
- func SourceAliasesFromEnv() map[string]string
- func TitleStrings(s []string) []string
- func TxSourcName(uri string) string
- func TxToRLPString(tx *types.Transaction) (string, error)
- type Analyzer2
- type Analyzer2Opts
- type BlxRawTxMsg
- type EdenRawTxMsg
- type SourceComp
- type TrashEntry
- type TxIn
- type TxSummaryEntry
Constants ¶
const ( SourceTagLocal = "local" SourceTagBloxroute = "bloxroute" SourceTagChainbound = "chainbound" SourceTagEden = "eden" SourceTagAlchemy = "alchemy" SourceTagInfura = "infura" // Trash tx reasons TrashTxAlreadyOnChain = "tx-already-onchain" TrashTxSignatureError = "signature-error" // GRPCWindowSize is recommended window size by bloxroute-labs: // https://docs.bloxroute.com/streams/working-with-streams/creating-a-subscription/grpc GRPCWindowSize = 128 * 1024 // TxAlreadyIncludedThreshold sets the threshold for discarding transactions (if included that many ms before received) TxAlreadyIncludedThreshold = 12_000 )
Variables ¶
var ( ErrUnsupportedFileFormat = errors.New("unsupported file format") Printer = message.NewPrinter(language.English) Caser = cases.Title(language.English) Title = Caser.String )
var DefaultSourceComparisons = []SourceComp{ {SourceTagBloxroute, SourceTagLocal}, {SourceTagChainbound, SourceTagLocal}, {SourceTagBloxroute, SourceTagChainbound}, {SourceTagBloxroute, SourceTagEden}, {SourceTagChainbound, SourceTagEden}, }
var TxSummaryEntryCSVHeader = []string{
"timestamp_ms",
"hash",
"chain_id",
"from",
"to",
"value",
"nonce",
"gas",
"gas_price",
"gas_tip_cap",
"gas_fee_cap",
"data_size",
"data_4bytes",
"sources",
"included_at_block_height",
"included_block_timestamp_ms",
"inclusion_delay_ms",
"tx_type",
}
Functions ¶
func FmtDateDay ¶ added in v0.6.0
func FmtDateDayTime ¶ added in v0.6.0
func FmtDuration ¶ added in v0.6.0
func GetAuthTokenAndURL ¶ added in v0.6.0
GetAuthTokenAndURL takes in auth strings like "token" or "token@url" and returns token and url separately
func GetCSVFromFiles ¶ added in v0.5.2
func GetLogger ¶
func GetLogger(debug, prod bool) *zap.SugaredLogger
func GetMemUsageHuman ¶ added in v0.6.0
func GetMemUsageHuman() string
func GetMemUsageMb ¶
func GetMemUsageMb() uint64
func HumanBytes ¶
HumanBytes returns size in the same format as AWS S3
func Int64DiffPercentFmt ¶
func Int64DiffPercentFmtC ¶ added in v0.6.0
func IntDiffPercentFmt ¶
func IntDiffPercentFmtC ¶ added in v0.6.0
func IsWebsocketProtocol ¶ added in v0.5.2
func LoadSourcelogFiles ¶ added in v0.5.2
func LoadSourcelogFiles(log *zap.SugaredLogger, files []string) (txs map[string]map[string]int64, cntProcessedRecords int64)
LoadSourcelogFiles loads sourcelog .csv (or .csv.zip) files (format: <timestamp_ms>,<tx_hash>,<source>) and returns a map[hash][source] = timestampMs
func LoadTransactionCSVFiles ¶
func LoadTransactionCSVFiles(log *zap.SugaredLogger, txInputFiles, txBlacklistFiles []string) (txs map[string]*TxSummaryEntry, err error)
LoadTransactionCSVFiles loads transaction CSV files into a map[txHash]*TxSummaryEntry All transactions occurring in []knownTxsFiles are skipped
func LoadTrashFiles ¶ added in v0.5.2
func LoadTrashFiles(log *zap.SugaredLogger, files []string) (txs map[string]map[string]*TrashEntry, err error)
LoadTrashFiles loads sourcelog .csv (or .csv.zip) files (format: <timestamp_ms>,<tx_hash>,<source>) and returns a map[hash][source] = *TrashEntry
func LoadTxHashesFromMetadataCSVFiles ¶
func LoadTxHashesFromMetadataCSVFiles(log *zap.SugaredLogger, files []string) (txs map[string]bool, err error)
LoadTxHashesFromMetadataCSVFiles loads transaction hashes from metadata CSV (or .csv.zip) files into a map[txHash]bool
func MustBeCSVFile ¶ added in v0.6.0
func MustBeCSVFile(log *zap.SugaredLogger, fn string)
func MustBeFile ¶
func MustBeFile(log *zap.SugaredLogger, fn string, extensions []string)
func MustBeParquetFile ¶ added in v0.6.0
func MustBeParquetFile(log *zap.SugaredLogger, fn string)
func MustNotExist ¶
func MustNotExist(log *zap.SugaredLogger, fn string)
func PrettyInt64 ¶ added in v0.6.0
func PrintMemUsage ¶
func PrintMemUsage()
func RLPStringToTx ¶
func RLPStringToTx(rlpHex string) (*types.Transaction, error)
func SetupMarkdownTableWriter ¶ added in v0.6.0
func SetupMarkdownTableWriter(table *tablewriter.Table)
func SourceAliasesFromEnv ¶
func TitleStrings ¶ added in v0.6.0
func TxSourcName ¶
func TxToRLPString ¶
func TxToRLPString(tx *types.Transaction) (string, error)
Types ¶
type Analyzer2 ¶ added in v0.6.0
type Analyzer2 struct { Transactions map[string]*TxSummaryEntry Sourelog map[string]map[string]int64 SourceComps []SourceComp // contains filtered or unexported fields }
func NewAnalyzer2 ¶ added in v0.6.0
func NewAnalyzer2(opts Analyzer2Opts) *Analyzer2
func (*Analyzer2) WriteToFile ¶ added in v0.6.0
type Analyzer2Opts ¶ added in v0.6.0
type Analyzer2Opts struct { Transactions map[string]*TxSummaryEntry Sourelog map[string]map[string]int64 // [hash][source] = timestampMs SourceComps []SourceComp }
type BlxRawTxMsg ¶
type BlxRawTxMsg struct { Params struct { Result struct { RawTx string } } }
type EdenRawTxMsg ¶
type EdenRawTxMsg struct { Params struct { Result struct { RLP string } } }
type SourceComp ¶
func NewSourceComps ¶
func NewSourceComps(args []string) (srcComp []SourceComp)
type TrashEntry ¶ added in v0.5.2
func NewTrashEntryFromCSVRow ¶ added in v0.5.2
func NewTrashEntryFromCSVRow(row []string) *TrashEntry
func (*TrashEntry) TrashEntryToCSVRow ¶ added in v0.5.2
func (entry *TrashEntry) TrashEntryToCSVRow() string
type TxSummaryEntry ¶
type TxSummaryEntry struct { // The fields are written to CSV, and the order shouldn't change (for backwards compatibility) Timestamp int64 `parquet:"name=timestamp, type=INT64, convertedtype=TIMESTAMP_MILLIS"` Hash string `parquet:"name=hash, type=BYTE_ARRAY, convertedtype=UTF8, encoding=PLAIN, omitstats=true"` ChainID string `parquet:"name=chainId, type=BYTE_ARRAY, convertedtype=UTF8, encoding=PLAIN"` TxType int64 `parquet:"name=txType, type=INT64, encoding=PLAIN_DICTIONARY"` From string `parquet:"name=from, type=BYTE_ARRAY, convertedtype=UTF8, encoding=PLAIN, omitstats=true"` To string `parquet:"name=to, type=BYTE_ARRAY, convertedtype=UTF8, encoding=PLAIN_DICTIONARY"` Value string `parquet:"name=value, type=BYTE_ARRAY, convertedtype=UTF8, encoding=PLAIN, omitstats=true"` Nonce string `parquet:"name=nonce, type=BYTE_ARRAY, convertedtype=UTF8, encoding=PLAIN, omitstats=true"` Gas string `parquet:"name=gas, type=BYTE_ARRAY, convertedtype=UTF8, encoding=PLAIN, omitstats=true"` GasPrice string `parquet:"name=gasPrice, type=BYTE_ARRAY, convertedtype=UTF8, encoding=PLAIN, omitstats=true"` GasTipCap string `parquet:"name=gasTipCap, type=BYTE_ARRAY, convertedtype=UTF8, encoding=PLAIN, omitstats=true"` GasFeeCap string `parquet:"name=gasFeeCap, type=BYTE_ARRAY, convertedtype=UTF8, encoding=PLAIN, omitstats=true"` DataSize int64 `parquet:"name=dataSize, type=INT64"` Data4Bytes string `parquet:"name=data4Bytes, type=BYTE_ARRAY, convertedtype=UTF8, encoding=PLAIN_DICTIONARY"` Sources []string `parquet:"name=sources, type=MAP, convertedtype=LIST, valuetype=BYTE_ARRAY, valueconvertedtype=UTF8"` // Inclusion stats IncludedAtBlockHeight int64 `parquet:"name=includedAtBlockHeight, type=INT64"` IncludedBlockTimestamp int64 `parquet:"name=includedBlockTimestamp, type=INT64, convertedtype=TIMESTAMP_MILLIS"` InclusionDelayMs int64 `parquet:"name=inclusionDelayMs, type=INT64"` // Finally, the raw transaction (not written to CSV) RawTx string `parquet:"name=rawTx, type=BYTE_ARRAY, encoding=PLAIN, omitstats=true"` }
TxSummaryEntry is a struct that represents a single transaction in the summary CSV and Parquet file see also https://github.com/xitongsys/parquet-go for more details on parquet tags
func ParseTx ¶
func ParseTx(timestampMs int64, rawTxHex string) (TxSummaryEntry, *types.Transaction, error)
func (*TxSummaryEntry) HasSource ¶ added in v0.6.0
func (t *TxSummaryEntry) HasSource(src string) bool
func (*TxSummaryEntry) RawTxHex ¶
func (t *TxSummaryEntry) RawTxHex() string
func (*TxSummaryEntry) ToCSVRow ¶
func (t *TxSummaryEntry) ToCSVRow() []string
func (*TxSummaryEntry) UpdateInclusionStatus ¶ added in v0.6.0
func (*TxSummaryEntry) WasIncludedBeforeReceived ¶ added in v0.6.0
func (t *TxSummaryEntry) WasIncludedBeforeReceived() bool