blockchain

package
v0.0.0-...-f0b43a4 Latest Latest
Warning

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

Go to latest
Published: Feb 18, 2020 License: MIT Imports: 14 Imported by: 0

Documentation

Overview

Package contains all necessary tools to interact with and store the block chain

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func AddBlock

func AddBlock(b block.Block, file *os.File, database *sql.DB) error

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 Airdrop

func Airdrop(blockchain string, metadata string, accountBalanceTable string, genesisBlock block.Block) error

func GetBlockByHash

func GetBlockByHash(hash []byte, file *os.File, db *sql.DB) ([]byte, error)

Given a block hash and extracts the block that matches that block's hash

func GetBlockByHeight

func GetBlockByHeight(height int, file *os.File, db *sql.DB) ([]byte, error)

Given a height number and extracts the block of that height

func GetBlockByPosition

func GetBlockByPosition(position int, file *os.File, db *sql.DB) ([]byte, error)

Given a file position and extracts the block at that position

func GetYoungestBlock

func GetYoungestBlock(file *os.File, db *sql.DB) (block.Block, error)

Retrieves Block with the largest height in deserialized form

func GetYoungestBlockHeader

func GetYoungestBlockHeader(file *os.File, metadata *sql.DB) (block.BlockHeader, error)

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) AddBlock

func (m *LedgerManager) AddBlock(b block.Block) error

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()

Jump to

Keyboard shortcuts

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