blockchain

package
v0.0.0-...-5d652c1 Latest Latest
Warning

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

Go to latest
Published: Jan 15, 2024 License: MIT Imports: 7 Imported by: 3

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Block

type Block struct {
	Timestamp     int64  `json:"timestamp"`
	Data          []byte `json:"data"`
	PrevBlockHash []byte `json:"prev_block_hash"`
	Hash          string `json:"hash"`
	Nonce         int    `json:"nonce"`
}

Block represents a single block in the blockchain

func NewBlock

func NewBlock(data string, prevBlockHash []byte) *Block

NewBlock creates a new Block

func (*Block) SetHash

func (b *Block) SetHash()

SetHash calculates and sets the hash of the block

type Blockchain

type Blockchain struct {
	Blocks []*Block
}

Blockchain represents the chain of blocks

func NewBlockchain

func NewBlockchain() *Blockchain

NewBlockchain creates a new Blockchain with genesis Block

func (*Blockchain) AddBlock

func (bc *Blockchain) AddBlock(data string) error

AddBlock adds a new block to the blockchain Returns an error if it fails to create a new block

type Transaction

type Transaction struct {
	ID        string    `json:"id"`
	Timestamp time.Time `json:"timestamp"`
	Sender    string    `json:"sender"`
	Recipient string    `json:"recipient"`
	Amount    float64   `json:"amount"`
	Signature string    `json:"signature"` // Placeholder for digital signature
}

Transaction represents a blockchain transaction

func NewTransaction

func NewTransaction(sender, recipient string, amount float64) *Transaction

NewTransaction creates a new Transaction

Jump to

Keyboard shortcuts

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