Documentation
¶
Index ¶
Constants ¶
const WorkDifficulty = 18
Variables ¶
This section is empty.
Functions ¶
func BlockSerialize ¶
A function to serialize a Block into gob of bytes
Types ¶
type Block ¶
type Block struct { Hash []byte // Represents the hash of the Block Data []byte // Represents the data of the Block PrevHash []byte // Represents the hash of the previous Block Nonce int // Represents the nonce number that signed the block Difficulty int // Represent the difficulty value to sign the block }
A structure that represents a single Block on the Animus BlockChain
func BlockDeserialize ¶
A function to deserialize a gob of bytes into a Block
func NewBlock ¶
A constructor function that generates and returns a new block from th hash of the previous block and a block data. Adds the data to a block and signs it using the PoW algorithm.
func (*Block) Compose ¶
A method of Block that composes and returns the block data as slice of bytes for a given nonce number.
Considers the block data, the hash of the previous block, the block work difficulty and the given nonce number.
func (*Block) GenerateProofTarget ¶
A method of Block that generates the max value of the hash to sign the block. Returns a big integer
type BlockChain ¶
type BlockChain struct { Database *badger.DB // Represents the reference to the chain database LastHash []byte // Represents the hash of the last block on the chain }
A structure that represents the Animus BlockChain
func NewBlockChain ¶
func NewBlockChain() *BlockChain
A constructor function that generates a BlockChain from the database. If the blockchain does not exist on the database, a new is created and initialized with a Genesis Block.
func (*BlockChain) AddBlock ¶
func (chain *BlockChain) AddBlock(blockdata string)
A method of BlockChain that adds a new Block to the chain
type BlockChainIterator ¶
type BlockChainIterator struct { CursorHash []byte // Represents the hash of the block that the iterator is currently on Database *badger.DB // Represents the reference to the chain database }
A structure that represents an Iterator for the Animus BlockChain
func NewIterator ¶
func NewIterator(chain *BlockChain) *BlockChainIterator
A constructor function that generates an iterator for the BlockChain
func (*BlockChainIterator) Next ¶
func (iter *BlockChainIterator) Next() *Block
A method of BlockChainIterator that iterates over chain and returns the next block on the chain (backwards) from the chain DB and returns it