blockchain

package
v0.0.1 Latest Latest
Warning

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

Go to latest
Published: Jul 2, 2022 License: MPL-2.0 Imports: 8 Imported by: 0

Documentation

Index

Constants

View Source
const Difficulty = 5

Difficulty describes the difficulty of the algorithm

Variables

This section is empty.

Functions

This section is empty.

Types

type Block

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

Block defines a Block on the BlockChain.

type BlockChain

type BlockChain []Block

BlockChain represents a BlockChain

func NewBlockChain

func NewBlockChain() (blockchain BlockChain)

NewBlockChain creates an empty BlockChain with a Genesis block

func UnMarshal

func UnMarshal(data []byte) (blockchain BlockChain, err error)

UnMarshal deserializes a slice of bytes into a BlockChain data the array of bytes to deserialize

func (*BlockChain) IsEmpty

func (bc *BlockChain) IsEmpty() bool

IsEmpty checks to see if the blockchain is empty

func (*BlockChain) Iterator

func (bc *BlockChain) Iterator() *BlockChainIterator

func (*BlockChain) Last

func (bc *BlockChain) Last() (block Block, err error)

Pop removes and returns the last element of blockchain

func (*BlockChain) Marshal

func (bc *BlockChain) Marshal() (data []byte, err error)

Marshal will marshal a BlockChain into an slice of bytes

func (*BlockChain) Push

func (bc *BlockChain) Push(data []byte) (err error)

Push pushes new data onto the blockchain

type BlockChainIterator

type BlockChainIterator struct {
	// contains filtered or unexported fields
}

func (*BlockChainIterator) Next

func (iter *BlockChainIterator) Next() (block Block, err error)

Next walks through the blockchain history from latest to the genesis block

type Proof

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

func NewProof

func NewProof(b Block) (proof Proof)

NewProof creates a Proof struct from a Block b is the Block object to use

func (*Proof) Run

func (proof *Proof) Run() (int, []byte)

func (*Proof) Validate

func (proof *Proof) Validate() bool

Jump to

Keyboard shortcuts

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