-
Notifications
You must be signed in to change notification settings - Fork 180
/
cache.go
96 lines (81 loc) · 2.19 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
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
package types
import (
"sync"
)
var evmParamsCache = NewCache()
type Cache struct {
paramsCache Params
needParamsUpdate bool
paramsMutex sync.RWMutex
blockedContractMethodsCache map[string]BlockedContract
needBlockedUpdate bool
blockedMutex sync.RWMutex
}
func NewCache() *Cache {
return &Cache{
paramsCache: DefaultParams(),
blockedContractMethodsCache: make(map[string]BlockedContract, 0),
needParamsUpdate: true,
needBlockedUpdate: true,
}
}
func (c *Cache) UpdateParams(params Params) {
c.paramsMutex.Lock()
defer c.paramsMutex.Unlock()
c.paramsCache = params
c.needParamsUpdate = false
}
func (c *Cache) SetNeedParamsUpdate() {
c.paramsMutex.Lock()
defer c.paramsMutex.Unlock()
c.needParamsUpdate = true
}
func (c *Cache) IsNeedParamsUpdate() bool {
c.paramsMutex.RLock()
defer c.paramsMutex.RUnlock()
return c.needParamsUpdate
}
func (c *Cache) GetParams() Params {
c.paramsMutex.RLock()
defer c.paramsMutex.RUnlock()
return NewParams(c.paramsCache.EnableCreate,
c.paramsCache.EnableCall,
c.paramsCache.EnableContractDeploymentWhitelist,
c.paramsCache.EnableContractBlockedList,
c.paramsCache.MaxGasLimitPerTx,
c.paramsCache.ExtraEIPs...)
}
func (c *Cache) SetNeedBlockedUpdate() {
c.blockedMutex.Lock()
defer c.blockedMutex.Unlock()
c.needBlockedUpdate = true
}
func (c *Cache) IsNeedBlockedUpdate() bool {
c.blockedMutex.RLock()
defer c.blockedMutex.RUnlock()
return c.needBlockedUpdate
}
func (c *Cache) GetBlockedContractMethod(addr string) (contract *BlockedContract) {
c.blockedMutex.RLock()
bc, ok := c.blockedContractMethodsCache[addr]
c.blockedMutex.RUnlock()
if ok {
return NewBlockContract(bc.Address, bc.BlockMethods)
}
return nil
}
func (c *Cache) UpdateBlockedContractMethod(bcl BlockedContractList) {
c.blockedMutex.Lock()
c.blockedContractMethodsCache = make(map[string]BlockedContract, 0)
for i, _ := range bcl {
c.blockedContractMethodsCache[bcl[i].Address.String()] = bcl[i]
}
c.blockedMutex.Unlock()
c.needBlockedUpdate = false
}
func SetEvmParamsNeedUpdate() {
GetEvmParamsCache().SetNeedParamsUpdate()
}
func GetEvmParamsCache() *Cache {
return evmParamsCache
}