proof

package
v0.0.0-...-ce8ee10 Latest Latest
Warning

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

Go to latest
Published: Apr 12, 2024 License: MIT Imports: 6 Imported by: 0

Documentation

Overview

Package proof will contain the logic for the proof of work (PoW) algorithm.

Index

Constants

View Source
const Difficulty int = 10

Difficulty represents the difficulty level for validating the proof of work algorithm The number of leading zeros required in the block’s hash determines the difficulty level. The more leading zeros required, the higher the difficulty.

Variables

This section is empty.

Functions

This section is empty.

Types

type ProofOfWork

type ProofOfWork[T any] struct {
	// Block is the block to be validated
	Block *block.Block[T]

	// Target is the difficulty level for mining
	Target *big.Int
}

ProofOfWork is the structure representing the PoW algorithm

func NewProofOfWork

func NewProofOfWork[T any](block block.Block[T]) *ProofOfWork[T]

NewProofOfWork creates a new PoW structure

func (*ProofOfWork[T]) ComputeData

func (pow *ProofOfWork[T]) ComputeData(nonce int) []byte

ComputeData takes a nonce integer and returns the computed for hashing the block A number used once (nonce) is a value that miners update and include in the data they are hashing in order to find a valid block hash. It is continuously changed for the same input data until a hash is generated that meets the target.

func (*ProofOfWork[T]) MineBlock

func (pow *ProofOfWork[T]) MineBlock() (int, []byte)

MineBlock performs the mining process to find a valid block hash that meets a target

func (*ProofOfWork[T]) Validate

func (pow *ProofOfWork[T]) Validate() bool

Validate validates the derived has from the proof of work algorithm

Jump to

Keyboard shortcuts

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