github.com/fibonacci-chain/fbc@v0.0.0-20231124064014-c7636198c1e9/x/infura/cache.go (about)

     1  package infura
     2  
     3  import evm "github.com/fibonacci-chain/fbc/x/evm/watcher"
     4  
     5  const defaultCacheCap = 2000
     6  
     7  type Cache struct {
     8  	transactionReceipts []evm.TransactionReceipt
     9  	block               *evm.Block
    10  	transactions        []evm.Transaction
    11  	contractCodes       map[string][]byte
    12  }
    13  
    14  func NewCache() *Cache {
    15  	return &Cache{
    16  		transactionReceipts: make([]evm.TransactionReceipt, 0, defaultCacheCap),
    17  		block:               nil,
    18  		transactions:        make([]evm.Transaction, 0, defaultCacheCap),
    19  		contractCodes:       make(map[string][]byte, defaultCacheCap),
    20  	}
    21  }
    22  
    23  func (c *Cache) Reset() {
    24  	c.transactionReceipts = make([]evm.TransactionReceipt, 0, defaultCacheCap)
    25  	c.block = nil
    26  	c.transactions = make([]evm.Transaction, 0, defaultCacheCap)
    27  	c.contractCodes = make(map[string][]byte, defaultCacheCap)
    28  }
    29  
    30  func (c *Cache) AddTransactionReceipt(tr evm.TransactionReceipt) {
    31  	c.transactionReceipts = append(c.transactionReceipts, tr)
    32  }
    33  
    34  func (c *Cache) GetTransactionReceipts() []evm.TransactionReceipt {
    35  	return c.transactionReceipts
    36  }
    37  
    38  func (c *Cache) AddBlock(b evm.Block) {
    39  	c.block = &b
    40  }
    41  
    42  func (c *Cache) GetBlock() evm.Block {
    43  	return *c.block
    44  }
    45  
    46  func (c *Cache) AddTransaction(t evm.Transaction) {
    47  	c.transactions = append(c.transactions, t)
    48  }
    49  
    50  func (c *Cache) GetTransactions() []evm.Transaction {
    51  	return c.transactions
    52  }
    53  
    54  func (c *Cache) AddContractCode(address string, code []byte) {
    55  	c.contractCodes[address] = code
    56  }
    57  
    58  func (c *Cache) GetContractCodes() map[string][]byte {
    59  	return c.contractCodes
    60  }