Documentation
¶
Overview ¶
Package blockchain provides a simple blockchain implementation.
Index ¶
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
type Block ¶
type Block struct { Header *BlockHeader `json:"header"` Data [][]byte `json:"data"` }
Block holds batches of valid data/transactions.
type BlockHeader ¶
type BlockHeader struct { Index int `json:"index"` Time int64 `json:"time"` PrevHash []byte `json:"prevHash"` MerkleRoot []byte `json:"merkleRoot"` Extra []byte `json:"extra"` }
BlockHeader holds the metadata of a block
func (*BlockHeader) Hash ¶
func (bh *BlockHeader) Hash() []byte
Hash returns the SHA256 hash of the block header.
func (*BlockHeader) ToByte ¶
func (bh *BlockHeader) ToByte() []byte
ToByte converts the block header to bytes.
type Blockchain ¶
type Blockchain struct { DB *bolt.DB // DB stored the blockchain Tips []*Block // last block of all branches BestTip *Block // last block of longest branch }
Blockchain implements interactions with a DB.
func NewBlockchain ¶
func NewBlockchain(dbFile string, genesis *Block) *Blockchain
NewBlockchain creates a blockchain from DB file. If the file does not exist then it will be created and initialize a new blockchain with genesis block.
type Iterator ¶
type Iterator struct {
// contains filtered or unexported fields
}
Iterator is used to iterate over blockchain's blocks.
func NewIterator ¶
func NewIterator(bc *Blockchain, blockHash []byte) *Iterator
NewIterator returns a iterator with a start block.
Click to show internal directories.
Click to hide internal directories.