github.com/unicornultrafoundation/go-u2u@v1.0.0-rc1.0.20240205080301-e74a83d3fadc/gossip/evmstore/store_tx.go (about) 1 package evmstore 2 3 import ( 4 "github.com/unicornultrafoundation/go-helios/hash" 5 "github.com/unicornultrafoundation/go-helios/native/idx" 6 "github.com/unicornultrafoundation/go-u2u/common" 7 "github.com/unicornultrafoundation/go-u2u/core/types" 8 "github.com/unicornultrafoundation/go-u2u/log" 9 10 "github.com/unicornultrafoundation/go-u2u/native" 11 ) 12 13 // SetTx stores non-event transaction. 14 func (s *Store) SetTx(txid common.Hash, tx *types.Transaction) { 15 s.rlp.Set(s.table.Txs, txid.Bytes(), tx) 16 } 17 18 // GetTx returns stored non-event transaction. 19 func (s *Store) GetTx(txid common.Hash) *types.Transaction { 20 tx, _ := s.rlp.Get(s.table.Txs, txid.Bytes(), &types.Transaction{}).(*types.Transaction) 21 22 return tx 23 } 24 25 func (s *Store) GetBlockTxs(n idx.Block, block native.Block, getEventPayload func(hash.Event) *native.EventPayload) types.Transactions { 26 if cached := s.GetCachedEvmBlock(n); cached != nil { 27 return cached.Transactions 28 } 29 30 transactions := make(types.Transactions, 0, len(block.Txs)+len(block.InternalTxs)+len(block.Events)*10) 31 for _, txid := range block.InternalTxs { 32 tx := s.GetTx(txid) 33 if tx == nil { 34 log.Crit("Internal tx not found", "tx", txid.String()) 35 continue 36 } 37 transactions = append(transactions, tx) 38 } 39 for _, txid := range block.Txs { 40 tx := s.GetTx(txid) 41 if tx == nil { 42 log.Crit("Tx not found", "tx", txid.String()) 43 continue 44 } 45 transactions = append(transactions, tx) 46 } 47 for _, id := range block.Events { 48 e := getEventPayload(id) 49 if e == nil { 50 log.Crit("Block event not found", "event", id.String()) 51 continue 52 } 53 transactions = append(transactions, e.Txs()...) 54 } 55 56 transactions = native.FilterSkippedTxs(transactions, block.SkippedTxs) 57 58 return transactions 59 }