blockchain

package
v0.0.0-...-d575e71 Latest Latest
Warning

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

Go to latest
Published: Jan 30, 2022 License: MIT Imports: 9 Imported by: 0

Documentation

Index

Constants

View Source
const Difficulty = 16

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
	PrevHash []byte
	Nonce    int
}

func CreateBlock

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

func Deserialize

func Deserialize(data []byte) *Block

func Genesis

func Genesis() *Block

func (*Block) Serialize

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

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