blockchain

package
v0.0.0-...-bc89c17 Latest Latest
Warning

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

Go to latest
Published: Dec 10, 2021 License: MIT Imports: 9 Imported by: 0

Documentation

Overview

proof of work algorithm

Index

Constants

View Source
const Difficulty = 12 // means how many zeros we want in the beginning of the hash byte, the difficulty will dynamically increase in reallity

Variables

This section is empty.

Functions

func Handle

func Handle(err error)

func ToHex

func ToHex(num int64) []byte

Types

type Block

type Block struct {
	Hash         []byte
	Data         []byte
	PreviousHash []byte
	Nonce        int
}

func CreateBlock

func CreateBlock(data string, previousHash []byte) *Block

func Deserialize

func Deserialize(data []byte) *Block

func Genesis

func Genesis() *Block

Genesis Block is the first block in the chain

func (*Block) Serialize

func (b *Block) Serialize() []byte

Serialize the block into bytes in order to be stored by using BadgerDB

type BlockChain

type BlockChain struct {
	LastHash []byte
	Database *badger.DB
}

func InitBlockChain

func InitBlockChain() *BlockChain

func (*BlockChain) AddBlock

func (chain *BlockChain) AddBlock(data string)

func (*BlockChain) Iterator

func (chain *BlockChain) Iterator() *BlockChainIterator

type BlockChainIterator

type BlockChainIterator struct {
	CurrentHash []byte
	Database    *badger.DB
}

func (*BlockChainIterator) Next

func (iter *BlockChainIterator) Next() *Block

type ProofOfWork

type ProofOfWork struct {
	Block  *Block
	Target *big.Int
}

func NewProof

func NewProof(b *Block) *ProofOfWork

func (*ProofOfWork) InitData

func (pow *ProofOfWork) InitData(nonce int) []byte

func (*ProofOfWork) Run

func (pow *ProofOfWork) Run() (int, []byte)

func (*ProofOfWork) Validate

func (pow *ProofOfWork) Validate() bool

Jump to

Keyboard shortcuts

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