blockdata

package
v8.0.0-...-ae3472c Latest Latest
Warning

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

Go to latest
Published: Apr 19, 2023 License: ISC Imports: 20 Imported by: 2

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func DisableLog

func DisableLog()

DisableLog disables all library log output. Logging output is disabled by default until UseLogger is called.

func JSONFormatBlockData

func JSONFormatBlockData(data *BlockData) (*bytes.Buffer, error)

JSONFormatBlockData concatenates block data results into a single JSON object with primary keys for the result type

func NewChainMonitor

func NewChainMonitor(ctx context.Context, collector *Collector, savers []BlockDataSaver,
	reorgSavers []BlockDataSaver) *chainMonitor

NewChainMonitor creates a new chainMonitor.

func UseLogger

func UseLogger(logger slog.Logger)

UseLogger uses a specified Logger to output package logging info.

Types

type BlockData

type BlockData struct {
	Header           chainjson.GetBlockHeaderVerboseResult
	Connections      int32
	FeeInfo          chainjson.FeeInfoBlock
	CurrentStakeDiff chainjson.GetStakeDifficultyResult
	EstStakeDiff     chainjson.EstimateStakeDiffResult
	PoolInfo         *apitypes.TicketPoolInfo
	ExtraInfo        apitypes.BlockExplorerExtraInfo
	BlockchainInfo   *chainjson.GetBlockChainInfoResult
	PriceWindowNum   int
	IdxBlockInWindow int
	WinningTickets   []string
}

BlockData contains all the data collected by a Collector and stored by a BlockDataSaver. TODO: consider if pointers are desirable here.

func (*BlockData) ToBlockExplorerSummary

func (b *BlockData) ToBlockExplorerSummary() apitypes.BlockExplorerBasic

ToBlockExplorerSummary returns a BlockExplorerBasic

func (*BlockData) ToBlockSummary

func (b *BlockData) ToBlockSummary() apitypes.BlockDataBasic

ToBlockSummary returns an apitypes.BlockDataBasic object from the blockdata

func (*BlockData) ToStakeInfoExtended

func (b *BlockData) ToStakeInfoExtended() apitypes.StakeInfoExtended

ToStakeInfoExtended returns an apitypes.StakeInfoExtended object from the blockdata

func (*BlockData) ToStakeInfoExtendedEstimates

func (b *BlockData) ToStakeInfoExtendedEstimates() apitypes.StakeInfoExtendedEstimates

ToStakeInfoExtendedEstimates returns an apitypes.StakeInfoExtendedEstimates object from the blockdata

type BlockDataSaver

type BlockDataSaver interface {
	Store(*BlockData, *wire.MsgBlock) error
}

BlockDataSaver is an interface for saving/storing BlockData

type BlockDataToJSONFiles

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

BlockDataToJSONFiles implements BlockDataSaver interface for JSON output to the file system.

func NewBlockDataToJSONFiles

func NewBlockDataToJSONFiles(folder string, fileBase string, m ...*sync.Mutex) *BlockDataToJSONFiles

NewBlockDataToJSONFiles creates a new BlockDataToJSONFiles with optional existing mutex

func (*BlockDataToJSONFiles) Store

func (s *BlockDataToJSONFiles) Store(data *BlockData, _ *wire.MsgBlock) error

Store writes BlockData to a file in JSON format The file name is nameBase+height+".json".

type BlockDataToJSONStdOut

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

BlockDataToJSONStdOut implements BlockDataSaver interface for JSON output to stdout.

func NewBlockDataToJSONStdOut

func NewBlockDataToJSONStdOut(m ...*sync.Mutex) *BlockDataToJSONStdOut

NewBlockDataToJSONStdOut creates a new BlockDataToJSONStdOut with optional existing mutex.

func (*BlockDataToJSONStdOut) Store

func (s *BlockDataToJSONStdOut) Store(data *BlockData, _ *wire.MsgBlock) error

Store writes BlockData to stdout in JSON format

type BlockDataToSummaryStdOut

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

BlockDataToSummaryStdOut implements BlockDataSaver interface for plain text summary to stdout.

func NewBlockDataToSummaryStdOut

func NewBlockDataToSummaryStdOut(sdiffWinSize int64, m ...*sync.Mutex) *BlockDataToSummaryStdOut

NewBlockDataToSummaryStdOut creates a new BlockDataToSummaryStdOut with optional existing mutex

func (*BlockDataToSummaryStdOut) Store

Store writes BlockData to stdout as plain text summary

type BlockTrigger

type BlockTrigger struct {
	Async bool
	Saver func(string, uint32) error
}

BlockTrigger wraps a simple function of builtin-typed hash and height.

func (BlockTrigger) Store

func (s BlockTrigger) Store(bd *BlockData, _ *wire.MsgBlock) error

Store reduces the block data to the hash and height in builtin types, and passes the data to the saver.

type Collector

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

Collector models a structure for the source of the blockdata

func NewCollector

func NewCollector(dcrdChainSvr NodeClient, params *chaincfg.Params,
	stakeDB *stakedb.StakeDatabase) *Collector

NewCollector creates a new Collector.

func (*Collector) Collect

func (t *Collector) Collect() (*BlockData, *wire.MsgBlock, error)

Collect collects chain data at the current best block.

func (*Collector) CollectAPITypes

func (t *Collector) CollectAPITypes(hash *chainhash.Hash) (*apitypes.BlockDataBasic, *apitypes.StakeInfoExtended)

CollectAPITypes uses CollectBlockInfo to collect block data, then organizes it into the BlockDataBasic and StakeInfoExtended and dcrdataapi types.

func (*Collector) CollectBlockInfo

CollectBlockInfo uses the chain server and the stake DB to collect most of the block data required by Collect() that is specific to the block with the given hash.

func (*Collector) CollectHash

func (t *Collector) CollectHash(hash *chainhash.Hash) (*BlockData, *wire.MsgBlock, error)

CollectHash collects chain data at the block with the specified hash.

type NodeClient

type NodeClient interface {
	GetBlockCount(ctx context.Context) (int64, error)
	GetBlock(ctx context.Context, blockHash *chainhash.Hash) (*wire.MsgBlock, error)
	GetBlockHeaderVerbose(ctx context.Context, hash *chainhash.Hash) (*chainjson.GetBlockHeaderVerboseResult, error)
	GetCoinSupply(ctx context.Context) (dcrutil.Amount, error)
	GetBlockSubsidy(ctx context.Context, height int64, voters uint16) (*chainjson.GetBlockSubsidyResult, error)
	GetBlockChainInfo(ctx context.Context) (*chainjson.GetBlockChainInfoResult, error)
	GetConnectionCount(ctx context.Context) (int64, error)
	EstimateStakeDiff(ctx context.Context, tickets *uint32) (*chainjson.EstimateStakeDiffResult, error)
	GetStakeDifficulty(ctx context.Context) (*chainjson.GetStakeDifficultyResult, error)
}

NodeClient is the RPC client functionality required by Collector.

Jump to

Keyboard shortcuts

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