blc01

package
v0.0.0-...-b8c1206 Latest Latest
Warning

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

Go to latest
Published: Jun 24, 2022 License: Apache-2.0 Imports: 6 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func IntToHex

func IntToHex(num int64) []byte

* 将一个int64的整数:转为二进制后,每8bit一个byte。转为[]byte

Types

type Block

type Block struct {
	//高度Height:其实就是区块的编号,第一个区块叫创世区块,高度为0
	Height int64
	//上一个区块的哈希值ProvHash:
	PrevBlockHash []byte
	//交易数据 date 目前先设计为[]byte,后期是Transaction
	Data []byte
	//时间戳
	TimeStamp int64
	//哈希值hash 32字节 64个16进制数
	Hash []byte
}

step1:创建Block结构体

func CreateGenesisBlock

func CreateGenesisBlock(data string) *Block

step6:创建区块链,带有创世区块

func NewBlock

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

func (*Block) SetHash

func (block *Block) SetHash()

step3:设置区块的hash

type BlockChain

type BlockChain struct {
	Blocks []*Block //存储有序的区块
}

step5:创建区块链

func CreateBlockChainWithGenesisBlock

func CreateBlockChainWithGenesisBlock(data string) *BlockChain

step6:创建区块链,带有创世区块

func (*BlockChain) AddBlockToBlockChain

func (bc *BlockChain) AddBlockToBlockChain(data string, height int64, prevHash []byte)

step7:添加一个新的区块,到区块链中

Jump to

Keyboard shortcuts

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