database

package
v0.0.4 Latest Latest
Warning

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

Go to latest
Published: Jun 2, 2019 License: MIT Imports: 2 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type ChainStore

type ChainStore interface {
	// Extend from DB interface
	DB

	// Headers returns the headers database that stored
	// all blockchain headers.
	Headers() Headers

	// CommitBlock save a block into database, returns how many
	// false positive transactions are and error.
	CommitBlock(block *util.Block, newTip bool) (fps uint32, err error)

	// ProcessReorganize switch chain data to the new best chain.
	ProcessReorganize(commonAncestor, prevTip, newTip *util.Header) error
}

func NewChainDB

func NewChainDB(h Headers, t TxsDB) ChainStore

type DB

type DB interface {
	// Clear delete all data in database.
	Clear() error

	// Close database.
	Close() error
}

DB is the common interface to all database implementations.

type Headers

type Headers interface {
	// Extend from DB interface
	DB

	// Save a header to database
	Put(header *util.Header, newTip bool) error

	// Get previous block of the given header
	GetPrevious(header *util.Header) (*util.Header, error)

	// Get full header with it's hash
	Get(hash *common.Uint256) (*util.Header, error)

	// Get the header on chain tip
	GetBest() (*util.Header, error)
}

type TxsDB

type TxsDB interface {
	// Extend from DB interface
	DB

	// PutTxs persists the main chain transactions into database and can be
	// queried by GetTxs(height).  Returns the false positive transaction count
	// and error.
	PutTxs(txs []util.Transaction, height uint32) (uint32, error)

	// PutForkTxs persists the fork chain transactions into database with the
	// fork block hash and can be queried by GetForkTxs(hash).
	PutForkTxs(txs []util.Transaction, hash *common.Uint256) error

	// HaveTx returns if the transaction already saved in database
	// by it's id.
	HaveTx(txId *common.Uint256) (bool, error)

	// GetTxs returns all transactions in main chain within the given height.
	GetTxs(height uint32) ([]util.Transaction, error)

	// GetForkTxs returns all transactions within the fork block hash.
	GetForkTxs(hash *common.Uint256) ([]util.Transaction, error)

	// DelTxs remove all transactions in main chain within the given height.
	DelTxs(height uint32) error
}

TxsDB stores all transactions in main chain and fork chains.

Jump to

Keyboard shortcuts

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