core

package
v0.0.0-...-68378b0 Latest Latest
Warning

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

Go to latest
Published: Jan 2, 2024 License: MIT Imports: 4 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

Functions

This section is empty.

Types

type Block

type Block struct {
	Hash         string `json:"hash"`
	PreviousHash string `json:"previous_hash"`
	MerkleRoot   string `json:"merkle_root"`
	Txs          []Tx   `json:"tx"`
	Index        int    `json:"index"`
	Timestamp    int64  `json:"timestamp"`
	Nonce        int    `json:"Nonce"`
	Difficulty   int    `json:"difficulty"`
}

func NewBlock

func NewBlock(tx []Tx, previousHash string) *Block

func (*Block) CalculateHash

func (b *Block) CalculateHash() string

func (*Block) CalculateMerkleRoot

func (b *Block) CalculateMerkleRoot() string

func (*Block) IsValid

func (b *Block) IsValid() error

func (*Block) MineBlock

func (b *Block) MineBlock(difficulty int)

func (*Block) Print

func (b *Block) Print()

type Blockchain

type Blockchain struct {
	Chain               []Block `json:"chain"`
	PendingTransactions []Tx    `json:"pending_transactions"`
	Difficulty          int     `json:"difficulty"`
	MiningReward        int     `json:"mining_reward"`
}

func NewBlockchain

func NewBlockchain() *Blockchain

func (*Blockchain) GetLatestBlock

func (bc *Blockchain) GetLatestBlock() Block

func (*Blockchain) Print

func (bc *Blockchain) Print()

type Tx

type Tx struct {
	From      string `json:"from"`
	To        string `json:"to"`
	Signature string `json:"signature"`
	Hash      string `json:"hash"`
	Amount    int    `json:"amount"`
	Timestamp int64  `json:"timestamp"`
}

func NewTx

func NewTx(from string, to string, amount int, signature string) *Tx

func (*Tx) CalculateHash

func (tx *Tx) CalculateHash() string

func (*Tx) IsValid

func (tx *Tx) IsValid() error

func (*Tx) Print

func (tx *Tx) Print()

func (*Tx) VerifySignature

func (tx *Tx) VerifySignature() error

Jump to

Keyboard shortcuts

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