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: 13 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func IntToHex

func IntToHex(num int64) []byte

将int类型转换成16进制

Types

type Block

type Block struct {
	Timestamp     int64  //区块创建的时间
	Data          []byte //区块存储的实际的有效信息
	PrevBlockHash []byte // 前一个区块的哈希 父哈希
	Hash          []byte //当前区块的哈希
	Nonce         int
}

区块的结构体

func DeserializeBlock

func DeserializeBlock(d []byte) *Block

将字节类型反序列化成Block类型

func NewBlock

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

创建一个新的区块

func NewGensisBlock

func NewGensisBlock() *Block

创世区块的创建

func (*Block) Serialize

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

将block类型序列化成字节

func (*Block) SetHash

func (b *Block) SetHash()

设置hash

type BlockChain

type BlockChain struct {
	//	Blocks []*Block
	Tip []byte   //存储最后一个区块的哈希
	Db  *bolt.DB //存储了一个数据库的连接
}

区块链的结构体

func NewBlockChain

func NewBlockChain() *BlockChain

创建一个新的区块链的方法

func (*BlockChain) AddBlock

func (bc *BlockChain) AddBlock(data string)

向区块链中添加区块

func (*BlockChain) Iterator

func (bc *BlockChain) Iterator() *BlockchainIterator

创建新的迭代器的方法

type BlockchainIterator

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

区块链的迭代器

func (*BlockchainIterator) Next

func (i *BlockchainIterator) Next() *Block

返回链中的下一个区块的方法

type CLI

type CLI struct {
	Bc *BlockChain
}

func (*CLI) Run

func (cli *CLI) Run()

Run 函数

type ProofOfWork

type ProofOfWork struct {
	Block *Block //区块
	// contains filtered or unexported fields
}

工作量证明的结构体

func NewproofOfWork

func NewproofOfWork(b *Block) *ProofOfWork

新建工作量证明

func (*ProofOfWork) Run

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

展示工作量证明 显示核心

func (*ProofOfWork) Validate

func (pow *ProofOfWork) Validate() bool

验证区块的工作量证明

Jump to

Keyboard shortcuts

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