Assignment01bca

package module
v0.0.0-...-5a01444 Latest Latest
Warning

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

Go to latest
Published: Oct 9, 2023 License: MIT Imports: 3 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func CalculateHash

func CalculateHash(block *Block) string

CalculateHash computes the hash of a block using its transaction, nonce, and previous hash.

func ChangeBlock

func ChangeBlock(block *Block, newTransaction string)

ChangeBlock updates a block with a new transaction and resets the nonce.

func DisplayBlocks

func DisplayBlocks(blocks []*Block)

DisplayBlocks prints information about each block in the blockchain.

func ValidateProofOfWork

func ValidateProofOfWork(block *Block) bool

ValidateProofOfWork checks if the block's current hash satisfies the proof of work requirement.

func VerifyChain

func VerifyChain(blocks []*Block) bool

VerifyChain checks if the blockchain is valid by verifying previous hashes and proof of work.

Types

type Block

type Block struct {
	Transaction  string // The data or transaction stored in the block.
	Nonce        int    // A random number used in the proof of work process.
	PreviousHash string // The hash of the previous block in the chain.
	CurrentHash  string // The hash of the current block.
}

Block represents a single block in the blockchain.

func NewBlock

func NewBlock(transaction string, previousHash string) *Block

NewBlock creates a new block with the given transaction and previous hash.

Jump to

Keyboard shortcuts

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