Documentation ¶
Overview ¶
Package block contains struct definitions and functions for Block which is an important struct for the blockchain.
Index ¶
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func GetCurrentTime ¶
func GetCurrentTime() uint64
GetCurrentTime returns the current timestamp so that it can be used as BlockTime which is uint64. It returns the epoch time in seconds (10 digits for the next many years).
func GetGenesisBlock ¶
func GetGenesisBlock(fullBlock bool) interface{}
GetGenesisBlock takes a bool value (get block full or light) and creates the static genesis block or header and returns it. Note that PrevBlockHash points to an imaginary hash, as block index -1 does not exist.
Types ¶
type Block ¶
type Block struct { // header (stored by full node + light node) BlockHeader Header // header being a struct makes serialization (with light node support) easier // stored by full node only Transactions []transaction.Transaction // list of transactions SimulationTask simpar.SimulationTask }
Block holds blockchain data and is serialized and stored in the chaindb bucket of the database. A full node will store the entire block, will a light node will only store the header of the block.
func NewBlock ¶
func NewBlock(blockID uint32, blockTime uint64, prevBlockHash hash.Hash, stateMerkleRoot hash.Hash, problemID hash.Hash, blockWinner winner.BlockWinner, transactions []transaction.Transaction, simTask simpar.SimulationTask) Block
NewBlock is the constructor function for Block. By using this constructor to create a new block, a Merkle Tree for the transaction list is automatically constructed and its root hash stored in the header of the block.
type Header ¶
type Header struct { BlockID uint32 // 0, 1, 2, ... BlockTime uint64 // block timestamp (epoch time in seconds) PrevBlockHash hash.Hash // hash of previous block (more specifically, the hash of a block is the hash of a block's header) TransactionsMerkleRoot hash.Hash // root hash of transactions merkle tree StateMerkleRoot hash.Hash // root hash of state merkle tree ProblemID hash.Hash // hash of block problem that is bound to this block BlockWinner winner.BlockWinner // address of winner node, hash of solution, amount of token reward }
Header holds block metadata and is part of every block. Headers are equipped with Merkle tree root hash data so that light node protocols can exist.
Directories ¶
Path | Synopsis |
---|---|
Package hash defines functions around keccak256 and useful helper functions.
|
Package hash defines functions around keccak256 and useful helper functions. |
Package merkletree contains structs and functions required to enable Merkle Trees and Merkle Proofs.
|
Package merkletree contains structs and functions required to enable Merkle Trees and Merkle Proofs. |
Package simpar stands for 'simulation parameters'.
|
Package simpar stands for 'simulation parameters'. |
Package simsol stands for 'simulation solution' and it contains structs and functions to work with files created by running simulation tasks.
|
Package simsol stands for 'simulation solution' and it contains structs and functions to work with files created by running simulation tasks. |
Package transaction contains structs and functions for enabling transaction support.
|
Package transaction contains structs and functions for enabling transaction support. |
Package winner contains structs and functions for describing which miner was calculated to be the winner of the current block.
|
Package winner contains structs and functions for describing which miner was calculated to be the winner of the current block. |