Documentation
¶
Overview ¶
本包应当使用/ds内的函数和结构体
Index ¶
- Constants
- func ExamineNewBlock(newBlock *ds.Block) bool
- func MiningNewBlock(txs []entity.Transaction) ds.Block
- func VerifyNonce(lastNonce uint64, nonce uint64) bool
- type AbstractController
- type AbstractTxPool
- type Controller
- type DefualtTxPool
- func (pool *DefualtTxPool) AllSortedByGas()
- func (pool *DefualtTxPool) CreateTxsBlk(tx entity.Transaction, address string)
- func (pool *DefualtTxPool) DeleteFromPending(tx entity.Transaction)
- func (pool *DefualtTxPool) DeleteQueueRow(address string)
- func (pool DefualtTxPool) GetPendingLastNonce(address string) uint64
- func (pool *DefualtTxPool) Insert(tx entity.Transaction)
- func (pool *DefualtTxPool) IsFull() bool
- func (pool *DefualtTxPool) Length() int
- func (pool *DefualtTxPool) Poll() entity.Transaction
- func (pool *DefualtTxPool) PollFromQueueToPending(address string)
- func (pool *DefualtTxPool) QueueInsertToPending(tx entity.Transaction, address string)
- type SortedTxsBlk
- type TxPool
- type Txs
- type TxsBlks
Constants ¶
View Source
const MAX_POOL_SIZE = 10
MAX_POOL_SIZE PoolSize fixed
Variables ¶
This section is empty.
Functions ¶
func MiningNewBlock ¶
func MiningNewBlock(txs []entity.Transaction) ds.Block
打包多个交易并生成新区块,生成过程中应不断调整区块nonce值以满足PoW约束
func VerifyNonce ¶
Types ¶
type AbstractController ¶
type AbstractTxPool ¶
type AbstractTxPool interface { Insert(entity.Transaction) Poll() entity.Transaction Length() int IsFull() bool }
type Controller ¶
type Controller struct {
// contains filtered or unexported fields
}
用于核心控制的结构体,上层包应当直接调用这里的函数,其他地方的函数不对包外公开
func NewController ¶
func NewController() *Controller
func (*Controller) AddBlock ¶
func (c *Controller) AddBlock(block ds.Block)
加入由其他节点挖出来的新区块。应当先进行验证再加入到本地区块链中,注意加入区块链时是直接对ds进行操作。 验证流程:1.满足PoW约束 2.MPT证明通过
func (*Controller) AddTransaction ¶
func (c *Controller) AddTransaction(tx entity.Transaction)
加入新交易。在交易池未满时放入交易池,交易池已满则进行挖矿,挖矿完成则将新区块返回到Communicator来发布
func (*Controller) QueryAccount ¶
func (c *Controller) QueryAccount(key []byte) entity.Account
询问账号信息,从/ds中得到账号信息并返回
type DefualtTxPool ¶
type DefualtTxPool struct { StatDB *ds.MPT Pendings map[string]TxsBlks // map to store pending transactions grouped by nonce Queues map[string]Txs // queue for out-of-order nonce transactions MiniPool Txs // in order to poll one by one }
func (*DefualtTxPool) AllSortedByGas ¶
func (pool *DefualtTxPool) AllSortedByGas()
func (*DefualtTxPool) CreateTxsBlk ¶
func (pool *DefualtTxPool) CreateTxsBlk(tx entity.Transaction, address string)
CreateTxsBlk Create Blk and append the first new transaction
func (*DefualtTxPool) DeleteFromPending ¶
func (pool *DefualtTxPool) DeleteFromPending(tx entity.Transaction)
DeleteFromPending Delete the transaction from the pending list
func (*DefualtTxPool) DeleteQueueRow ¶
func (pool *DefualtTxPool) DeleteQueueRow(address string)
func (DefualtTxPool) GetPendingLastNonce ¶
func (pool DefualtTxPool) GetPendingLastNonce(address string) uint64
func (*DefualtTxPool) Insert ¶
func (pool *DefualtTxPool) Insert(tx entity.Transaction)
Insert 向合约池放入新的交易数据
func (*DefualtTxPool) IsFull ¶
func (pool *DefualtTxPool) IsFull() bool
func (*DefualtTxPool) Length ¶
func (pool *DefualtTxPool) Length() int
func (*DefualtTxPool) Poll ¶
func (pool *DefualtTxPool) Poll() entity.Transaction
Poll 从合约池中取出第一个交易,并从合约池中弹出该交易
func (*DefualtTxPool) PollFromQueueToPending ¶
func (pool *DefualtTxPool) PollFromQueueToPending(address string)
PollFromQueueToPending Put the transactions to pending
func (*DefualtTxPool) QueueInsertToPending ¶
func (pool *DefualtTxPool) QueueInsertToPending(tx entity.Transaction, address string)
type SortedTxsBlk ¶
type SortedTxsBlk struct { Txs []entity.Transaction GasPrice uint64 // equal to Gas in the transaction struct // contains filtered or unexported fields }
type TxPool ¶
type TxPool interface { Insert(tx entity.Transaction) Poll() entity.Transaction IsFull() bool Length() int }
type Txs ¶
type Txs []entity.Transaction
Click to show internal directories.
Click to hide internal directories.