core

package
v0.0.0-...-85ef136 Latest Latest
Warning

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

Go to latest
Published: Jan 23, 2024 License: MIT Imports: 8 Imported by: 0

Documentation

Index

Constants

View Source
const MAX_NONCE = ^uint64(0)

Variables

Functions

This section is empty.

Types

type Block

type Block struct {
	Difficulty   *big.Int `json:"difficulty"`
	Hash         string   `json:"hash"`
	PreviousHash string   `json:"previous_hash"`
	MerkleRoot   string   `json:"merkle_root"`
	Txs          []Tx     `json:"tx"`
	Index        uint     `json:"index"`
	Timestamp    uint     `json:"timestamp"`
	Nonce        uint64   `json:"nonce"`
}

func GenesisBlock

func GenesisBlock() *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() error

func (*Block) Print

func (b *Block) Print()

type Blockchain

type Blockchain struct {
	Difficulty   *big.Int `json:"difficulty"`
	Chain        []Block  `json:"chain"`
	PendingBlock Block    `json:"pending_block"`
	MiningReward uint     `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    uint   `json:"amount"`
	Timestamp uint   `json:"timestamp"`
}

func NewTx

func NewTx(from string, to string, amount uint, 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