Documentation ¶
Overview ¶
Package contains all necessary tools to interact with and store the block chain
Index ¶
- func AddBlock(b block.Block, file *os.File, database *sql.DB) error
- func Airdrop(blockchain string, metadata string, accountBalanceTable string, ...) error
- func GetBlockByHash(hash []byte, file *os.File, db *sql.DB) ([]byte, error)
- func GetBlockByHeight(height int, file *os.File, db *sql.DB) ([]byte, error)
- func GetBlockByPosition(position int, file *os.File, db *sql.DB) ([]byte, error)
- func GetYoungestBlock(file *os.File, db *sql.DB) (block.Block, error)
- func GetYoungestBlockHeader(file *os.File, metadata *sql.DB) (block.BlockHeader, error)
- func RecoverBlockchainMetadata(ledgerFilename string, metadataFilename string, accountBalanceTable string) error
- type LedgerManager
- func (m *LedgerManager) AddBlock(b block.Block) error
- func (m *LedgerManager) GetBlockByHash(hash []byte) ([]byte, error)
- func (m *LedgerManager) GetBlockByHeight(height int) ([]byte, error)
- func (m *LedgerManager) GetBlockByPosition(position int) ([]byte, error)
- func (m *LedgerManager) GetYoungestBlock() (block.Block, error)
- func (m *LedgerManager) GetYoungestBlockHeader() (block.BlockHeader, error)
- func (m *LedgerManager) Lock()
- func (m *LedgerManager) Unlock()
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func AddBlock ¶
Adds a block to a given file, also adds metadata file about that block into a database
This metadata include height, position, size and hash
func GetBlockByHash ¶
Given a block hash and extracts the block that matches that block's hash
func GetBlockByHeight ¶
Given a height number and extracts the block of that height
func GetBlockByPosition ¶
Given a file position and extracts the block at that position
func GetYoungestBlock ¶
Retrieves Block with the largest height in deserialized form
func GetYoungestBlockHeader ¶
Calls GetYoungestBlock and returns a Header version of the result
func RecoverBlockchainMetadata ¶
func RecoverBlockchainMetadata(ledgerFilename string, metadataFilename string, accountBalanceTable string) error
This is a security feature for the ledger. If the metadata table gets lost somehow, this function will restore it completely.
Another situation is when a producer in a decentralized system joins the network and wants the full ledger.
Types ¶
type LedgerManager ¶
type LedgerManager struct {
// contains filtered or unexported fields
}
func (*LedgerManager) GetBlockByHash ¶
func (m *LedgerManager) GetBlockByHash(hash []byte) ([]byte, error)
func (*LedgerManager) GetBlockByHeight ¶
func (m *LedgerManager) GetBlockByHeight(height int) ([]byte, error)
func (*LedgerManager) GetBlockByPosition ¶
func (m *LedgerManager) GetBlockByPosition(position int) ([]byte, error)
func (*LedgerManager) GetYoungestBlock ¶
func (m *LedgerManager) GetYoungestBlock() (block.Block, error)
func (*LedgerManager) GetYoungestBlockHeader ¶
func (m *LedgerManager) GetYoungestBlockHeader() (block.BlockHeader, error)
func (*LedgerManager) Lock ¶
func (m *LedgerManager) Lock()
func (*LedgerManager) Unlock ¶
func (m *LedgerManager) Unlock()