blockchain

package
v0.0.0-...-190f0f3 Latest Latest
Warning

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

Go to latest
Published: Mar 19, 2023 License: MIT Imports: 9 Imported by: 0

Documentation

Index

Constants

View Source
const Difficulty = 18

static in a real blockchain, it has to increase overtime due to increase in number of miners growing and also computation power

Variables

This section is empty.

Functions

func Handle

func Handle(err error)

func InitBlockchain

func InitBlockchain()

returns a pointer to the blockchain

func ToHex

func ToHex(num int64) []byte

a utility function

Types

type Block

type Block struct {
	// block's hash = Data + prevHash
	Hash []byte
	//any type of data
	Data []byte
	// previous block's hash
	PrevHash []byte
	// the nonce value that meets the target for the block
	Nonce int
}

a struct (a data structure to represent to represent our block)

func CreateBlock

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

outputs a pointer to a block

func Deserialize

func Deserialize(data []byte) *Block

func Genesis

func Genesis() *Block

returns a pointer to a block

func (*Block) Serialize

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

type BlockChain

type BlockChain struct {
	Blocks []*Block

	Database *badger.DB
	// contains filtered or unexported fields
}

func (*BlockChain) AddBlock

func (chain *BlockChain) AddBlock(data string)

any blockchain struct instance can use this function

type ProofOfWork

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

func NewProof

func NewProof(b *Block) *ProofOfWork

produce a pointer to a POW

func (*ProofOfWork) InitData

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

create a method on a struct

func (*ProofOfWork) Run

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

func (*ProofOfWork) Validate

func (pow *ProofOfWork) Validate() bool

to validate a block relatively simpler than getting the nonce

Jump to

Keyboard shortcuts

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