github.com/koko1123/flow-go-1@v0.29.6/module/mempool/stdmap/transactions.go (about) 1 // (c) 2019 Dapper Labs - ALL RIGHTS RESERVED 2 3 package stdmap 4 5 import ( 6 "fmt" 7 8 "github.com/koko1123/flow-go-1/model/flow" 9 ) 10 11 // Transactions implements the transactions memory pool of the consensus nodes, 12 // used to store transactions and to generate block payloads. 13 type Transactions struct { 14 *Backend 15 } 16 17 // NewTransactions creates a new memory pool for transactions. 18 // Deprecated: use herocache.Transactions instead. 19 func NewTransactions(limit uint) *Transactions { 20 t := &Transactions{ 21 Backend: NewBackend(WithLimit(limit)), 22 } 23 24 return t 25 } 26 27 // Add adds a transaction to the mempool. 28 func (t *Transactions) Add(tx *flow.TransactionBody) bool { 29 return t.Backend.Add(tx) 30 } 31 32 // ByID returns the transaction with the given ID from the mempool. 33 func (t *Transactions) ByID(txID flow.Identifier) (*flow.TransactionBody, bool) { 34 entity, exists := t.Backend.ByID(txID) 35 if !exists { 36 return nil, false 37 } 38 tx, ok := entity.(*flow.TransactionBody) 39 if !ok { 40 panic(fmt.Sprintf("invalid entity in transaction pool (%T)", entity)) 41 } 42 return tx, true 43 } 44 45 // All returns all transactions from the mempool. 46 func (t *Transactions) All() []*flow.TransactionBody { 47 entities := t.Backend.All() 48 txs := make([]*flow.TransactionBody, 0, len(entities)) 49 for _, entity := range entities { 50 txs = append(txs, entity.(*flow.TransactionBody)) 51 } 52 return txs 53 }