Skip to content

Commit dcfeceb

Browse files
committed
core: get transaction by hash from transaction pool
1 parent 258a7b9 commit dcfeceb

File tree

1 file changed

+21
-0
lines changed

1 file changed

+21
-0
lines changed

core/transaction_pool.go

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -204,6 +204,27 @@ func (self *TxPool) AddTransactions(txs []*types.Transaction) {
204204
}
205205
}
206206

207+
// GetTransaction allows you to check the pending and queued transaction in the
208+
// transaction pool.
209+
// It has two stategies, first check the pool (map) then check the queue
210+
func (tp *TxPool) GetTransaction(hash common.Hash) *types.Transaction {
211+
// check the txs first
212+
if tx, ok := tp.txs[hash]; ok {
213+
return tx
214+
}
215+
216+
// check queue
217+
for _, txs := range tp.queue {
218+
for _, tx := range txs {
219+
if tx.Hash() == hash {
220+
return tx
221+
}
222+
}
223+
}
224+
225+
return nil
226+
}
227+
207228
func (self *TxPool) GetTransactions() (txs types.Transactions) {
208229
self.mu.RLock()
209230
defer self.mu.RUnlock()

0 commit comments

Comments
 (0)