assignment01bca

package module
v0.0.0-...-9f076ed Latest Latest
Warning

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

Go to latest
Published: Oct 9, 2023 License: MIT Imports: 2 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 based on its transaction data, nonce, and previous hash.

func ChangeBlock

func ChangeBlock(block *Block, newTransaction string)

ChangeBlock updates the transaction data of a block and recalculates its hash.

func DisplayBlocks

func DisplayBlocks(blocks []*Block)

DisplayBlocks prints out the details of each block in the blockchain.

func VerifyChain

func VerifyChain(blocks []*Block) bool

VerifyChain checks if the blockchain is valid by verifying hashes and previous block references.

Types

type Block

type Block struct {
	Transaction  string // The transaction data stored in the block.
	Nonce        int    // Nonce is a random number used in the mining process.
	PreviousHash string // PreviousHash is the hash of the previous block.
	CurrentHash  string // CurrentHash is the hash of the current block.
}

Block represents a single unit in the blockchain.

func NewBlock

func NewBlock(transaction string, nonce int, previousHash string) *Block

NewBlock creates and returns a new block with the provided data.

Jump to

Keyboard shortcuts

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