lib

package
v0.0.0-...-61264d6 Latest Latest
Warning

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

Go to latest
Published: Oct 30, 2023 License: MIT Imports: 12 Imported by: 0

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
	Nonce         int64
	Transactions  []*Transaction
	PrevBlockHash []byte
	Hash          []byte
}

Main blockchain element, The Block

func DecodeBlock

func DecodeBlock(buffer []byte) *Block

Deserializing the block to use it after its retrieval.

func NewBlock

func NewBlock(transactions []*Transaction, prevBlockHash []byte) *Block

Constructor method for the Block

func NewGenesisBlock

func NewGenesisBlock(coinbase *Transaction) *Block

Constructor method for Genesis Block

func (*Block) Encode

func (block *Block) Encode() []byte

Serializing the block for its proper storage

func (*Block) HashTransactions

func (block *Block) HashTransactions() []byte

Method that joins and hases every trabsaction id stored in the block.

func (*Block) Print

func (block *Block) Print()

Printing the block's attributes.

func (*Block) SetHash

func (block *Block) SetHash()

Method that geneterates the block's hash via PoW

type Blockchain

type Blockchain struct {
	Database *bolt.DB
	Head     []byte
}

List of Blocks, The Blockchain

func CreateBlockchain

func CreateBlockchain(address, nodeID string) *Blockchain

Method that instatiates a totally new blockchain for some given address and nodeID.

func NewBlockchain

func NewBlockchain(nodeID string) *Blockchain

Constructor function for The Blockchain.

func (*Blockchain) AddBlock

func (blockchain *Blockchain) AddBlock(newBlock *Block)

Method that adds a new block to The Blockchain

func (*Blockchain) Print

func (blockchain *Blockchain) Print()

Method that prints every block within the chain.

type ProofOfWork

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

Proof of Work using Hascash

func NewProofOfWork

func NewProofOfWork(block *Block) *ProofOfWork

Constructor of PoW for a given block

func (*ProofOfWork) Run

func (pow *ProofOfWork) Run() (int64, []byte)

Running the PoW algorithm

func (*ProofOfWork) Validate

func (pow *ProofOfWork) Validate() bool

Validate the proof of work using the bolck's nonce

type TXInput

type TXInput struct {
	Txid      []byte
	Vout      int
	ScriptSig string
}

func NewTXInput

func NewTXInput(txid []byte, vout int, scriptSig string) TXInput

type TXOutput

type TXOutput struct {
	Value        int
	ScriptPubKey string
}

func NewTXOutput

func NewTXOutput(value int, address string) TXOutput

type Transaction

type Transaction struct {
	ID   []byte
	Vin  []TXInput
	Vout []TXOutput
}

func NewCoinbaseTX

func NewCoinbaseTX(to, data string) *Transaction

Jump to

Keyboard shortcuts

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