blockchain

package
v0.0.0-...-c990347 Latest Latest
Warning

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

Go to latest
Published: Sep 29, 2019 License: Apache-2.0 Imports: 11 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func DBExists

func DBExists() bool

判断数据库是否存在

func NewBlockchainWithGenesisBlock

func NewBlockchainWithGenesisBlock(address string)

Types

type Block

type Block struct {
	// 区块高度
	Height int64
	//上一个区块hash
	PreBlockHash []byte
	//交易数据
	Txs []*Transaction
	//时间戳
	TimeStamp int64
	//本区块的hash
	Hash []byte
	// 随机值
	Nonce int64
}

func DeSerialize

func DeSerialize(blockBytes []byte) *Block

func NewBlock

func NewBlock(txs []*Transaction, height int64, preBlockHash []byte) *Block

func NewGenesisBlock

func NewGenesisBlock(txs []*Transaction) *Block

func (*Block) HashTransactions

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

需要将Txs转换成[]byte

func (*Block) Serialize

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

type Blockchain

type Blockchain struct {
	Tip []byte //最新的区块的Hash
	DB  *bolt.DB
}
var (
	G_Blockchain *Blockchain
)

func BlockchainObject

func BlockchainObject() *Blockchain

返回Blockchain对象

func (*Blockchain) AddBlock

func (b *Blockchain) AddBlock(txs []*Transaction)

func (*Blockchain) Iterator

func (blockchain *Blockchain) Iterator() *BlockchainIterator

func (*Blockchain) MineNewBlock

func (blockchain *Blockchain) MineNewBlock(from []string, to []string, amount []string)

挖掘新的区块

func (*Blockchain) Printchain

func (b *Blockchain) Printchain()

type BlockchainIterator

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

func (*BlockchainIterator) Next

func (blockchainIterator *BlockchainIterator) Next() *Block

type Pow

type Pow struct {
	Block *Block
	// contains filtered or unexported fields
}

func NewPow

func NewPow(block *Block) *Pow

func (*Pow) IsValid

func (p *Pow) IsValid() bool

func (*Pow) Run

func (p *Pow) Run() ([]byte, int64)

type TXInput

type TXInput struct {
	// 1. 交易的Hash
	TxHash []byte
	// 2. 存储TXOutput在Vout里面的索引
	Vout int
	// 3. 用户名
	ScriptSig string
}

type TXOutput

type TXOutput struct {
	Value        int64
	ScriptPubKey string //用户名
}

type Transaction

type Transaction struct {

	//1. 交易hash
	TxHash []byte

	//2. 输入
	Vins []*TXInput

	//3. 输出
	Vouts []*TXOutput
}

func NewCoinbaseTransaction

func NewCoinbaseTransaction(address string) *Transaction

func NewSimpleTransaction

func NewSimpleTransaction(from string, to string, amount int) *Transaction

func UnSpentTransationsWithAdress

func UnSpentTransationsWithAdress(address string) []*Transaction

如果一个地址对应的TXOutput未花费,那么这个Transaction就应该添加到数组中返回

func (*Transaction) HashTransaction

func (tx *Transaction) HashTransaction()

Jump to

Keyboard shortcuts

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