utils

package
v1.4.1-rc-184 Latest Latest
Warning

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

Go to latest
Published: May 26, 2022 License: GPL-2.0 Imports: 22 Imported by: 12

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func AfterDay

func AfterDay(date1, date2 time.Time) bool

AfterDay returns true if date1 is a date after date2, irrespective of the daytime. The go method "After" respects daytime.

func CheckWeekDay

func CheckWeekDay(date time.Time) bool

CheckWeekDay returns true if @date is not weekend and false otherwise.

func CloseHTTPResp added in v1.2.0

func CloseHTTPResp(resp *http.Response)

CloseHTTPResp is a wrapper for closing http response bodies while complying with the linter.

func Contains

func Contains(s *[]string, str string) bool

Contains takes a slice of strings and a string and checks if it is contained in the slice.

func ContainsDay

func ContainsDay(s []time.Time, date time.Time) bool

ContainsDay returns true if day @date is contained in slice @s, independent of the daytime. As a consequence, be cautious when comparing days in different timezones.

func CountDays

func CountDays(dateInit, dateFinal time.Time, business bool) (days int, err error)

CountDays returns the number of days between @dateInit and @dateFinal, both given as converted from a string in the format yyyy-mm-dd, excluding the last day. @bool If true only business days are counted.

func DownloadResource

func DownloadResource(filepath, url string) (err error)

DownloadResource is a simple utility that downloads a resource from @url and stores it into @filepath.

func GetCoinPrice

func GetCoinPrice(coin string) (float64, error)

GetCoinPrice Gets the price in USD of coin through our API. Looks it up on coingecko in case it doesn't find it there.

func GetHolidays

func GetHolidays(workdays []time.Time, dateInit, dateFinal time.Time) []time.Time

GetHolidays returns "holidays" as non-weekend complement of given days @workdays

func GetRequest

func GetRequest(url string) ([]byte, int, error)

GetRequest performs a get request on @url and returns the response body as a slice of byte data.

func GetRequestWithStatus added in v1.2.0

func GetRequestWithStatus(url string) ([]byte, int, error)

GetRequest performs a get request on @url and returns the response body as a slice of byte data.

func GetTomorrow

func GetTomorrow(date, layout string) string

GetTomorrow returns the day before @date in the world of strings, formatted as @layout

func GetYesterday

func GetYesterday(date, layout string) string

GetYesterday returns the day before @date in the world of strings, formatted as @layout

func Getenv added in v1.2.0

func Getenv(key, fallback string) string

func GraphQLGet

func GraphQLGet(url string, query []byte, bearer string) ([]byte, int, error)

GraphQLGet returns the body of the result of a graphQL GET query. @url is the base url of the graphQL API @query is a byte slice representing the graphQL query message @bearer contains the API key if present

func HTTPRequest added in v1.2.0

func HTTPRequest(request *http.Request) (body []byte, statusCode int, err error)

HTTPRequest returns the request body and defers the closing compliant to linting.

func IsEnvExist added in v1.2.0

func IsEnvExist(key string) bool

func MakeTimeRanges added in v1.4.2

func MakeTimeRanges(timeInit, timeFinal time.Time, numRanges int) (starttimes, endtimes []time.Time)

MakeTimeRanges returns @numRanges start- and endtimes partitioning [@timeInit, @timeFinal] in intervals of identical size.

func MaxString

func MaxString(sl []string) (string, int64)

MaxString return the maximum of a slice of strings along with its index

func MinString

func MinString(sl []string) (string, int64)

MinString return the maximum of a slice of strings along with its index

func OpenseaGetRequest added in v1.2.0

func OpenseaGetRequest(OpenseaURL string) ([]byte, int, error)

OpenseaGetRequest returns the data for a get request on @url with an Opensea API key.

func PostRequest

func PostRequest(url string, body io.Reader) ([]byte, error)

PostRequest performs a POST request on @url and returns the response body as a slice of byte data.

func SameDays

func SameDays(date1, date2 time.Time) bool

SameDays returns true if @date1 is the same date as @date2, independent of the daytime.

func SliceDifference

func SliceDifference(slice1, slice2 []string) []string

SliceDifference returns the elements in @slice1 that aren't in @slice2.

func StrToUnixtime

func StrToUnixtime(s string) (t time.Time, err error)

StrToUnixtime converts a string corresponding to an int to Unix time

func UniqueStrings

func UniqueStrings(s []string) []string

UniqueStrings returns a subslice of @s such that each entry only appears once

Types

type ArgsortableSlice added in v1.2.0

type ArgsortableSlice struct {
	sort.Interface
	// contains filtered or unexported fields
}

ArgsortableSlice is a wrapper struct around the sort interface. It allows for implemetation of argsort for all sortable types.

func NewFloat64Slice added in v1.2.0

func NewFloat64Slice(sf sort.Float64Slice) *ArgsortableSlice

NewFloat64Slice returns the wrapped float64slice that can be argsorted.

func (ArgsortableSlice) Ind added in v1.2.0

func (as ArgsortableSlice) Ind() []int

func (ArgsortableSlice) Swap added in v1.2.0

func (s ArgsortableSlice) Swap(i, j int)

Swap swaps the corresponding indices together with the values.

type EthFilteredTx added in v1.2.0

type EthFilteredTx struct {
	BlockNum  uint64
	BlockHash common.Hash
	TXIndex   uint
	TXHash    common.Hash
	Logs      []types.Log // list of matched log records if Events or EvAddrs were used, otherwise all logs of the transaction
}

EthFilteredTx holds limited info for found transactions

type EthTxFilterCriteria added in v1.2.0

type EthTxFilterCriteria struct {
	StartBlockNum      uint64           // inclusive. filter transactions from the specific block
	StartTxIndex       uint             // inclusive. filter transactions from specific index in the given StartBlockNum
	LimitBlocks        int              // filter transactions in the specific number of blocks, zero means up to highest possible block
	BehindHighestBlock int              // stay behind the highest synched block if StartBlockNum+LimitBlocks in excess of the head
	EvAddrs            []common.Address // list of addresses from which transaction events should originate
	Events             []common.Hash    // list of events from which transactions should contain
}

EthTxFilterCriteria used for filtering transaction records

type EthTxFilterResult added in v1.2.0

type EthTxFilterResult struct {
	Synced       bool             // it means the most recent inspected block matches the highest known block (see BehindHighestBlock)
	NumBlocks    int              // number of blocks found
	NumTXs       int              // number of transactions found
	NumLogs      int              // number of log records found
	TXs          []*EthFilteredTx // list of found transactions
	LastBlockNum uint64           // block number of most recent transaction inspected
}

EthTxFilterResult describes filter results and holds found transactions

func EthFilterTXs added in v1.2.0

func EthFilterTXs(ctx context.Context, ethClient *ethclient.Client, filter EthTxFilterCriteria) (*EthTxFilterResult, error)

EthFilterTXs returns transactions filtered by log records

Jump to

Keyboard shortcuts

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