db

package
v0.0.0-...-031fc53 Latest Latest
Warning

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

Go to latest
Published: Nov 5, 2020 License: AGPL-3.0 Imports: 15 Imported by: 0

Documentation

Index

Constants

View Source
const AverageTotalHashrateKey = "average_total_hashrate"

AverageTotalHashrateKey is used to identify if key is average total hashrate item

View Source
const BestSharePrefix = "best__"

BestSharePrefix is used to map best share db objects

View Source
const MinedBlockPrefix = "block__"

MinedBlockPrefix is used to map block db objects

View Source
const MinedValidSharesKey = "mined_valid_shares"

MinedValidSharesKey is used to identify if key is mined valid shares counter

View Source
const StatPrefix = "stat__"

StatPrefix is used to map stat db objects

View Source
const TotalSharesKey = "total_shares"

TotalSharesKey is used to identify if key is total shares item

View Source
const TotalStatPrefix = "total__"

TotalStatPrefix is used to map summarized stat db objects

Variables

This section is empty.

Functions

func WriteStatToBatch

func WriteStatToBatch(batch *leveldb.Batch, stat Stat, timestamp int64)

WriteStatToBatch writes worker stat object to the LevelDB batch

func WriteTotalStatToBatch

func WriteTotalStatToBatch(batch *leveldb.Batch, stat TotalStat, timestamp int64)

WriteTotalStatToBatch writes worker stat object to the LevelDB batch

Types

type BestShare

type BestShare struct {
	WorkerName            string  `json:"worker_name"`
	ActualShareDifficulty float64 `json:"actual_share_difficulty"`
	Timestamp             int64   `json:"timestamp"`
}

BestShare represents an interface for a best share DB object

type Block

type Block struct {
	Hash        string  `json:"hash"`
	Number      uint64  `json:"number"`
	Type        string  `json:"type"`
	WorkerName  string  `json:"worker_name"`
	Difficulty  float64 `json:"difficulty"`
	Timestamp   int64   `json:"timestamp"`
	Confirmed   bool    `json:"confirmed"`
	MinedHashes float64 `json:"mined_hashes"`
	RoundTime   int64   `json:"round_time"`
	Luck        float64 `json:"luck"`
}

Block represents an interface for a block DB object

type Database

type Database struct {
	DB   *leveldb.DB
	Path string
}

Database represents the interface to the LevelDB database

func OpenDB

func OpenDB(path string) (*Database, error)

OpenDB opens LevelDB database by path, and creates a new Database object

func (*Database) Close

func (db *Database) Close()

Close closes LevelDB database

func (*Database) GetAndWriteCachedValues

func (db *Database) GetAndWriteCachedValues() error

GetAndWriteCachedValues gets (calculates) and writes cached values to the db

func (*Database) GetBlocksUnsorted

func (db *Database) GetBlocksUnsorted() []Block

GetBlocksUnsorted returns the unsorted blocks from the Database

func (*Database) GetRoundTime

func (db *Database) GetRoundTime() int64

GetRoundTime returns round time

func (*Database) GetTotalAverageHashrate

func (db *Database) GetTotalAverageHashrate() *big.Int

GetTotalAverageHashrate returns total average hashrate which was put by GetAndWriteCachedValues

func (*Database) GetTotalHistory

func (db *Database) GetTotalHistory() ([]TotalStat, error)

GetTotalHistory returns all "total" history (a day)

func (*Database) GetTotalShares

func (db *Database) GetTotalShares() (TotalShares, error)

GetTotalShares returns total amount of shares which was put by GetAndWriteCachedValues

func (*Database) GetTotalStatsByTimestamp

func (db *Database) GetTotalStatsByTimestamp(timestamp int64) (TotalStat, error)

GetTotalStatsByTimestamp returns TotalStat by specified timestamp

func (*Database) GetUnsortedBestShares

func (db *Database) GetUnsortedBestShares() []BestShare

GetUnsortedBestShares returns the unsorted best shares from the Database

func (*Database) GetValidSharesThenReset

func (db *Database) GetValidSharesThenReset() (uint64, error)

GetValidSharesThenReset gets the mined valid shares counter and resets it

func (*Database) GetWorkers

func (db *Database) GetWorkers() []Worker

GetWorkers returns current workers

func (*Database) IncrValidShares

func (db *Database) IncrValidShares() error

IncrValidShares increments mined valid shares counter (used to precisely calculate luck)

func (*Database) PruneStats

func (db *Database) PruneStats(deleteDataOlderThanSecs int64)

PruneStats removes data with the age more than `deleteDataOlderThanSecs`

func (*Database) WriteBestShare

func (db *Database) WriteBestShare(bestShare BestShare, timestamp int64) error

WriteBestShare writes best share to the database

func (*Database) WriteMinedBlock

func (db *Database) WriteMinedBlock(block Block) error

WriteMinedBlock writes mined block to the database

type Stat

type Stat struct {
	Timestamp         int64   `json:"timestamp"`
	WorkerName        string  `json:"worker_name"`
	ValidShareCount   uint64  `json:"valid_share_count"`
	StaleShareCount   uint64  `json:"stale_share_count"`
	InvalidShareCount uint64  `json:"invalid_share_count"`
	ReportedHashrate  float64 `json:"reported_hashrate"`
	EffectiveHashrate float64 `json:"effective_hashrate"`
	IPAddress         string  `json:"ip_address"`
}

Stat represents an interface for a stat DB object

type TotalShares

type TotalShares struct {
	ValidShares   uint64 `json:"valid_shares"`
	StaleShares   uint64 `json:"stale_shares"`
	InvalidShares uint64 `json:"invalidShares"`
}

TotalShares represents an interface to total shares db object

type TotalStat

type TotalStat struct {
	ValidShareCount   uint64  `json:"valid_share_count"`
	StaleShareCount   uint64  `json:"stale_share_count"`
	InvalidShareCount uint64  `json:"invalid_share_count"`
	ReportedHashrate  float64 `json:"reported_hashrate"`
	EffectiveHashrate float64 `json:"effective_hashrate"`
	WorkerCount       uint64  `json:"worker_count"`
}

TotalStat represents an interface for a summarized stat DB object

type Worker

type Worker struct {
	Name              string
	LastSeen          int64
	IsOnline          bool
	EffectiveHashrate float64
	ReportedHashrate  float64
	ValidShares       uint64
	StaleShares       uint64
	InvalidShares     uint64
}

Worker is a struct returned by GetWorkers function

Jump to

Keyboard shortcuts

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