animus

package
v0.0.0-...-b248a6e Latest Latest
Warning

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

Go to latest
Published: May 31, 2021 License: MIT Imports: 9 Imported by: 0

Documentation

Index

Constants

View Source
const WorkDifficulty = 18

Variables

This section is empty.

Functions

func BlockSerialize

func BlockSerialize(block *Block) []byte

A function to serialize a Block into gob of bytes

func Handle

func Handle(err error)

A function to handle errors.

func Hexify

func Hexify(number int64) []byte

A function that generates and returns the Hex/Bytes representation of an int64

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

func BlockDeserialize(gobdata []byte) *Block

A function to deserialize a gob of bytes into a Block

func NewBlock

func NewBlock(data string, prevHash []byte) *Block

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

func (block *Block) Compose(nonce int) []byte

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

func (block *Block) GenerateProofTarget() *big.Int

A method of Block that generates the max value of the hash to sign the block. Returns a big integer

func (*Block) Sign

func (block *Block) Sign() (int, []byte)

A method of Block that runs the Proof of Work algorithm to generate the hash of the block and to sign it. Returns the nonce number that signed the block and the hash of the block

func (*Block) Validate

func (block *Block) Validate() bool

A method of Block that validates the block signature (hash)

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

Jump to

Keyboard shortcuts

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