BLC

package
v0.0.0-...-e5bb5d5 Latest Latest
Warning

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

Go to latest
Published: Jan 3, 2020 License: Apache-2.0 Imports: 11 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func IntToHex

func IntToHex(data int64) []byte

实现int64转换成byte字节数组

func IsValidArgs

func IsValidArgs()

参数数量检测函数

func PrintUsage

func PrintUsage()

用法展示

Types

type Block

type Block struct {
	TimeStamp     int64  //区块的时间戳 代表区块时间
	Hash          []byte //当前区块哈希
	PrevBlockHash []byte //前区块哈希
	Height        int64  //区块的高度
	Data          []byte //交易数据
	Nonce         int64  //在运行pow时生成的哈希变化值,也代表pow运行时动态修改的数据
}

区块的基本结构以及功能管理文件 实现一个最基本的区块结构

func CreateGensisBlock

func CreateGensisBlock(data []byte) *Block

生成创世区块

func DeserializeBlock

func DeserializeBlock(blockBytes []byte) *Block

区块结构反序列化

func NewBlock

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

新建区块

func (*Block) Serialize

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

区块结构序列化

func (*Block) SetHash

func (b *Block) SetHash()

计算区块哈希 为了不传参

type BlockChain

type BlockChain struct {
	//Blocks []*Block //区块的切片
	Db  *bolt.DB //数据库对象
	Tip []byte   //保存最新区块的哈希值
}

区块链的基本结构

func CreateBlockChainWithGensisBlock

func CreateBlockChainWithGensisBlock() *BlockChain

初始化区块链

func (*BlockChain) AddBlock

func (bc *BlockChain) AddBlock(data []byte)

添加区块到区块链

func (*BlockChain) Iterator

func (blc *BlockChain) Iterator() *BlockChainIterator

next()函数 创建迭代器对象 实现迭代函数next 获取到每一个区块

func (*BlockChain) PrintChain

func (bc *BlockChain) PrintChain()

遍历数据库,输出所有区块信息

type BlockChainIterator

type BlockChainIterator struct {
	Db          *bolt.DB //迭代目标
	CurrentHash []byte   //当前的迭代目标的哈希
}

实现迭代器基本结构

func (*BlockChainIterator) Next

func (bcit *BlockChainIterator) Next() *Block

实现迭代函数next 读取到每一个区块

type CLI

type CLI struct {
	BC *BlockChain //BlockChain对象
}

client对象

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

创建一个Pow的对象

func (*ProofOfWork) Run

func (proofOfWork *ProofOfWork) Run() ([]byte, int)

执行pow 比较哈希 返回哈希值以及碰撞的次数

Jump to

Keyboard shortcuts

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