BLC

package
v0.0.0-...-afd30a4 Latest Latest
Warning

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

Go to latest
Published: Jul 27, 2024 License: MIT Imports: 11 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func Int64ToBytes

func Int64ToBytes(num int64) []byte

Types

type Block

type Block struct {
	// 区块高度
	Height int64
	// 当前区块 HASH 值
	Hash []byte
	// 上一个区块的 HASH 值
	PrevBlockHash []byte
	// 交易数据
	Data []byte
	// 时间戳
	Timestamp int64
	// Nonce 用于工作量整蒙
	Nonce int64
}

func CreateGenesisBlock

func CreateGenesisBlock(data string) *Block

CreateGenesisBlock 单独写一个方法,生成创世区块

func DeserializeBlock

func DeserializeBlock(blockBytes []byte) *Block

DeserializeBlock 反序列化区块

func NewBlock

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

NewBlock 创建新的区块

func (*Block) Serialize

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

Serialize 将区块序列化成字节数组

type BlockChain

type BlockChain struct {
	Tip []byte   // 最新的区块的 Hash
	DB  *bolt.DB // 数据库
}

func CreateBlockchainWithGenesisBlock

func CreateBlockchainWithGenesisBlock() *BlockChain

CreateBlockchainWithGenesisBlock 创建带有创世区块的区块链

func (*BlockChain) AddBlockToBlockchain

func (blc *BlockChain) AddBlockToBlockchain(data string)

AddBlockToBlockchain 增加区块到区块链里面

func (*BlockChain) Iterator

func (blc *BlockChain) Iterator() *BlockChainIterator

func (*BlockChain) PrintBlockChain

func (blc *BlockChain) PrintBlockChain()

PrintBlockChain 遍历输出所有区块的信息

type BlockChainIterator

type BlockChainIterator struct {
	CurrentHash []byte
	DB          *bolt.DB
}

func (*BlockChainIterator) Next

func (blcIterator *BlockChainIterator) Next() *Block

type CLI

type CLI struct {
	BlockChain *BlockChain
}

func (*CLI) Run

func (cli *CLI) Run()

type ProofOfWork

type ProofOfWork struct {
	Block *Block // 当前要验证的区块
	// contains filtered or unexported fields
}

func NewProofOfWork

func NewProofOfWork(block *Block) *ProofOfWork

func (ProofOfWork) Run

func (proofOfWork ProofOfWork) Run() ([]byte, int64)

Jump to

Keyboard shortcuts

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