MCPcopy Create free account
hub / github.com/DNAProject/DNA / GetTxPool

Method GetTxPool

txnpool/common/transaction_pool.go:128–163  ·  view source on GitHub ↗

GetTxPool gets the transaction lists from the pool for the consensus, if the byCount is marked, return the configured number at most; if the the byCount is not marked, return all of the current transaction pool.

(byCount bool, height uint32)

Source from the content-addressed store, hash-verified

126// if the byCount is marked, return the configured number at most; if the
127// the byCount is not marked, return all of the current transaction pool.
128func (tp *TXPool) GetTxPool(byCount bool, height uint32) ([]*TXEntry,
129 []*types.Transaction) {
130 tp.RLock()
131 defer tp.RUnlock()
132
133 orderByFee := make([]*TXEntry, 0, len(tp.txList))
134 for _, txEntry := range tp.txList {
135 orderByFee = append(orderByFee, txEntry)
136 }
137 sort.Sort(OrderByNetWorkFee(orderByFee))
138
139 count := int(config.DefConfig.Consensus.MaxTxInBlock)
140 if count <= 0 {
141 byCount = false
142 }
143 if len(tp.txList) < count || !byCount {
144 count = len(tp.txList)
145 }
146
147 var num int
148 txList := make([]*TXEntry, 0, count)
149 oldTxList := make([]*types.Transaction, 0)
150 for _, txEntry := range orderByFee {
151 if !tp.compareTxHeight(txEntry, height) {
152 oldTxList = append(oldTxList, txEntry.Tx)
153 continue
154 }
155 txList = append(txList, txEntry)
156 num++
157 if num >= count {
158 break
159 }
160 }
161
162 return txList, oldTxList
163}
164
165// GetTransaction returns a transaction if it is contained in the pool
166// and nil otherwise.

Callers 2

TestTxPoolFunction · 0.95
getTxPoolMethod · 0.80

Calls 2

compareTxHeightMethod · 0.95
OrderByNetWorkFeeTypeAlias · 0.85

Tested by 1

TestTxPoolFunction · 0.76