Documentation ¶
Index ¶
Constants ¶
View Source
const InitDifficulty = 12
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
type Block ¶
type Block struct { Timestamp int64 `json:"timestamp"` Data []byte `json:"data"` Hash []byte `json:"hash"` LastHash []byte `json:"lasthash"` Nonce int `json:"nonce"` Difficulty int `json:"difficulty"` }
func Deserialize ¶
Deserializes bytestring into block when loading from persistance storage
func Genesis ¶
func Genesis() *Block
Generates the first hardcoded Gensis block. The data used for the hash is NYTimes headline title from August 7, 2020.
func (*Block) AdjustDiff ¶
Utility function to adjust the difficulty of the proof of work algorithm. Difficulty is adjusted based on mineRate set at top line
func (*Block) PrintBlock ¶
func (block *Block) PrintBlock()
Prints block information for debugging purposes
type Blockchain ¶
func CreateBlockchain ¶
func CreateBlockchain() *Blockchain
Creates a new blockchain if there is no existing blockchain and store Gensis block inside. If there is an existing blockchain, set the head of the blockchain instance to the last block block hash stored in the database
func (*Blockchain) AddBlock ¶
func (chain *Blockchain) AddBlock(data string)
func (*Blockchain) Iterator ¶
func (chain *Blockchain) Iterator() *ChainIterator
type ChainIterator ¶
func (*ChainIterator) Next ¶
func (i *ChainIterator) Next() *Block
type ProofOfWork ¶
func CreatePow ¶
func CreatePow(b *Block) *ProofOfWork
func (*ProofOfWork) ComputeHash ¶
func (pow *ProofOfWork) ComputeHash() (int, []byte)
Click to show internal directories.
Click to hide internal directories.