chain

package
v0.0.7 Latest Latest
Warning

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

Go to latest
Published: Dec 19, 2018 License: BSD-2-Clause Imports: 16 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

View Source
var HashAssumeValid util.Hash

Functions

func Close added in v0.0.7

func Close()

Close FIXME: this is only for test. We must do it in a graceful way

func InitGlobalChain

func InitGlobalChain()

Types

type BehaviorFlags

type BehaviorFlags uint32

BehaviorFlags is a bitmask defining tweaks to the normal behavior when performing chain processing and consensus rules checks.

const (
	// BFFastAdd may be set to indicate that several checks can be avoided
	// for the block since it is already known to fit into the chain due to
	// already proving it correct links into the chain up to a known
	// checkpoint.  This is primarily used for headers-first mode.
	BFFastAdd BehaviorFlags = 1 << iota

	// BFNoPoWCheck may be set to indicate the proof of work check which
	// ensures a block hashes to a value less than the required target will
	// not be performed.
	BFNoPoWCheck

	// BFNone is a convenience value to specifically indicate no flags.
	BFNone BehaviorFlags = 0
)

type BlockLocator

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

func NewBlockLocator

func NewBlockLocator(vHaveIn []util.Hash) *BlockLocator

func (*BlockLocator) GetBlockHashList

func (blt *BlockLocator) GetBlockHashList() []util.Hash

func (*BlockLocator) IsNull

func (blt *BlockLocator) IsNull() bool

func (*BlockLocator) SetNull

func (blt *BlockLocator) SetNull()

type Chain

type Chain struct {
	*SyncingState
	// contains filtered or unexported fields
}

Chain An in-memory blIndexed chain of blocks.

func GetInstance

func GetInstance() *Chain

func NewChain

func NewChain() *Chain

func (*Chain) AddToBranch

func (c *Chain) AddToBranch(bis *blockindex.BlockIndex) error

func (*Chain) AddToIndexMap

func (c *Chain) AddToIndexMap(bi *blockindex.BlockIndex) error

func (*Chain) AddToOrphan

func (c *Chain) AddToOrphan(bi *blockindex.BlockIndex) error

func (*Chain) BuildForwardTree added in v0.0.3

func (c *Chain) BuildForwardTree() (forward map[*blockindex.BlockIndex][]*blockindex.BlockIndex)

BuildForwardTree Build forward-pointing map of the entire block tree.

func (*Chain) CanDirectFetch added in v0.0.7

func (c *Chain) CanDirectFetch() bool

func (*Chain) ChainOrphanLen

func (c *Chain) ChainOrphanLen() int32

func (*Chain) ClearActive added in v0.0.3

func (c *Chain) ClearActive()

func (*Chain) Contains

func (c *Chain) Contains(index *blockindex.BlockIndex) bool

Contains /** Efficiently check whether a block is present in this chain

func (*Chain) Equal

func (c *Chain) Equal(dst *Chain) bool

func (*Chain) FindBlockIndex

func (c *Chain) FindBlockIndex(hash util.Hash) *blockindex.BlockIndex

FindBlockIndex finds blockindex from blockIndexMap

func (*Chain) FindFork

func (c *Chain) FindFork(blIndex *blockindex.BlockIndex) *blockindex.BlockIndex

FindFork Find the last common block between this chain and a block blIndex entry.

func (*Chain) FindHashInActive

func (c *Chain) FindHashInActive(hash util.Hash) *blockindex.BlockIndex

FindHashInActive finds blockindex from active

func (*Chain) FindMostWorkChain

func (c *Chain) FindMostWorkChain() *blockindex.BlockIndex

func (*Chain) Genesis

func (c *Chain) Genesis() *blockindex.BlockIndex

Genesis Returns the blIndex entry for the genesis block of this chain, or nullptr if none.

func (*Chain) GetAncestor

func (c *Chain) GetAncestor(height int32) *blockindex.BlockIndex

GetAncestor gets ancestor from active chain.

func (*Chain) GetBlockScriptFlags

func (c *Chain) GetBlockScriptFlags(pindex *blockindex.BlockIndex) uint32

func (*Chain) GetChainTips added in v0.0.3

func (c *Chain) GetChainTips() *set.Set

GetChainTips Returns fork tip, no activate chain tip

func (*Chain) GetIndex

func (c *Chain) GetIndex(height int32) *blockindex.BlockIndex

GetIndex Returns the blIndex entry at a particular height in this chain, or nullptr if no such height exists.

func (*Chain) GetIndexBestHeader added in v0.0.7

func (c *Chain) GetIndexBestHeader() *blockindex.BlockIndex

func (*Chain) GetLocator

func (c *Chain) GetLocator(index *blockindex.BlockIndex) *BlockLocator

GetLocator get a series blockHash, which slice contain blocks sort by height from Highest to lowest.

func (*Chain) GetParams

func (c *Chain) GetParams() *model.BitcoinParams

func (*Chain) GetReceivedID

func (c *Chain) GetReceivedID() uint64

func (*Chain) GetSpendHeight

func (c *Chain) GetSpendHeight(hash *util.Hash) int32

func (*Chain) Height

func (c *Chain) Height() int32

Height Return the maximal height in the chain. Is equal to chain.Tip() ? chain.Tip()->nHeight : -1.

func (*Chain) InBranch

func (c *Chain) InBranch(pindex *blockindex.BlockIndex) bool

InBranch finds blockindex in branch

func (*Chain) IndexMapSize added in v0.0.3

func (c *Chain) IndexMapSize() int

func (*Chain) InitLoad

func (c *Chain) InitLoad(indexMap map[util.Hash]*blockindex.BlockIndex, branch []*blockindex.BlockIndex)

InitLoad load the maps of the chain

func (*Chain) Next

func (c *Chain) Next(index *blockindex.BlockIndex) *blockindex.BlockIndex

Next Find the successor of a block in this chain, or nullptr if the given index is not found or is the tip.

func (*Chain) ParentInBranch

func (c *Chain) ParentInBranch(pindex *blockindex.BlockIndex) bool

ParentInBranch finds blockindex'parent in branch

func (*Chain) RemoveFromBranch

func (c *Chain) RemoveFromBranch(bis *blockindex.BlockIndex) error

func (*Chain) ResetBlockFailureFlags added in v0.0.3

func (c *Chain) ResetBlockFailureFlags(targetBI *blockindex.BlockIndex)

func (*Chain) SendNotification

func (c *Chain) SendNotification(typ NotificationType, data interface{})

SendNotification sends a notification with the passed type and data if the caller requested notifications by providing a callback function in the call to New.

func (*Chain) SetIndexBestHeader added in v0.0.7

func (c *Chain) SetIndexBestHeader(idx *blockindex.BlockIndex)

func (*Chain) SetTip

func (c *Chain) SetTip(index *blockindex.BlockIndex)

SetTip Set/initialize a chain with a given tip.

func (*Chain) Subscribe

func (c *Chain) Subscribe(callback NotificationCallback)

Subscribe to block chain notifications. Registers a callback to be executed when various events take place. See the documentation on Notification and NotificationType for details on the types and contents of notifications.

func (*Chain) Tip

func (c *Chain) Tip() *blockindex.BlockIndex

Tip Returns the blIndex entry for the tip of this chain, or nullptr if none.

func (*Chain) TipHeight

func (c *Chain) TipHeight() int32

type Notification

type Notification struct {
	Type NotificationType
	Data interface{}
}

Notification defines notification that is sent to the caller via the callback function provided during the call to New and consists of a notification type as well as associated data that depends on the type as follows:

  • NTNewPoWValidBlock: *btcutil.Block
  • NTBlockConnected: *btcutil.Block
  • NTBlockDisconnected: *btcutil.Block

type NotificationCallback

type NotificationCallback func(*Notification)

NotificationCallback is used for a caller to provide a callback for notifications about various chain events.

type NotificationType

type NotificationType int

NotificationType represents the type of a notification message.

const (
	// NTNewPoWValidBlock indicates the associated block was accepted into
	// the block chain.  Note that this does not necessarily mean it was
	// added to the main chain.  For that, use NTBlockConnected.
	NTNewPoWValidBlock NotificationType = iota

	// NTBlockConnected indicates the associated block was connected to the
	// main chain.
	NTBlockConnected

	// NTBlockDisconnected indicates the associated block was disconnected
	// from the main chain.
	NTBlockDisconnected

	// NTChainTipUpdated indicates the associated blocks leads to the new main chain.
	NTChainTipUpdated
)

Constants for the type of a notification message.

func (NotificationType) String

func (n NotificationType) String() string

String returns the NotificationType in human-readable form.

type SyncingState

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

func (*SyncingState) IsAlmostSynced

func (ds *SyncingState) IsAlmostSynced() bool

func (*SyncingState) UpdateSyncingState

func (ds *SyncingState) UpdateSyncingState()

type TipUpdatedEvent

type TipUpdatedEvent struct {
	TipIndex          *blockindex.BlockIndex
	ForkIndex         *blockindex.BlockIndex
	IsInitialDownload bool
}

Jump to

Keyboard shortcuts

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