aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorobscuren <geffobscura@gmail.com>2015-05-07 23:27:17 +0800
committerobscuren <geffobscura@gmail.com>2015-05-08 00:22:57 +0800
commitdcfecebe1fbd977e4c6bd95e2ba14dd4d26f9532 (patch)
treedf8ea49e3a3135fd6c317b48ae85b9025ba24258
parent258a7b9a936b206ee61d04a04cbb930d4d479e0d (diff)
downloaddexon-dcfecebe1fbd977e4c6bd95e2ba14dd4d26f9532.tar.gz
dexon-dcfecebe1fbd977e4c6bd95e2ba14dd4d26f9532.tar.zst
dexon-dcfecebe1fbd977e4c6bd95e2ba14dd4d26f9532.zip
core: get transaction by hash from transaction pool
-rw-r--r--core/transaction_pool.go21
1 files changed, 21 insertions, 0 deletions
diff --git a/core/transaction_pool.go b/core/transaction_pool.go
index bac6b7f0b..6898a4bda 100644
--- a/core/transaction_pool.go
+++ b/core/transaction_pool.go
@@ -204,6 +204,27 @@ func (self *TxPool) AddTransactions(txs []*types.Transaction) {
}
}
+// GetTransaction allows you to check the pending and queued transaction in the
+// transaction pool.
+// It has two stategies, first check the pool (map) then check the queue
+func (tp *TxPool) GetTransaction(hash common.Hash) *types.Transaction {
+ // check the txs first
+ if tx, ok := tp.txs[hash]; ok {
+ return tx
+ }
+
+ // check queue
+ for _, txs := range tp.queue {
+ for _, tx := range txs {
+ if tx.Hash() == hash {
+ return tx
+ }
+ }
+ }
+
+ return nil
+}
+
func (self *TxPool) GetTransactions() (txs types.Transactions) {
self.mu.RLock()
defer self.mu.RUnlock()