common

package
v0.4.0 Latest Latest
Warning

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

Go to latest
Published: Feb 1, 2023 License: AGPL-3.0 Imports: 11 Imported by: 11

Documentation

Index

Constants

View Source
const (
	// DbStateClosed means db was closed gracefully
	DbStateClosed = uint32(iota)
	// DbStateOpen means db is open or application died without closing the db
	DbStateOpen
	// DbStateInconsistent means db is in inconsistent state and cannot be used
	DbStateInconsistent
)

Variables

View Source
var (
	// TickerRecalculateTokenRate signals if it is necessary to recalculate token rate to base rate
	// this happens when token rates are downloaded in TokenVsCurrency different from the base currency
	TickerRecalculateTokenRate bool
	// TickerTokenVsCurrency is the currency in which the token rates are downloaded
	TickerTokenVsCurrency string
)

Functions

func IsInShutdown added in v0.4.0

func IsInShutdown() bool

IsInShutdown returns true if in application shutdown state

func IsSuitableTicker added in v0.4.0

func IsSuitableTicker(ticker *CurrencyRatesTicker, vsCurrency string, token string) bool

IsSuitableTicker checks if the ticker can provide data for given vsCurrency or token

func SetInShutdown added in v0.4.0

func SetInShutdown()

SetInShutdown sets the internal state to in shutdown state

func TickAndDebounce added in v0.4.0

func TickAndDebounce(tickTime time.Duration, debounceTime time.Duration, trigger chan struct{}, f func())

TickAndDebounce calls function f on trigger channel or with tickTime period (whatever is sooner) with debounce

Types

type BackendInfo added in v0.3.5

type BackendInfo struct {
	BackendError     string      `json:"error,omitempty"`
	Chain            string      `json:"chain,omitempty"`
	Blocks           int         `json:"blocks,omitempty"`
	Headers          int         `json:"headers,omitempty"`
	BestBlockHash    string      `json:"bestBlockHash,omitempty"`
	Difficulty       string      `json:"difficulty,omitempty"`
	SizeOnDisk       int64       `json:"sizeOnDisk,omitempty"`
	Version          string      `json:"version,omitempty"`
	Subversion       string      `json:"subversion,omitempty"`
	ProtocolVersion  string      `json:"protocolVersion,omitempty"`
	Timeoffset       float64     `json:"timeOffset,omitempty"`
	Warnings         string      `json:"warnings,omitempty"`
	ConsensusVersion string      `json:"consensus_version,omitempty"`
	Consensus        interface{} `json:"consensus,omitempty"`
}

BackendInfo is used to get information about blockchain

type CurrencyRatesTicker added in v0.4.0

type CurrencyRatesTicker struct {
	Timestamp  time.Time          `json:"timestamp"`  // return as unix timestamp in API
	Rates      map[string]float32 `json:"rates"`      // rates of the base currency against a list of vs currencies
	TokenRates map[string]float32 `json:"tokenRates"` // rates of the tokens (identified by the address of the contract) against the base currency
}

CurrencyRatesTicker contains coin ticker data fetched from API

func (*CurrencyRatesTicker) Convert added in v0.4.0

func (t *CurrencyRatesTicker) Convert(baseValue float64, toCurrency string) float64

Convert converts value in base currency to toCurrency

func (*CurrencyRatesTicker) ConvertToken added in v0.4.0

func (t *CurrencyRatesTicker) ConvertToken(value float64, token string, toCurrency string) float64

ConvertTokenToBase converts token value to toCurrency currency

func (*CurrencyRatesTicker) ConvertTokenToBase added in v0.4.0

func (t *CurrencyRatesTicker) ConvertTokenToBase(value float64, token string) float64

ConvertTokenToBase converts token value to base currency

func (*CurrencyRatesTicker) GetTokenRate added in v0.4.0

func (t *CurrencyRatesTicker) GetTokenRate(token string) (float32, bool)

Convert returns token rate in base currency

func (*CurrencyRatesTicker) TokenRateInCurrency added in v0.4.0

func (t *CurrencyRatesTicker) TokenRateInCurrency(token string, toCurrency string) float32

TokenRateInCurrency return token rate in toCurrency currency

type InternalState

type InternalState struct {
	Coin         string `json:"coin"`
	CoinShortcut string `json:"coinShortcut"`
	CoinLabel    string `json:"coinLabel"`
	Host         string `json:"host"`

	DbState uint32 `json:"dbState"`

	LastStore time.Time `json:"lastStore"`

	// true if application is with flag --sync
	SyncMode bool `json:"syncMode"`

	InitialSync    bool      `json:"initialSync"`
	IsSynchronized bool      `json:"isSynchronized"`
	BestHeight     uint32    `json:"bestHeight"`
	LastSync       time.Time `json:"lastSync"`
	BlockTimes     []uint32  `json:"-"`
	AvgBlockPeriod uint32    `json:"-"`

	IsMempoolSynchronized bool      `json:"isMempoolSynchronized"`
	MempoolSize           int       `json:"mempoolSize"`
	LastMempoolSync       time.Time `json:"lastMempoolSync"`

	DbColumns []InternalStateColumn `json:"dbColumns"`

	UtxoChecked bool `json:"utxoChecked"`

	HasFiatRates                 bool                 `json:"-"`
	HasTokenFiatRates            bool                 `json:"-"`
	HistoricalFiatRatesTime      time.Time            `json:"historicalFiatRatesTime"`
	HistoricalTokenFiatRatesTime time.Time            `json:"historicalTokenFiatRatesTime"`
	CurrentTicker                *CurrencyRatesTicker `json:"currentTicker"`

	BackendInfo BackendInfo `json:"-"`
	// contains filtered or unexported fields
}

InternalState contains the data of the internal state

func UnpackInternalState

func UnpackInternalState(buf []byte) (*InternalState, error)

UnpackInternalState unmarshals internal state from json

func (*InternalState) AddDBColumnStats

func (is *InternalState) AddDBColumnStats(c int, rowsDiff int64, keyBytesDiff int64, valueBytesDiff int64)

AddDBColumnStats adds differences in column statistics to column stats

func (*InternalState) AppendBlockTime added in v0.3.2

func (is *InternalState) AppendBlockTime(time uint32) uint32

AppendBlockTime appends block time to BlockTimes, returns AvgBlockPeriod

func (*InternalState) DBSizeTotal

func (is *InternalState) DBSizeTotal() int64

DBSizeTotal sums the computed sizes of all columns

func (*InternalState) FinishedMempoolSync

func (is *InternalState) FinishedMempoolSync(mempoolSize int)

FinishedMempoolSync marks end of mempool synchronization

func (*InternalState) FinishedSync

func (is *InternalState) FinishedSync(bestHeight uint32)

FinishedSync marks end of synchronization, bestHeight specifies new best block height

func (*InternalState) FinishedSyncNoChange

func (is *InternalState) FinishedSyncNoChange()

FinishedSyncNoChange marks end of synchronization in case no index update was necessary, it does not update lastSync time

func (*InternalState) GetAllDBColumnStats

func (is *InternalState) GetAllDBColumnStats() []InternalStateColumn

GetAllDBColumnStats returns stats for all columns

func (*InternalState) GetAvgBlockPeriod added in v0.4.0

func (is *InternalState) GetAvgBlockPeriod() uint32

Avg100BlocksPeriod returns average period of the last 100 blocks in seconds

func (*InternalState) GetBackendInfo added in v0.3.5

func (is *InternalState) GetBackendInfo() BackendInfo

GetBackendInfo gets BackendInfo

func (*InternalState) GetBlockHeightOfTime added in v0.3.2

func (is *InternalState) GetBlockHeightOfTime(time uint32) uint32

GetBlockHeightOfTime returns block height of the first block with time greater or equal to the given time or MaxUint32 if no such block

func (*InternalState) GetBlockTime added in v0.3.2

func (is *InternalState) GetBlockTime(height uint32) uint32

GetBlockTime returns block time if block found or 0

func (*InternalState) GetCurrentTicker added in v0.4.0

func (is *InternalState) GetCurrentTicker(vsCurrency string, token string) *CurrencyRatesTicker

GetCurrentTicker returns current ticker

func (*InternalState) GetDBColumnStatValues

func (is *InternalState) GetDBColumnStatValues(c int) (int64, int64, int64)

GetDBColumnStatValues gets stat values for given column

func (*InternalState) GetLastBlockTime added in v0.4.0

func (is *InternalState) GetLastBlockTime() uint32

GetLastBlockTime returns time of the last block

func (*InternalState) GetMempoolSyncState

func (is *InternalState) GetMempoolSyncState() (bool, time.Time, int)

GetMempoolSyncState gets the state of mempool synchronization

func (*InternalState) GetSyncState

func (is *InternalState) GetSyncState() (bool, uint32, time.Time)

GetSyncState gets the state of synchronization

func (*InternalState) Pack

func (is *InternalState) Pack() ([]byte, error)

Pack marshals internal state to json

func (*InternalState) RemoveLastBlockTimes added in v0.3.2

func (is *InternalState) RemoveLastBlockTimes(count int)

RemoveLastBlockTimes removes last times from BlockTimes

func (*InternalState) SetBackendInfo added in v0.3.5

func (is *InternalState) SetBackendInfo(bi *BackendInfo)

SetBackendInfo sets new BackendInfo

func (*InternalState) SetBlockTimes added in v0.4.0

func (is *InternalState) SetBlockTimes(blockTimes []uint32) uint32

SetBlockTimes initializes BlockTimes array, returns AvgBlockPeriod

func (*InternalState) SetCurrentTicker added in v0.4.0

func (is *InternalState) SetCurrentTicker(t *CurrencyRatesTicker)

SetCurrentTicker sets current ticker

func (*InternalState) SetDBColumnStats

func (is *InternalState) SetDBColumnStats(c int, rows int64, keyBytes int64, valueBytes int64)

SetDBColumnStats sets new values of column stats

func (*InternalState) StartedMempoolSync

func (is *InternalState) StartedMempoolSync()

StartedMempoolSync signals start of mempool synchronization

func (*InternalState) StartedSync

func (is *InternalState) StartedSync()

StartedSync signals start of synchronization

func (*InternalState) UpdateBestHeight added in v0.1.0

func (is *InternalState) UpdateBestHeight(bestHeight uint32)

UpdateBestHeight sets new best height, without changing IsSynchronized flag

type InternalStateColumn

type InternalStateColumn struct {
	Name       string    `json:"name"`
	Version    uint32    `json:"version"`
	Rows       int64     `json:"rows"`
	KeyBytes   int64     `json:"keyBytes"`
	ValueBytes int64     `json:"valueBytes"`
	Updated    time.Time `json:"updated"`
}

InternalStateColumn contains the data of a db column

type JSONNumber added in v0.3.3

type JSONNumber string

JSONNumber is used instead of json.Number after upgrade to go 1.14

to handle data which can be numbers in double quotes or possibly not numbers at all

see https://github.com/golang/go/issues/37308

func (JSONNumber) Float64 added in v0.3.3

func (c JSONNumber) Float64() (float64, error)

Float64 returns JSONNumber as float64

func (JSONNumber) Int64 added in v0.3.3

func (c JSONNumber) Int64() (int64, error)

Int64 returns JSONNumber as int64

func (JSONNumber) MarshalJSON added in v0.3.3

func (c JSONNumber) MarshalJSON() ([]byte, error)

MarshalJSON marsalls JSONNumber to []byte if possible, return a number without quotes, otherwise string value in quotes empty string is treated as number 0

func (JSONNumber) String added in v0.3.3

func (c JSONNumber) String() string

func (*JSONNumber) UnmarshalJSON added in v0.3.3

func (c *JSONNumber) UnmarshalJSON(d []byte) error

UnmarshalJSON unmarshalls JSONNumber from []byte if the value is in quotes, remove them

type Labels

type Labels = prometheus.Labels

Labels represents a collection of label name -> value mappings.

type Metrics

type Metrics struct {
	SocketIORequests         *prometheus.CounterVec
	SocketIOSubscribes       *prometheus.CounterVec
	SocketIOClients          prometheus.Gauge
	SocketIOReqDuration      *prometheus.HistogramVec
	WebsocketRequests        *prometheus.CounterVec
	WebsocketSubscribes      *prometheus.GaugeVec
	WebsocketClients         prometheus.Gauge
	WebsocketReqDuration     *prometheus.HistogramVec
	IndexResyncDuration      prometheus.Histogram
	MempoolResyncDuration    prometheus.Histogram
	TxCacheEfficiency        *prometheus.CounterVec
	RPCLatency               *prometheus.HistogramVec
	IndexResyncErrors        *prometheus.CounterVec
	IndexDBSize              prometheus.Gauge
	ExplorerViews            *prometheus.CounterVec
	MempoolSize              prometheus.Gauge
	EstimatedFee             *prometheus.GaugeVec
	AvgBlockPeriod           prometheus.Gauge
	DbColumnRows             *prometheus.GaugeVec
	DbColumnSize             *prometheus.GaugeVec
	BlockbookAppInfo         *prometheus.GaugeVec
	BackendBestHeight        prometheus.Gauge
	BlockbookBestHeight      prometheus.Gauge
	ExplorerPendingRequests  *prometheus.GaugeVec
	WebsocketPendingRequests *prometheus.GaugeVec
	SocketIOPendingRequests  *prometheus.GaugeVec
	XPubCacheSize            prometheus.Gauge
}

Metrics holds prometheus collectors for various metrics collected by Blockbook

func GetMetrics

func GetMetrics(coin string) (*Metrics, error)

GetMetrics returns struct holding prometheus collectors for various metrics collected by Blockbook

type VersionInfo

type VersionInfo struct {
	Version   string `json:"version"`
	GitCommit string `json:"gitcommit"`
	BuildTime string `json:"buildtime"`
	GoVersion string `json:"goversion"`
	OSArch    string `json:"os/arch"`
}

VersionInfo holds information about the running Blockbook instance

func GetVersionInfo

func GetVersionInfo() VersionInfo

GetVersionInfo returns VersionInfo of the running Blockbook instance

Jump to

Keyboard shortcuts

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