Documentation
¶
Index ¶
- func BuildMerkleTree(txs []common.Transaction) []byte
- func LoadConfig(filepath string)
- type BlockBuffer
- type BlockChain
- func (bc *BlockChain) AppendBlockTask(block *common.Block)
- func (bc *BlockChain) BlockProcessRoutine()
- func (bc *BlockChain) BufferFull() bool
- func (bc *BlockChain) BufferedHeight() int64
- func (bc *BlockChain) GetBlockByHash(hash *common.Hash) (*common.Block, error)
- func (bc *BlockChain) GetBlockByHeight(height int64) (*common.Block, error)
- func (bc *BlockChain) GetLatestBlock() (*common.Block, error)
- func (bc *BlockChain) GetTransactionByHash(hash common.Hash) (*common.Transaction, error)
- func (bc *BlockChain) Height() int64
- func (bc *BlockChain) InsertBlock(block *common.Block)
- func (bc *BlockChain) NewGenesisBlock()
- func (bc *BlockChain) PackageNewBlock(txs []common.Transaction, timestamp int64, params *common.GeneralParams, ...) (*common.Block, error)
- func (bc *BlockChain) ReadAddressData(address, key string) ([]byte, error)
- type DataProcessor
- type DataTask
- type TxPool
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func BuildMerkleTree ¶
func BuildMerkleTree(txs []common.Transaction) []byte
Types ¶
type BlockBuffer ¶
type BlockBuffer struct {
// contains filtered or unexported fields
}
BlockBuffer 维护一个树形结构的缓冲区,保存当前视图下的区块信息
func NewBlockBuffer ¶
func (*BlockBuffer) AppendBlock ¶
func (b *BlockBuffer) AppendBlock(block *common.Block)
AppendBlock 添加区块到该缓冲区处理队列 传入一个区块,区块会被添加到 channel 中
func (*BlockBuffer) GetPriorityLeaf ¶
func (b *BlockBuffer) GetPriorityLeaf(nowHeight int64) *common.Block
GetPriorityLeaf 获取当前视图下的最优树叶
func (*BlockBuffer) PopSelectedBlock ¶
func (b *BlockBuffer) PopSelectedBlock() *common.Block
PopSelectedBlock 推出头部的最优区块什么时候触发? 应该来说是在 bufferedHeight - latestBlockHeight >= maxSize 的情况下触发? 以及,收到其他节点发来的已选取区块时触发该逻辑,但是需要确定一下高度和哈希值
func (*BlockBuffer) Process ¶
func (b *BlockBuffer) Process()
Process 是 BlockBuffer 的线程函数,它依次接收区块进行处理
type BlockChain ¶
type BlockChain struct {
// contains filtered or unexported fields
}
func NewBlockchain ¶
func NewBlockchain(db *utils.LevelDB) *BlockChain
NewBlockchain 创建一个 BlockChain 实,需要传入一个 LevelDB 实例 db
func (*BlockChain) AppendBlockTask ¶
func (bc *BlockChain) AppendBlockTask(block *common.Block)
AppendBlockTask 向区块缓冲视图中添加区块处理任务
func (*BlockChain) BlockProcessRoutine ¶
func (bc *BlockChain) BlockProcessRoutine()
BlockProcessRoutine 接收处理 channel 中的区块
func (*BlockChain) BufferFull ¶
func (bc *BlockChain) BufferFull() bool
func (*BlockChain) BufferedHeight ¶
func (bc *BlockChain) BufferedHeight() int64
func (*BlockChain) GetBlockByHash ¶
func (*BlockChain) GetBlockByHeight ¶
func (bc *BlockChain) GetBlockByHeight(height int64) (*common.Block, error)
GetBlockByHeight 根据高度拉取区块,需要考虑一下同步时是否换用其他的函数?
func (*BlockChain) GetLatestBlock ¶
func (bc *BlockChain) GetLatestBlock() (*common.Block, error)
GetLatestBlock 获取当前的最新区块
func (*BlockChain) GetTransactionByHash ¶
func (bc *BlockChain) GetTransactionByHash(hash common.Hash) (*common.Transaction, error)
GetTransactionByHash 通过交易的哈希值来获取交易
func (*BlockChain) Height ¶
func (bc *BlockChain) Height() int64
func (*BlockChain) InsertBlock ¶
func (bc *BlockChain) InsertBlock(block *common.Block)
func (*BlockChain) PackageNewBlock ¶
func (bc *BlockChain) PackageNewBlock(txs []common.Transaction, timestamp int64, params *common.GeneralParams, packageInterval int64) (*common.Block, error)
PackageNewBlock 打包新的区块,传入交易序列
func (*BlockChain) ReadAddressData ¶
func (bc *BlockChain) ReadAddressData(address, key string) ([]byte, error)
type DataProcessor ¶
type DataProcessor struct {
// contains filtered or unexported fields
}
func NewDataProcessor ¶
func NewDataProcessor() *DataProcessor
func (*DataProcessor) Run ¶
func (dp *DataProcessor) Run()
type TxPool ¶
type TxPool struct {
// contains filtered or unexported fields
}
func GetTxPoolInst ¶
func GetTxPoolInst() *TxPool
func NewTxPool ¶
func NewTxPool(chain *BlockChain) *TxPool
func (*TxPool) Add ¶
func (pool *TxPool) Add(transaction *common.Transaction)
func (*TxPool) Package ¶
func (pool *TxPool) Package() []common.Transaction
Package 用于打包交易,这里返回的是 Transaction 的切片 todo: 需要具体观察打包交易时的效率问题
Click to show internal directories.
Click to hide internal directories.