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